~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to test-suite/success/Cases.v

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(****************************************************************************)
 
2
(* Pattern-matching when non inductive terms occur                          *)
 
3
 
 
4
(* Dependent form of annotation *)
 
5
Type match 0 as n, eq return nat with
 
6
     | O, x => 0
 
7
     | S x, y => x
 
8
     end.
 
9
Type match 0, eq, 0 return nat with
 
10
     | O, x, y => 0
 
11
     | S x, y, z => x
 
12
     end.
 
13
Type match 0, eq, 0 return _ with
 
14
     | O, x, y => 0
 
15
     | S x, y, z => x
 
16
     end.
 
17
 
 
18
(* Non dependent form of annotation *)
 
19
Type match 0, eq return nat with
 
20
     | O, x => 0
 
21
     | S x, y => x
 
22
     end.
 
23
 
 
24
(* Combining dependencies and non inductive arguments *)
 
25
Type
 
26
  (fun (A : Set) (a : A) (H : 0 = 0) =>
 
27
   match H in (_ = x), a return (H = H) with
 
28
   | _, _ => refl_equal H
 
29
   end).
 
30
 
 
31
(* Interaction with coercions *)
 
32
Parameter bool2nat : bool -> nat.
 
33
Coercion bool2nat : bool >-> nat.
 
34
Check (fun x => match x with
 
35
                | O => true
 
36
                | S _ => 0
 
37
                end:nat).
 
38
 
 
39
(****************************************************************************)
 
40
(* All remaining examples come from Cristina Cornes' V6 TESTS/MultCases.v   *)
 
41
 
 
42
Inductive IFExpr : Set :=
 
43
  | Var : nat -> IFExpr
 
44
  | Tr : IFExpr
 
45
  | Fa : IFExpr
 
46
  | IfE : IFExpr -> IFExpr -> IFExpr -> IFExpr.
 
47
 
 
48
Inductive List (A : Set) : Set :=
 
49
  | Nil : List A
 
50
  | Cons : A -> List A -> List A.
 
51
 
 
52
Inductive listn : nat -> Set :=
 
53
  | niln : listn 0
 
54
  | consn : forall n : nat, nat -> listn n -> listn (S n).
 
55
 
 
56
Inductive Listn (A : Set) : nat -> Set :=
 
57
  | Niln : Listn A 0
 
58
  | Consn : forall n : nat, nat -> Listn A n -> Listn A (S n).
 
59
 
 
60
Inductive Le : nat -> nat -> Set :=
 
61
  | LeO : forall n : nat, Le 0 n
 
62
  | LeS : forall n m : nat, Le n m -> Le (S n) (S m).
 
63
 
 
64
Inductive LE (n : nat) : nat -> Set :=
 
65
  | LE_n : LE n n
 
66
  | LE_S : forall m : nat, LE n m -> LE n (S m).
 
67
 
 
68
Require Import Bool.
 
69
 
 
70
 
 
71
 
 
72
Inductive PropForm : Set :=
 
73
  | Fvar : nat -> PropForm
 
74
  | Or : PropForm -> PropForm -> PropForm.
 
75
 
 
76
Section testIFExpr.
 
77
Definition Assign := nat -> bool.
 
78
Parameter Prop_sem : Assign -> PropForm -> bool.
 
79
 
 
80
Type
 
81
  (fun (A : Assign) (F : PropForm) =>
 
82
   match F return bool with
 
83
   | Fvar n => A n
 
84
   | Or F G => Prop_sem A F || Prop_sem A G
 
85
   end).
 
86
 
 
87
Type
 
88
  (fun (A : Assign) (H : PropForm) =>
 
89
   match H return bool with
 
90
   | Fvar n => A n
 
91
   | Or F G => Prop_sem A F || Prop_sem A G
 
92
   end).
 
93
End testIFExpr.
 
94
 
 
95
 
 
96
 
 
97
Type (fun x : nat => match x return nat with
 
98
                     | O => 0
 
99
                     | x => x
 
100
                     end).
 
101
 
 
102
Section testlist.
 
103
Parameter A : Set.
 
104
Inductive list : Set :=
 
105
  | nil : list
 
106
  | cons : A -> list -> list.
 
107
Parameter inf : A -> A -> Prop.
 
108
 
 
109
 
 
110
Definition list_Lowert2 (a : A) (l : list) :=
 
111
  match l return Prop with
 
112
  | nil => True
 
113
  | cons b l => inf a b
 
114
  end.
 
115
 
 
116
Definition titi (a : A) (l : list) :=
 
117
  match l return list with
 
118
  | nil => l
 
119
  | cons b l => l
 
120
  end.
 
121
Reset list.
 
122
End testlist.
 
123
 
 
124
 
 
125
(* To test translation *)
 
126
(* ------------------- *)
 
127
 
 
128
 
 
129
Type match 0 return nat with
 
130
     | O => 0
 
131
     | _ => 0
 
132
     end.
 
133
 
 
134
Type match 0 return nat with
 
135
     | O as b => b
 
136
     | S O => 0
 
137
     | S (S x) => x
 
138
     end.
 
139
 
 
140
Type match 0 with
 
141
     | O as b => b
 
142
     | S O => 0
 
143
     | S (S x) => x
 
144
     end.
 
145
 
 
146
 
 
147
Type (fun x : nat => match x return nat with
 
148
                     | O as b => b
 
149
                     | S x => x
 
150
                     end).
 
151
 
 
152
Type (fun x : nat => match x with
 
153
                     | O as b => b
 
154
                     | S x => x
 
155
                     end).
 
156
 
 
157
Type match 0 return nat with
 
158
     | O as b => b
 
159
     | S x => x
 
160
     end.
 
161
 
 
162
Type match 0 return nat with
 
163
     | x => x
 
164
     end.
 
165
 
 
166
Type match 0 with
 
167
     | x => x
 
168
     end.
 
169
 
 
170
Type match 0 return nat with
 
171
     | O => 0
 
172
     | S x as b => b
 
173
     end.
 
174
 
 
175
Type (fun x : nat => match x return nat with
 
176
                     | O => 0
 
177
                     | S x as b => b
 
178
                     end).
 
179
 
 
180
Type (fun x : nat => match x with
 
181
                     | O => 0
 
182
                     | S x as b => b
 
183
                     end).
 
184
 
 
185
 
 
186
Type match 0 return nat with
 
187
     | O => 0
 
188
     | S x => 0
 
189
     end.
 
190
 
 
191
 
 
192
Type match 0 return (nat * nat) with
 
193
     | O => (0, 0)
 
194
     | S x => (x, 0)
 
195
     end.
 
196
 
 
197
Type match 0 with
 
198
     | O => (0, 0)
 
199
     | S x => (x, 0)
 
200
     end.
 
201
 
 
202
Type
 
203
  match 0 return (nat -> nat) with
 
204
  | O => fun n : nat => 0
 
205
  | S x => fun n : nat => 0
 
206
  end.
 
207
 
 
208
Type match 0 with
 
209
     | O => fun n : nat => 0
 
210
     | S x => fun n : nat => 0
 
211
     end.
 
212
 
 
213
 
 
214
Type
 
215
  match 0 return (nat -> nat) with
 
216
  | O => fun n : nat => 0
 
217
  | S x => fun n : nat => x + n
 
218
  end.
 
219
 
 
220
Type match 0 with
 
221
     | O => fun n : nat => 0
 
222
     | S x => fun n : nat => x + n
 
223
     end.
 
224
 
 
225
 
 
226
Type match 0 return nat with
 
227
     | O => 0
 
228
     | S x as b => b + x
 
229
     end.
 
230
 
 
231
Type match 0 return nat with
 
232
     | O => 0
 
233
     | S a as b => b + a
 
234
     end.
 
235
Type match 0 with
 
236
     | O => 0
 
237
     | S a as b => b + a
 
238
     end.
 
239
 
 
240
 
 
241
Type match 0 with
 
242
     | O => 0
 
243
     | _ => 0
 
244
     end.
 
245
 
 
246
Type match 0 return nat with
 
247
     | O => 0
 
248
     | x => x
 
249
     end.
 
250
 
 
251
Type match 0, 1 return nat with
 
252
     | x, y => x + y
 
253
     end.
 
254
 
 
255
Type match 0, 1 with
 
256
     | x, y => x + y
 
257
     end.
 
258
 
 
259
Type match 0, 1 return nat with
 
260
     | O, y => y
 
261
     | S x, y => x + y
 
262
     end.
 
263
 
 
264
Type match 0, 1 with
 
265
     | O, y => y
 
266
     | S x, y => x + y
 
267
     end.
 
268
 
 
269
 
 
270
Type match 0, 1 return nat with
 
271
     | O, x => x
 
272
     | S y, O => y
 
273
     | x, y => x + y
 
274
     end.
 
275
 
 
276
 
 
277
 
 
278
 
 
279
Type match 0, 1 with
 
280
     | O, x => x + 0
 
281
     | S y, O => y + 0
 
282
     | x, y => x + y
 
283
     end.
 
284
 
 
285
Type
 
286
  match 0, 1 return nat with
 
287
  | O, x => x + 0
 
288
  | S y, O => y + 0
 
289
  | x, y => x + y
 
290
  end.
 
291
 
 
292
 
 
293
Type
 
294
  match 0, 1 return nat with
 
295
  | O, x => x
 
296
  | S x as b, S y => b + x + y
 
297
  | x, y => x + y
 
298
  end.
 
299
 
 
300
 
 
301
Type
 
302
  match 0, 1 with
 
303
  | O, x => x
 
304
  | S x as b, S y => b + x + y
 
305
  | x, y => x + y
 
306
  end.
 
307
 
 
308
 
 
309
Type
 
310
  (fun l : List nat =>
 
311
   match l return (List nat) with
 
312
   | Nil => Nil nat
 
313
   | Cons a l => l
 
314
   end).
 
315
 
 
316
Type (fun l : List nat => match l with
 
317
                          | Nil => Nil nat
 
318
                          | Cons a l => l
 
319
                          end).
 
320
 
 
321
Type match Nil nat return nat with
 
322
     | Nil => 0
 
323
     | Cons a l => S a
 
324
     end.
 
325
Type match Nil nat with
 
326
     | Nil => 0
 
327
     | Cons a l => S a
 
328
     end.
 
329
 
 
330
Type match Nil nat return (List nat) with
 
331
     | Cons a l => l
 
332
     | x => x
 
333
     end.
 
334
 
 
335
Type match Nil nat with
 
336
     | Cons a l => l
 
337
     | x => x
 
338
     end.
 
339
 
 
340
Type
 
341
  match Nil nat return (List nat) with
 
342
  | Nil => Nil nat
 
343
  | Cons a l => l
 
344
  end.
 
345
 
 
346
Type match Nil nat with
 
347
     | Nil => Nil nat
 
348
     | Cons a l => l
 
349
     end.
 
350
 
 
351
 
 
352
Type
 
353
  match 0 return nat with
 
354
  | O => 0
 
355
  | S x => match Nil nat return nat with
 
356
           | Nil => x
 
357
           | Cons a l => x + a
 
358
           end
 
359
  end.
 
360
 
 
361
Type
 
362
  match 0 with
 
363
  | O => 0
 
364
  | S x => match Nil nat with
 
365
           | Nil => x
 
366
           | Cons a l => x + a
 
367
           end
 
368
  end.
 
369
 
 
370
Type
 
371
  (fun y : nat =>
 
372
   match y with
 
373
   | O => 0
 
374
   | S x => match Nil nat with
 
375
            | Nil => x
 
376
            | Cons a l => x + a
 
377
            end
 
378
   end).
 
379
 
 
380
 
 
381
Type
 
382
  match 0, Nil nat return nat with
 
383
  | O, x => 0
 
384
  | S x, Nil => x
 
385
  | S x, Cons a l => x + a
 
386
  end.
 
387
 
 
388
 
 
389
 
 
390
Type
 
391
  (fun (n : nat) (l : listn n) =>
 
392
   match l return nat with
 
393
   | niln => 0
 
394
   | x => 0
 
395
   end).
 
396
 
 
397
Type (fun (n : nat) (l : listn n) => match l with
 
398
                                     | niln => 0
 
399
                                     | x => 0
 
400
                                     end).
 
401
 
 
402
 
 
403
Type match niln return nat with
 
404
     | niln => 0
 
405
     | x => 0
 
406
     end.
 
407
 
 
408
Type match niln with
 
409
     | niln => 0
 
410
     | x => 0
 
411
     end.
 
412
 
 
413
Type match niln return nat with
 
414
     | niln => 0
 
415
     | consn n a l => a
 
416
     end.
 
417
Type match niln with
 
418
     | niln => 0
 
419
     | consn n a l => a
 
420
     end.
 
421
 
 
422
 
 
423
Type
 
424
  match niln in (listn n) return nat with
 
425
  | consn m _ niln => m
 
426
  | _ => 1
 
427
  end.
 
428
 
 
429
 
 
430
 
 
431
Type
 
432
  (fun (n x : nat) (l : listn n) =>
 
433
   match x, l return nat with
 
434
   | O, niln => 0
 
435
   | y, x => 0
 
436
   end).
 
437
 
 
438
Type match 0, niln return nat with
 
439
     | O, niln => 0
 
440
     | y, x => 0
 
441
     end.
 
442
 
 
443
 
 
444
Type match niln, 0 return nat with
 
445
     | niln, O => 0
 
446
     | y, x => 0
 
447
     end.
 
448
 
 
449
Type match niln, 0 with
 
450
     | niln, O => 0
 
451
     | y, x => 0
 
452
     end.
 
453
 
 
454
Type match niln, niln return nat with
 
455
     | niln, niln => 0
 
456
     | x, y => 0
 
457
     end.
 
458
 
 
459
Type match niln, niln with
 
460
     | niln, niln => 0
 
461
     | x, y => 0
 
462
     end.
 
463
 
 
464
Type
 
465
  match niln, niln, niln return nat with
 
466
  | niln, niln, niln => 0
 
467
  | x, y, z => 0
 
468
  end.
 
469
 
 
470
 
 
471
Type match niln, niln, niln with
 
472
     | niln, niln, niln => 0
 
473
     | x, y, z => 0
 
474
     end.
 
475
 
 
476
 
 
477
 
 
478
Type match niln return nat with
 
479
     | niln => 0
 
480
     | consn n a l => 0
 
481
     end.
 
482
 
 
483
Type match niln with
 
484
     | niln => 0
 
485
     | consn n a l => 0
 
486
     end.
 
487
 
 
488
 
 
489
Type
 
490
  match niln, niln return nat with
 
491
  | niln, niln => 0
 
492
  | niln, consn n a l => n
 
493
  | consn n a l, x => a
 
494
  end.
 
495
 
 
496
 
 
497
Type
 
498
  match niln, niln with
 
499
  | niln, niln => 0
 
500
  | niln, consn n a l => n
 
501
  | consn n a l, x => a
 
502
  end.
 
503
 
 
504
 
 
505
Type
 
506
  (fun (n : nat) (l : listn n) =>
 
507
   match l return nat with
 
508
   | niln => 0
 
509
   | x => 0
 
510
   end).
 
511
 
 
512
Type
 
513
  (fun (c : nat) (s : bool) =>
 
514
   match c, s return nat with
 
515
   | O, _ => 0
 
516
   | _, _ => c
 
517
   end).
 
518
 
 
519
Type
 
520
  (fun (c : nat) (s : bool) =>
 
521
   match c, s return nat with
 
522
   | O, _ => 0
 
523
   | S _, _ => c
 
524
   end).
 
525
         
 
526
 
 
527
(* Rows of pattern variables: some tricky cases *)
 
528
Axioms (P : nat -> Prop) (f : forall n : nat, P n).
 
529
 
 
530
Type
 
531
  (fun i : nat =>
 
532
   match true, i as n return (P n) with
 
533
   | true, k => f k
 
534
   | _, k => f k
 
535
   end).
 
536
 
 
537
Type
 
538
  (fun i : nat =>
 
539
   match i as n, true return (P n) with
 
540
   | k, true => f k
 
541
   | k, _ => f k
 
542
   end).
 
543
 
 
544
(* Nested Cases: the SYNTH of the Cases on n used to make Multcase believe
 
545
 * it has to synthtize the predicate on O (which he can't)
 
546
 *)
 
547
Type
 
548
  match 0 as n return match n with
 
549
                      | O => bool
 
550
                      | S _ => nat
 
551
                      end with
 
552
  | O => true
 
553
  | S _ => 0
 
554
  end.
 
555
 
 
556
Type (fun (n : nat) (l : listn n) => match l with
 
557
                                     | niln => 0
 
558
                                     | x => 0
 
559
                                     end).
 
560
 
 
561
Type
 
562
  (fun (n : nat) (l : listn n) =>
 
563
   match l return nat with
 
564
   | niln => 0
 
565
   | consn n a niln => 0
 
566
   | consn n a (consn m b l) => n + m
 
567
   end).
 
568
 
 
569
 
 
570
Type
 
571
  (fun (n : nat) (l : listn n) =>
 
572
   match l with
 
573
   | niln => 0
 
574
   | consn n a niln => 0
 
575
   | consn n a (consn m b l) => n + m
 
576
   end).
 
577
 
 
578
 
 
579
 
 
580
Type
 
581
  (fun (n : nat) (l : listn n) =>
 
582
   match l return nat with
 
583
   | niln => 0
 
584
   | consn n a niln => 0
 
585
   | consn n a (consn m b l) => n + m
 
586
   end).
 
587
 
 
588
Type
 
589
  (fun (n : nat) (l : listn n) =>
 
590
   match l with
 
591
   | niln => 0
 
592
   | consn n a niln => 0
 
593
   | consn n a (consn m b l) => n + m
 
594
   end).
 
595
 
 
596
 
 
597
Type
 
598
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
599
   match l return nat with
 
600
   | Niln => 0
 
601
   | Consn n a Niln => 0
 
602
   | Consn n a (Consn m b l) => n + m
 
603
   end).
 
604
 
 
605
Type
 
606
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
607
   match l with
 
608
   | Niln => 0
 
609
   | Consn n a Niln => 0
 
610
   | Consn n a (Consn m b l) => n + m
 
611
   end).
 
612
 
 
613
(*
 
614
Type [A:Set][n:nat][l:(Listn A n)]
 
615
                   <[_:nat](Listn A O)>Cases l of 
 
616
                         (Niln  as b) => b
 
617
                      | (Consn  n a (Niln  as b))=> (Niln A)
 
618
                      | (Consn  n a (Consn m b l)) => (Niln A)
 
619
                      end.
 
620
 
 
621
Type [A:Set][n:nat][l:(Listn A n)]
 
622
                    Cases l of 
 
623
                         (Niln  as b) => b
 
624
                      | (Consn  n a (Niln  as b))=> (Niln A)
 
625
                      | (Consn  n a (Consn m b l)) => (Niln A)
 
626
                      end.
 
627
*)
 
628
(******** This example rises an error unconstrained_variables!
 
629
Type [A:Set][n:nat][l:(Listn A n)]
 
630
                    Cases l of 
 
631
                         (Niln  as b) => (Consn A O O b)
 
632
                      | ((Consn  n a Niln) as L) =>  L 
 
633
                      | (Consn  n a _)  =>  (Consn A O O (Niln A))
 
634
                      end.
 
635
**********)
 
636
 
 
637
(* To test tratement of as-patterns in depth *)
 
638
Type
 
639
  (fun (A : Set) (l : List A) =>
 
640
   match l with
 
641
   | Nil as b => Nil A
 
642
   | Cons a Nil as L => L
 
643
   | Cons a (Cons b m) as L => L
 
644
   end).
 
645
 
 
646
 
 
647
Type
 
648
  (fun (n : nat) (l : listn n) =>
 
649
   match l return (listn n) with
 
650
   | niln => l
 
651
   | consn n a c => l
 
652
   end).
 
653
Type
 
654
  (fun (n : nat) (l : listn n) =>
 
655
   match l with
 
656
   | niln => l
 
657
   | consn n a c => l
 
658
   end).
 
659
 
 
660
 
 
661
Type
 
662
  (fun (n : nat) (l : listn n) =>
 
663
   match l return (listn n) with
 
664
   | niln as b => l
 
665
   | _ => l
 
666
   end).
 
667
 
 
668
 
 
669
Type
 
670
  (fun (n : nat) (l : listn n) => match l with
 
671
                                  | niln as b => l
 
672
                                  | _ => l
 
673
                                  end).
 
674
 
 
675
Type
 
676
  (fun (n : nat) (l : listn n) =>
 
677
   match l return (listn n) with
 
678
   | niln as b => l
 
679
   | x => l
 
680
   end).
 
681
 
 
682
 
 
683
Type
 
684
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
685
   match l with
 
686
   | Niln as b => l
 
687
   | _ => l
 
688
   end).
 
689
 
 
690
Type
 
691
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
692
   match l return (Listn A n) with
 
693
   | Niln => l
 
694
   | Consn n a Niln => l
 
695
   | Consn n a (Consn m b c) => l
 
696
   end).
 
697
 
 
698
Type
 
699
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
700
   match l with
 
701
   | Niln => l
 
702
   | Consn n a Niln => l
 
703
   | Consn n a (Consn m b c) => l
 
704
   end).
 
705
 
 
706
Type
 
707
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
708
   match l return (Listn A n) with
 
709
   | Niln as b => l
 
710
   | Consn n a (Niln as b) => l
 
711
   | Consn n a (Consn m b _) => l
 
712
   end).
 
713
 
 
714
Type
 
715
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
716
   match l with
 
717
   | Niln as b => l
 
718
   | Consn n a (Niln as b) => l
 
719
   | Consn n a (Consn m b _) => l
 
720
   end).
 
721
 
 
722
 
 
723
Type
 
724
  match niln return nat with
 
725
  | niln => 0
 
726
  | consn n a niln => 0
 
727
  | consn n a (consn m b l) => n + m
 
728
  end.
 
729
 
 
730
 
 
731
Type
 
732
  match niln with
 
733
  | niln => 0
 
734
  | consn n a niln => 0
 
735
  | consn n a (consn m b l) => n + m
 
736
  end.
 
737
 
 
738
Type match LeO 0 return nat with
 
739
     | LeO x => x
 
740
     | LeS n m h => n + m
 
741
     end.
 
742
 
 
743
 
 
744
Type match LeO 0 with
 
745
     | LeO x => x
 
746
     | LeS n m h => n + m
 
747
     end.
 
748
 
 
749
Type
 
750
  (fun (n : nat) (l : Listn nat n) =>
 
751
   match l return nat with
 
752
   | Niln => 0
 
753
   | Consn n a l => 0
 
754
   end).
 
755
 
 
756
 
 
757
Type
 
758
  (fun (n : nat) (l : Listn nat n) =>
 
759
   match l with
 
760
   | Niln => 0
 
761
   | Consn n a l => 0
 
762
   end).
 
763
 
 
764
 
 
765
Type match Niln nat with
 
766
     | Niln => 0
 
767
     | Consn n a l => 0
 
768
     end.
 
769
 
 
770
Type match LE_n 0 return nat with
 
771
     | LE_n => 0
 
772
     | LE_S m h => 0
 
773
     end.
 
774
 
 
775
 
 
776
Type match LE_n 0 with
 
777
     | LE_n => 0
 
778
     | LE_S m h => 0
 
779
     end.
 
780
 
 
781
 
 
782
 
 
783
Type match LE_n 0 with
 
784
     | LE_n => 0
 
785
     | LE_S m h => 0
 
786
     end.
 
787
 
 
788
 
 
789
 
 
790
Type
 
791
  match niln return nat with
 
792
  | niln => 0
 
793
  | consn n a niln => n
 
794
  | consn n a (consn m b l) => n + m
 
795
  end.
 
796
 
 
797
Type
 
798
  match niln with
 
799
  | niln => 0
 
800
  | consn n a niln => n
 
801
  | consn n a (consn m b l) => n + m
 
802
  end.
 
803
 
 
804
 
 
805
Type
 
806
  match Niln nat return nat with
 
807
  | Niln => 0
 
808
  | Consn n a Niln => n
 
809
  | Consn n a (Consn m b l) => n + m
 
810
  end.
 
811
 
 
812
Type
 
813
  match Niln nat with
 
814
  | Niln => 0
 
