Debian Codegraph @

test-suite/success/induct.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* Test des definitions inductives imbriquees *)
12
13 Inductive X : Set :=
14 cons1 : list X -> X.
15
16 Inductive Y : Set :=
17 cons2 : list (Y * Y) -> Y.
18
19 (* Test inductive types with local definitions *)
20
21 Inductive eq1 : forall A:Type, let B:=A in A -> Prop :=
22 refl1 : eq1 True I.
23
24 Check
25 fun (P : forall A : Type, let B := A in A -> Type) (f : P True I) (A : Type) =>
26 let B := A in
27 fun (a : A) (e : eq1 A a) =>
28 match e in (eq1 A0 a0) return (P A0 a0) with
29 | refl1 => f
30 end.
31
32 Inductive eq2 (A:Type) (a:A)
33 : forall B C:Type, let D:=(A*B*C)%type in D -> Prop :=
34 refl2 : eq2 A a unit bool (a,tt,true).
35
36 (* Check that induction variables are cleared even with in clause *)
37
38 Lemma foo : forall n m : nat, n + m = n + m.
39 Proof.
40 intros; induction m as [|m] in n |- *.
41 auto.
42 auto.
43 Qed.
44
45 (* Check selection of occurrences by pattern *)
46
47 Goal forall x, S x = S (S x).
48 intros.
49 induction (S _) in |- * at -2.
50 now_show (0=1).
51 Undo 2.
52 induction (S _) in |- * at 1 3.
53 now_show (0=1).
54 Undo 2.
55 induction (S _) in |- * at 1.
56 now_show (0=S (S x)).
57 Undo 2.
58 induction (S _) in |- * at 2.
59 now_show (S x=0).
60 Undo 2.
61 induction (S _) in |- * at 3.
62 now_show (S x=1).
63 Undo 2.
64 Fail induction (S _) in |- * at 4.
65 Abort.
66
67 (* Check use of "as" clause *)
68
69 Inductive I := C : forall x, x<0 -> I -> I.
70
71 Goal forall x:I, x=x.
72 intros.
73 induction x as [y * IHx].
74 change (x = x) in IHx. (* We should have IHx:x=x *)
75 Abort.
76
77 (* This was not working in 8.4 *)
78
79 Goal forall h:nat->nat, h 0 = h 1 -> h 1 = h 2 -> h 0 = h 2.
80 intros.
81 induction h.
82 2:change (n = h 1 -> n = h 2) in IHn.
83 Abort.
84
85 (* This was not working in 8.4 *)
86
87 Goal forall h:nat->nat, h 0 = h 1 -> h 1 = h 2 -> h 0 = h 2.
88 intros h H H0.
89 induction h in H |- *.
90 Abort.
91
92 (* "at" was not granted in 8.4 in the next two examples *)
93
94 Goal forall h:nat->nat, h 0 = h 1 -> h 1 = h 2 -> h 0 = h 2.
95 intros h H H0.
96 induction h in H at 2, H0 at 1.
97 change (h 0 = 0) in H.
98 Abort.
99
100 Goal forall h:nat->nat, h 0 = h 1 -> h 1 = h 2 -> h 0 = h 2.
101 intros h H H0.
102 Fail induction h in H at 2 |- *. (* Incompatible occurrences *)
103 Abort.
104
105 (* Check generalization with dependencies in section variables *)
106
107 Section S3.
108 Variables x : nat.
109 Definition cond := x = x.
110 Goal cond -> x = 0.
111 intros H.
112 induction x as [|n IHn].
113 2:change (n = 0) in IHn. (* We don't want a generalization over cond *)
114 Abort.
115 End S3.
116
117 (* These examples show somehow arbitrary choices of generalization wrt
118 to indices, when those indices are not linear. We check here 8.4
119 compatibility: when an index is a subterm of a parameter of the
120 inductive type, it is not generalized. *)
121
122 Inductive repr (x:nat) : nat -> Prop := reprc z : repr x z -> repr x z.
123
124 Goal forall x, 0 = x -> repr x x -> True.
125 intros x H1 H.
126 induction H.
127 change True in IHrepr.
128 Abort.
129
130 Goal forall x, 0 = S x -> repr (S x) (S x) -> True.
131 intros x H1 H.
132 induction H.
133 change True in IHrepr.
134 Abort.
135
136 Inductive repr' (x:nat) : nat -> Prop := reprc' z : repr' x (S z) -> repr' x z.
137
138 Goal forall x, 0 = x -> repr' x x -> True.
139 intros x H1 H.
140 induction H.
141 change True in IHrepr'.
142 Abort.
143
144 (* In this case, generalization was done in 8.4 and we preserve it; this
145 is arbitrary choice *)
146
147 Inductive repr'' : nat -> nat -> Prop := reprc'' x z : repr'' x z -> repr'' x z.
148
149 Goal forall x, 0 = x -> repr'' x x -> True.
150 intros x H1 H.
151 induction H.
152 change (0 = z -> True) in IHrepr''.
153 Abort.
154
155 (* Mentioned as part of bug #12944 *)
156
157 Inductive test : Set := cons : forall (IHv : nat) (v : test), test.
158
159 Goal test -> test.
160 induction 1 as [? IHv].
161 Undo.
162 destruct 1 as [? IHv].
163 exact IHv. (* Check that the name is granted *)
164 Qed.