File size: 13,827 Bytes
8769036
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import OAI.NumberTheory.TwoPoint.Walks.ReversedSegments

namespace OAI

/-! Active numerical labels in minimal prohibited witnesses. -/

namespace TwoPointCorrelations

open Finset

noncomputable def wordPrimeContribution (h : ℕ) (w : List SignedStep) (p a b : ℕ) : ℤ := by
  classical
  exact ∑ i ∈ Ico a b, if TuplePrimeAt w p i then wordStepDisplacement h w i else 0

/-- A contiguous relation with a nonzero contribution from this label. -/
def ActivePrime (h : ℕ) (w : List SignedStep) (p : ℕ) : Prop :=
  ∃ c a b, a ≤ b ∧ b ≤ w.length ∧ (∃ i, TuplePrimeAt w c i) ∧
    (c : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) a b ∧
    ¬(c : ℤ) ∣ wordPrimeContribution h w p a b

lemma wordPrimeContribution_eq_interval (h : ℕ) (w : List SignedStep) (p a b : ℕ)
    (hp : ∀ i ∈ Ico a b, TuplePrimeAt w p i) :
    wordPrimeContribution h w p a b = intervalDisplacement (wordStepDisplacement h w) a b := by
  classical
  unfold wordPrimeContribution intervalDisplacement
  apply sum_congr rfl
  intro i hi
  simp only [hp i hi, ite_true]

lemma wordPrimeContribution_eq_singleton (h : ℕ) (w : List SignedStep) (p a b j : ℕ)
    (hj : j ∈ Ico a b) (hp : TuplePrimeAt w p j)
    (hunique : ∀ i ∈ Ico a b, TuplePrimeAt w p i → i = j) :
    wordPrimeContribution h w p a b = wordStepDisplacement h w j := by
  classical
  unfold wordPrimeContribution
  rw [sum_eq_single j]
  · simp only [hp, ite_true]
  · intro i hi hne
    have hnot : ¬TuplePrimeAt w p i := fun hpi => hne (hunique i hi hpi)
    simp only [hnot, ite_false]
  · exact fun h => False.elim (h hj)

/-- A label first entering at the last step is active in the original
prohibited suffix, because its contribution is exactly that last step. -/
lemma ForwardProhibited.last_new_active {h s : ℕ} {supply : ℕ → ℕ → Prop}
    {w : List SignedStep} (hw : ForwardProhibited h s supply w) {z : ℕ}
    (hz : TuplePrimeAt w z (w.length - 1))
    (hearlier : ∀ i, i < w.length - 1 → ¬TuplePrimeAt w z i)
    (hoff : ∀ p i, (∃ j, TuplePrimeAt w p j) → i < w.length →
      ¬TuplePrimeAt w p i → ¬(p : ℤ) ∣ wordStepDisplacement h w i) :
    ActivePrime h w z := by
  rcases hw with ⟨hlen, _, _, _, _, c, hc, hclast, a, ha, halast, hdiv⟩
  refine ⟨c, a, w.length, by omega, le_rfl, ⟨0, hc⟩, ?_, ?_⟩
  · simpa only [wordSlice, Nat.sub_self, List.take_length, List.length_drop] using
      (show (c : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) a w.length from by
        rw [← wordSlice_displacement h w (by omega)]
        simpa only [wordSlice, ← List.length_drop, List.take_length] using hdiv)
  · rw [wordPrimeContribution_eq_singleton h w z a w.length (w.length - 1)
      (by simp only [mem_Ico]; omega) hz]
    · exact hoff c (w.length - 1) ⟨0, hc⟩ (by omega) hclast
    · intro i hi hzi
      have hi' := (mem_Ico.mp hi).2
      by_contra hne
      exact hearlier i (by omega) hzi

lemma prime_dvd_wordPrimeContribution (h : ℕ) (w : List SignedStep) (p a b : ℕ) :
    (p : ℤ) ∣ wordPrimeContribution h w p a b := by
  classical
  unfold wordPrimeContribution
  apply Finset.dvd_sum
  intro i _
  by_cases hpi : TuplePrimeAt w p i
  · simpa only [hpi, ite_true] using (tuplePrime_dvd_step (h := h) hpi)
  · simp only [hpi, ite_false, dvd_zero]

lemma ActivePrime.distinct_controller {h p : ℕ} {w : List SignedStep}
    (hp : ActivePrime h w p) :
    ∃ c a b, c ≠ p ∧ a ≤ b ∧ b ≤ w.length ∧ (∃ i, TuplePrimeAt w c i) ∧
      (c : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) a b ∧
      ¬(c : ℤ) ∣ wordPrimeContribution h w p a b := by
  obtain ⟨c, a, b, hab, hb, hc, hd, hn⟩ := hp
  refine ⟨c, a, b, ?_, hab, hb, hc, hd, hn⟩
  intro heq
  subst c
  exact hn (prime_dvd_wordPrimeContribution h w p a b)

