Debian Codegraph @

examples/example_curry_howard_tactics.v

raw
1 From elpi Require Import elpi.
2
3 (* Tactics
4
5 The entry point of a tactic is called solve
6 and the goal is made of a proof context, a type
7 to inhabit and the corresponding evar to assign *)
8
9 Elpi Tactic id.
10 Elpi Accumulate lp:{{
11 solve (goal Ctx Ev Ty _ _) _ :-
12 coq.say "goal" Ev "is\n" Ctx "\n-------\n" Ty.
13 }}.
14
15
16
17 Lemma l0 x y z (H : x < y) : y < z -> x < z.
18 Proof.
19 elpi id.
20 Abort.
21
22 (* Things are wired up in such a way that assigning a
23 "wrong" value to Ev fails *)
24
25 Elpi Tactic silly.
26 Elpi Accumulate lp:{{
27 solve (goal _ Ev _ _ _) _ :- Ev = {{true}}.
28 solve (goal _ Ev _ _ _) _ :- Ev = {{3}}.
29 }}.
30
31
32 Lemma l1 : nat.
33 Proof.
34 elpi silly.
35 Show Proof.
36 Qed.
37
38 (* Now we write "intro" in Curry-Howard style *)
39
40 Elpi Tactic intro.
41 Elpi Accumulate lp:{{
42 solve (goal _ _ _ _ [str S] as G) GS :-
43 coq.string->name S N,
44 refine (fun N Src_ Tgt_) G GS.
45 }}.
46
47
48 Lemma l2 x y z (H : x < y) : y < z -> x < z.
49 Proof.
50 elpi intro H1.
51 Abort.
52
53 (* Now let's write a little automation *)
54
55 Elpi Tactic auto.
56 Elpi Accumulate lp:{{
57 shorten coq.ltac.{ open , or , repeat }.
58
59 pred intro i:name, i:goal, o:list sealed-goal.
60 intro S G GS :- refine (fun S Src_ Tgt_) G GS.
61
62 % Ex falso
63 pred exf i:goal, o:list sealed-goal.
64 exf (goal Ctx _ Ty _ _ as G) [] :-
65 std.exists Ctx (x\ sigma w\ x = decl V w {{False}}),
66 refine {{ match lp:V in False return lp:Ty with end }} G [].
67
68 % Constructor
69 pred kon i:goal, o:list sealed-goal.
70 kon (goal _ _ Ty _ _ as G) GS :-
71 coq.safe-dest-app Ty (global (indt GR)) _,
72 coq.env.indt GR _ _ _ _ Ks Kt,
73 std.exists2 Ks Kt (k\ t\
74 coq.saturate t (global (indc k)) P,
75 refine P G GS).
76
77 % entry point; we assert no goals are left
78 solve G [] :-
79 repeat (or [open exf, open kon, open (intro `H`)]) (seal G) [].
80
81 }}.
82
83
84 Lemma l3 : forall P : Prop, (False -> P) /\ (False \/ True).
85 Proof.
86 elpi auto.
87 Qed.
88
89
90