-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |