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