815
  | Consn n a Niln => n
 
816
  | Consn n a (Consn m b l) => n + m
 
817
  end.
 
818
 
 
819
 
 
820
Type
 
821
  match LeO 0 return nat with
 
822
  | LeO x => x
 
823
  | LeS n m (LeO x) => x + m
 
824
  | LeS n m (LeS x y h) => n + x
 
825
  end.
 
826
 
 
827
 
 
828
Type
 
829
  match LeO 0 with
 
830
  | LeO x => x
 
831
  | LeS n m (LeO x) => x + m
 
832
  | LeS n m (LeS x y h) => n + x
 
833
  end.
 
834
 
 
835
 
 
836
Type
 
837
  match LeO 0 return nat with
 
838
  | LeO x => x
 
839
  | LeS n m (LeO x) => x + m
 
840
  | LeS n m (LeS x y h) => m
 
841
  end.
 
842
 
 
843
Type
 
844
  match LeO 0 with
 
845
  | LeO x => x
 
846
  | LeS n m (LeO x) => x + m
 
847
  | LeS n m (LeS x y h) => m
 
848
  end.
 
849
 
 
850
 
 
851
Type
 
852
  (fun (n m : nat) (h : Le n m) =>
 
853
   match h return nat with
 
854
   | LeO x => x
 
855
   | x => 0
 
856
   end).
 
857
 
 
858
Type (fun (n m : nat) (h : Le n m) => match h with
 
859
                                      | LeO x => x
 
860
                                      | x => 0
 
861
                                      end).
 
862
 
 
863
 
 
864
Type
 
865
  (fun (n m : nat) (h : Le n m) =>
 
866
   match h return nat with
 
867
   | LeS n m h => n
 
868
   | x => 0
 
869
   end).
 
870
 
 
871
 
 
872
Type
 
873
  (fun (n m : nat) (h : Le n m) => match h with
 
874
                                   | LeS n m h => n
 
875
                                   | x => 0
 
876
                                   end).
 
877
 
 
878
 
 
879
Type
 
880
  (fun (n m : nat) (h : Le n m) =>
 
881
   match h return (nat * nat) with
 
882
   | LeO n => (0, n)
 
883
   | LeS n m _ => (S n, S m)
 
884
   end).
 
885
 
 
886
 
 
887
Type
 
888
  (fun (n m : nat) (h : Le n m) =>
 
889
   match h with
 
890
   | LeO n => (0, n)
 
891
   | LeS n m _ => (S n, S m)
 
892
   end).
 
893
 
 
894
 
 
895
Fixpoint F (n m : nat) (h : Le n m) {struct h} : Le n (S m) :=
 
896
  match h in (Le n m) return (Le n (S m)) with
 
897
  | LeO m' => LeO (S m')
 
898
  | LeS n' m' h' => LeS n' (S m') (F n' m' h')
 
899
  end.
 
900
 
 
901
Reset F.
 
902
 
 
903
Fixpoint F (n m : nat) (h : Le n m) {struct h} : Le n (S m) :=
 
904
  match h in (Le n m) return (Le n (S m)) with
 
905
  | LeS n m h => LeS n (S m) (F n m h)
 
906
  | LeO m => LeO (S m)
 
907
  end.
 
908
 
 
909
(* Rend la longueur de la liste *)
 
910
Definition length1 (n : nat) (l : listn n) :=
 
911
  match l return nat with
 
912
  | consn n _ (consn m _ _) => S (S m)
 
913
  | consn n _ _ => 1
 
914
  | _ => 0
 
915
  end.
 
916
 
 
917
Reset length1.
 
918
Definition length1 (n : nat) (l : listn n) :=
 
919
  match l with
 
920
  | consn n _ (consn m _ _) => S (S m)
 
921
  | consn n _ _ => 1
 
922
  | _ => 0
 
923
  end.
 
924
 
 
925
 
 
926
Definition length2 (n : nat) (l : listn n) :=
 
927
  match l return nat with
 
928
  | consn n _ (consn m _ _) => S (S m)
 
929
  | consn n _ _ => S n
 
930
  | _ => 0
 
931
  end.
 
932
 
 
933
Reset length2.
 
934
 
 
935
Definition length2 (n : nat) (l : listn n) :=
 
936
  match l with
 
937
  | consn n _ (consn m _ _) => S (S m)
 
938
  | consn n _ _ => S n
 
939
  | _ => 0
 
940
  end.
 
941
 
 
942
Definition length3 (n : nat) (l : listn n) :=
 
943
  match l return nat with
 
944
  | consn n _ (consn m _ l) => S n
 
945
  | consn n _ _ => 1
 
946
  | _ => 0
 
947
  end.
 
948
 
 
949
 
 
950
Reset length3.
 
951
 
 
952
Definition length3 (n : nat) (l : listn n) :=
 
953
  match l with
 
954
  | consn n _ (consn m _ l) => S n
 
955
  | consn n _ _ => 1
 
956
  | _ => 0
 
957
  end.
 
958
 
 
959
 
 
960
Type match LeO 0 return nat with
 
961
     | LeS n m h => n + m
 
962
     | x => 0
 
963
     end.
 
964
Type match LeO 0 with
 
965
     | LeS n m h => n + m
 
966
     | x => 0
 
967
     end.
 
968
 
 
969
Type
 
970
  (fun (n m : nat) (h : Le n m) =>
 
971
   match h return nat with
 
972
   | LeO x => x
 
973
   | LeS n m (LeO x) => x + m
 
974
   | LeS n m (LeS x y h) => n + (m + (x + y))
 
975
   end).
 
976
 
 
977
 
 
978
Type
 
979
  (fun (n m : nat) (h : Le n m) =>
 
980
   match h with
 
981
   | LeO x => x
 
982
   | LeS n m (LeO x) => x + m
 
983
   | LeS n m (LeS x y h) => n + (m + (x + y))
 
984
   end).
 
985
 
 
986
Type
 
987
  match LeO 0 return nat with
 
988
  | LeO x => x
 
989
  | LeS n m (LeO x) => x + m
 
990
  | LeS n m (LeS x y h) => n + (m + (x + y))
 
991
  end.
 
992
 
 
993
Type
 
994
  match LeO 0 with
 
995
  | LeO x => x
 
996
  | LeS n m (LeO x) => x + m
 
997
  | LeS n m (LeS x y h) => n + (m + (x + y))
 
998
  end.
 
999
 
 
1000
 
 
1001
Type
 
1002
  match LE_n 0 return nat with
 
1003
  | LE_n => 0
 
1004
  | LE_S m LE_n => 0 + m
 
1005
  | LE_S m (LE_S y h) => 0 + m
 
1006
  end.
 
1007
 
 
1008
 
 
1009
Type
 
1010
  match LE_n 0 with
 
1011
  | LE_n => 0
 
1012
  | LE_S m LE_n => 0 + m
 
1013
  | LE_S m (LE_S y h) => 0 + m
 
1014
  end.
 
1015
 
 
1016
 
 
1017
Type (fun (n m : nat) (h : Le n m) => match h with
 
1018
                                      | x => x
 
1019
                                      end).
 
1020
 
 
1021
Type
 
1022
  (fun (n m : nat) (h : Le n m) =>
 
1023
   match h return nat with
 
1024
   | LeO n => n
 
1025
   | x => 0
 
1026
   end).
 
1027
Type (fun (n m : nat) (h : Le n m) => match h with
 
1028
                                      | LeO n => n
 
1029
                                      | x => 0
 
1030
                                      end).
 
1031
 
 
1032
 
 
1033
Type
 
1034
  (fun n : nat =>
 
1035
   match niln return (nat -> nat) with
 
1036
   | niln => fun _ : nat => 0
 
1037
   | consn n a niln => fun _ : nat => 0
 
1038
   | consn n a (consn m b l) => fun _ : nat => n + m
 
1039
   end).
 
1040
 
 
1041
 
 
1042
Type
 
1043
  (fun n : nat =>
 
1044
   match niln with
 
1045
   | niln => fun _ : nat => 0
 
1046
   | consn n a niln => fun _ : nat => 0
 
1047
   | consn n a (consn m b l) => fun _ : nat => n + m
 
1048
   end).
 
1049
 
 
1050
Type
 