/-- Intersecting an interval-shaped occurrence set with a prefix gives an
explicit nonempty interval of indices. -/
lemma TuplePrimeIntervals.prefix_occurrences {w : List SignedStep}
    (hw : TuplePrimeIntervals w) (p n : ℕ) (hn : n ≤ w.length)
    (hp : ∃ j, j < n ∧ TuplePrimeAt w p j) :
    ∃ a b, a < b ∧ b ≤ n ∧ ∀ i, i < n →
      (TuplePrimeAt w p i ↔ a ≤ i ∧ i < b) := by
  classical
  let S := (range n).filter (TuplePrimeAt w p)
  have hS : S.Nonempty := by
    obtain ⟨j, hj, hpj⟩ := hp
    exact ⟨j, mem_filter.mpr ⟨mem_range.mpr hj, hpj⟩⟩
  let a := S.min' hS
  let b := S.max' hS + 1
  have haS : a ∈ S := min'_mem S hS
  have hbS : b - 1 ∈ S := by
    simpa only [b, Nat.add_sub_cancel] using max'_mem S hS
  have han := (mem_range.mp (mem_filter.mp haS).1)
  have hbn := (mem_range.mp (mem_filter.mp hbS).1)
  have hab : a < b := by
    have h := min'_le S (S.max' hS) (max'_mem S hS)
    dsimp [a, b]
    omega
  refine ⟨a, b, hab, by dsimp [b] at *; omega, ?_⟩
  intro i hi
  constructor
  · intro hpi
    have hiS : i ∈ S := mem_filter.mpr ⟨mem_range.mpr hi, hpi⟩
    exact ⟨min'_le S i hiS, Nat.lt_succ_of_le (le_max' S i hiS)⟩
  · rintro ⟨hai, hib⟩
    exact hw p a i (b - 1) hai (by omega) (by omega)
      (mem_filter.mp haS).2 (mem_filter.mp hbS).2

lemma wordPrimeContribution_restrict (h : ℕ) (w : List SignedStep) (p n a b : ℕ)
    (hbn : b ≤ n)
    (hp : ∀ i, i < n → (TuplePrimeAt w p i ↔ a ≤ i ∧ i < b)) :
    wordPrimeContribution h w p 0 n = intervalDisplacement (wordStepDisplacement h w) a b := by
  classical
  unfold wordPrimeContribution intervalDisplacement
  calc
    _ = ∑ i ∈ Ico a b, if TuplePrimeAt w p i then wordStepDisplacement h w i else 0 := by
      symm
      apply Finset.sum_subset (Ico_subset_Ico (Nat.zero_le a) hbn)
      intro i hi hin
      have hnot : ¬TuplePrimeAt w p i := by
        intro hpi
        exact hin (mem_Ico.mpr ((hp i (mem_Ico.mp hi).2).mp hpi))
      simp only [hnot, ite_false]
    _ = _ := by
      apply sum_congr rfl
      intro i hi
      simp only [(hp i (lt_of_lt_of_le (mem_Ico.mp hi).2 hbn)).mpr
        ⟨(mem_Ico.mp hi).1, (mem_Ico.mp hi).2⟩, ite_true]

/-- Minimality forbids a reversed suffix starting at a strictly positive
index, when an internal initial segment is divisible by its final prime. -/
lemma MinimalWord.no_reversed_divisible_interval {h s : ℕ} {supply : ℕ → ℕ → Prop}
    {w : List SignedStep} (hw : MinimalWord (ForwardProhibited h s supply) w)
    {a c p : ℕ} (ha : 0 < a) (hac : a + 1 < c) (hc : c < w.length)
    (hp : TuplePrimeAt w p (w.length - 1)) (hnot : ¬TuplePrimeAt w p a) :
    ¬(p : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) a c := by
  intro hdiv
  have hpro := reversed_interval_forwardProhibited h s supply w hw.1.2.1 hw.1.2.2.1
    hw.1.2.2.2.1 hw.1.2.2.2.2.1 hac hc le_rfl hp hnot hdiv
  apply hw.2 (reverseWord (wordSlice w a w.length))
    (Or.inr (reverseWord_infix (wordSlice_infix w a w.length))) ?_ hpro
  rw [reverseWord_length, wordSlice_length w (by omega) le_rfl]
  omega

