-
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.
Draft different options for reduction rules
- Loading branch information
Showing
1 changed file
with
306 additions
and
0 deletions.
There are no files selected for viewing
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,306 @@ | ||
set_option autoImplicit false | ||
|
||
@[reducible] | ||
def Attr := String | ||
@[reducible] | ||
def Function := String | ||
@[reducible] | ||
def Bytes := String | ||
|
||
-- inductive Attr where | ||
-- | Ο : Attr | ||
-- | Ο : Attr | ||
-- | Ο : Attr | ||
-- | Ξ½ : Attr | ||
-- | Ξ± : String β Attr | ||
|
||
mutual | ||
inductive Binder : Attr β Type where | ||
| alpha : (a : Attr) β Term β Binder a | ||
| empty : (a : Attr) β Binder a | ||
| delta : Bytes β Binder "Ξ" | ||
| lambda : Function β Binder "Ξ»" | ||
|
||
inductive Bindings : List Attr β Type where | ||
| nil : Bindings [] | ||
| cons | ||
: { lst : List Attr } | ||
β { a : Attr } | ||
β a β lst | ||
β Binder a | ||
β Bindings lst | ||
β Bindings (a :: lst) | ||
|
||
inductive Term : Type where | ||
| obj : { attrs : List Attr } β Bindings attrs β Term -- β¦ Ξ±β β¦ uβ, ... Ξ±β β¦ uβ β§ | ||
| app : { attrs : List Attr } β Term β Bindings attrs β Term -- t(Ξ±β β¦ uβ, ... Ξ±β β¦ uβ) | ||
-- | obj : Bindings _ β Term | ||
-- | app : Term β Bindings _ β Term | ||
| dot : Term β Attr β Term -- t.a | ||
| glob : Term -- Ξ¦ | ||
| this : Term -- ΞΎ | ||
| termination : Term -- β₯ | ||
end | ||
open Term | ||
|
||
namespace Bindings | ||
|
||
def singleton (a : Attr) (t : Term) : Bindings [a] | ||
:= cons (Ξ» isin => by contradiction) (Binder.alpha a t) nil | ||
|
||
end Bindings | ||
|
||
inductive IsAttached : { attrs : List Attr } β Attr β Term β Bindings attrs β Type where | ||
-- | zeroth_attached | ||
-- : { lst : List Attr } | ||
-- β (a : Attr) | ||
-- β (not_in : a β lst) | ||
-- β (t : Term) | ||
-- β (l : Bindings lst) | ||
-- β IsAttached a t (Bindings.cons a not_in (attached t) l) | ||
-- | next_attached | ||
-- : { lst : List Attr } | ||
-- β (a : Attr) | ||
-- β (t : Term) | ||
-- β (l : Bindings lst) | ||
-- β (b : Attr) | ||
-- β (a β b) | ||
-- β (not_in : b β lst) | ||
-- β (u : OptionalAttr) | ||
-- β IsAttached a t l | ||
-- β IsAttached a t (Bindings.cons b not_in u l) | ||
|
||
inductive IsVoid : { attrs : List Attr } β Attr β Bindings attrs β Type | ||
|
||
universe u v | ||
inductive ForAll : { Ξ± : Type u } β (f : Ξ± β Type v) β (List Ξ±) β Prop where | ||
| nil : { Ξ± : Type u } β { f : Ξ± β Type v } β ForAll f [] | ||
| cons : { Ξ± : Type u } β { f : Ξ± β Type v } β (l : List Ξ±) β (a : Ξ±) β (fa : f a) β ForAll f l β ForAll f (a :: l) | ||
|
||
def insert | ||
{ attrs : List Attr } | ||
(bnds : Bindings attrs) | ||
(a : Attr) | ||
(u : Term) | ||
: (Bindings attrs) | ||
:= sorry | ||
|
||
def remove | ||
{ attrs : List Attr } | ||
(bnds : Bindings attrs) | ||
(a : Attr) | ||
: Bindings (List.removeAll attrs [a]) | ||
:= sorry | ||
|
||
def insertAll | ||
{ attrs_from : List Attr } | ||
{ attrs_to : List Attr } | ||
(bnds_from : Bindings attrs_from) | ||
(bnds_to : Bindings attrs_to) | ||
: (Bindings attrs_to) | ||
:= sorry | ||
|
||
def subst_this_head | ||
(t : Term) | ||
(u : Term) | ||
: Term | ||
:= match t with | ||
| obj bnds => obj bnds | ||
| app t' bnds => app t' bnds | ||
| dot t' a => dot (subst_this_head t' u) a | ||
| glob => glob | ||
| this => u | ||
| termination => termination | ||
|
||
inductive NormalForm : Term β Type where | ||
| nf : (t : Term) β NormalForm t | ||
|
||
inductive Prog : Type where | ||
| prog : { attrs : List Attr } β Bindings attrs β Prog | ||
def get_bindings (prog : Prog) : Ξ£ attrs : List Attr, Bindings attrs | ||
:= match prog with | ||
| @Prog.prog attrs bnds => β¨attrs, bndsβ© | ||
|
||
inductive Reduce : Prog β Term β Term β Type where | ||
| congDot | ||
: { a : Attr } | ||
β { t t' : Term } | ||
β { prog : Prog } | ||
β Reduce prog t t' | ||
β Reduce prog (dot t a) (dot t' a) | ||
| congObj | ||
: { a : Attr } | ||
β { t t' : Term } | ||
β { prog : Prog } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β IsAttached a t bnds | ||
β Reduce prog t t' -- Ξ¦ β¦ β¦Bβ§ β’ t β t' | ||
β Reduce | ||
prog | ||
(obj bnds) -- β¦ a β¦ t, B β§ | ||
(obj (insert bnds a t')) -- β¦ a β¦ t', B β§ | ||
| r4 | ||
: { prog : Prog } | ||
β Reduce | ||
prog -- Ξ¦ β¦ β¦Bβ§ | ||
glob -- Ξ¦ | ||
(obj (insert (get_bindings prog).snd "Ο" glob)) -- β¦ B, Ο β¦ Ξ¦ β§ | ||
| r5 | ||
: { prog : Prog } | ||
β { a : Attr } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β (t : Term) | ||
β IsAttached a t bnds | ||
β Reduce | ||
prog | ||
(obj bnds) -- β¦ a β¦ ΞΎ β’ t', B β§ | ||
(obj (insert bnds a (subst_this_head t (obj bnds)))) -- β¦ a β¦ β¦Bβ§ β’ t', B β§ ?add recursion? | ||
| r6 | ||
: { a : Attr } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } -- B | ||
β (n : Term) | ||
β IsAttached a n bnds | ||
β (prog : Prog) | ||
β NormalForm n | ||
β Reduce | ||
prog | ||
(dot (obj bnds) a) -- β¦ a β¦ n, B β§.a | ||
(app n (Bindings.singleton "Ο" (obj (remove bnds a)))) -- n(Ο β¦ β¦Bβ§), ?should keep a β¦ n? | ||
| r7 | ||
: { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β { void_attrs : List Attr } | ||
β ForAll (Ξ» a => IsVoid a bnds) void_attrs | ||
β (prog : Prog) | ||
β (void_bnds : Bindings void_attrs) | ||
β Reduce | ||
prog | ||
(app (obj bnds) void_bnds) -- β¦ Οβ β¦ β , Οβ β¦ β , ... Bβ§(Οβ β¦ nβ, Οβ β¦ nβ, ...) | ||
(obj (insertAll void_bnds (remove bnds "Ξ½"))) -- β¦ Οβ β¦ nβ, Οβ β¦ nβ, ... B β Ξ½ β§ | ||
| r8 | ||
: { a : Attr } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β (prog : Prog) | ||
β a β attrs | ||
β (n : Term) | ||
β NormalForm n | ||
β IsAttached "Ο" n bnds | ||
β Reduce | ||
prog | ||
(dot (obj bnds) a) -- β¦ Ο β¦ n, B β§.a | ||
(dot n a) -- n.a | ||
| r9 | ||
: { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β { n : Term } | ||
β (prog : Prog) | ||
β NormalForm n | ||
β Reduce | ||
prog | ||
(app (obj bnds) (Bindings.singleton "Ο" n)) -- β¦ B β§(Ο β¦ n) | ||
(obj (insert bnds "Ο" n)) -- β¦ Ο β¦ n, B β Ο β§ | ||
|
||
inductive Context where | ||
| prog : { attrs : List Attr } β Bindings attrs β Context | ||
| cons : { attrs : List Attr } β Bindings attrs β Context β Context | ||
|
||
def top (ctx : Context) : Ξ£ attrs : List Attr, Bindings attrs | ||
:= match ctx with | ||
| @Context.prog a b => β¨a, bβ© | ||
| @Context.cons a b _ => β¨a, bβ© | ||
|
||
def getProg (ctx : Context) : Ξ£ attrs : List Attr, Bindings attrs | ||
:= match ctx with | ||
| @Context.prog a b => β¨a, bβ© | ||
| Context.cons _ c => getProg c | ||
|
||
mutual | ||
inductive Entails : Context β Term β Type where | ||
-- | ??? | ||
|
||
-- infix:20 " β’ " => WithContext.entails | ||
inductive ReduceCtx : Context β Term β Term β Type where | ||
| congDot | ||
: { a : Attr } | ||
β { t t' : Term } | ||
β { ctx : Context } | ||
β ReduceCtx ctx t t' | ||
β ReduceCtx ctx (dot t a) (dot t' a) | ||
| congObj | ||
: { a : Attr } | ||
β { t t' : Term } | ||
β { ctx : Context } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β IsAttached a t bnds | ||
β ReduceCtx (Context.cons (remove bnds a) ctx) t t' -- β¦Bβ§ β’ t β t' | ||
β ReduceCtx | ||
ctx | ||
(obj bnds) -- β¦ a β¦ t, B β§ | ||
(obj (insert bnds a t')) -- β¦ a β¦ t', B β§ | ||
| r4 | ||
: { ctx : Context } | ||
β ReduceCtx | ||
ctx -- β¦Bβ§, Ξ | ||
glob -- Ξ¦ | ||
(obj (insert (getProg ctx).snd "Ο" glob)) -- β¦ B, Ο β¦ Ξ¦ β§ | ||
| r5 | ||
: { ctx : Context } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β ReduceCtx | ||
(Context.cons bnds ctx) -- Ξ , β¦ B β§ ?α΅? | ||
this -- ΞΎ | ||
(obj bnds) -- β¦ B β§ | ||
| r6 | ||
: { a : Attr } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } -- B | ||
β a β attrs | ||
β (n : Term) | ||
β (ctx : Context) -- Ξ | ||
β Entails (Context.cons bnds ctx) n -- Ξ, β¦Bβ§ β’ n | ||
β NormalForm n | ||
β ReduceCtx | ||
ctx | ||
(dot (obj (insert bnds a n)) a) -- β¦ a β¦ n, B β§.a | ||
(app n (Bindings.singleton "Ο" (obj bnds))) -- n(Ο β¦ β¦ B β§), ?should add a β¦ n? | ||
| r7 | ||
: { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β { void_attrs : List Attr } | ||
β ForAll (Ξ» a => IsVoid a bnds) void_attrs | ||
β (ctx : Context) | ||
β (void_bnds : Bindings void_attrs) | ||
β ReduceCtx | ||
ctx | ||
(app (obj bnds) void_bnds) -- β¦ Οβ β¦ β , Οβ β¦ β , ... Bβ§(Οβ β¦ nβ, Οβ β¦ nβ, ...) | ||
(obj (insertAll void_bnds bnds)) -- β¦ Οβ β¦ nβ, Οβ β¦ nβ, ... B β§ todo: B β Ξ½ | ||
| r8 | ||
: { a : Attr } | ||
β { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β (ctx : Context) | ||
β a β attrs | ||
β (n : Term) | ||
β NormalForm n | ||
β IsAttached "Ο" n bnds | ||
β ReduceCtx | ||
ctx | ||
(dot (obj bnds) a) | ||
(dot n a) | ||
| r9 | ||
: { attrs : List Attr } | ||
β { bnds : Bindings attrs } | ||
β { n : Term } | ||
β (ctx : Context) | ||
β NormalForm n | ||
β ReduceCtx | ||
ctx | ||
(app (obj bnds) (Bindings.singleton "Ο" n)) -- β¦ B β§(Ο β¦ n) | ||
(obj (insert bnds "Ο" n)) -- β¦ Ο β¦ n, B β Ο β§ | ||
end |