Elpi, the extension language for your ITP Enrico Tassi Deducteam seminars - 2020
This talk is about Elpi, that is... ● An extension language – its interpreter comes as a library – with an API/FFI to write glue code ● A very high level, domain specific, language – Data with binders – Data with unification variables ● LGPL, by C.Sacerdoti Coen and myself Elpi = �Prolog + CHR Enrico Tassi Feb 20, 2020
Outline ● Elpi 101 – ,Prolog 101: type checker for , → – ,Prolog + CHR 101: even & odd ● POC: Deducti + Elpi ● Example of a Coq-Elpi based tool Enrico Tassi Feb 20, 2020
,Prolog 101 % HOAS of terms type app term → term → term. type lam (term → term) → term. % HOAS of types type arrow ty → ty → ty. % Example: identity function lam (x\ x) % Example: fst lam x\ lam y\ x Enrico Tassi Feb 20, 2020
,Prolog 101 pred of i:term, o:ty. of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. % Convention X % universally quantified around the rule X i % not quantified (existentially quantified, globally) Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of (lam x\ lam y\ app x y) Q 0 . of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. Assignments Q 0 = ... Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of ((x\ lam y\ app x y) c 1 ) T 1. of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 S 1 . Assignments Q 0 = arrow S 1 T 1 F 1 = (x\ lam y\ app x y) Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of (lam y\ app c 1 y) T 1. of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 S 1 . Assignments Q 0 = arrow S 1 T 1 F 1 = (x\ lam y\ app x y) Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of ((y\ app c 1 y) c 2 ) T 2. of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 S 1 . of c 2 S 2 . Assignments Q 0 = arrow S 1 (arrow S 2 T 2 ) F 1 = (x\ lam y\ app x y) F 2 = (y\ app c 1 y) Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of (app c 1 c 2 ) T 2. of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 S 1 . of c 2 S 2 . Assignments Q 0 = arrow S 1 (arrow S 2 T 2 ) F 1 = (x\ lam y\ app x y) F 2 = (y\ app c 1 y) Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of c 1 (arrow S 3 T 2 ). of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- of c 2 S 3 . pi x\ of x S => of (F x) T. of c 1 S 1 . of c 2 S 2 . Assignments Q 0 = arrow S 1 (arrow S 2 T 2 ) F 1 = (x\ lam y\ app x y) F 2 = (y\ app c 1 y) H 3 = c 1 A 3 = c 2 Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of c 2 S 3 . of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 (arrow S 3 T 2 ). of c 2 S 2 . Assignments Q 0 = arrow (arrow S 3 T 2 ) (arrow S 2 T 2 ) F 1 = (x\ lam y\ app x y) F 2 = (y\ app c 1 y) H 3 = c 1 S 1 = (arrow S 3 T 2 ) A 3 = c 2 Enrico Tassi Feb 20, 2020
,Prolog 101 Goal Program of (app H A) T :- of H (arrow S T), of A S. of (lam F) (arrow S T) :- pi x\ of x S => of (F x) T. of c 1 (arrow S 2 T 2 ). of c 2 S 2 . Assignments Q 0 = arrow (arrow S 2 T 2 ) (arrow S 2 T 2 ) F 1 = (x\ lam y\ app x y) F 2 = (y\ app c 1 y) H 3 = c 1 S 1 = (arrow S 3 T 2 ) A 3 = c 2 S 3 = S 2 Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 PL level Goals 1 g 4 Clauses g :- g , ... CHR 1 g :- new_constraint c [X] 2 rule “c” \ “d” | t <=> “g”. 3 4 … X = t … 3 “c” X 2 “d” Y 4 4 Constraints d Y meta level Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 type zero nat. type succ nat -> nat. pred odd i:nat. pred even i:nat. pred double i:nat, o:nat. even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. double X Y :- var X, new_constraint (double X Y) [X]. constraint even odd double { rule (even X) (odd X) <=> fail. rule (double _ X) <=> (even X). } Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program even X even zero. X = succ Y odd (succ X) :- even X. not (double Z Y) even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program X = succ Y even zero. not (double Z Y) odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. even f X Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program even (succ Y) even zero. not (double Z Y) odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program odd Y even zero. not (double Z Y) odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program not (double Z Y) even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program not ( ) even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y double f Z f Rules Y (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program not (even Y) even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y double f Z f Rules Y (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program not ( ) even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y double f Z f Rules Y even f Y (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program not ( fail ) even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y double f Z f Rules Y even f Y (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
,Prolog + CHR 101 even X, X = succ Y, not (double Z Y) Goals Program even zero. odd (succ X) :- even X. even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X]. odd X :- var X, new_constraint (odd X) [X]. double zero zero. double (succ X) (succ (succ Y)) :- double X Y. Constraint store double X Y :- var X, new_constraint (double X Y) [X]. odd f Y Rules (even X) (odd X) <=> fail. (double _ X) <=> (even X). Enrico Tassi Feb 20, 2020
Recommend
More recommend