| 1 |
Require Import ListDef. |
| 2 |
|
| 3 |
Check |
| 4 |
(fix F (A B : Set) (f : A -> B) (l : list A) {struct l} : |
| 5 |
list B := match l with |
| 6 |
| nil => nil |
| 7 |
| a :: l => f a :: F _ _ f l |
| 8 |
end). |
| 9 |
|
| 10 |
(* V8 printing of this term used to failed in V8.0 and V8.0pl1 (cf BZ#860) *) |
| 11 |
Check |
| 12 |
let fix f (m : nat) : nat := |
| 13 |
match m with |
| 14 |
| O => 0 |
| 15 |
| S m' => f m' |
| 16 |
end |
| 17 |
in f 0. |
| 18 |
|
| 19 |
Inductive even : nat -> Type := |
| 20 |
| even_O : even 0 |
| 21 |
| even_S : forall n, odd n -> even (S n) |
| 22 |
with odd : nat -> Type := |
| 23 |
odd_S : forall n, even n -> odd (S n). |
| 24 |
|
| 25 |
(* Check printing of fix *) |
| 26 |
Ltac f id1 id2 := fix id1 2 with (id2 n (H:odd n) {struct H} : n >= 1). |
| 27 |
Print Ltac f. |
| 28 |
|
| 29 |
CoInductive Inf := IS { projS : Inf }. |
| 30 |
Definition expand_Inf (x : Inf) := IS (projS x). |
| 31 |
CoFixpoint inf := IS inf. |
| 32 |
Eval compute in inf. |
| 33 |
|
| 34 |
Module Recursivity. |
| 35 |
|
| 36 |
Open Scope nat_scope. |
| 37 |
|
| 38 |
Fixpoint f n := match n with 0 => 0 | S n => f n end. |
| 39 |
Fixpoint g n := match n with 0 => 0 | S n => n end. |
| 40 |
Fixpoint h1 n := match n with 0 => 0 | S n => h2 n end |
| 41 |
with h2 n := match n with 0 => 0 | S n => h1 n end. |
| 42 |
Fixpoint k1 n := match n with 0 => 0 | S n => k2 n end |
| 43 |
with k2 n := match n with 0 => 0 | S n => n end. |
| 44 |
Fixpoint l1 n := match n with 0 => 0 | S n => l1 n end |
| 45 |
with l2 n := match n with 0 => 0 | S n => l2 n end. |
| 46 |
Fixpoint m1 n := match n with 0 => 0 | S n => m1 n end |
| 47 |
with m2 n := match n with 0 => 0 | S n => n end. |
| 48 |
(* Why not to allow this definition ? |
| 49 |
Fixpoint h1' n := match n with 0 => 0 | S n => h2' n end |
| 50 |
with h2' n := h1' n. |
| 51 |
*) |
| 52 |
CoInductive S := cons : nat -> S -> S. |
| 53 |
CoFixpoint c := cons 0 c. |
| 54 |
CoFixpoint d := cons 0 c. |
| 55 |
CoFixpoint e1 := cons 0 e2 |
| 56 |
with e2 := cons 1 e1. |
| 57 |
CoFixpoint a1 := cons 0 a1 |
| 58 |
with a2 := cons 1 a2. |
| 59 |
(* Why not to allow this definition ? |
| 60 |
CoFixpoint b1 := cons 0 b2 |
| 61 |
with b2 := b1. |
| 62 |
*) |
| 63 |
|
| 64 |
End Recursivity. |
| 65 |
|
| 66 |
Module Guard. |
| 67 |
|
| 68 |
Open Scope nat_scope. |
| 69 |
|
| 70 |
Lemma foo : nat -> nat -> bool |
| 71 |
with bar : nat -> nat -> bool. |
| 72 |
Proof. |
| 73 |
Fail Guarded. (* not enough abstractions in the definition *) |
| 74 |
all:intros n m. |
| 75 |
Guarded. |
| 76 |
- destruct n as [|n]. |
| 77 |
+ exact (bar 0 0). |
| 78 |
Fail Guarded. (* failure is correct here *) |
| 79 |
Abort. |
| 80 |
|
| 81 |
Lemma foo : nat -> nat -> bool |
| 82 |
with bar : nat -> nat -> bool. |
| 83 |
Proof. |
| 84 |
all:intros n m. |
| 85 |
- destruct n as [|n]. |
| 86 |
+ exact true. |
| 87 |
+ Guarded. |
| 88 |
exact (bar m n). |
| 89 |
- Guarded. |
| 90 |
destruct m as [|m]. |
| 91 |
+ exact false. |
| 92 |
+ exact (foo m n). |
| 93 |
Guarded. |
| 94 |
Defined. |
| 95 |
|
| 96 |
Inductive STrue : SProp := SI. |
| 97 |
|
| 98 |
Lemma foo' : nat -> Prop -> bool |
| 99 |
with bar' : STrue -> nat -> bool. |
| 100 |
Proof. |
| 101 |
all:intros n m. |
| 102 |
- destruct n as [|n]. |
| 103 |
Guarded. |
| 104 |
+ exact (bar' SI 0). |
| 105 |
Fail Guarded. |
| 106 |
Abort. |
| 107 |
|
| 108 |
End Guard. |