| 1 |
(* This example was proposed by Cuihtlauac ALVARADO *) |
| 2 |
|
| 3 |
Fixpoint mult2 (n : nat) : nat := |
| 4 |
match n with |
| 5 |
| O => 0 |
| 6 |
| S n => S (S (mult2 n)) |
| 7 |
end. |
| 8 |
|
| 9 |
Inductive list : nat -> Set := |
| 10 |
| nil : list 0 |
| 11 |
| cons : forall n : nat, list (mult2 n) -> list (S (S (mult2 n))). |
| 12 |
|
| 13 |
Type |
| 14 |
(fun (P : forall n : nat, list n -> Prop) (f : P 0 nil) |
| 15 |
(f0 : forall (n : nat) (l : list (mult2 n)), |
| 16 |
P (mult2 n) l -> P (S (S (mult2 n))) (cons n l)) => |
| 17 |
fix F (n : nat) (l : list n) {struct l} : P n l := |
| 18 |
match l as x0 in (list x) return (P x x0) with |
| 19 |
| nil => f |
| 20 |
| cons n0 l0 => f0 n0 l0 (F (mult2 n0) l0) |
| 21 |
end). |
| 22 |
|
| 23 |
Inductive list' : nat -> Set := |
| 24 |
| nil' : list' 0 |
| 25 |
| cons' : forall n : nat, let m := mult2 n in list' m -> list' (S (S m)). |
| 26 |
|
| 27 |
Fixpoint length n (l : list' n) {struct l} : nat := |
| 28 |
match l with |
| 29 |
| nil' => 0 |
| 30 |
| cons' _ m l0 => S (length m l0) |
| 31 |
end. |
| 32 |
|
| 33 |
Type |
| 34 |
(fun (P : forall n : nat, list' n -> Prop) (f : P 0 nil') |
| 35 |
(f0 : forall n : nat, |
| 36 |
let m := mult2 n in |
| 37 |
forall l : list' m, P m l -> P (S (S m)) (cons' n l)) => |
| 38 |
fix F (n : nat) (l : list' n) {struct l} : P n l := |
| 39 |
match l as x0 in (list' x) return (P x x0) with |
| 40 |
| nil' => f |
| 41 |
| cons' n0 m l0 => f0 n0 l0 (F m l0) |
| 42 |
end). |
| 43 |
|
| 44 |
(* Check on-the-fly insertion of let-in patterns for compatibility *) |
| 45 |
|
| 46 |
Inductive list'' : nat -> Set := |
| 47 |
| nil'' : list'' 0 |
| 48 |
| cons'' : |
| 49 |
forall n : nat, |
| 50 |
let m := mult2 n in list'' m -> let p := S (S m) in list'' p. |
| 51 |
|
| 52 |
Check |
| 53 |
(fix length n (l : list'' n) {struct l} : nat := |
| 54 |
match l with |
| 55 |
| nil'' => 0 |
| 56 |
| cons'' n l0 => S (length (mult2 n) l0) |
| 57 |
end). |
| 58 |
|
| 59 |
(* Check let-in in both parameters and in constructors *) |
| 60 |
|
| 61 |
Inductive list''' (A:Set) (B:=(A*A)%type) (a:A) : B -> Set := |
| 62 |
| nil''' : list''' A a (a,a) |
| 63 |
| cons''' : |
| 64 |
forall a' : A, let m := (a',a) in list''' A a m -> list''' A a (a,a). |
| 65 |
|
| 66 |
Fixpoint length''' (A:Set) (B:=(A*A)%type) (a:A) (m:B) (l:list''' A a m) |
| 67 |
{struct l} : nat := |
| 68 |
match l with |
| 69 |
| nil''' _ _ => 0 |
| 70 |
| @cons''' _ _ _ _ m l0 => S (length''' A a m l0) |
| 71 |
end. |