1051
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
1052
   match l return (nat -> nat) with
 
1053
   | Niln => fun _ : nat => 0
 
1054
   | Consn n a Niln => fun _ : nat => n
 
1055
   | Consn n a (Consn m b l) => fun _ : nat => n + m
 
1056
   end).
 
1057
 
 
1058
Type
 
1059
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
1060
   match l with
 
1061
   | Niln => fun _ : nat => 0
 
1062
   | Consn n a Niln => fun _ : nat => n
 
1063
   | Consn n a (Consn m b l) => fun _ : nat => n + m
 
1064
   end).
 
1065
 
 
1066
(* Alsos tests for multiple _ patterns *)
 
1067
Type
 
1068
  (fun (A : Set) (n : nat) (l : Listn A n) =>
 
1069
   match l in (Listn _ n) return (Listn A n) with
 
1070
   | Niln as b => b
 
1071
   | Consn _ _ _ as b => b
 
1072
   end).
 
1073
 
 
1074
(** Horrible error message! 
 
1075
 
 
1076
Type [A:Set][n:nat][l:(Listn A n)]
 
1077
                        Cases l of 
 
1078
                        (Niln as b) => b
 
1079
                      | ((Consn _ _ _ ) as b)=>  b
 
1080
                      end.
 
1081
******)
 
1082
 
 
1083
Type
 
1084
  match niln in (listn n) return (listn n) with
 
1085
  | niln as b => b
 
1086
  | consn _ _ _ as b => b
 
1087
  end.
 
1088
 
 
1089
 
 
1090
Type
 
1091
  match niln in (listn n) return (listn n) with
 
1092
  | niln as b => b
 
1093
  | x => x
 
1094
  end.
 
1095
 
 
1096
Type
 
1097
  (fun (n m : nat) (h : LE n m) =>
 
1098
   match h return (nat -> nat) with
 
1099
   | LE_n => fun _ : nat => n
 
1100
   | LE_S m LE_n => fun _ : nat => n + m
 
1101
   | LE_S m (LE_S y h) => fun _ : nat => m + y
 
1102
   end).
 
1103
Type
 
1104
  (fun (n m : nat) (h : LE n m) =>
 
1105
   match h with
 
1106
   | LE_n => fun _ : nat => n
 
1107
   | LE_S m LE_n => fun _ : nat => n + m
 
1108
   | LE_S m (LE_S y h) => fun _ : nat => m + y
 
1109
   end).
 
1110
 
 
1111
 
 
1112
Type
 
