SNAPKITTYWEST's picture
push from SNAPKITTYWEST/hyperkitty-constraint-dsl
224e773 verified
Raw History Blame Contribute Delete
5.71 kB
21
structure Witness where
body · 3 lines
  w : List Glyph
  len_constraint : w.length = 3
  deriving Repr
27
def canonicalWitness : Witness :=
body · 1 line
  ⟨[Glyph.Pi, Glyph.Gamma, Glyph.Delta], rfl⟩
35
def evolveWitness (w : Witness) : Option Witness := by
body · 4 lines
  match w.w with
  | [a, b, c] =>
    exact some ⟨[a.next b, b.next c, c.next a], rfl⟩
  | _ => exact none
45
theorem witness_first_evolution :
    evolveWitness canonicalWitness =
    some ⟨[Glyph.Delta, Glyph.Omega, Glyph.Omega], rfl⟩ := by
proof · 2 lines
  simp [evolveWitness, canonicalWitness, Glyph.next, Glyph.idx, Q]
  rfl
55
theorem witness_second_evolution :
    let w₁ := evolveWitness canonicalWitness
proof · 4 lines
    let w₂ := w₁ >>= evolveWitness
    w₂ = some ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩ := by
  simp [evolveWitness, canonicalWitness, Glyph.next, Glyph.idx, Q]
  rfl
67
theorem witness_canonical_exhaustion :
    ∃ w₁ w₂ : Witness,
      evolveWitness canonicalWitness = some w₁ ∧
      evolveWitness w₁ = some w₂ ∧
      w₂.w = [Glyph.Omega, Glyph.Omega, Glyph.Omega] := by
proof · 3 lines
  use ⟨[Glyph.Delta, Glyph.Omega, Glyph.Omega], rfl⟩
  use ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩
  simp [witness_first_evolution, witness_second_evolution]
80
theorem witness_omega_fixed :
    evolveWitness ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩ =
    some ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩ := by
proof · 2 lines
  simp [evolveWitness, Glyph.next, Glyph.idx, Q]
  rfl
90
theorem witness_lambda_fixed_invalid :
    evolveWitness ⟨[Glyph.Lambda, Glyph.Lambda, Glyph.Lambda], rfl⟩ =
    some ⟨[Glyph.Lambda, Glyph.Lambda, Glyph.Lambda], rfl⟩ := by
proof · 2 lines
  simp [evolveWitness, Glyph.next, Glyph.idx, Q]
  rfl
100
theorem witness_evolution_preserves_len (w : Witness) :
    (∃ w' : Witness, evolveWitness w = some w') ∧
    (∀ w' : Witness, evolveWitness w = some w' → w'.w.length = 3) := by
proof · 13 lines
  constructor
  · -- evolveWitness always succeeds on any witness with len_constraint
    match w.w, w.len_constraint with
    | [a, b, c], hlen =>
      use ⟨[a.next b, b.next c, c.next a], rfl⟩
      simp [evolveWitness]
    | _, hlen =>
      -- This case is impossible due to len_constraint
      exfalso
      simp [List.length] at hlen
  · -- The second part is immediate from Witness.len_constraint
    intro w' _
    exact w'.len_constraint
121
theorem witness_exhaustion_exactly_two :
    ∃ w₁ : Witness,
      evolveWitness canonicalWitness = some w₁ ∧
      ∃ w₂ : Witness,
        evolveWitness w₁ = some w₂ ∧
        w₂.w.all (· = Glyph.Omega) := by
proof · 5 lines
  use ⟨[Glyph.Delta, Glyph.Omega, Glyph.Omega], rfl⟩
  refine ⟨by simp [witness_first_evolution], ?_⟩
  use ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩
  refine ⟨by simp [witness_second_evolution], ?_⟩
  simp
137
theorem witness_deterministic (w : Witness) :
    let w₁ := evolveWitness w
proof · 3 lines
    let w₂ := evolveWitness w
    w₁ = w₂ := by
  rfl
147
theorem witness_non_exhausted_evolves (w : Witness)
    (h : w.w ≠ [Glyph.Omega, Glyph.Omega, Glyph.Omega]) :
    ∃ w' : Witness, evolveWitness w = some w' := by
proof · 10 lines
  match w.w, w.len_constraint with
  | [a, b, c], hlen =>
    -- By len_constraint, w.w must be [a, b, c]
    -- evolveWitness succeeds on any such witness
    use ⟨[a.next b, b.next c, c.next a], rfl⟩
    simp [evolveWitness]
  | _, hlen =>
    -- This case is impossible due to len_constraint
    exfalso
    simp [List.length] at hlen
165
theorem witness_canonical_terminates :
    ∃ n : ℕ,
      ∃ w : Witness,
      w.w = [Glyph.Omega, Glyph.Omega, Glyph.Omega] ∧
      n ≤ 36 := by
proof · 3 lines
  use 2
  use ⟨[Glyph.Omega, Glyph.Omega, Glyph.Omega], rfl⟩
  simp