SNAPKITTYWEST's picture
Sync with GitHub, license metadata from LICENSE files, commercial license notice
dbd3deb verified
Raw History Blame Contribute Delete
8.25 kB
31
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
41
@[simp] def Glyph.idx : Glyph → Fin 6
body · 2 lines
  | .Pi => 0 | .Gamma => 1 | .Delta => 2
  | .Omega => 3 | .Lambda => 4 | .Psi => 5
45
@[simp] def Glyph.ofIdx : Fin 6 → Glyph
body · 2 lines
  | 0 => .Pi | 1 => .Gamma | 2 => .Delta
  | 3 => .Omega | 4 => .Lambda | 5 => .Psi
49
@[simp] theorem Glyph.idx_ofIdx (i : Fin 6) : (Glyph.ofIdx i).idx = i := by
proof · 1 line
  fin_cases i <;> rfl
52
@[simp] theorem Glyph.ofIdx_idx (g : Glyph) : Glyph.ofIdx g.idx = g := by
proof · 1 line
  cases g <;> rfl
57
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
  | _, _ => 3
66
def Glyph.next (curr prev : Glyph) : Glyph :=
body · 1 line
  Glyph.ofIdx (Q curr.idx prev.idx)
70
structure Ledger where
body · 5 lines
  s : ℤ   -- size
  δ : ℤ   -- debit
  ι : ℤ   -- credit
  ω : ℤ   -- domain
  deriving Repr
78
def Ledger.balance (λ : Ledger) : Prop := λ.δ + λ.ι = 0
80
def Ledger.mkBalanced (s δ ω : ℤ) : Ledger :=
body · 1 line
  {s := s, δ := δ, ι := -δ, ω := ω}
83
@[simp] theorem Ledger.balance_mkBalanced (s δ ω : ℤ) :
    (Ledger.mkBalanced s δ ω).balance := by
proof · 2 lines
  simp [Ledger.balance]
  omega
89
def Ledger.comp (λ₁ λ₂ : Ledger) : Option Ledger :=
body · 7 lines
  if h : λ₁.ω = λ₂.ω then
    some { s := λ₁.s + λ₂.s
           δ := λ₁.δ + λ₂.δ
           ι := λ₁.ι + λ₂.ι
           ω := λ₁.ω }
  else
    none
99
structure Vec3 where
body · 4 lines
  x : ℤ
  y : ℤ
  z : ℤ
  deriving Repr
106
def QLG.canonical (v : Vec3) : Prop := v.x^2 + v.y^2 + v.z^2 = 1
107
def QLG.K : ℤ := 1
111
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}
119
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
135
theorem qra_routing_grounded :
    ∀ (curr prev : Glyph), ∃ next : Glyph, next = curr.next prev := by
proof · 3 lines
  intro curr prev
  use curr.next prev
  rfl
218
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]
  decide
225
theorem 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]
  decide
232
theorem 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]
  decide
243
theorem zero_not_balanced : ¬QLG.canonical {x:=0,y:=0,z:=0} :=