| 1 |
From Corelib Require Import PrimInt63 PrimFloat PrimString. |
| 2 |
|
| 3 |
Register PrimString.string as elpi.pstring. |
| 4 |
|
| 5 |
From elpi_elpi Extra Dependency "elpi_elaborator.elpi" as elab. |
| 6 |
|
| 7 |
From elpi Require Import elpi. |
| 8 |
|
| 9 |
Elpi Command test.refiner. |
| 10 |
|
| 11 |
Elpi Accumulate File elab. |
| 12 |
|
| 13 |
|
| 14 |
Elpi Bound Steps 10000. |
| 15 |
(* -------------------------------------------------------------*) |
| 16 |
(* tests on full terms *) |
| 17 |
|
| 18 |
Elpi Query lp:{{ |
| 19 |
{{plus}} = global (const GR), coq.env.const GR (some B) T, |
| 20 |
of B TY RB. |
| 21 |
}}. |
| 22 |
|
| 23 |
Elpi Query lp:{{ |
| 24 |
{{plus_n_O}} = global (const GR), coq.env.const-body GR (some B), |
| 25 |
of B TY RB |
| 26 |
}}. |
| 27 |
|
| 28 |
(* -------------------------------------------------------------*) |
| 29 |
(* tests with implicit arguments *) |
| 30 |
|
| 31 |
Elpi Query lp:{{ of {{fun x : _ => x}} T R }}. |
| 32 |
|
| 33 |
Elpi Query lp:{{ of {{fun x : _ => x + 0}} T R }}. |
| 34 |
|
| 35 |
(* -------------------------------------------------------------*) |
| 36 |
(* test with universes *) |
| 37 |
|
| 38 |
Elpi Query lp:{{ coq.say {{Type}} }}. |
| 39 |
|
| 40 |
Elpi Query lp:{{ of {{Type}} S T. }}. |
| 41 |
|
| 42 |
Elpi Query lp:{{ |
| 43 |
of {{Type}} S T, of {{Type}} T W, |
| 44 |
coq.typecheck (@cast W T) TW ok |
| 45 |
}}. |
| 46 |
|
| 47 |
Elpi Query lp:{{ |
| 48 |
X = {{Type}}, |
| 49 |
std.assert! (not (of X X _)) "Universe inconsistent" |
| 50 |
}}. |
| 51 |
|
| 52 |
Elpi Accumulate lp:{{ |
| 53 |
pred fresh-ty o:term. |
| 54 |
fresh-ty X :- X = {{Type}}. |
| 55 |
}}. |
| 56 |
Elpi Query lp:{{ |
| 57 |
fresh-ty X, fresh-ty Y, of X Y _. |
| 58 |
}}. |
| 59 |
|
| 60 |
(* -------------------------------------------------------------*) |
| 61 |
(* tests with HO unification *) |
| 62 |
|
| 63 |
Axiom p : 0 = 0. |
| 64 |
|
| 65 |
Elpi Query lp:{{ |
| 66 |
of {{ @ex_intro _ _ _ p }} TY R, |
| 67 |
!, std.assert! (TY = |
| 68 |
app [ {{ex}}, D, (fun _ D x0 \ {{@eq nat 0 0}})]) "No skipping flex args". |
| 69 |
}}. |
| 70 |
|
| 71 |
Elpi Query lp:{{ |
| 72 |
get-option "unif:greedy" tt => ( |
| 73 |
of {{ @ex_intro _ _ 0 p }} TY R, |
| 74 |
!, std.assert! (TY = {{ @ex nat (fun n : nat => @eq nat n n) }}) "Not greedy" |
| 75 |
). |
| 76 |
}}. |
| 77 |
|
| 78 |
Elpi Query lp:{{ |
| 79 |
of {{ exists n : nat, n = 0 }} _ TY, |
| 80 |
std.assert! (of {{ @ex_intro _ _ 0 p }} TY R) "Not searching all solutions". |
| 81 |
}}. |
| 82 |
|
| 83 |
Elpi Accumulate lp:{{ |
| 84 |
:before "of:bidirectional-app" % Like declaring an Arguments directive |
| 85 |
bidir-app {{ex_intro}} Prod [_, _] Ty :- |
| 86 |
saturate-dummy Prod Ty1, unify-leq Ty1 Ty, !. |
| 87 |
}}. |
| 88 |
|
| 89 |
Elpi Query lp:{{ |
| 90 |
get-option "unif:greedy" tt => ( |
| 91 |
of {{ exists n : nat, n = 0 }} _ TY, |
| 92 |
std.assert! (of {{ @ex_intro _ _ 0 p }} TY R) "Not bidirectional" |
| 93 |
). |
| 94 |
}}. |
| 95 |
|
| 96 |
(* -------------------------------------------------------------*) |
| 97 |
(* tests with coercions *) |
| 98 |
|
| 99 |
Elpi Query lp:{{ {{bool}} = global (indt GR), coq.env.indt GR A B C D E F }}. |
| 100 |
|
| 101 |
Axiom nat_of_bool : bool -> nat. |
| 102 |
|
| 103 |
Elpi Accumulate lp:{{ |
| 104 |
pred coercible o:term, o:term, o:term, o:term. |
| 105 |
coerce {{bool}} {{nat}} X {{nat_of_bool lp:X}}. |
| 106 |
coerced {{bool}} {{nat}} X {{nat_of_bool lp:X}}. |
| 107 |
coercible {{bool}} {{nat}} X {{nat_of_bool lp:X}}. |
| 108 |
}}. |
| 109 |
|
| 110 |
Elpi Query lp:{{get-option "of:coerce" tt => (of {{true}} {{nat}} F).}}. |
| 111 |
|
| 112 |
Axiom map : forall A B (F : A -> B), list A -> list B. |
| 113 |
Open Scope list_scope. |
| 114 |
|
| 115 |
Elpi Accumulate lp:{{ |
| 116 |
coerced {{list lp:X}} {{list lp:Y}} L R :- |
| 117 |
(pi x\ coerced X Y x (F x)), |
| 118 |
coq.say F, |
| 119 |
R = app[{{map}},X,Y,fun `x` X F,L]. |
| 120 |
}}. |
| 121 |
|
| 122 |
Elpi Query lp:{{get-option "of:coerce" tt => |
| 123 |
(of {{true :: nil}} {{list nat}} Res). |
| 124 |
}}. |
| 125 |
|
| 126 |
Axiom Z : Type. |
| 127 |
Axiom Z_of_nat : nat -> Z. |
| 128 |
|
| 129 |
Elpi Accumulate lp:{{ |
| 130 |
coerce {{nat}} {{Z}} X {{Z_of_nat lp:X}}. |
| 131 |
coerced {{nat}} {{Z}} X {{Z_of_nat lp:X}}. |
| 132 |
coercible {{nat}} {{Z}} X {{Z_of_nat lp:X}}. |
| 133 |
coerced X Y T F :- not(var X), not(var Y), |
| 134 |
coercible X Mid T FT, coerced Mid Y FT F. |
| 135 |
}}. |
| 136 |
|
| 137 |
Elpi Query lp:{{get-option "of:coerce" tt => (of {{true}} {{Z}} Res). }}. |
| 138 |
|
| 139 |
Elpi Query lp:{{get-option "of:coerce" tt => |
| 140 |
(of {{true :: nil}} {{list Z}} Res). |
| 141 |
}}. |
| 142 |
|
| 143 |
Axiom ring : Type. |
| 144 |
Axiom carr : ring -> Type. |
| 145 |
|
| 146 |
Elpi Accumulate lp:{{ |
| 147 |
coerce {{ring}} (sort _) X {{carr lp:X}}. |
| 148 |
coerced {{ring}} (sort _) X {{carr lp:X}}. |
| 149 |
coercible {{ring}} (sort _) X {{carr lp:X}}. |
| 150 |
}}. |
| 151 |
|
| 152 |
Elpi Query lp:{{get-option "of:coerce" tt => |
| 153 |
(of {{forall r : ring, forall x : r, x = x}} T R). |
| 154 |
}}. |
| 155 |
|
| 156 |
(* primitive *) |
| 157 |
From Corelib Require Import PrimInt63. |
| 158 |
Elpi Query lp:{{ of {{ 99%uint63 }} T X }}. |
| 159 |
Elpi Query lp:{{ of {{ 99.3e4%float }} T X }}. |
| 160 |
Elpi Query lp:{{ whd1 {{ PrimInt63.add 99 1 }} {{ 100%uint63 }} }}. |
| 161 |
Elpi Query lp:{{ not(whd1 {{ PrimInt63.add 99 _ }} _) }}. |