Elpi, the extension language for your ITP Enrico Tassi Deducteam - - PowerPoint PPT Presentation

elpi the extension language for your itp
SMART_READER_LITE
LIVE PREVIEW

Elpi, the extension language for your ITP Enrico Tassi Deducteam - - PowerPoint PPT Presentation

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,


slide-1
SLIDE 1

Elpi, the extension language for your ITP

Enrico Tassi Deducteam seminars - 2020

slide-2
SLIDE 2

Feb 20, 2020 Enrico Tassi

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

slide-3
SLIDE 3

Feb 20, 2020 Enrico Tassi

Outline

  • Elpi 101

– ,Prolog 101: type checker for ,→ – ,Prolog + CHR 101: even & odd

  • POC: Deducti + Elpi
  • Example of a Coq-Elpi based tool
slide-4
SLIDE 4

Feb 20, 2020 Enrico Tassi

,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

slide-5
SLIDE 5

Feb 20, 2020 Enrico Tassi

,Prolog 101

pred of i:term, o:ty.

  • f (app H A) T :-
  • f H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T. % Convention X % universally quantified around the rule Xi % not quantified (existentially quantified, globally)

slide-6
SLIDE 6

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f (lam x\ lam y\ app x y) Q0.

Q0 = ... Program Goal Assignments

slide-7
SLIDE 7

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 S1.
  • f ((x\ lam y\ app x y) c1) T1.

Q0 = arrow S1 T1 F1 = (x\ lam y\ app x y) Program Goal Assignments

slide-8
SLIDE 8

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 S1.
  • f (lam y\ app c1 y) T1.

Q0 = arrow S1 T1 F1 = (x\ lam y\ app x y) Program Goal Assignments

slide-9
SLIDE 9

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 S1.
  • f c2 S2.
  • f ((y\ app c1 y) c2) T2.

Q0 = arrow S1 (arrow S2 T2) F1 = (x\ lam y\ app x y) F2 = (y\ app c1 y) Program Goal Assignments

slide-10
SLIDE 10

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 S1.
  • f c2 S2.
  • f (app c1 c2) T2.

Q0 = arrow S1 (arrow S2 T2) F1 = (x\ lam y\ app x y) F2 = (y\ app c1 y) Program Goal Assignments

slide-11
SLIDE 11

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 S1.
  • f c2 S2.
  • f c1 (arrow S3 T2).
  • f c2 S3.

Q0 = arrow S1 (arrow S2 T2) F1 = (x\ lam y\ app x y) F2 = (y\ app c1 y) H3 = c1 A3 = c2 Program Goal Assignments

slide-12
SLIDE 12

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 (arrow S3 T2).
  • f c2 S2.
  • f c2 S3.

Q0 = arrow (arrow S3 T2) (arrow S2 T2) F1 = (x\ lam y\ app x y) F2 = (y\ app c1 y) H3 = c1 S1 = (arrow S3 T2) A3 = c2 Program Goal Assignments

slide-13
SLIDE 13

Feb 20, 2020 Enrico Tassi

,Prolog 101

  • f (app H A) T :- of H (arrow S T), of A S.
  • f (lam F) (arrow S T) :-

pi x\ of x S => of (F x) T.

  • f c1 (arrow S2 T2).
  • f c2 S2.

Q0 = arrow (arrow S2 T2) (arrow S2 T2) F1 = (x\ lam y\ app x y) F2 = (y\ app c1 y) H3 = c1 S1 = (arrow S3 T2) A3 = c2 S3 = S2 Program Goal Assignments

slide-14
SLIDE 14

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

g Goals rule “c” \ “d” | t <=> “g”. CHR “c”X “d”Y Constraints g :- g , ... g :- new_constraint c [X] … X = t … Clauses

1 2 3 1 2 3 4 4 4 4

dY

meta level PL level

slide-15
SLIDE 15

Feb 20, 2020 Enrico Tassi

,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.

  • dd (succ X) :- even X.

even (succ X) :- odd X. even X :- var X, new_constraint (even X) [X].

  • dd 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). }

slide-16
SLIDE 16

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

even X X = succ Y not (double Z Y) Program Goals (even X) (odd X) <=> fail. (double _ X) <=> (even X). Rules Constraint store even X, X = succ Y, not (double Z Y)

slide-17
SLIDE 17

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

X = succ Y not (double Z Y) Program Goals Rules even f

X

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-18
SLIDE 18

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

even (succ Y) not (double Z Y) Program Goals Rules Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-19
SLIDE 19

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

  • dd Y

not (double Z Y) Program Goals Rules Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-20
SLIDE 20

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

not (double Z Y) Program Goals Rules

  • dd f

Y

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-21
SLIDE 21

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

not ( ) Program Goals Rules

  • dd f

Y

double f

Z f Y

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-22
SLIDE 22

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

not (even Y) Program Goals Rules

  • dd f

Y

double f

Z f Y

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-23
SLIDE 23

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

not ( ) Program Goals Rules

  • dd f

Y

double f

Z f Y

even f

Y

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-24
SLIDE 24

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

not ( fail ) Program Goals Rules Constraint store

  • dd f

Y

double f

Z f Y

even f

Y

even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-25
SLIDE 25

Feb 20, 2020 Enrico Tassi

,Prolog + CHR 101

even zero.

  • dd (succ X) :- even X.

even (succ X) :- odd X.

even X :- var X, new_constraint (even X) [X].

  • dd 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].

Program Goals Rules

  • dd f

Y

Constraint store even X, X = succ Y, not (double Z Y) (even X) (odd X) <=> fail. (double _ X) <=> (even X).

slide-26
SLIDE 26

Feb 20, 2020 Enrico Tassi

Elpi = ,Prolog + CHR

  • ,Prolog for …

 backward reasoning, search ✔ programming with binders recursively

  • CHR for …

 forward reasoning ✔ manipulate (frozen) unification variables ✔ handle metadata on unification variables

slide-27
SLIDE 27

Feb 20, 2020 Enrico Tassi

What about Deducti

https://github.com/Deducteam/lambdapi/pull/418

  • Demo
  • Code overview
slide-28
SLIDE 28

Feb 20, 2020 Enrico Tassi

What about Coq-Elpi

https://github.com/LPCIC/coq-elpi/

  • Coq’s syntax

predicate {{ nat → lp:X }} :- use X, print {{ bool → lp:X }}.

  • Coq’s API

$ grep pred coq-builtin.elpi | wc -l

102

$ grep pred coq-lib.elpi | wc -l

37

  • Coq’s vernacular commands:

Elpi Command foo

Elpi Tactic bar

  • Hierarchy Builder (example)
slide-29
SLIDE 29

Feb 20, 2020 Enrico Tassi

Thanks!

  • Questions?