Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed Extended/.gitkeep
Empty file.
163 changes: 163 additions & 0 deletions Extended/Calculus.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
set_option autoImplicit false

@[reducible]
def Attr := String

mutual
inductive OptionalAttr where
| attached : Term β†’ OptionalAttr
| void : OptionalAttr

inductive Bindings : List Attr β†’ Type where
| nil : Bindings []
| cons
: { lst : List Attr }
β†’ (a : Attr)
β†’ a βˆ‰ lst
β†’ OptionalAttr
β†’ Bindings lst
β†’ Bindings (a :: lst)

inductive Term : Type where
| obj : { lst : List Attr } β†’ Bindings lst β†’ Term
| dot : Term β†’ Attr β†’ Term
| app : Term β†’ Attr β†’ Term β†’ Term
| ΞΎ : Term
| Ξ¦ : Term
end
open OptionalAttr
open Term


-- def substitute (tξ : Term) (tΦ : Term) : Term → Term
-- | obj o => obj o
-- | dot t a => dot (substitute tξ tΦ t) a
-- | app t a u => app (substitute tξ tΦ t) a (substitute tξ tΦ u)
-- | ΞΎ => tΞΎ
-- | Φ => tΦ

def substitute (tΞΎ : Term) : Term β†’ Term
| obj o => obj o
| dot t a => dot (substitute tΞΎ t) a
| app t a u => app (substitute tΞΎ t) a (substitute tΞΎ u)
| ΞΎ => tΞΎ
| Ξ¦ => Ξ¦

def lookup { lst : List Attr } (l : Bindings lst) (a : Attr)
: Option OptionalAttr
:= match l with
| Bindings.nil => none
| Bindings.cons name _ opAttr tail =>
if (name == a) then some opAttr
else lookup tail a

def insert
{ lst : List Attr }
(l : Bindings lst)
(a : Attr)
(u : OptionalAttr)
: (Bindings lst)
:= match l with
| Bindings.nil => Bindings.nil
| Bindings.cons name not_in opAttr tail =>
if name == a then Bindings.cons name not_in u tail
else Bindings.cons name not_in opAttr (insert tail a u)

def has_no_void_attrs { lst : List Attr } : Bindings lst β†’ Bool
| Bindings.nil => true
| Bindings.cons _ _ u tail => match u with
| void => false
| attached _ => has_no_void_attrs tail

@[reducible]
def Context := Term

inductive Reduce : Context β†’ Term β†’ Term β†’ Type where
| congOBJ
: { a : Attr }
β†’ { t t' : Term }
β†’ { attrs : List Attr }
β†’ { bnds : Bindings attrs }
β†’ { ctx : Context }
β†’ has_no_void_attrs bnds
β†’ lookup bnds a = some (attached t)
β†’ Reduce ctx t t'
β†’ Reduce ctx
(obj bnds)
(obj (insert bnds a (attached t')))
| congDOT
: { a : Attr }
β†’ { t t' : Term }
β†’ { ctx : Context }
β†’ Reduce ctx t t'
β†’ Reduce ctx (dot t a) (dot t' a)
| congAPPβ‚—
: { a : Attr }
β†’ { t t' u : Term }
β†’ { ctx : Context }
β†’ Reduce ctx t t'
β†’ Reduce ctx (app t a u) (app t' a u)
| congAPPα΅£
: { a : Attr }
β†’ { t u u' : Term }
β†’ { ctx : Context }
β†’ Reduce ctx u u'
β†’ Reduce ctx (app t a u) (app t a u')
| dot_c
: (ctx : Context)
β†’ (t : Term)
β†’ (c : Attr)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l c = some (attached t)
β†’ Reduce ctx
(dot (obj l) c)
(app (substitute (obj l) t) "ρ" ξ)
| dot_ρ
: (ctx : Context)
β†’ (t : Term)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l "ρ" = some (attached t)
β†’ Reduce ctx
(dot (obj l) "ρ")
(substitute (obj l) t)
| dot_Ο†
: (ctx : Context)
β†’ (c : Attr)
→ (tφ : Term)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l c = none
→ lookup l "φ" = some (attached tφ)
β†’ Reduce ctx
(dot (obj l) c)
(dot (app (substitute (obj l) tΟ†) "ρ" ΞΎ) c)
| dot_Ξ¦
: (a : Attr)
β†’ (t_a : Term)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l a = some (attached t_a)
β†’ Reduce (obj l)
(dot Ξ¦ a)
(app (substitute (obj l) t_a) "ρ" Φ)
| app_c
: (ctx : Context)
β†’ (u : Term)
β†’ (c : Attr)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l c = some void
β†’ Reduce ctx
(app (obj l) c u)
(obj (insert l c (attached u)))
| app_ρ
: (ctx : Context)
β†’ (u : Term)
β†’ { lst : List Attr }
β†’ (l : Bindings lst)
β†’ lookup l "ρ" = some _
β†’ Reduce ctx
(app (obj l) "ρ" u)
(obj (insert l "ρ" (attached u)))