| 1 |
From elpi.apps Require Import derive.std derive.legacy derive.experimental. |
| 2 |
From elpi.apps Require Import test_derive_corelib. |
| 3 |
|
| 4 |
Elpi derive Coverage.empty. |
| 5 |
Elpi derive Coverage.unit. |
| 6 |
Elpi derive Coverage.peano. |
| 7 |
Elpi derive Coverage.option. |
| 8 |
Elpi derive Coverage.pair. |
| 9 |
Elpi derive Coverage.seq. |
| 10 |
Elpi derive Coverage.box_peano. |
| 11 |
Elpi derive Coverage.rose. |
| 12 |
Elpi derive Coverage.rose_p. |
| 13 |
Elpi derive Coverage.rose_o. |
| 14 |
Elpi derive Coverage.nest. |
| 15 |
Elpi derive Coverage.w. |
| 16 |
Elpi derive Coverage.vect. |
| 17 |
Elpi derive Coverage.dyn. |
| 18 |
Fail Elpi derive Coverage.zeta. |
| 19 |
Elpi derive Coverage.beta. |
| 20 |
Elpi derive Coverage.iota. |
| 21 |
(* Elpi derive Coverage.large. search slow *) |
| 22 |
Elpi derive Coverage.prim_int. |
| 23 |
Elpi derive Coverage.fo_record. |
| 24 |
Elpi derive Coverage.pa_record. |
| 25 |
Elpi derive Coverage.pr_record. |
| 26 |
Elpi derive Coverage.dep_record. |
| 27 |
Elpi derive Coverage.enum. |
| 28 |
|
| 29 |
(* ---------------------------------------------------- *) |
| 30 |
|
| 31 |
Elpi derive bool. |
| 32 |
|
| 33 |
#[verbose] Elpi derive nat. |
| 34 |
|
| 35 |
Redirect "tmp" Check nat_eqb : nat -> nat -> bool. |
| 36 |
Redirect "tmp" Check is_nat : nat -> Type. |
| 37 |
Redirect "tmp" Check is_nat_inhab : forall x, is_nat x. |
| 38 |
Redirect "tmp" Check is_nat_functor : forall x, is_nat x -> is_nat x. |
| 39 |
Redirect "tmp" Check nat_induction : forall P, P 0 -> (forall n, P n -> P (S n)) -> forall x, is_nat x -> P x. |
| 40 |
|
| 41 |
Redirect "tmp" Check nat_tag : nat -> Numbers.BinNums.positive. |
| 42 |
Redirect "tmp" Check nat_fields_t : Numbers.BinNums.positive -> Type. |
| 43 |
Redirect "tmp" Check nat_fields : forall (n:nat), nat_fields_t (nat_tag n). |
| 44 |
Redirect "tmp" Check nat_construct : forall (p: Numbers.BinNums.positive), nat_fields_t p -> option nat. |
| 45 |
Redirect "tmp" Check nat_constructP : forall (n:nat), nat_construct (nat_tag n) (nat_fields n) = Some n. |
| 46 |
Redirect "tmp" Check nat_eqb : nat -> nat -> bool. |
| 47 |
Redirect "tmp" Check nat_eqb_correct. |
| 48 |
Redirect "tmp" Check nat_eqb_refl. |
| 49 |
(* ---------------------------------------------------- *) |
| 50 |
|
| 51 |
Elpi derive.param1 andb. |
| 52 |
|
| 53 |
(* Prelude: Elpi derive list. *) |
| 54 |
|
| 55 |
Redirect "tmp" Check list_map : forall A B, (A -> B) -> list A -> list B. |
| 56 |
Redirect "tmp" Check is_nil : forall A P, is_list A P (@nil A). |
| 57 |
Redirect "tmp" Check is_cons : forall A P x (Px : P x) tl (Ptl : is_list A P tl), is_list A P (cons x tl). |
| 58 |
Redirect "tmp" Check is_list_functor : forall A P Q, (forall x, P x -> Q x) -> forall l, is_list A P l -> is_list A Q l. |
| 59 |
Redirect "tmp" Check list_induction : forall A PA P, P nil -> (forall x, PA x -> forall xs, P xs -> P (cons x xs)) -> forall l, is_list A PA l -> P l. |
| 60 |
Redirect "tmp" Check list_tag : forall A, list A -> Numbers.BinNums.positive. |
| 61 |
Redirect "tmp" Check list_fields_t : (Type -> Numbers.BinNums.positive -> Type). |
| 62 |
Redirect "tmp" Check list_fields : forall (A:Type) (l:list A), list_fields_t A (list_tag A l). |
| 63 |
Redirect "tmp" Check list_construct : forall (A:Type) (p: Numbers.BinNums.positive), list_fields_t A p -> option (list A). |
| 64 |
Redirect "tmp" Check list_constructP : forall (A:Type) (l:list A), list_construct A (list_tag A l) (list_fields A l) = Some l. |
| 65 |
Redirect "tmp" Check list_eqb : forall A, (A -> A -> bool) -> list A -> list A -> bool. |
| 66 |
Redirect "tmp" Check list_eqb_correct. |
| 67 |
Redirect "tmp" Check list_eqb_refl. |
| 68 |
(* ---------------------------------------------------- *) |
| 69 |
|
| 70 |
From Stdlib Require Vector. |
| 71 |
Elpi Print derive "elpi.apps.derive.tests/derive". |
| 72 |
#[only(eqOK), verbose] derive nat. |
| 73 |
Module Vector. |
| 74 |
derive Vector.t. |
| 75 |
End Vector. |
| 76 |
|
| 77 |
Redirect "tmp" Check Vector.t_eq : forall A, (A -> A -> bool) -> forall n, Vector.t A n -> Vector.t A n -> bool. |
| 78 |
Redirect "tmp" Check Vector.t_isk_nil : forall A n, Vector.t A n -> bool. |
| 79 |
Redirect "tmp" Check Vector.t_isk_cons : forall A n, Vector.t A n -> bool. |
| 80 |
Redirect "tmp" Check Vector.t_map : forall A B, (A -> B) -> forall n, Vector.t A n -> Vector.t B n. |
| 81 |
Redirect "tmp" Check Vector.t_getk_cons1 : forall A n, A -> forall m, Vector.t A m -> Vector.t A n -> A. |
| 82 |
Redirect "tmp" Check Vector.t_getk_cons2 : forall A n, A -> forall m, Vector.t A m -> Vector.t A n -> nat. |
| 83 |
Redirect "tmp" Check Vector.t_getk_cons3 : forall A n, A -> forall m, Vector.t A m -> Vector.t A n -> { k : nat & Vector.t A k}. |
| 84 |
Redirect "tmp" Check Vector.is_t : forall A, (A -> Type) -> forall n, is_nat n -> Vector.t A n -> Type. |
| 85 |
Redirect "tmp" Check Vector.is_nil : forall A (PA : A -> Type), Vector.is_t A PA 0 is_O (Vector.nil A). |
| 86 |
Redirect "tmp" Check Vector.is_cons : forall A (PA : A -> Type) (a : A), PA a -> forall n (Pn : is_nat n) (H : Vector.t A n), |
| 87 |
Vector.is_t A PA n Pn H -> Vector.is_t A PA (S n) (is_S n Pn) (Vector.cons A a n H). |
| 88 |
Redirect "tmp" Check Vector.is_t_functor : forall A PA QA (H : forall x, PA x -> QA x), forall n nR v, Vector.is_t A PA n nR v -> Vector.is_t A QA n nR v. |
| 89 |
Redirect "tmp" Check Vector.t_induction : forall A PA (P : forall n, is_nat n -> Vector.t A n -> Type), P 0 is_O (Vector.nil A) -> (forall a, PA a -> forall m mR, forall (v : Vector.t A m), P m mR v -> P (S m) (is_S m mR) (Vector.cons A a m v)) -> forall n nR v, Vector.is_t A PA n nR v -> P n nR v. |
| 90 |
Redirect "tmp" Check Vector.t_tag : forall A i, Vector.t A i -> Numbers.BinNums.positive. |
| 91 |
Fail Check Vector.t_fields_t : (Type -> Numbers.BinNums.positive -> Type). |
| 92 |
Fail Check Vector.t_fields : forall (A:Type) (n:nat) (l:Vector.t A n), Vector.t_fields_t A (Vector.t_tag A l). |
| 93 |
Fail Check Vector.t_construct : forall (A:Type) (p: Numbers.BinNums.positive), Vector.t_fields_t A p -> option (Vector.t A). |
| 94 |
Fail Check Vector.t_constructP : forall (A:Type) (l:Vector.t A), Vector.t_construct A (Vector.t_tag A l) (Vector.t_fields A l) = Some l. |
| 95 |
Fail Check Vector.t_eqb : forall A, (A -> A -> bool) -> forall n, Vector.t A n -> Vector.t A n -> bool. |
| 96 |
|
| 97 |
(* ---------------------------------------------------- *) |
| 98 |
|
| 99 |
Inductive W A := B (f : A -> W). |
| 100 |
|
| 101 |
Elpi derive W. |
| 102 |
(* Not implemented yet :-/ *) |
| 103 |
Fail Check W_induction : forall A (P : W A -> Type), |
| 104 |
(forall f, (forall x, UnitPred A x -> P (f x)) -> P (B A f)) -> |
| 105 |
forall x, P x. |
| 106 |
Redirect "tmp" Check W_tag : forall A, W A -> Numbers.BinNums.positive. |
| 107 |
Fail Check W_fields_t : (Type -> Numbers.BinNums.positive -> Type). |
| 108 |
Fail Check W_fields : forall (A:Type) (l:W A), W_fields_t A (W_tag A l). |
| 109 |
Fail Check W_construct : forall (A:Type) (p: Numbers.BinNums.positive), W_fields_t A p -> option (W A). |
| 110 |
Fail Check W_constructP : forall (A:Type) (l:W A), W_construct A (W_tag A l) (W_fields A l) = Some l. |
| 111 |
|
| 112 |
(* ---------------------------------------------------- *) |
| 113 |
|
| 114 |
Inductive horror A (a : A) : forall T, T -> Type := K W w (k : horror W w) : horror W w. |
| 115 |
Fail #[only(eqbOK)] derive horror. |
| 116 |
|
| 117 |
(* TODO add test for fields? *) |
| 118 |
(* ---------------------------------------------------- *) |
| 119 |
|
| 120 |
Inductive rtree A : Type := |
| 121 |
Leaf (n : A) | Node (l : list rtree). |
| 122 |
|
| 123 |
Module XXX. |
| 124 |
derive list. |
| 125 |
derive rtree. |
| 126 |
End XXX. |
| 127 |
|
| 128 |
Fail Check XXX.rtree_is_rtree_map. |
| 129 |
Redirect "tmp" Check XXX.rtree_tag : forall A, rtree A -> Numbers.BinNums.positive. |
| 130 |
Redirect "tmp" Check XXX.rtree_fields_t : (Type -> Numbers.BinNums.positive -> Type). |
| 131 |
Redirect "tmp" Check XXX.rtree_fields : forall (A:Type) (l:rtree A), XXX.rtree_fields_t A (XXX.rtree_tag A l). |
| 132 |
Redirect "tmp" Check XXX.rtree_construct : forall (A:Type) (p: Numbers.BinNums.positive), XXX.rtree_fields_t A p -> option (rtree A). |
| 133 |
Redirect "tmp" Check XXX.rtree_constructP : forall (A:Type) (l:rtree A), XXX.rtree_construct A (XXX.rtree_tag A l) (XXX.rtree_fields A l) = Some l. |
| 134 |
Redirect "tmp" Check XXX.rtree_eqb : forall (A:Type), (A -> A -> bool) -> rtree A -> rtree A -> bool. |
| 135 |
(* bug #270 *) |
| 136 |
|
| 137 |
#[module] derive |
| 138 |
Inductive triv : Coverage.unit -> Prop := |
| 139 |
| one t : triv t | more x : triv x. |
| 140 |
|
| 141 |
Redirect "tmp" Check triv.induction : |
| 142 |
forall P : (forall H : Coverage.unit, is_unit H -> triv H -> Prop), |
| 143 |
(forall t (Pt : is_unit t), P t Pt (one t)) -> |
| 144 |
(forall x (Px : is_unit x), P x Px (more x)) -> |
| 145 |
forall u (p : is_unit u) (s : triv u), triv.is_triv u p s -> P u p s. |
| 146 |
|
| 147 |
(* #271 *) |
| 148 |
derive |
| 149 |
Inductive RoseTree : Type := |
| 150 |
| RT_ctr (branches : list RoseTree). |
| 151 |
|
| 152 |
Elpi derive.param1 is_list. |
| 153 |
|
| 154 |
#[module] derive |
| 155 |
Inductive Pred : RoseTree -> Type := |
| 156 |
| Pred_ctr branches : |
| 157 |
is_list _ Pred branches -> |
| 158 |
Pred (RT_ctr branches). |
| 159 |
|
| 160 |
Redirect "tmp" Check Pred.Pred_to_Predinv : forall T, Pred T -> Pred.Predinv T. |
| 161 |
|
| 162 |
(* #286 *) |
| 163 |
Module Import derive_container. |
| 164 |
Unset Implicit Arguments. |
| 165 |
Import XXX. |
| 166 |
derive |
| 167 |
Inductive wimpls {A} `{rtree A} := Kwi (x:A) (y : x = x) : wimpls | Kwa. |
| 168 |
|
| 169 |
End derive_container. |
| 170 |
About wimpls.wimpls. |
| 171 |
About wimpls.Kwi. |
| 172 |
Redirect "tmp" Check Kwi _ (refl_equal 3). |
| 173 |
|
| 174 |
Section TestRegister. |
| 175 |
Variable T : Type. |
| 176 |
Definition is_T : T -> Type := fun x => True. |
| 177 |
Definition is_T_inhab : forall x : T, is_T x := fun x => I. |
| 178 |
Variable eqb : T -> T -> bool. |
| 179 |
Variable eqb_correct : forall x y,eqb x y = true -> x = y. |
| 180 |
Variable eqb_refl : forall x, eqb x x = true. |
| 181 |
|
| 182 |
derive.eqbOK.register_axiom T is_T is_T_inhab eqb eqb_correct eqb_refl. |
| 183 |
|
| 184 |
Inductive foo := X : T -> foo. |
| 185 |
|
| 186 |
#[only(eqbOK),verbose] derive foo. |
| 187 |
|
| 188 |
Redirect "tmp" Print foo_eqb_OK. |
| 189 |
|
| 190 |
End TestRegister. |
| 191 |
|
| 192 |
Module TestAlias. |
| 193 |
|
| 194 |
Definition nat' := nat. |
| 195 |
#[only(eqb_alias)] derive nat'. |
| 196 |
|
| 197 |
Check nat'_eqb. |
| 198 |
|
| 199 |
End TestAlias. |
| 200 |
|
| 201 |
Module TestAlias2. |
| 202 |
Definition P := nat. |
| 203 |
derive P. |
| 204 |
(* Elpi derive.eqbOK.register_axiom P is_P is_nat_inhab P_eqb P_eqb_correct P_eqb_refl. *) |
| 205 |
|
| 206 |
Definition V := nat. |
| 207 |
derive V. |
| 208 |
(* Elpi derive.eqbOK.register_axiom V is_V is_nat_inhab V_eqb V_eqb_correct V_eqb_refl. *) |
| 209 |
|
| 210 |
Inductive C := |
| 211 |
| p of P |
| 212 |
| v of V. |
| 213 |
#[verbose] derive C. |
| 214 |
End TestAlias2. |