/-- Every label of a minimal prohibited word is active or has a nonzero
prefix contribution modulo an active label used at that departure. -/
theorem MinimalWord.active_dichotomy {h s : ℕ} {supply : ℕ → ℕ → Prop}
    {w : List SignedStep} (hw : MinimalWord (ForwardProhibited h s supply) w)
    (hnew : ∀ i, i + 1 < w.length →
      ∃ p, TuplePrimeAt w p (i + 1) ∧ ¬TuplePrimeAt w p i)
    (hoff : ∀ p i, (∃ j, TuplePrimeAt w p j) → i < w.length →
      ¬TuplePrimeAt w p i → ¬(p : ℤ) ∣ wordStepDisplacement h w i)
    (y : ℕ) (hy : ∃ j, TuplePrimeAt w y j) :
    ActivePrime h w y ∨ ∃ z i, ActivePrime h w z ∧ TuplePrimeAt w z i ∧
      ¬(z : ℤ) ∣ wordPrimeContribution h w y 0 i := by
  classical
  have hlen : 3 ≤ w.length := hw.1.1
  have hinter : TuplePrimeIntervals w := hw.1.2.2.2.2.1
  obtain ⟨z, hzlast', hzprev⟩ := hnew (w.length - 2) (by omega)
  have heqlast : w.length - 2 + 1 = w.length - 1 := by omega
  have hzlast : TuplePrimeAt w z (w.length - 1) := heqlast ▸ hzlast'
  have hzearly : ∀ i, i < w.length - 1 → ¬TuplePrimeAt w z i := by
    intro i hi hzi
    exact hzprev (hinter z i (w.length - 2) (w.length - 1)
      (by omega) (by omega) (by omega) hzi hzlast)
  have hzactive := hw.1.last_new_active hzlast hzearly hoff
  by_cases hypre : ∃ j, j < w.length - 1 ∧ TuplePrimeAt w y j
  · obtain ⟨a, b, hab, hbn, hyinterval⟩ :=
      hinter.prefix_occurrences y (w.length - 1) (by omega) hypre
    have hyeq := wordPrimeContribution_restrict h w y (w.length - 1) a b hbn hyinterval
    by_cases hzd : (z : ℤ) ∣ wordPrimeContribution h w y 0 (w.length - 1)
    · have hdiv : (z : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) a b := by
        rwa [hyeq] at hzd
      have hab2 : a + 1 < b := by
        by_contra hn
        have hb : b = a + 1 := by omega
        have hd := hoff z a ⟨w.length - 1, hzlast⟩ (by omega) (hzearly a (by omega))
        exact hd (by simpa only [hb, intervalDisplacement_singleton] using hdiv)
      have ha : a = 0 := by
        by_contra hn
        exact hw.no_reversed_divisible_interval (by omega) hab2 (by omega)
          hzlast (hzearly a (by omega)) hdiv
      obtain ⟨z', hz'one, hz'zero⟩ := hnew 0 (by omega)
      obtain ⟨a', b', hab', hb'b, hz'interval⟩ :=
        hinter.prefix_occurrences z' b (by omega) ⟨1, by omega, hz'one⟩
      have ha' : a' = 1 := by
        have hle := ((hz'interval 1 (by omega)).mp hz'one).1
        have hne : a' ≠ 0 := by
          intro heq
          have hp := (hz'interval a' (by omega)).mpr ⟨le_rfl, hab'⟩
          exact hz'zero (by simpa only [heq] using hp)
        omega
      have hzeq := wordPrimeContribution_restrict h w z' b a' b' hb'b hz'interval
      have hnonzero : ¬(z : ℤ) ∣ wordPrimeContribution h w z' 0 b := by
        intro hzero
        have hdiv' : (z : ℤ) ∣ intervalDisplacement (wordStepDisplacement h w) 1 b' := by
          simpa only [hzeq, ha'] using hzero
        have hb' : 2 < b' := by
          by_contra hn
          have hb'eq : b' = 1 + 1 := by omega
          exact (hoff z 1 ⟨w.length - 1, hzlast⟩ (by omega) (hzearly 1 (by omega)))
            (by simpa only [hb'eq, intervalDisplacement_singleton] using hdiv')
        exact hw.no_reversed_divisible_interval (by omega) hb' (by omega)
          hzlast (hzearly 1 (by omega)) hdiv'
      have hz'active : ActivePrime h w z' := by
        refine ⟨z, 0, b, by omega, by omega, ⟨w.length - 1, hzlast⟩, ?_, hnonzero⟩
        simpa only [ha] using hdiv
      right
      refine ⟨z', 1, hz'active, hz'one, ?_⟩
      have hyzero : TuplePrimeAt w y 0 := (hyinterval 0 (by omega)).mpr ⟨by omega, by omega⟩
      rw [wordPrimeContribution_eq_singleton h w y 0 1 0 (by simp) hyzero]
      · exact hoff z' 0 ⟨1, hz'one⟩ (by omega) hz'zero
      · intro i hi _
        have := mem_Ico.mp hi
        omega
    · exact Or.inr ⟨z, w.length - 1, hzactive, hzlast, hzd⟩
  · left
    have hyearly : ∀ i, i < w.length - 1 → ¬TuplePrimeAt w y i := by
      intro i hi hpi
      exact hypre ⟨i, hi, hpi⟩
    obtain ⟨j, hyj⟩ := hy
    have hj := hyj.index_lt
    have hjeq : j = w.length - 1 := by
      by_contra hn
      exact hyearly j (by omega) hyj
    exact hw.1.last_new_active (hjeq ▸ hyj) hyearly hoff

/-- Equal-size squarefree tuples that change must also acquire a new prime. -/
lemma adjacent_tuple_new_prime (w : List SignedStep) (J : ℕ)
    (hsq : ∀ a ∈ w, Squarefree a.tuple)
    (hcard : ∀ a ∈ w, a.tuple.primeFactors.card = J)
    (hchain : w.IsChain (fun a b => a.tuple ≠ b.tuple)) :
    ∀ i, i + 1 < w.length → ∃ p, TuplePrimeAt w p (i + 1) ∧ ¬TuplePrimeAt w p i := by
  intro i hi
  have hi0 : i < w.length := by omega
  have ha := List.getElem_mem hi0
  have hb := List.getElem_mem hi
  have hneq : w[i].tuple ≠ w[i + 1].tuple := (List.isChain_iff_getElem.mp hchain) i hi
  have hsets : w[i + 1].tuple.primeFactors ≠ w[i].tuple.primeFactors := by
    intro heq
    apply hneq
    calc
      _ = ∏ p ∈ w[i].tuple.primeFactors, p := (Nat.prod_primeFactors_of_squarefree (hsq _ ha)).symm
      _ = ∏ p ∈ w[i + 1].tuple.primeFactors, p := by rw [heq]
      _ = _ := Nat.prod_primeFactors_of_squarefree (hsq _ hb)
  have hnot : ¬w[i + 1].tuple.primeFactors ⊆ w[i].tuple.primeFactors := by
    intro hsub
    apply hsets
    exact Finset.eq_of_subset_of_card_le hsub (by rw [hcard _ ha, hcard _ hb])
  obtain ⟨p, hpb, hpa⟩ := Finset.not_subset.mp hnot
  have hp := Nat.mem_primeFactors.mp hpb
  refine ⟨p, (tuplePrimeAt_iff_getElem w p (i + 1) hi).mpr ⟨hp.1, hp.2.1⟩, ?_⟩
  intro hpi
  have hpai := (tuplePrimeAt_iff_getElem w p i hi0).mp hpi
  exact hpa (Nat.mem_primeFactors.mpr ⟨hpai.1, hpai.2, (hsq _ ha).ne_zero⟩)

/-- The active-label dichotomy with the manuscript's concrete arithmetic
hypotheses: squarefree whole tuples of fixed prime-factor count, and prime
exclusion from the common multiplier and all padding factors. -/
theorem MinimalWord.active_dichotomy_of_squarefree {h s J : ℕ}
    {supply : ℕ → ℕ → Prop} {w : List SignedStep}
    (hw : MinimalWord (ForwardProhibited h s supply) w)
    (hsq : ∀ a ∈ w, Squarefree a.tuple)
    (hcard : ∀ a ∈ w, a.tuple.primeFactors.card = J)
    (hsupport : ∀ p j, TuplePrimeAt w p j → ¬p ∣ h ∧ ∀ a ∈ w, ¬p ∣ a.padding)
    (y : ℕ) (hy : ∃ j, TuplePrimeAt w y j) :
    ActivePrime h w y ∨ ∃ z i, ActivePrime h w z ∧ TuplePrimeAt w z i ∧
      ¬(z : ℤ) ∣ wordPrimeContribution h w y 0 i := by
  apply hw.active_dichotomy (adjacent_tuple_new_prime w J hsq hcard hw.1.2.2.2.1) ?_ y hy
  intro p i hseen hi hnot
  apply word_prime_support hsupport p i ?_ hi hnot
  obtain ⟨j, hj⟩ := hseen
  exact ⟨j, hj.index_lt, hj⟩

end TwoPointCorrelations

end OAI