Download lean/HyperKitty/Witness.lean from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 5.71 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/Witness.lean
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/lean/HyperKitty/Witness.lean
-
curl -L -o Witness.lean https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/Witness.lean
5.71 kB
Lean 4 · 13
declarations statementsfull
structure Witness where body · 3 lines
w : List Glyph
len_constraint : w.length = 3
deriving Reprdef canonicalWitness : Witness := body · 1 line
⟨[Glyph.Pi, Glyph.Gamma, Glyph.Delta], rfl⟩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 nonetheorem 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]
rfltheorem 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]
rfltheorem 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]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]
rfltheorem 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]
rfltheorem 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_constrainttheorem 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], ?_⟩
simptheorem witness_deterministic (w : Witness) :
let w₁ := evolveWitness w proof · 3 lines
let w₂ := evolveWitness w
w₁ = w₂ := by
rfltheorem 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 hlentheorem 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⟩
simpOutline
- structure
Witness21 - def
canonicalWitness27 - def
evolveWitness35 - theorem
witness_first_evolution45 - theorem
witness_second_evolution55 - theorem
witness_canonical_exhaustion67 - theorem
witness_omega_fixed80 - theorem
witness_lambda_fixed_invalid90 - theorem
witness_evolution_preserves_len100 - theorem
witness_exhaustion_exactly_two121 - theorem
witness_deterministic137 - theorem
witness_non_exhausted_evolves147 - theorem
witness_canonical_terminates165