1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
|
(* Check forward dependencies *)
Check
(fun (P : nat -> Prop) Q (A : P 0 -> Q) (B : forall n : nat, P (S n) -> Q)
x =>
match x return Q with
| exist _ O H => A H
| exist _ (S n) H => B n H
end).
(* Check dependencies in anonymous arguments (from FTA/listn.v) *)
Inductive listn (A : Set) : nat -> Set :=
| niln : listn A 0
| consn : forall (a : A) (n : nat), listn A n -> listn A (S n).
Section Folding.
Variable B C : Set.
Variable g : B -> C -> C.
Variable c : C.
Fixpoint foldrn (n : nat) (bs : listn B n) {struct bs} : C :=
match bs with
| niln _ => c
| consn _ b _ tl => g b (foldrn _ tl)
end.
End Folding.
(** Testing post-processing of nested dependencies *)
Check fun x:{x|x=0}*nat+nat => match x with
| inl ((exist _ 0 eq_refl),0) => None
| _ => Some 0
end.
Check fun x:{_:{x|x=0}|True}+nat => match x with
| inl (exist _ (exist _ 0 eq_refl) I) => None
| _ => Some 0
end.
Check fun x:{_:{x|x=0}|True}+nat => match x with
| inl (exist _ (exist _ 0 eq_refl) I) => None
| _ => Some 0
end.
Check fun x:{_:{x|x=0}|True}+nat => match x return option nat with
| inl (exist _ (exist _ 0 eq_refl) I) => None
| _ => Some 0
end.
(* the next two examples were failing from r14703 (Nov 22 2011) to r14732 *)
(* due to a bug in dependencies postprocessing (revealed by CoLoR) *)
Check fun x:{x:nat*nat|fst x = 0 & True} => match x return option nat with
| exist2 _ _ (x,y) eq_refl I => None
end.
Check fun x:{_:{x:nat*nat|fst x = 0 & True}|True}+nat => match x return option nat with
| inl (exist _ (exist2 _ _ (x,y) eq_refl I) I) => None
| _ => Some 0
end.
(* -------------------------------------------------------------------- *)
(* Example to test patterns matching on dependent families *)
(* This exemple extracted from the development done by Nacira Chabane *)
(* (equipe Paris 6) *)
(* -------------------------------------------------------------------- *)
Require Import Prelude.
Section Orderings.
Variable U : Type.
Definition Relation := U -> U -> Prop.
Variable R : Relation.
Definition Reflexive : Prop := forall x : U, R x x.
Definition Transitive : Prop := forall x y z : U, R x y -> R y z -> R x z.
Definition Symmetric : Prop := forall x y : U, R x y -> R y x.
Definition Antisymmetric : Prop := forall x y : U, R x y -> R y x -> x = y.
Definition contains (R R' : Relation) : Prop :=
forall x y : U, R' x y -> R x y.
Definition same_relation (R R' : Relation) : Prop :=
contains R R' /\ contains R' R.
Inductive Equivalence : Prop :=
Build_Equivalence : Reflexive -> Transitive -> Symmetric -> Equivalence.
Inductive PER : Prop :=
Build_PER : Symmetric -> Transitive -> PER.
End Orderings.
(***** Setoid *******)
Inductive Setoid : Type :=
Build_Setoid :
forall (S : Type) (R : Relation S), Equivalence _ R -> Setoid.
Definition elem (A : Setoid) := let (S, R, e) := A in S.
Definition equal (A : Setoid) :=
let (S, R, e) as s return (Relation (elem s)) := A in R.
Axiom prf_equiv : forall A : Setoid, Equivalence (elem A) (equal A).
Axiom prf_refl : forall A : Setoid, Reflexive (elem A) (equal A).
Axiom prf_sym : forall A : Setoid, Symmetric (elem A) (equal A).
Axiom prf_trans : forall A : Setoid, Transitive (elem A) (equal A).
Section Maps.
Variable A B : Setoid.
Definition Map_law (f : elem A -> elem B) :=
forall x y : elem A, equal _ x y -> equal _ (f x) (f y).
Inductive Map : Type :=
Build_Map : forall (f : elem A -> elem B) (p : Map_law f), Map.
Definition explicit_ap (m : Map) :=
match m return (elem A -> elem B) with
| Build_Map f p => f
end.
Axiom pres : forall m : Map, Map_law (explicit_ap m).
Definition ext (f g : Map) :=
forall x : elem A, equal _ (explicit_ap f x) (explicit_ap g x).
Axiom Equiv_map_eq : Equivalence Map ext.
Definition Map_setoid := Build_Setoid Map ext Equiv_map_eq.
End Maps.
Notation ap := (explicit_ap _ _).
(* <Warning> : Grammar is replaced by Notation *)
Definition ap2 (A B C : Setoid) (f : elem (Map_setoid A (Map_setoid B C)))
(a : elem A) := ap (ap f a).
(***** posint ******)
Inductive posint : Type :=
| Z : posint
| Suc : posint -> posint.
Axiom
f_equal : forall (A B : Type) (f : A -> B) (x y : A), x = y -> f x = f y.
Axiom eq_Suc : forall n m : posint, n = m -> Suc n = Suc m.
(* The predecessor function *)
Definition pred (n : posint) : posint :=
match n return posint with
| Z => (* Z *) Z
(* Suc u *)
| Suc u => u
end.
Axiom pred_Sucn : forall m : posint, m = pred (Suc m).
Axiom eq_add_Suc : forall n m : posint, Suc n = Suc m -> n = m.
Axiom not_eq_Suc : forall n m : posint, n <> m -> Suc n <> Suc m.
Definition IsSuc (n : posint) : Prop :=
match n return Prop with
| Z => (* Z *) False
(* Suc p *)
| Suc p => True
end.
Definition IsZero (n : posint) : Prop :=
match n with
| Z => True
| Suc _ => False
end.
Axiom Z_Suc : forall n : posint, Z <> Suc n.
Axiom Suc_Z : forall n : posint, Suc n <> Z.
Axiom n_Sucn : forall n : posint, n <> Suc n.
Axiom Sucn_n : forall n : posint, Suc n <> n.
Axiom eqT_symt : forall a b : posint, a <> b -> b <> a.
(******* Dsetoid *****)
Definition Decidable (A : Type) (R : Relation A) :=
forall x y : A, R x y \/ ~ R x y.
Record DSetoid : Type :=
{Set_of : Setoid; prf_decid : Decidable (elem Set_of) (equal Set_of)}.
(* example de Dsetoide d'entiers *)
Axiom eqT_equiv : Equivalence posint (eq (A:=posint)).
Axiom Eq_posint_deci : Decidable posint (eq (A:=posint)).
(* Dsetoide des posint*)
Definition Set_of_posint := Build_Setoid posint (eq (A:=posint)) eqT_equiv.
Definition Dposint := Build_DSetoid Set_of_posint Eq_posint_deci.
(**************************************)
(* Definition des signatures *)
(* une signature est un ensemble d'operateurs muni
de l'arite de chaque operateur *)
Module Sig.
Record Signature : Type :=
{Sigma : DSetoid; Arity : Map (Set_of Sigma) (Set_of Dposint)}.
Parameter S : Signature.
Parameter Var : DSetoid.
Inductive TERM : Type :=
| var : elem (Set_of Var) -> TERM
| oper :
forall op : elem (Set_of (Sigma S)), LTERM (ap (Arity S) op) -> TERM
with LTERM : posint -> Type :=
| nil : LTERM Z
| cons : TERM -> forall n : posint, LTERM n -> LTERM (Suc n).
(* -------------------------------------------------------------------- *)
(* Examples *)
(* -------------------------------------------------------------------- *)
Parameter t1 t2 : TERM.
Type
match t1, t2 with
| var v1, var v2 => True
| oper op1 l1, oper op2 l2 => False
| _, _ => False
end.
Parameter n2 : posint.
Parameter l1 l2 : LTERM n2.
Type
match l1, l2 with
| nil, nil => True
| cons v m y, nil => False
| _, _ => False
end.
Type
match l1, l2 with
| nil, nil => True
| cons u n x, cons v m y => False
| _, _ => False
end.
Module Type Version1.
Definition equalT (t1 t2 : TERM) : Prop :=
match t1, t2 with
| var v1, var v2 => True
| oper op1 l1, oper op2 l2 => False
| _, _ => False
end.
Definition EqListT (n1 : posint) (l1 : LTERM n1) (n2 : posint)
(l2 : LTERM n2) : Prop :=
match l1, l2 with
| nil, nil => True
| cons t1 n1' l1', cons t2 n2' l2' => False
| _, _ => False
end.
End Version1.
(* ------------------------------------------------------------------*)
(* Initial example (without patterns) *)
(*-------------------------------------------------------------------*)
Module Version2.
Fixpoint equalT (t1 : TERM) : TERM -> Prop :=
match t1 return (TERM -> Prop) with
| var v1 =>
(*var*)
fun t2 : TERM =>
match t2 return Prop with
| var v2 =>
(*var*) equal _ v1 v2
(*oper*)
| oper op2 _ => False
end
(*oper*)
| oper op1 l1 =>
fun t2 : TERM =>
match t2 return Prop with
| var v2 =>
(*var*) False
(*oper*)
| oper op2 l2 =>
equal _ op1 op2 /\
EqListT (ap (Arity S) op1) l1 (ap (Arity S) op2) l2
end
end
with EqListT (n1 : posint) (l1 : LTERM n1) {struct l1} :
forall n2 : posint, LTERM n2 -> Prop :=
match l1 in (LTERM _) return (forall n2 : posint, LTERM n2 -> Prop) with
| nil =>
(*nil*)
fun (n2 : posint) (l2 : LTERM n2) =>
match l2 in (LTERM _) return Prop with
| nil =>
(*nil*) True
(*cons*)
| cons t2 n2' l2' => False
end
(*cons*)
| cons t1 n1' l1' =>
fun (n2 : posint) (l2 : LTERM n2) =>
match l2 in (LTERM _) return Prop with
| nil =>
(*nil*) False
(*cons*)
| cons t2 n2' l2' => equalT t1 t2 /\ EqListT n1' l1' n2' l2'
end
end.
End Version2.
(* ---------------------------------------------------------------- *)
(* Version with simple patterns *)
(* ---------------------------------------------------------------- *)
Module Version3.
Fixpoint equalT (t1 : TERM) : TERM -> Prop :=
match t1 with
| var v1 =>
fun t2 : TERM =>
match t2 with
| var v2 => equal _ v1 v2
| oper op2 _ => False
end
| oper op1 l1 =>
fun t2 : TERM =>
match t2 with
| var _ => False
| oper op2 l2 =>
equal _ op1 op2 /\
EqListT (ap (Arity S) op1) l1 (ap (Arity S) op2) l2
end
end
with EqListT (n1 : posint) (l1 : LTERM n1) {struct l1} :
forall n2 : posint, LTERM n2 -> Prop :=
match l1 return (forall n2 : posint, LTERM n2 -> Prop) with
| nil =>
fun (n2 : posint) (l2 : LTERM n2) =>
match l2 with
| nil => True
| _ => False
end
| cons t1 n1' l1' =>
fun (n2 : posint) (l2 : LTERM n2) =>
match l2 with
| nil => False
| cons t2 n2' l2' => equalT t1 t2 /\ EqListT n1' l1' n2' l2'
end
end.
End Version3.
Module Version4.
Fixpoint equalT (t1 : TERM) : TERM -> Prop :=
match t1 with
| var v1 =>
fun t2 : TERM =>
match t2 with
| var v2 => equal _ v1 v2
| oper op2 _ => False
end
| oper op1 l1 =>
fun t2 : TERM =>
match t2 with
| var _ => False
| oper op2 l2 =>
equal _ op1 op2 /\
EqListT (ap (Arity S) op1) l1 (ap (Arity S) op2) l2
end
end
with EqListT (n1 : posint) (l1 : LTERM n1) (n2 : posint)
(l2 : LTERM n2) {struct l1} : Prop :=
match l1 with
| nil => match l2 with
| nil => True
| _ => False
end
| cons t1 n1' l1' =>
match l2 with
| nil => False
| cons t2 n2' l2' => equalT t1 t2 /\ EqListT n1' l1' n2' l2'
end
end.
End Version4.
(* ---------------------------------------------------------------- *)
(* Version with multiple patterns *)
(* ---------------------------------------------------------------- *)
Module Version5.
Fixpoint equalT (t1 t2 : TERM) {struct t1} : Prop :=
match t1, t2 with
| var v1, var v2 => equal _ v1 v2
| oper op1 l1, oper op2 l2 =>
equal _ op1 op2 /\ EqListT (ap (Arity S) op1) l1 (ap (Arity S) op2) l2
| _, _ => False
end
with EqListT (n1 : posint) (l1 : LTERM n1) (n2 : posint)
(l2 : LTERM n2) {struct l1} : Prop :=
match l1, l2 with
| nil, nil => True
| cons t1 n1' l1', cons t2 n2' l2' =>
equalT t1 t2 /\ EqListT n1' l1' n2' l2'
| _, _ => False
end.
End Version5.
(* ------------------------------------------------------------------ *)
End Sig.
(* Exemple soumis par Bruno *)
Definition bProp (b : bool) : Prop := if b then True else False.
Definition f0 (F : False) (ty : bool) : bProp ty :=
match ty as _, ty return (bProp ty) with
| true, true => I
| _, false => F
| _, true => I
end.
(* Simplification of bug/wish #1671 *)
Inductive I : unit -> Type :=
| C : forall a, I a -> I tt.
(*
Definition F (l:I tt) : l = l :=
match l return l = l with
| C tt (C _ l') => refl_equal (C tt (C _ l'))
end.
one would expect that the compilation of F (this involves
some kind of pattern-unification) would produce:
*)
Definition F (l:I tt) : l = l :=
match l return l = l with
| C tt l' => match l' return C _ l' = C _ l' with C _ l'' => refl_equal (C tt (C _ l'')) end
end.
Inductive J : nat -> Type :=
| D : forall a, J (S a) -> J a.
(*
Definition G (l:J O) : l = l :=
match l return l = l with
| D O (D 1 l') => refl_equal (D O (D 1 l'))
| D _ _ => refl_equal _
end.
one would expect that the compilation of G (this involves inversion)
would produce:
*)
Definition G (l:J O) : l = l :=
match l return l = l with
| D 0 l'' =>
match l'' as _l'' in J n return
match n return forall l:J n, Prop with
| O => fun _ => l = l
| S p => fun l'' => D p l'' = D p l''
end _l'' with
| D 1 l' => refl_equal (D O (D 1 l'))
| _ => refl_equal _
end
| _ => refl_equal _
end.
Fixpoint app {A} {n m} (v : listn A n) (w : listn A m) : listn A (n + m) :=
match v with
| niln _ => w
| consn _ a n' v' => consn _ a _ (app v' w)
end.
(* Testing regression of bug 2106 *)
Set Implicit Arguments.
Require Import List.
Inductive nt := E.
Definition root := E.
Inductive ctor : list nt -> nt -> Type :=
Plus : ctor (cons E (cons E nil)) E.
Inductive term : nt -> Type :=
| Term : forall s n, ctor s n -> spine s -> term n
with spine : list nt -> Type :=
| EmptySpine : spine nil
| ConsSpine : forall n s, term n -> spine s -> spine (n :: s).
Inductive step : nt -> nt -> Type :=
| Step : forall l n r n' (c:ctor (l++n::r) n'), spine l -> spine r -> step n
n'.
Definition test (s:step E E) :=
match s with
| @Step nil _ (cons E nil) _ Plus l l' => true
| _ => false
end.
(* Testing regression of bug 2454 ("get" used not be type-checkable when
defined with its type constraint) *)
Inductive K : nat -> Type := KC : forall (p q:nat), K p.
Definition get : K O -> nat := fun x => match x with KC p q => q end.
(* Checking correct order of substitution of realargs *)
(* (was broken from revision 14664 to 14669) *)
(* Example extracted from contrib CoLoR *)
Inductive EQ : nat -> nat -> Prop := R x y : EQ x y.
Check fun e t (d1 d2:EQ e t) =>
match d1 in EQ e1 t1, d2 in EQ e2 t2 return
(e1,t1) = (e2,t2) -> (e1,t1) = (e,t) -> 0=0
with
| R _ _, R _ _ => fun _ _ => eq_refl
end.
|