Download lean/HyperKitty/Core.lean from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 7.32 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/Core.lean
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/lean/HyperKitty/Core.lean
-
curl -L -o Core.lean https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/lean/HyperKitty/Core.lean
7.32 kB
Lean 4 · 20
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
| 3, _ => 3 -- Omega row: absorber
| 0, j => if j = 2 ∨ j = 3 then 3 else 2 -- Pi: Omega when prev∈{Delta,Omega}, else Delta
| 1, j => if j = 0 ∨ j = 4 then 2 else 3 -- Gamma: Delta when prev∈{Pi,Lambda}, else Omega
| 2, j => if j = 4 then 2 else 3 -- Delta: Delta when prev=Lambda, else Omega
| 5, j => if j = 0 ∨ j = 4 then 2 else 3 -- Psi: Delta when prev∈{Pi,Lambda}, else Omega
| _, _ => 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
| _ => nonestructure SpinFactor where body · 3 lines
scalar : ℤ
vector : List ℤ
deriving Reprdef SpinFactor.mul (x y : SpinFactor) : SpinFactor := body · 6 lines
let α := x.scalar
let β := y.scalar
let dot := List.zipWith (· * ·) x.vector y.vector |> List.sum
let scalar_part := α * β + dot
let vector_part := List.map (· * β) x.vector ++ List.map (· * α) y.vector
{scalar := scalar_part, vector := vector_part}def SpinFactor.commutative (x y : SpinFactor) : Prop := body · 1 line
x.mul y = y.mul x
Outline
- inductive
Glyph24 - def
Glyph.idx34 - def
Glyph.ofIdx38 - theorem
Glyph.idx_ofIdx42 - theorem
Glyph.ofIdx_idx45 - def
Q77 - def
Glyph.next92 - structure
Ledger108 - def
Ledger.balance116 - def
Ledger.mkBalanced124 - theorem
Ledger.balance_mkBalanced127 - def
Ledger.comp138 - structure
Vec3158 - def
QLG.canonical165 - def
QLG.K166 - def
Vec3.ofGlyph179 - def
Glyph.ofVec3193 - structure
SpinFactor213 - def
SpinFactor.mul226 - def
SpinFactor.commutative235