Download lean/QLG.lean from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 8.25 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/QLG.lean
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/lean/QLG.lean
-
curl -L -o QLG.lean https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/QLG.lean
8.25 kB
Lean 4 · 22
declarations statementsfull
inductive Glyph where body · 7 lines
| Pi -- Propositio: send proposition (0x01)
| Gamma -- Guard: receive guard check (0x03)
| Delta -- Transition: execute state transition (0x04)
| Omega -- Conclusio: absorbing terminal (0x0A)
| Lambda-- Locality: identity element (0xFF)
| Psi -- Negative transition (0x0B)
deriving DecidableEq, Repr@[simp] def Glyph.idx : Glyph → Fin 6 body · 2 lines
| .Pi => 0 | .Gamma => 1 | .Delta => 2
| .Omega => 3 | .Lambda => 4 | .Psi => 5@[simp] def Glyph.ofIdx : Fin 6 → Glyph body · 2 lines
| 0 => .Pi | 1 => .Gamma | 2 => .Delta
| 3 => .Omega | 4 => .Lambda | 5 => .Psi@[simp] theorem Glyph.idx_ofIdx (i : Fin 6) : (Glyph.ofIdx i).idx = i := by proof · 1 line
fin_cases i <;> rfl
@[simp] theorem Glyph.ofIdx_idx (g : Glyph) : Glyph.ofIdx g.idx = g := by proof · 1 line
cases g <;> rfl
def Q : Fin 6 → Fin 6 → Fin 6 body · 7 lines
| 4, j => j -- Lambda row: identity (row 4 = [0,1,2,3,4,5])
| 3, _ => 3 -- Omega row: absorber (row 3 = [3,3,3,3,3,3])
| 0, _ => 2 -- Pi row
| 1, j => if j = 4 then 2 else 3 -- Gamma row
| 2, _ => 3 -- Delta row
| 5, j => if j = 4 then 2 else 3 -- Psi row
| _, _ => 3def Glyph.next (curr prev : Glyph) : Glyph := body · 1 line
Glyph.ofIdx (Q curr.idx prev.idx)structure Ledger where body · 5 lines
s : ℤ -- size
δ : ℤ -- debit
ι : ℤ -- credit
ω : ℤ -- domain
deriving Reprdef Ledger.balance (λ : Ledger) : Prop := λ.δ + λ.ι = 0 def Ledger.mkBalanced (s δ ω : ℤ) : Ledger := body · 1 line
{s := s, δ := δ, ι := -δ, ω := ω}@[simp] theorem Ledger.balance_mkBalanced (s δ ω : ℤ) :
(Ledger.mkBalanced s δ ω).balance := by proof · 2 lines
simp [Ledger.balance]
omegadef Ledger.comp (λ₁ λ₂ : Ledger) : Option Ledger := body · 7 lines
if h : λ₁.ω = λ₂.ω then
some { s := λ₁.s + λ₂.s
δ := λ₁.δ + λ₂.δ
ι := λ₁.ι + λ₂.ι
ω := λ₁.ω }
else
nonestructure Vec3 where body · 4 lines
x : ℤ
y : ℤ
z : ℤ
deriving Reprdef QLG.canonical (v : Vec3) : Prop := v.x^2 + v.y^2 + v.z^2 = 1 def QLG.K : ℤ := 1 def Vec3.ofGlyph : Glyph → Vec3 body · 6 lines
| .Pi => {x:=1,y:=0,z:=0}
| .Gamma => {x:=-1,y:=0,z:=0}
| .Delta => {x:=0,y:=1,z:=0}
| .Psi => {x:=0,y:=-1,z:=0}
| .Lambda => {x:=0,y:=0,z:=1}
| .Omega => {x:=0,y:=0,z:=-1}def Glyph.ofVec3 : Vec3 → Option Glyph body · 7 lines
| {x:=1,y:=0,z:=0} => some .Pi
| {x:=-1,y:=0,z:=0} => some .Gamma
| {x:=0,y:=1,z:=0} => some .Delta
| {x:=0,y:=-1,z:=0} => some .Psi
| {x:=0,y:=0,z:=1} => some .Lambda
| {x:=0,y:=0,z:=-1} => some .Omega
| _ => nonetheorem qra_routing_grounded :
∀ (curr prev : Glyph), ∃ next : Glyph, next = curr.next prev := by proof · 3 lines
intro curr prev use curr.next prev rfl
theorem pi_route_valid :
Glyph.Pi.next Glyph.Lambda = Glyph.Delta ∧
Glyph.Lambda.next Glyph.Omega = Glyph.Omega := by proof · 2 lines
simp [Glyph.next, Q]
decidetheorem gamma_route_valid :
Glyph.Gamma.next Glyph.Lambda = Glyph.Delta ∧
Glyph.Lambda.next Glyph.Omega = Glyph.Omega := by proof · 2 lines
simp [Glyph.next, Q]
decidetheorem delta_route_valid :
Glyph.Delta.next Glyph.Lambda = Glyph.Delta ∧
Glyph.Lambda.next Glyph.Omega = Glyph.Omega := by proof · 2 lines
simp [Glyph.next, Q]
decidetheorem zero_not_balanced : ¬QLG.canonical {x:=0,y:=0,z:=0} := Outline
- inductive
Glyph31 - def
Glyph.idx41 - def
Glyph.ofIdx45 - theorem
Glyph.idx_ofIdx49 - theorem
Glyph.ofIdx_idx52 - def
Q57 - def
Glyph.next66 - structure
Ledger70 - def
Ledger.balance78 - def
Ledger.mkBalanced80 - theorem
Ledger.balance_mkBalanced83 - def
Ledger.comp89 - structure
Vec399 - def
QLG.canonical106 - def
QLG.K107 - def
Vec3.ofGlyph111 - def
Glyph.ofVec3119 - theorem
qra_routing_grounded135 - theorem
pi_route_valid218 - theorem
gamma_route_valid225 - theorem
delta_route_valid232 - theorem
zero_not_balanced243