1113
  (fun (n m : nat) (h : LE n m) =>
 
1114
   match h return nat with
 
1115
   | LE_n => n
 
1116
   | LE_S m LE_n => n + m
 
1117
   | LE_S m (LE_S y LE_n) => n + m + y
 
1118
   | LE_S m (LE_S y (LE_S y' h)) => n + m + (y + y')
 
1119
   end).
 
1120
 
 
1121
 
 
1122
 
 
1123
Type
 
1124
  (fun (n m : nat) (h : LE n m) =>
 
1125
   match h with
 
1126
   | LE_n => n
 
1127
   | LE_S m LE_n => n + m
 
1128
   | LE_S m (LE_S y LE_n) => n + m + y
 
1129
   | LE_S m (LE_S y (LE_S y' h)) => n + m + (y + y')
 
1130
   end).
 
1131
 
 
1132
 
 
1133
Type
 
1134
  (fun (n m : nat) (h : LE n m) =>
 
1135
   match h return nat with
 
1136
   | LE_n => n
 
1137
   | LE_S m LE_n => n + m
 
1138
   | LE_S m (LE_S y h) => n + m + y
 
1139
   end).
 
1140
 
 
1141
 
 
1142
Type
 
1143
  (fun (n m : nat) (h : LE n m) =>
 
1144
   match h with
 
1145
   | LE_n => n
 
1146
   | LE_S m LE_n => n + m
 
1147
   | LE_S m (LE_S y h) => n + m + y
 
1148
   end).
 
1149
 
 
1150
Type
 
1151
  (fun n m : nat =>
 
1152
   match LeO 0 return nat with
 
1153
   | LeS n m h => n + m
 
1154
   | x => 0
 
1155
   end).
 
1156
 
 
1157
Type (fun n m : nat => match LeO 0 with
 
1158
                       | LeS n m h => n + m
 
1159
                       | x => 0
 
1160
                       end).
 
1161
 
 
1162
Parameter test : forall n : nat, {0 <= n} + {False}.
 
1163
Type (fun n : nat => match test n return nat with
 
1164
                     | left _ => 0
 
1165
                     | _ => 0
 
1166
                     end).
 
1167
 
 
1168
 
 
1169
Type (fun n : nat => match test n return nat with
 
1170
                     | left _ => 0
 
1171
                     | _ => 0
 
1172
                     end).
 
1173
 
 
1174
Type (fun n : nat => match test n with
 
1175
                     | left _ => 0
 
1176
                     | _ => 0
 
1177
                     end).
 
1178
 
 
1179
Parameter compare : forall n m : nat, {n < m} + {n = m} + {n > m}.
 
1180
Type
 
1181
  match compare 0 0 return nat with
 
1182
  
 
1183
      (* k<i *) | inleft (left _) => 0
 
1184
   (* k=i *) | inleft _ => 0
 
1185
   (* k>i *) | inright _ => 0
 
1186
  end.
 
1187
 
 
1188
Type
 
1189
  match compare 0 0 with
 
1190
  
 
1191
      (* k<i *) | inleft (left _) => 0
 
1192
   (* k=i *) | inleft _ => 0
 
1193
   (* k>i *) | inright _ => 0
 
1194
  end.
 
1195
 
 
1196
 
 
1197
 
 
1198
CoInductive SStream (A : Set) : (nat -> A -> Prop) -> Type :=
 
1199
    scons :
 
1200
      forall (P : nat -> A -> Prop) (a : A),
 
1201
      P 0 a -> SStream A (fun n : nat => P (S n)) -> SStream A P.
 
1202
Parameter B : Set.
 
1203
 
 
1204
Type
 
1205
  (fun (P : nat -> B -> Prop) (x : SStream B P) =>
 
1206
   match x return B with
 
1207
   | scons _ a _ _ => a
 
1208
   end).
 
1209
 
 
1210
 
 
1211
Type
 
1212
  (fun (P : nat -> B -> Prop) (x : SStream B P) =>
 
1213
   match x with
 
1214
   | scons _ a _ _ => a
 
1215
   end).
 
1216
 
 
1217
Type match (0, 0) return (nat * nat) with
 
1218
     | (x, y) => (S x, S y)
 
1219
     end.
 
1220
Type match (0, 0) return (nat * nat) with
 
1221
     | (b, y) => (S b, S y)
 
1222
     end.
 
1223
Type match (0, 0) return (nat * nat) with
 
1224
     | (x, y) => (S x, S y)
 
1225
     end.
 
1226
 
 
1227
Type match (0, 0) with
 
1228
     | (x, y) => (S x, S y)
 
1229
     end.
 
1230
Type match (0, 0) with
 
1231
     | (b, y) => (S b, S y)
 
1232
     end.
 
1233
Type match (0, 0) with
 
1234
     | (x, y) => (S x, S y)
 
1235
     end.
 
1236
 
 
1237
 
 
1238
 
 
1239
Parameter concat : forall A : Set, List A -> List A -> List A.
 
1240
 
 
1241
Type
 
1242
  match Nil nat, Nil nat return (List nat) with
 
1243
  | Nil as b, x => concat nat b x
 
1244
  | Cons _ _ as d, Nil as c => concat nat d c
 
1245
  | _, _ => Nil nat
 
1246
  end.
 
1247
Type
 
1248
  match Nil nat, Nil nat with
 
1249
  | Nil as b, x => concat nat b x
 
1250
  | Cons _ _ as d, Nil as c => concat nat d c
 
1251
  | _, _ => Nil nat
 
1252
  end.
 
1253
 
 
1254
 
 
1255
Inductive redexes : Set :=
 
1256
  | VAR : nat -> redexes
 
1257
  | Fun : redexes -> redexes
 
1258
  | Ap : bool -> redexes -> redexes -> redexes.
 
1259
 
 
1260
Fixpoint regular (U : redexes) : Prop :=
 
1261
  match U return Prop with
 
1262
  | VAR n => True
 
1263
  | Fun V => regular V
 
1264
  | Ap true (Fun _ as V) W => regular V /\ regular W
 
1265
  | Ap true _ W => False
 
1266
  | Ap false V W => regular V /\ regular W
 
1267
  end.
 
1268
 
 
1269
 
 
1270
Type (fun n : nat => match n with
 
1271
                     | O => 0
 
1272
                     | S (S n as V) => V
 
1273
                     | _ => 0
 
1274
                     end).
 
1275
 
 
1276
Reset concat.
 
1277
Parameter
 
1278
  concat :
 
1279
    forall n : nat, listn n -> forall m : nat, listn m -> listn (n + m).
 
1280
Type
 
1281
  (fun (n : nat) (l : listn n) (m : nat) (l' : listn m) =>
 
1282
   match l in (listn n), l' return (listn (n + m)) with
 
1283
   | niln, x => x
 
1284
   | consn n a l'', x => consn (n + m) a (concat n l'' m x)
 
1285
   end).
 
1286
 
 
1287
Type
 
1288
  (fun (x y z : nat) (H : x = y) (H0 : y = z) =>
 
1289
   match H return (x = z) with
 
1290
   | refl_equal =>
 
1291
       match H0 in (_ = n) return (x = n) with
 
1292
       | refl_equal => H
 
1293
       end
 
1294
   end).
 
1295
 
 
1296
Type (fun h : False => match h return False with
 
1297
                       end).
 
1298
 
 
1299
Type (fun h : False => match h return True with
 
1300
                       end).
 
1301
 
 
1302
Definition is_zero (n : nat) := match n with
 
1303
                                | O => True
 
1304
                                | _ => False
 
1305
                                end.
 
1306
 
 
1307
Type
 
1308
  (fun (n : nat) (h : 0 = S n) =>
 
1309
   match h in (_ = n) return (is_zero n) with
 
1310
   | refl_equal => I
 
1311
   end).
 
1312
 
 
1313
Definition disc (n : nat) (h : 0 = S n) : False :=
 
1314
  match h in (_ = n) return (is_zero n) with
 
1315
  | refl_equal => I
 
1316
  end.
 
1317
 
 
1318
Definition nlength3 (n : nat) (l : listn n) :=
 
1319
  match l with
 
1320
  | niln => 0
 
1321
  | consn O _ _ => 1
 
1322
  | consn (S n) _ _ => S (S n)
 
1323
  end.
 
1324
 
 
1325
(* == Testing strategy elimintation predicate  synthesis == *)
 
1326
Section titi.
 
1327
Variable h : False.
 
1328
Type match 0 with
 
1329
     | O => 0
 
1330
     | _ => except h
 
1331
     end.
 
1332
End titi.
 
1333
 
 
1334
Type match niln with
 
1335
     | consn _ a niln => a
 
1336
     | consn n _ x => 0
 
1337
     | niln => 0
 
1338
     end.
 
1339
 
 
1340
 
 
1341
 
 
1342
Inductive wsort : Set :=
 
1343
  | ws : wsort
 
1344
  | wt : wsort.
 
1345
Inductive TS : wsort -> Set :=
 
1346
  | id : TS ws
 
1347
  | lift : TS ws -> TS ws.
 
1348
 
 
1349
Type
 
1350
  (fun (b : wsort) (M N : TS b) =>
 
1351
   match M, N with
 
1352
   | lift M1, id => False
 
1353
   | _, _ => True
 
1354
   end).
 
1355
 
 
1356
 
 
1357
 
 
1358
(* ===================================================================== *)
 
1359
(* To test pattern matching over a non-dependent inductive type, but     *)
 
1360
(* having constructors with some arguments that depend on others         *)
 
1361
(* I.e. to test manipulation of elimination predicate                    *)
 
1362
(* ===================================================================== *)
 
1363
 
 
1364
 
 
1365
Parameter LTERM : nat -> Set.
 
1366
Inductive TERM : Type :=
 
1367
  | var : TERM
 
1368
  | oper : forall op : nat, LTERM op -> TERM.
 
1369
 
 
1370
Parameter t1 t2 : TERM.
 
1371
 
 
1372
Type
 
1373
  match t1, t2 with
 
1374
  | var, var => True
 
1375
  | oper op1 l1, oper op2 l2 => False
 
1376
  | _, _ => False
 
1377
  end. 
 
1378
Reset LTERM.
 
1379
 
 
1380
 
 
1381
 
 
1382
Require Import Peano_dec.
 
1383
Parameter n : nat.
 
1384
Definition eq_prf := exists m : _, n = m.
 
1385
Parameter p : eq_prf.
 
1386
 
 
1387
Type
 
1388
  match p with
 
1389
  | ex_intro c eqc =>
 
1390
      match eq_nat_dec c n with
 
1391
      | right _ => refl_equal n
 
1392
      | left y => (* c=n*)  refl_equal n
 
1393
      end
 
1394
  end.
 
1395
 
 
1396
 
 
1397
Parameter ordre_total : nat -> nat -> Prop.
 
1398
 
 
1399
Parameter N_cla : forall N : nat, {N = 0} + {N = 1} + {N >= 2}.
 
1400
 
 
1401
Parameter
 
1402
  exist_U2 :
 
1403
    forall N : nat,
 
1404
    N >= 2 ->
 
1405
    {n : nat |
 
1406
    forall m : nat, 0 < m /\ m <= N /\ ordre_total n m /\ 0 < n /\ n < N}.
 
1407
 
 
1408
Type
 
1409
  (fun N : nat =>
 
1410
   match N_cla N with
 
1411
   | inright H => match exist_U2 N H with
 
1412
                  | exist a b => a
 
1413
                  end
 
1414
   | _ => 0
 
1415
   end).
 
1416
 
 
1417
 
 
1418
 
 
1419
(* ============================================== *)
 
1420
(*     To test compilation of dependent case      *)
 
1421
(*  Nested patterns                               *)
 
1422
(* ============================================== *)
 
1423
 
 
1424
(* == To test that terms named with AS are correctly absolutized before
 
1425
      substitution in rhs   == *)
 
1426
 
 
1427
Type
 
1428
  (fun n : nat =>
 
1429
   match n return nat with
 
1430
   | O => 0
 
1431
   | S O => 0
 
1432
   | S (S n1) as N => N
 
1433
   end).
 
1434
 
 
1435
(* ========= *)
 
1436
 
 
1437
Type
 
1438
  match niln in (listn n) return Prop with
 
1439
  | niln => True
 
1440
  | consn (S O) _ _ => False
 
1441
  | _ => True
 
1442
  end.
 
1443
 
 
1444
Type
 
1445
  match niln in (listn n) return Prop with
 
1446
  | niln => True
 
1447
  | consn (S (S O)) _ _ => False
 
1448
  | _ => True
 
1449
  end.
 
1450
 
 
1451
 
 
1452
Type
 
1453
  match LeO 0 as h in (Le n m) return nat with
 
1454
  | LeO _ => 0
 
1455
  | LeS (S x) _ _ => x
 
1456
  | _ => 1
 
1457
  end.
 
1458
 
 
1459
Type
 
1460
  match LeO 0 as h in (Le n m) return nat with
 
1461
  | LeO _ => 0
 
1462
  | LeS (S x) (S y) _ => x
 
1463
  | _ => 1
 
1464
  end.
 
1465
 
 
1466
Type
 
1467
  match LeO 0 as h in (Le n m) return nat with
 
1468
  | LeO _ => 0
 
1469
  | LeS (S x as b) (S y) _ => b
 
1470
  | _ => 1
 
1471
  end.
 
1472
 
 
1473
 
 
1474
 
 
1475
Parameter ff : forall n m : nat, n <> m -> S n <> S m.
 
1476
Parameter discr_r : forall n : nat, 0 <> S n.
 
1477
Parameter discr_l : forall n : nat, S n <> 0.
 
1478
 
 
1479
Type
 
1480
  (fun n : nat =>
 
1481
   match n return (n = 0 \/ n <> 0) with
 
1482
   | O => or_introl (0 <> 0) (refl_equal 0)
 
1483
   | S x => or_intror (S x = 0) (discr_l x)
 
1484
   end).
 
1485
 
 
1486
 
 
1487
Fixpoint eqdec (n m : nat) {struct n} : n = m \/ n <> m :=
 
1488
  match n, m return (n = m \/ n <> m) with
 
1489
  | O, O => or_introl (0 <> 0) (refl_equal 0)
 
1490
  | O, S x => or_intror (0 = S x) (discr_r x)
 
1491
  | S x, O => or_intror _ (discr_l x)
 
1492
  | S x, S y =>
 
1493
      match eqdec x y return (S x = S y \/ S x <> S y) with
 
1494
      | or_introl h => or_introl (S x <> S y) (f_equal S h)
 
1495
      | or_intror h => or_intror (S x = S y) (ff x y h)
 
1496
      end
 
1497
  end.
 
1498
 
 
1499
Reset eqdec.
 
1500
 
 
1501
Fixpoint eqdec (n : nat) : forall m : nat, n = m \/ n <> m :=
 
1502
  match n return (forall m : nat, n = m \/ n <> m) with
 
1503
  | O =>
 
1504
      fun m : nat =>
 
1505
      match m return (0 = m \/ 0 <> m) with
 
1506
      | O => or_introl (0 <> 0) (refl_equal 0)
 
1507
      | S x => or_intror (0 = S x) (discr_r x)
 
1508
      end
 
1509
  | S x =>
 
1510
      fun m : nat =>
 
1511
      match m return (S x = m \/ S x <> m) with
 
1512
      | O => or_intror (S x = 0) (discr_l x)
 
1513
      | S y =>
 
1514
          match eqdec x y return (S x = S y \/ S x <> S y) with
 
1515
          | or_introl h => or_introl (S x <> S y) (f_equal S h)
 
1516
          | or_intror h => or_intror (S x = S y) (ff x y h)
 
1517
          end
 
1518
      end
 
1519
  end.
 
1520
 
 
1521
 
 
1522
Inductive empty : forall n : nat, listn n -> Prop :=
 
1523
    intro_empty : empty 0 niln.
 
1524
 
 
1525
Parameter
 
1526
  inv_empty : forall (n a : nat) (l : listn n), ~ empty (S n) (consn n a l).
 
1527
 
 
1528
Type
 
1529
  (fun (n : nat) (l : listn n) =>
 
1530
   match l in (listn n) return (empty n l \/ ~ empty n l) with
 
1531
   | niln => or_introl (~ empty 0 niln) intro_empty
 
1532
   | consn n a y as b => or_intror (empty (S n) b) (inv_empty n a y)
 
1533
   end).
 
1534
 
 
1535
Reset ff.
 
1536
Parameter ff : forall n m : nat, n <> m -> S n <> S m.
 
1537
Parameter discr_r : forall n : nat, 0 <> S n.
 
1538
Parameter discr_l : forall n : nat, S n <> 0.
 
1539
 
 
1540
Type
 
1541
  (fun n : nat =>
 
1542
   match n return (n = 0 \/ n <> 0) with
 
1543
   | O => or_introl (0 <> 0) (refl_equal 0)
 
1544
   | S x => or_intror (S x = 0) (discr_l x)
 
1545
   end).
 
1546
 
 
1547
 
 
1548
Fixpoint eqdec (n m : nat) {struct n} : n = m \/ n <> m :=
 
1549
  match n, m return (n = m \/ n <> m) with
 
1550
  | O, O => or_introl (0 <> 0) (refl_equal 0)
 
1551
  | O, S x => or_intror (0 = S x) (discr_r x)
 
1552
  | S x, O => or_intror _ (discr_l x)
 
1553
  | S x, S y =>
 
1554
      match eqdec x y return (S x = S y \/ S x <> S y) with
 
1555
      | or_introl h => or_introl (S x <> S y) (f_equal S h)
 
1556
      | or_intror h => or_intror (S x = S y) (ff x y h)
 
1557
      end
 
1558
  end.
 
1559
Reset eqdec.
 
1560
 
 
1561
Fixpoint eqdec (n : nat) : forall m : nat, n = m \/ n <> m :=
 
1562
  match n return (forall m : nat, n = m \/ n <> m) with
 
1563
  | O =>
 
1564
      fun m : nat =>
 
1565
      match m return (0 = m \/ 0 <> m) with
 
1566
      | O => or_introl (0 <> 0) (refl_equal 0)
 
1567
      | S x => or_intror (0 = S x) (discr_r x)
 
1568
      end
 
1569
  | S x =>
 
1570
      fun m : nat =>
 
1571
      match m return (S x = m \/ S x <> m) with
 
1572
      | O => or_intror (S x = 0) (discr_l x)
 
1573
      | S y =>
 
1574
          match eqdec x y return (S x = S y \/ S x <> S y) with
 
1575
          | or_introl h => or_introl (S x <> S y) (f_equal S h)
 
1576
          | or_intror h => or_intror (S x = S y) (ff x y h)
 
1577
          end
 
1578
      end
 
1579
  end.
 
1580
 
 
1581
 
 
1582
(* ================================================== *)
 
1583
(* Pour tester parametres                             *)
 
1584
(* ================================================== *)
 
1585
 
 
1586
 
 
1587
Inductive Empty (A : Set) : List A -> Prop :=
 
1588
    intro_Empty : Empty A (Nil A).
 
1589
 
 
1590
Parameter
 
1591
  inv_Empty : forall (A : Set) (a : A) (x : List A), ~ Empty A (Cons A a x).
 
1592
 
 
1593
 
 
1594
Type
 
1595
  match Nil nat as l return (Empty nat l \/ ~ Empty nat l) with
 
1596
  | Nil => or_introl (~ Empty nat (Nil nat)) (intro_Empty nat)
 
1597
  | Cons a y => or_intror (Empty nat (Cons nat a y)) (inv_Empty nat a y)
 
1598
  end.
 
1599
 
 
1600
 
 
1601
(* ================================================== *)
 
1602
(* Sur les listes                                     *)
 
1603
(* ================================================== *)
 
1604
 
 
1605
 
 
1606
Inductive empty : forall n : nat, listn n -> Prop :=
 
1607
    intro_empty : empty 0 niln.
 
1608
 
 
1609
Parameter
 
1610
  inv_empty : forall (n a : nat) (l : listn n), ~ empty (S n) (consn n a l).
 
1611
 
 
1612
Type
 
1613
  (fun (n : nat) (l : listn n) =>
 
1614
   match l in (listn n) return (empty n l \/ ~ empty n l) with
 
1615
   | niln => or_introl (~ empty 0 niln) intro_empty
 
1616
   | consn n a y as b => or_intror (empty (S n) b) (inv_empty n a y)
 
1617
   end).
 
1618
 
 
1619
(* ===================================== *)
 
1620
(*   Test parametros:                    *)
 
1621
(* ===================================== *)
 
1622
 
 
1623
Inductive eqlong : List nat -> List nat -> Prop :=
 
1624
  | eql_cons :
 
1625
      forall (n m : nat) (x y : List nat),
 
1626
      eqlong x y -> eqlong (Cons nat n x) (Cons nat m y)
 
1627
  | eql_nil : eqlong (Nil nat) (Nil nat).
 
1628
 
 
1629
 
 
1630
Parameter V1 : eqlong (Nil nat) (Nil nat) \/ ~ eqlong (Nil nat) (Nil nat).
 
1631
Parameter
 
1632
  V2 :
 
1633
    forall (a : nat) (x : List nat),
 
1634
    eqlong (Nil nat) (Cons nat a x) \/ ~ eqlong (Nil nat) (Cons nat a x).
 
1635
Parameter
 
1636
  V3 :
 
1637
    forall (a : nat) (x : List nat),
 
1638
    eqlong (Cons nat a x) (Nil nat) \/ ~ eqlong (Cons nat a x) (Nil nat).
 
1639
Parameter
 
1640
  V4 :
 
1641
    forall (a : nat) (x : List nat) (b : nat) (y : List nat),
 
1642
    eqlong (Cons nat a x) (Cons nat b y) \/
 
1643
    ~ eqlong (Cons nat a x) (Cons nat b y).
 
1644
 
 
1645
Type
 
1646
  match Nil nat as x, Nil nat as y return (eqlong x y \/ ~ eqlong x y) with
 
1647
  | Nil, Nil => V1
 
1648
  | Nil, Cons a x => V2 a x
 
1649
  | Cons a x, Nil => V3 a x
 
1650
  | Cons a x, Cons b y => V4 a x b y
 
1651
  end.
 
1652
 
 
1653
 
 
1654
Type
 
1655
  (fun x y : List nat =>
 
1656
   match x, y return (eqlong x y \/ ~ eqlong x y) with
 
1657
   | Nil, Nil => V1
 
1658
   | Nil, Cons a x => V2 a x
 
1659
   | Cons a x, Nil => V3 a x
 
1660
   | Cons a x, Cons b y => V4 a x b y
 
1661
   end).
 
1662
 
 
1663
 
 
1664
(* ===================================== *)
 
1665
 
 
1666
Inductive Eqlong :
 
1667
forall n : nat, listn n -> forall m : nat, listn m -> Prop :=
 
1668
  | Eql_cons :
 
1669
      forall (n m : nat) (x : listn n) (y : listn m) (a b : nat),
 
1670
      Eqlong n x m y -> Eqlong (S n) (consn n a x) (S m) (consn m b y)
 
1671
  | Eql_niln : Eqlong 0 niln 0 niln.
 
1672
 
 
1673
 
 
1674
Parameter W1 : Eqlong 0 niln 0 niln \/ ~ Eqlong 0 niln 0 niln.
 
1675
Parameter
 
1676
  W2 :
 
1677
    forall (n a : nat) (x : listn n),
 
1678
    Eqlong 0 niln (S n) (consn n a x) \/ ~ Eqlong 0 niln (S n) (consn n a x).
 
1679
Parameter
 
1680
  W3 :
 
1681
    forall (n a : nat) (x : listn n),
 
1682
    Eqlong (S n) (consn n a x) 0 niln \/ ~ Eqlong (S n) (consn n a x) 0 niln.
 
1683
Parameter
 
1684
  W4 :
 
1685
    forall (n a : nat) (x : listn n) (m b : nat) (y : listn m),
 
1686
    Eqlong (S n) (consn n a x) (S m) (consn m b y) \/
 
1687
    ~ Eqlong (S n) (consn n a x) (S m) (consn m b y).
 
1688
 
 
1689
Type
 
1690
  match
 
1691
    niln as x in (listn n), niln as y in (listn m)
 
1692
    return (Eqlong n x m y \/ ~ Eqlong n x m y)
 
1693
  with
 
1694
  | niln, niln => W1
 
1695
  | niln, consn n a x => W2 n a x
 
1696
  | consn n a x, niln => W3 n a x
 
1697
  | consn n a x, consn m b y => W4 n a x m b y
 
1698
  end.
 
1699
 
 
1700
 
 
1701
Type
 
1702
  (fun (n m : nat) (x : listn n) (y : listn m) =>
 
1703
   match
 
1704
     x in (listn n), y in (listn m)
 
1705
     return (Eqlong n x m y \/ ~ Eqlong n x m y)
 
1706
   with
 
1707
   | niln, niln => W1
 
1708
   | niln, consn n a x => W2 n a x
 
1709
   | consn n a x, niln => W3 n a x
 
1710
   | consn n a x, consn m b y => W4 n a x m b y
 
1711
   end).
 
1712
 
 
1713
 
 
1714
Parameter
 
1715
  Inv_r :
 
1716
    forall (n a : nat) (x : listn n), ~ Eqlong 0 niln (S n) (consn n a x).
 
1717
Parameter
 
1718
  Inv_l :
 
1719
    forall (n a : nat) (x : listn n), ~ Eqlong (S n) (consn n a x) 0 niln.
 
1720
Parameter
 
1721
  Nff :
 
1722
    forall (n a : nat) (x : listn n) (m b : nat) (y : listn m),
 
1723
    ~ Eqlong n x m y -> ~ Eqlong (S n) (consn n a x) (S m) (consn m b y).
 
1724
 
 
1725
 
 
1726
 
 
1727
Fixpoint Eqlongdec (n : nat) (x : listn n) (m : nat) 
 
1728
 (y : listn m) {struct x} : Eqlong n x m y \/ ~ Eqlong n x m y :=
 
1729
  match
 
1730
    x in (listn n), y in (listn m)
 
1731
    return (Eqlong n x m y \/ ~ Eqlong n x m y)
 
1732
  with
 
1733
  | niln, niln => or_introl (~ Eqlong 0 niln 0 niln) Eql_niln
 
1734
  | niln, consn n a x as L => or_intror (Eqlong 0 niln (S n) L) (Inv_r n a x)
 
1735
  | consn n a x as L, niln => or_intror (Eqlong (S n) L 0 niln) (Inv_l n a x)
 
1736
  | consn n a x as L1, consn m b y as L2 =>
 
1737
      match
 
1738
        Eqlongdec n x m y
 
1739
        return (Eqlong (S n) L1 (S m) L2 \/ ~ Eqlong (S n) L1 (S m) L2)
 
1740
      with
 
1741
      | or_introl h =>
 
1742
          or_introl (~ Eqlong (S n) L1 (S m) L2) (Eql_cons n m x y a b h)
 
1743
      | or_intror h =>
 
1744
          or_intror (Eqlong (S n) L1 (S m) L2) (Nff n a x m b y h)
 
1745
      end
 
1746
  end.
 
1747
 
 
1748
(* ============================================== *)
 
1749
(*     To test compilation of dependent case      *)
 
1750
(*      Multiple Patterns                         *)
 
1751
(* ============================================== *)
 
1752
Inductive skel : Type :=
 
1753
  | PROP : skel
 
1754
  | PROD : skel -> skel -> skel.
 
1755
 
 
1756
Parameter Can : skel -> Type.
 
1757
Parameter default_can : forall s : skel, Can s.
 
1758
 
 
1759
Type
 
1760
  (fun s1 s2 s1 s2 : skel =>
 
1761
   match s1, s2 return (Can s1) with
 
1762
   | PROP, PROP => default_can PROP
 
1763
   | PROD x y, PROP => default_can (PROD x y)
 
1764
   | PROD x y, _ => default_can (PROD x y)
 
1765
   | PROP, _ => default_can PROP
 
1766
   end).
 
1767
 
 
1768
(* to test bindings in nested Cases *)
 
1769
(* ================================ *)
 
1770
Inductive Pair : Set :=
 
1771
  | pnil : Pair
 
1772
  | pcons : Pair -> Pair -> Pair.
 
1773
 
 
1774
Type
 
1775
  (fun p q : Pair =>
 
1776
   match p with
 
1777
   | pcons _ x => match q with
 
1778
                  | pcons _ (pcons _ x) => True
 
1779
                  | _ => False
 
1780
                  end
 
1781
   | _ => False
 
1782
   end).
 
1783
 
 
1784
 
 
1785
Type
 
1786
  (fun p q : Pair =>
 
1787
   match p with
 
1788
   | pcons _ x =>
 
1789
       match q with
 
1790
       | pcons _ (pcons _ x) =>
 
1791
           match q with
 
1792
           | pcons _ (pcons _ (pcons _ x)) => x
 
1793
           | _ => pnil
 
1794
           end
 
1795
       | _ => pnil
 
1796
       end
 
1797
   | _ => pnil
 
1798
   end).
 
1799
 
 
1800
Type
 
1801
  (fun (n : nat) (l : listn (S n)) =>
 
1802
   match l in (listn z) return (listn (pred z)) with
 
1803
   | niln => niln
 
1804
   | consn n _ l =>
 
1805
       match l in (listn m) return (listn m) with
 
1806
       | niln => niln
 
1807
       | b => b
 
1808
       end
 
1809
   end).
 
1810
 
 
1811
 
 
1812
 
 
1813
(* Test de la syntaxe avec nombres *)
 
1814
Require Import Arith.
 
1815
Type (fun n => match n with
 
1816
               | S (S O) => true
 
1817
               | _ => false
 
1818
               end).
 
1819
 
 
1820
Require Import ZArith.
 
1821
Type (fun n => match n with
 
1822
               | Z0 => true
 
1823
               | _ => false
 
1824
               end).