Debian Codegraph @

test-suite/success/SchemeEquality.v

raw
1 (* -*- coq-prog-args: ("-native-compiler" "no"); -*- *)
2 (* Examples of use of Scheme Equality *)
3
4 Module A.
5 Definition N := nat.
6 Inductive list := nil | cons : N -> list -> list.
7 Scheme Equality for list.
8 End A.
9
10 Module B.
11 Section A.
12 Context A (eq_A:A->A->bool)
13 (A_bl : forall x y, eq_A x y = true -> x = y)
14 (A_lb : forall x y, x = y -> eq_A x y = true).
15 Inductive I := C : A -> I.
16 Scheme Equality for I.
17 End A.
18 End B.
19
20 Module C.
21 Parameter A : Type.
22 Parameter eq_A : A->A->bool.
23 Parameter A_bl : forall x y, eq_A x y = true -> x = y.
24 Parameter A_lb : forall x y, x = y -> eq_A x y = true.
25 #[export] Hint Resolve A_bl A_lb : core.
26 Inductive I := C : A -> I.
27 Scheme Equality for I.
28 Inductive J := D : list A -> J.
29 Scheme Equality for J.
30 End C.
31
32 (* Universe polymorphism *)
33 Module D.
34 Set Universe Polymorphism.
35 Inductive unit := tt.
36 Scheme Equality for unit.
37
38 Inductive prod (A B:Type) := pair : A -> B -> prod A B.
39 Scheme Equality for prod.
40
41 (* With an indirection *)
42 Inductive box A := c : A -> box A.
43 Inductive prodbox (A B:Type) := pairbox : box A -> box B -> prodbox A B.
44 Scheme Equality for prodbox.
45 Check eq_refl : prodbox_beq @{Set Set} =
46 fun (A B : Type@{Set}) eq_A eq_B (X Y : prodbox A B) =>
47 match X, Y with
48 | pairbox _ _ x x0, pairbox _ _ x1 x2 =>
49 (internal_box_beq A eq_A x x1 &&
50 internal_box_beq B eq_B x0 x2)%bool
51 end.
52 End D.
53
54 (* With hidden "X" and "Y" (was formerly cause of collisions) *)
55 Module E.
56 Section S.
57 Variables X Y : Type.
58 Variable eq_X : X -> X -> bool.
59 Variable eq_Y : Y -> Y -> bool.
60 Inductive EI := EC : X -> Y -> EI.
61 Scheme Boolean Equality for EI.
62 End S.
63 End E.
64
65 (* With inductive parameters instantiated by non-variable types *)
66 Module F.
67 Inductive FI := FC : list nat -> FI.
68 Scheme Boolean Equality for FI.
69
70 Inductive tree := node : list tree -> tree.
71 Scheme Boolean Equality for tree.
72
73 Inductive rose A := Leaf : A -> rose A | Node : list (rose A) -> rose A.
74 Scheme Boolean Equality for rose.
75 Print rose_beq.
76 Check eq_refl : rose_beq =
77 fun (A : Type) (eq_A : A -> A -> bool) =>
78 fix rose_eqrec (X Y : rose A) {struct X} : bool :=
79 match X with
80 | Leaf _ x => match Y with
81 | Leaf _ x0 => eq_A x x0
82 | Node _ _ => false
83 end
84 | Node _ x =>
85 match Y with
86 | Leaf _ _ => false
87 | Node _ x0 => C.internal_list_beq (rose A) rose_eqrec x x0
88 end
89 end.
90 End F.
91
92 (* With higher-order parameters and non-Type parameters *)
93 Module G.
94 Inductive GI (F:Type->Type) A := GC : F A -> F nat -> GI F A.
95 Scheme Boolean Equality for GI.
96
97 Inductive GJ (F:nat->(nat->Type->Type)->Type) (f:nat->nat) (n:nat) (A:nat->Type->Type) :=
98 GD : F 0 (fun n => list) -> F 1 A -> GJ F f n A.
99 Scheme Boolean Equality for GJ.
100 End G.
101
102 (* With local definitions in constructors *)
103 Module H.
104 Inductive HJ A : Type := HD : let a := 0 in nat -> list A -> HJ A.
105 Scheme Boolean Equality for HJ.
106 End H.
107
108 (* With recursively non-uniform arguments *)
109 Module I.
110 Inductive T A := C : A -> T (option A) -> T A.
111 Scheme Boolean Equality for T.
112 Check eq_refl : T_beq =
113 fix T_eqrec
114 (A : Type) (eq_A : A -> A -> bool)
115 (X Y : T A) {struct X} : bool :=
116 match X, Y with
117 | C _ x x0, C _ x1 x2 =>
118 (eq_A x x1 &&
119 T_eqrec (option A)
120 (internal_option_beq A eq_A) x0 x2)%bool
121 end.
122 End I.
123
124 (* With mutual definitions *)
125 Module J.
126 Inductive tree A := node : forest A -> tree A
127 with forest A := nil : forest A | cons : A -> tree A -> forest A.
128 Scheme Boolean Equality for tree.
129
130 Inductive K (F:nat->(nat->Type->Type)->Type) (A:nat->Type->Type) :=
131 D : L F A -> F 1 A -> K F A
132 with L (F:nat->(nat->Type->Type)->Type) (A:nat->Type->Type) :=
133 E : F 0 (fun n => list) -> K F A -> L F A.
134 Scheme Boolean Equality for K.
135 End J.
136
137 (* With "match" or "fix" *)
138 Module K.
139 Inductive K1 (b:bool) (F : if b then Type else Type->Type) : Type :=
140 C1 : nat -> K1 b F.
141 Scheme Boolean Equality for K1.
142
143 Inductive K2 (b:bool) (F : if b then Type else Type->Type) : Type :=
144 C2 : (if b return (if b then Type else Type->Type) -> Type
145 then fun A => A else fun F => F nat) F ->
146 K2 b F.
147 Scheme Boolean Equality for K2.
148
149 (* Almost work *)
150 Inductive K3 (n:nat) (A : Type) : Type :=
151 C3 : (fix mkprod n := match n with 0 => A | S n => (mkprod n * A)%type end) n ->
152 K3 n A.
153 Fail Scheme Boolean Equality for K3.
154 End K.
155
156 Require PrimInt63 PrimFloat.
157
158 Module ElpiTestSuite.
159
160 Inductive empty := .
161 Scheme Equality for empty.
162
163 Inductive unit := tt.
164 Scheme Equality for unit.
165
166 Inductive peano := Zero | Succ (n : peano).
167 Scheme Equality for peano.
168
169 Inductive option A := None | Some (_ : A).
170 Scheme Equality for option.
171
172 Inductive pair A B := Comma (a : A) (b : B).
173 Scheme Equality for pair.
174
175 Inductive seq A := Nil | Cons (x : A) (xs : seq A).
176 Scheme Equality for seq.
177
178 Inductive nest A := NilN | ConsN (x : A) (xs : nest (pair A A)).
179 Scheme Boolean Equality for nest.
180
181 Inductive zeta Sender (Receiver := Sender) := Envelope (a : Sender) (ReplyTo := a) (c : Receiver).
182 Scheme Boolean Equality for zeta.
183
184 Inductive beta (A : (fun x : Type => x) Type) := Redex (a : (fun x : Type => x) A).
185 Scheme Boolean Equality for beta.
186
187 Inductive large :=
188 | K1 (_ : bool)
189 | K2 (_ : bool) (_ : bool)
190 | K3 (_ : bool) (_ : bool) (_ : bool)
191 | K4 (_ : bool) (_ : bool) (_ : bool) (_ : bool)
192 | K5 (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
193 | K6 (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
194 | K7 (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
195 | K8 (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
196 | K9 (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
197 | K10(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
198 | K11(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
199 | K12(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
200 | K13(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
201 | K14(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
202 | K15(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
203 | K16(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
204 | K17(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
205 | K18(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
206 | K19(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
207 | K20(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
208 | K21(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
209 | K22(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
210 | K23(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
211 | K24(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
212 | K25(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool)
213 | K26(_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool) (_ : bool).
214 Scheme Equality for large.
215
216 Inductive prim_int := PI (i : PrimInt63.int).
217 Scheme Boolean Equality for prim_int.
218
219 Inductive prim_float := PF (f : PrimFloat.float).
220 Scheme Boolean Equality for prim_float.
221
222 Record fo_record := { f1 : peano; f2 : bool; }.
223 Scheme Equality for fo_record.
224
225 Record pa_record A := { f3 : peano; f4 : A; }.
226 Scheme Equality for pa_record.
227
228 Set Primitive Projections.
229 Record pr_record A := { pf3 : peano; pf4 : A; }.
230 Unset Primitive Projections.
231 Scheme Boolean Equality for pr_record.
232
233 Variant enum := E1 | E2 | E3.
234 Scheme Equality for enum.
235
236 End ElpiTestSuite.
237
238 (* Ignoring SProp/Prop subterms *)
239 Module L.
240 Inductive seq {A} (x:A) : A -> SProp := seq_refl : seq x x.
241 Inductive A := C : forall n, seq n 0 -> A.
242 Scheme Boolean Equality for A.
243 Check eq_refl : A_beq =
244 fun (X Y : A) =>
245 match X, Y with
246 | C n _, C n0 _ => A.internal_nat_beq n n0
247 end.
248 End L.