Skip to content

Commit a0aaef2

Browse files
committed
proof: oeis-a167137
1 parent a2d1865 commit a0aaef2

1 file changed

Lines changed: 185 additions & 0 deletions

File tree

‎proofs/oeis-a167137.lean‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import OMAStatements.S_oeis_a167137
2+
import Mathlib
3+
4+
-- Problem: OEIS A167137 (Peter Bala's conjectures). For every integer sequence g, the numbers
5+
-- b(n) = Sum_{j=0..n} Stirling2(n,j) * j! * g(j) satisfy b(n + phi(k)) = b(n) mod k for n >= k.
6+
-- Proof. (1) Stirling2(n,j) * j! = Sum_{i=0..j} (-1)^(j+i) * C(j,i) * i^n (number of
7+
-- surjections), by induction on n from the recurrence. (2) For n >= k one has
8+
-- i^(n + phi(k)) = i^n mod k for every i: check it modulo each prime power p^e dividing k;
9+
-- if p divides i both sides vanish since e <= k <= n, otherwise use Euler's theorem and
10+
-- phi(p^e) | phi(k). (3) k divides j! for j >= k, so modulo k only the terms j < k of b(n)
11+
-- matter, and each of them is periodic by (1) and (2).
12+
13+
open Finset
14+
15+
lemma OMA.surj (s : ℕ → ℕ → ℕ) (h00 : s 0 0 = 1) (hn0 : ∀ n, s (n + 1) 0 = 0)
16+
(h0j : ∀ j, s 0 (j + 1) = 0)
17+
(hrec : ∀ n j, s (n + 1) (j + 1) = (j + 1) * s n (j + 1) + s n j) :
18+
∀ n j : ℕ, (s n j : ℤ) * (j.factorial : ℤ)
19+
= ∑ i ∈ range (j + 1), (-1 : ℤ) ^ (j + i) * (j.choose i : ℤ) * (i : ℤ) ^ n := by
20+
intro n
21+
induction n with
22+
| zero =>
23+
intro j
24+
rcases j with _ | j
25+
· simp [h00]
26+
· rw [h0j]
27+
have h := Int.alternating_sum_range_choose (n := j + 1)
28+
have h2 : ∑ i ∈ range (j + 1 + 1), (-1 : ℤ) ^ (j + 1 + i) * ((j + 1).choose i : ℤ) * (i : ℤ) ^ 0
29+
= (-1 : ℤ) ^ (j + 1) * ∑ i ∈ range (j + 1 + 1), (-1 : ℤ) ^ i * ((j + 1).choose i : ℤ) := by
30+
rw [Finset.mul_sum]
31+
refine Finset.sum_congr rfl (fun i _ => ?_)
32+
rw [pow_add]
33+
ring
34+
rw [h2, h]
35+
simp
36+
| succ n ih =>
37+
intro j
38+
rcases j with _ | j
39+
· rw [hn0]
40+
simp
41+
· have e1 : (s (n + 1) (j + 1) : ℤ) * ((j + 1).factorial : ℤ)
42+
= ((j : ℤ) + 1) * ((s n (j + 1) : ℤ) * ((j + 1).factorial : ℤ))
43+
+ ((j : ℤ) + 1) * ((s n j : ℤ) * (j.factorial : ℤ)) := by
44+
rw [hrec, Nat.factorial_succ]
45+
push_cast
46+
ring
47+
have e2 : ∑ i ∈ range (j + 1), (-1 : ℤ) ^ (j + i) * (j.choose i : ℤ) * (i : ℤ) ^ n
48+
= ∑ i ∈ range (j + 1 + 1), (-1 : ℤ) ^ (j + i) * (j.choose i : ℤ) * (i : ℤ) ^ n := by
49+
rw [Finset.sum_range_succ _ (j + 1), Nat.choose_succ_self]
50+
simp
51+
rw [e1, ih (j + 1), ih j, e2, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib]
52+
refine Finset.sum_congr rfl (fun i _ => ?_)
53+
rcases i with _ | i
54+
· simp only [Nat.choose_zero_right, Nat.cast_one, Nat.cast_zero, add_zero, mul_one]
55+
ring
56+
· have hc : ((j + 1).choose (i + 1) : ℤ) = (j.choose i : ℤ) + (j.choose (i + 1) : ℤ) := by
57+
rw [Nat.choose_succ_succ]
58+
push_cast
59+
ring
60+
have hm : ((j : ℤ) + 1) * (j.choose i : ℤ)
61+
= ((j + 1).choose (i + 1) : ℤ) * ((i : ℤ) + 1) := by
62+
have h3 := Nat.add_one_mul_choose_eq j i
63+
exact_mod_cast h3
64+
rw [hc] at hm
65+
have hs : (-1 : ℤ) ^ (j + 1 + (i + 1)) = -(-1 : ℤ) ^ (j + (i + 1)) := by
66+
have h4 : j + 1 + (i + 1) = (j + (i + 1)) + 1 := by ring
67+
rw [h4, pow_succ]
68+
ring
69+
push_cast
70+
rw [hs, hc, pow_succ]
71+
linear_combination (-(-1 : ℤ) ^ (j + (i + 1)) * ((i : ℤ) + 1) ^ n) * hm
72+
73+
lemma OMA.pow_per (k i n : ℕ) (hk : 1 ≤ k) (hn : k ≤ n) :
74+
i ^ (n + Nat.totient k) ≡ i ^ n [MOD k] := by
75+
rcases Nat.eq_zero_or_pos i with rfl | hi
76+
· have h1 : n ≠ 0 := by omega
77+
have h2 : n + Nat.totient k ≠ 0 := by omega
78+
rw [zero_pow h1, zero_pow h2]
79+
have hle : i ^ n ≤ i ^ (n + Nat.totient k) := Nat.pow_le_pow_right hi (Nat.le_add_right _ _)
80+
refine ((Nat.modEq_iff_dvd' hle).mpr ?_).symm
81+
rw [Nat.dvd_iff_prime_pow_dvd_dvd]
82+
intro p e hp hpe
83+
refine (Nat.modEq_iff_dvd' hle).mp ?_
84+
by_cases hpi : p ∣ i
85+
· have he : e ≤ n := by
86+
have h1 : p ^ e ≤ k := Nat.le_of_dvd (by omega) hpe
87+
have h2 : e < p ^ e := Nat.lt_pow_self hp.one_lt
88+
omega
89+
have hd1 : p ^ e ∣ i ^ n := (pow_dvd_pow p he).trans (pow_dvd_pow_of_dvd hpi n)
90+
have hd2 : p ^ e ∣ i ^ (n + Nat.totient k) :=
91+
hd1.trans (pow_dvd_pow i (Nat.le_add_right _ _))
92+
exact (Nat.modEq_zero_iff_dvd.mpr hd1).trans (Nat.modEq_zero_iff_dvd.mpr hd2).symm
93+
· have hcop : Nat.Coprime i (p ^ e) :=
94+
Nat.Coprime.pow_right e ((Nat.Prime.coprime_iff_not_dvd hp).mpr hpi).symm
95+
have h1 : i ^ Nat.totient (p ^ e) ≡ 1 [MOD p ^ e] := Nat.ModEq.pow_totient hcop
96+
obtain ⟨t, ht⟩ := Nat.totient_dvd_of_dvd hpe
97+
have h2 : i ^ Nat.totient k ≡ 1 [MOD p ^ e] := by
98+
rw [ht, pow_mul]
99+
have h5 := h1.pow t
100+
rwa [one_pow] at h5
101+
have h3 := h2.mul_left (i ^ n)
102+
rw [← pow_add, mul_one] at h3
103+
exact h3.symm
104+
105+
lemma OMA.trunc (s : ℕ → ℕ → ℕ) (g : ℕ → ℤ) (k m : ℕ) (hk : 1 ≤ k) (hm : k ≤ m + 1) :
106+
∑ j ∈ range (m + 1), ((s m j : ℤ) * (j.factorial : ℤ)) * g j
107+
≡ ∑ j ∈ range k, ((s m j : ℤ) * (j.factorial : ℤ)) * g j [ZMOD k] := by
108+
rw [Int.modEq_iff_dvd]
109+
have h := Finset.sum_Ico_eq_sub (fun j => ((s m j : ℤ) * (j.factorial : ℤ)) * g j) hm
110+
have hd : (k : ℤ) ∣ ∑ j ∈ Ico k (m + 1), ((s m j : ℤ) * (j.factorial : ℤ)) * g j := by
111+
refine Finset.dvd_sum (fun j hj => ?_)
112+
have hkj : k ≤ j := (Finset.mem_Ico.mp hj).1
113+
have h6 : (k : ℤ) ∣ (j.factorial : ℤ) :=
114+
Int.natCast_dvd_natCast.mpr (Nat.dvd_factorial (by omega) hkj)
115+
exact Dvd.dvd.mul_right (Dvd.dvd.mul_left h6 _) _
116+
rw [h] at hd
117+
have h7 := (dvd_neg (a := (k : ℤ))).mpr hd
118+
rwa [neg_sub] at h7
119+
120+
lemma OMA.T_per (s : ℕ → ℕ → ℕ) (h00 : s 0 0 = 1) (hn0 : ∀ n, s (n + 1) 0 = 0)
121+
(h0j : ∀ j, s 0 (j + 1) = 0)
122+
(hrec : ∀ n j, s (n + 1) (j + 1) = (j + 1) * s n (j + 1) + s n j)
123+
(k n j : ℕ) (hk : 1 ≤ k) (hn : k ≤ n) :
124+
(s (n + Nat.totient k) j : ℤ) * (j.factorial : ℤ)
125+
≡ (s n j : ℤ) * (j.factorial : ℤ) [ZMOD k] := by
126+
rw [OMA.surj s h00 hn0 h0j hrec, OMA.surj s h00 hn0 h0j hrec]
127+
refine Int.ModEq.sum (fun i _ => ?_)
128+
have h := OMA.pow_per k i n hk hn
129+
have h' : ((i ^ (n + Nat.totient k) : ℕ) : ℤ) ≡ ((i ^ n : ℕ) : ℤ) [ZMOD (k : ℤ)] :=
130+
Int.natCast_modEq_iff.mpr h
131+
push_cast at h'
132+
exact Int.ModEq.mul_left _ h'
133+
134+
theorem OMA.gen (s : ℕ → ℕ → ℕ) (h00 : s 0 0 = 1) (hn0 : ∀ n, s (n + 1) 0 = 0)
135+
(h0j : ∀ j, s 0 (j + 1) = 0)
136+
(hrec : ∀ n j, s (n + 1) (j + 1) = (j + 1) * s n (j + 1) + s n j)
137+
(g : ℕ → ℤ) (k : ℕ) (hk : 1 ≤ k) (n : ℕ) (hn : k ≤ n) :
138+
∑ j ∈ range (n + Nat.totient k + 1),
139+
((s (n + Nat.totient k) j : ℤ) * (j.factorial : ℤ)) * g j
140+
≡ ∑ j ∈ range (n + 1), ((s n j : ℤ) * (j.factorial : ℤ)) * g j [ZMOD k] := by
141+
have h1 := OMA.trunc s g k (n + Nat.totient k) hk (by omega)
142+
have h2 := OMA.trunc s g k n hk (by omega)
143+
have h3 : ∑ j ∈ range k, ((s (n + Nat.totient k) j : ℤ) * (j.factorial : ℤ)) * g j
144+
≡ ∑ j ∈ range k, ((s n j : ℤ) * (j.factorial : ℤ)) * g j [ZMOD k] := by
145+
refine Int.ModEq.sum (fun j _ => ?_)
146+
exact (OMA.T_per s h00 hn0 h0j hrec k n j hk hn).mul_right _
147+
exact (h1.trans h3).trans h2.symm
148+
149+
open OMA.S_oeis_a167137
150+
151+
theorem OMA.solution : type_of% @OMA.S_oeis_a167137.main := by
152+
have h00 : stirling2 0 0 = 1 := by
153+
rw [stirling2]
154+
have hn0 : ∀ n, stirling2 (n + 1) 0 = 0 := fun n => by
155+
rw [stirling2]
156+
have h0j : ∀ j, stirling2 0 (j + 1) = 0 := fun j => by
157+
rw [stirling2]
158+
have hrec : ∀ n j, stirling2 (n + 1) (j + 1)
159+
= (j + 1) * stirling2 n (j + 1) + stirling2 n j := fun n j => by
160+
rw [stirling2]
161+
constructor
162+
· have e : ∀ m, ((a m : ℕ) : ℤ)
163+
= ∑ j ∈ range (m + 1), ((stirling2 m j : ℤ) * (j.factorial : ℤ))
164+
* ((Fintype.card (Nat.Partition j) : ℕ) : ℤ) := by
165+
intro m
166+
unfold a
167+
push_cast
168+
refine Finset.sum_congr rfl (fun j _ => ?_)
169+
ring
170+
intro k hk
171+
refine ⟨k, fun n hn => ?_⟩
172+
apply Int.natCast_modEq_iff.mp
173+
rw [e, e]
174+
exact OMA.gen stirling2 h00 hn0 h0j hrec
175+
(fun j => ((Fintype.card (Nat.Partition j) : ℕ) : ℤ)) k hk n hn
176+
· intro g k hk
177+
have e : ∀ m, evalG g m
178+
= ∑ j ∈ range (m + 1), ((stirling2 m j : ℤ) * (j.factorial : ℤ)) * g j := by
179+
intro m
180+
unfold evalG
181+
refine Finset.sum_congr rfl (fun j _ => ?_)
182+
ring
183+
refine ⟨k, fun n hn => ?_⟩
184+
rw [e, e]
185+
exact OMA.gen stirling2 h00 hn0 h0j hrec g k hk n hn

0 commit comments

Comments
 (0)