SNAPKITTYWEST's picture
push from SNAPKITTYWEST/hyperkitty-constraint-dsl
224e773 verified
Raw History Blame Contribute Delete
7.32 kB
24
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
34
@[simp] def Glyph.idx : Glyph → Fin 6
body · 2 lines
  | .Pi => 0 | .Gamma => 1 | .Delta => 2
  | .Omega => 3 | .Lambda => 4 | .Psi => 5
38
@[simp] def Glyph.ofIdx : Fin 6 → Glyph
body · 2 lines
  | 0 => .Pi | 1 => .Gamma | 2 => .Delta
  | 3 => .Omega | 4 => .Lambda | 5 => .Psi
42
@[simp] theorem Glyph.idx_ofIdx (i : Fin 6) : (Glyph.ofIdx i).idx = i := by
proof · 1 line
  fin_cases i <;> rfl
45
@[simp] theorem Glyph.ofIdx_idx (g : Glyph) : Glyph.ofIdx g.idx = g := by
proof · 1 line
  cases g <;> rfl
77
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
  | _, _ => 3
92
def Glyph.next (curr prev : Glyph) : Glyph :=
body · 1 line
  Glyph.ofIdx (Q curr.idx prev.idx)
108
structure Ledger where
body · 5 lines
  s : ℤ   -- size
  δ : ℤ   -- debit
  ι : ℤ   -- credit
  ω : ℤ   -- domain
  deriving Repr
116
def Ledger.balance (λ : Ledger) : Prop := λ.δ + λ.ι = 0
124
def Ledger.mkBalanced (s δ ω : ℤ) : Ledger :=
body · 1 line
  {s := s, δ := δ, ι := -δ, ω := ω}
127
@[simp] theorem Ledger.balance_mkBalanced (s δ ω : ℤ) :
    (Ledger.mkBalanced s δ ω).balance := by
proof · 2 lines
  simp [Ledger.balance]
  omega
138
def Ledger.comp (λ₁ λ₂ : Ledger) : Option Ledger :=
body · 7 lines
  if h : λ₁.ω = λ₂.ω then
    some { s := λ₁.s + λ₂.s
           δ := λ₁.δ + λ₂.δ
           ι := λ₁.ι + λ₂.ι
           ω := λ₁.ω }
  else
    none
158
structure Vec3 where
body · 4 lines
  x : ℤ
  y : ℤ
  z : ℤ
  deriving Repr
165
def QLG.canonical (v : Vec3) : Prop := v.x^2 + v.y^2 + v.z^2 = 1
166
def QLG.K : ℤ := 1
179
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}
193
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
  | _ => none
213
structure SpinFactor where
body · 3 lines
  scalar : ℤ
  vector : List ℤ
  deriving Repr
226
def 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}
235
def SpinFactor.commutative (x y : SpinFactor) : Prop :=
body · 1 line
  x.mul y = y.mul x