| 1 |
From Stdlib Require Import Bool. |
| 2 |
From elpi.apps Require Import tc. |
| 3 |
|
| 4 |
Class Eqb (T: Type) := { |
| 5 |
eqb : T -> T -> bool; |
| 6 |
eqb_leibniz A B: eqb A B = true <-> A = B |
| 7 |
}. |
| 8 |
|
| 9 |
#[refine] Instance eqBool : Eqb bool := { |
| 10 |
eqb x y := if x then y else negb y |
| 11 |
}. |
| 12 |
Proof. intros [] []; intuition. Qed. |
| 13 |
|
| 14 |
#[refine] Instance eqProd (A B : Type) : Eqb A -> Eqb B -> Eqb (A * B) := { |
| 15 |
eqb x y := eqb (fst x) (fst y) && eqb (snd x) (snd y) |
| 16 |
}. |
| 17 |
Proof. |
| 18 |
intros [] []. split. intros; simpl in H. |
| 19 |
* case (eqb a a0) eqn:aB, (eqb b b0) eqn:bB; try easy. |
| 20 |
apply pair_equal_spec; destruct e, e0; split. |
| 21 |
apply eqb_leibniz0; auto. |
| 22 |
apply eqb_leibniz1; auto. |
| 23 |
* intros. apply pair_equal_spec in H; destruct H; subst. simpl. |
| 24 |
apply andb_true_intro; destruct e, e0; split. |
| 25 |
apply eqb_leibniz0; auto. |
| 26 |
apply eqb_leibniz1; auto. |
| 27 |
Qed. |
| 28 |
|
| 29 |
TC.Print_instances. |
| 30 |
TC.Get_class_info Eqb. |
| 31 |
|
| 32 |
(* Abstraction of elpi context variable *) |
| 33 |
Section Foo. |
| 34 |
Variable (A B: Type) (HA : Eqb A) (HB : Eqb B). |
| 35 |
#[refine] Global Instance eqProd' : Eqb (A * B) := { |
| 36 |
eqb x y := eqb (fst x) (fst y) && eqb (snd x) (snd y) |
| 37 |
}. |
| 38 |
Proof. |
| 39 |
intros [] []; simpl; split; intros. |
| 40 |
apply eqb_leibniz. destruct H. |
| 41 |
replace (eqb (a, b) (a0, b0)) with (eqb a a0 && eqb b b0); auto. admit. |
| 42 |
apply andb_true_intro; apply pair_equal_spec in H; split; |
| 43 |
apply eqb_leibniz; easy. |
| 44 |
Admitted. |
| 45 |
|
| 46 |
(* Here we see that HA and HB are compiled in elpi since their type is a class *) |
| 47 |
TC.Print_instances Eqb. |
| 48 |
|
| 49 |
(* The rules for eqProd' is as follows |
| 50 |
|
| 51 |
shorten tc-tutorial.{tc-Eqb}. |
| 52 |
tc-Eqb {{prod A B}} {{eqProd'}}. |
| 53 |
|
| 54 |
Remark: Here A and B are not elpi variables, but the coq variables from the |
| 55 |
context |
| 56 |
*) |
| 57 |
|
| 58 |
Elpi Print TC.Solver "elpi.apps.tc.examples/TC.Solver". |
| 59 |
End Foo. |
| 60 |
|
| 61 |
(* |
| 62 |
On section end the local instances are removed (i.e. HA and HB disappears) |
| 63 |
and eqProd' is recompiled |
| 64 |
*) |
| 65 |
TC.Print_instances Eqb. |
| 66 |
(* |
| 67 |
the rules for eqProd' is as follows |
| 68 |
|
| 69 |
shorten tc-tutorial.{tc-Eqb}. |
| 70 |
tc-Eqb {{prod lp:A lp:B}} {{eqProd' lp:A lp:B lp:PA lp:PB}} :- |
| 71 |
tc-Eqb A PA, tc-Eqb B PB. |
| 72 |
|
| 73 |
Remark: Here A and B are elpi variables and PA, PB are the proof that we can |
| 74 |
prove {{Eqb lp:A}} and {{Eqb lp:B}} |
| 75 |
*) |
| 76 |
|
| 77 |
TC.Get_class_info Eqb. |
| 78 |
|
| 79 |
Module Backtrack. |
| 80 |
Elpi TC Solver Override TC.Solver All. |
| 81 |
Class NoBacktrack (n: nat). |
| 82 |
TC.Set_deterministic NoBacktrack. |
| 83 |
Class A (n: nat). |
| 84 |
|
| 85 |
Instance a0 : A 0. Qed. |
| 86 |
Instance nb0 : NoBacktrack 0. Qed. |
| 87 |
Instance nb1 : NoBacktrack 1. Qed. |
| 88 |
Instance a3 n : NoBacktrack n -> A n -> A 3. Qed. |
| 89 |
|
| 90 |
Goal A 3. Fail apply _. Abort. |
| 91 |
|
| 92 |
Elpi Print TC.Solver "elpi.apps.tc.examples/TC.Solver". |
| 93 |
End Backtrack. |
| 94 |
|
| 95 |
TC.Print_instances. |
| 96 |
(* Require Stdlib *) |
| 97 |
(* TC.Get_class_info DecidableClass.Decidable. *) |