-
Notifications
You must be signed in to change notification settings - Fork 3
/
A012moreind.v
323 lines (274 loc) · 7.44 KB
/
A012moreind.v
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
Require Export A011profobj.
Print nat_ind.
(*
nat_ind =
fun P : nat -> Prop => nat_rect P
: forall P : nat -> Prop,
P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n
*)
Theorem mult_0_r' : forall n:nat,
n * 0 = 0.
Proof.
apply nat_ind. reflexivity.
simpl. intros. assumption.
Qed.
Print nat_rect.
(*
nat_rect =
fun (P : nat -> Type) (f : P 0) (f0 : forall n : nat, P n -> P (S n)) =>
fix F (n : nat) : P n :=
match n as n0 return (P n0) with
| 0 => f
| S n0 => f0 n0 (F n0)
end
: forall P : nat -> Type,
P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n
*)
Definition nat_ind' (P : nat -> Prop) :
(P 0) -> (forall n, P n -> P (S n)) -> forall n, P n.
Proof.
intros. induction n.
assumption. apply H0. assumption.
Defined.
Theorem plus_one_r' : forall n:nat,
n + 1 = S n.
Proof.
apply nat_ind'. reflexivity.
intros. simpl. rewrite H. reflexivity.
Qed.
Print plus_one_r'.
(*
plus_one_r' =
nat_ind (fun n : nat => n + 1 = S n) eq_refl
(fun (n : nat) (H : n + 1 = S n) =>
eq_ind_r (fun n0 : nat => S n0 = S (S n)) eq_refl H)
: forall n : nat, n + 1 = S n
*)
Inductive yesno : Type :=
| yes : yesno
| no : yesno.
Check yesno_ind.
Inductive rgb : Type :=
| red : rgb
| green : rgb
| blue : rgb.
Definition rgb_ind' (P : rgb -> Prop) (_ : P red) (_ : P green) (_ : P blue)
: forall a : rgb, P a.
Proof.
intros.
induction a; assumption.
Qed.
Check rgb_ind'. (* forall P : rgb -> Prop, P red -> P green -> P blue -> forall a : rgb, P a *)
Check rgb_ind. (* forall P : rgb -> Prop, P red -> P green -> P blue -> forall r : rgb, P r *)
Inductive natlist : Type :=
| nnil : natlist
| ncons : nat -> natlist -> natlist.
Definition natlist_ind' (P : natlist -> Prop)
(_ : P nnil)
(_ : forall x l, P l -> P (ncons x l))
(n : natlist) := P n.
Check natlist_ind'.
(* !!!Notice!!! Not correct!
natlist_ind'
: forall P : natlist -> Prop,
P nnil ->
(forall (x : nat) (l : natlist), P l -> P (ncons x l)) ->
natlist -> Prop
*)
Check natlist_ind.
(*
natlist_ind
: forall P : natlist -> Prop,
P nnil ->
(forall (n : nat) (n0 : natlist), P n0 -> P (ncons n n0)) ->
forall n : natlist, P n
*)
Inductive natlist1 : Type :=
| nnil1 : natlist1
| nsnoc1 : natlist1 -> nat -> natlist1.
(* natlist1_ind :
forall P : natlist1 -> Prop, P nnil1
-> (forall l, P l -> forall a, P (nsnoc1 l a))
-> forall l, P l.
*)
Check natlist1_ind.
(*
natlist1_ind
: forall P : natlist1 -> Prop,
P nnil1 ->
(forall n : natlist1, P n -> forall n0 : nat, P (nsnoc1 n n0)) ->
forall n : natlist1, P n
*)
Inductive byntree : Type :=
| bempty : byntree
| bleaf : yesno -> byntree
| nbranch : yesno -> byntree -> byntree -> byntree.
(* byntree_ind
: forall P: byntree -> Prop,
P empty
-> (forall x, P (bleaf x))
-> (forall x t1 t2, P t1 -> P t2 -> P (nbranch x t1 t2))
-> forall t, P t.
*)
Check byntree_ind.
(*
byntree_ind
: forall P : byntree -> Prop,
P bempty ->
(forall y : yesno, P (bleaf y)) ->
(forall (y : yesno) (b : byntree),
P b -> forall b0 : byntree, P b0 -> P (nbranch y b b0)) ->
forall b : byntree, P b
*)
(*
ExSet_ind :
∀P : ExSet → Prop,
(∀b : bool, P (con1 b)) →
(∀(n : nat) (e : ExSet), P e → P (con2 n e)) →
∀e : ExSet, P e
*)
Inductive ExSet :=
| con1 : bool -> ExSet
| con2 : nat -> ExSet -> ExSet.
Check ExSet_ind.
(*
ExSet_ind
: forall P : ExSet -> Prop,
(forall b : bool, P (con1 b)) ->
(forall (n : nat) (e : ExSet), P e -> P (con2 n e)) ->
forall e : ExSet, P e
*)
Inductive tree (X:Type) : Type :=
| leaf : X -> tree X
| node : tree X -> tree X -> tree X.
Definition tree_ind' {X} (P : tree X -> Prop) :
(forall x : X, P (leaf X x))
-> (forall t1 t2 : tree X, P t1 -> P t2 -> P (node X t1 t2))
-> forall t : tree X, P t.
admit.
Defined.
Check tree_ind.
(*
mytype_ind :
∀(X : Type) (P : mytype X → Prop),
(∀x : X, P (constr1 X x)) →
(∀n : nat, P (constr2 X n)) →
(∀m : mytype X, P m →
∀n : nat, P (constr3 X m n)) →
∀m : mytype X, P m
*)
Inductive mytype (X : Type) :=
| constr1 : X -> mytype X
| constr2 : nat -> mytype X
| constr3 : mytype X -> nat -> mytype X.
Check mytype_ind.
(*
mytype_ind
: forall (X : Type) (P : mytype X -> Prop),
(forall x : X, P (constr1 X x)) ->
(forall n : nat, P (constr2 X n)) ->
(forall m : mytype X, P m -> forall n : nat, P (constr3 X m n)) ->
forall m : mytype X, P m
*)
(*
foo_ind :
∀(X Y : Type) (P : foo X Y → Prop),
(∀x : X, P (bar X Y x)) →
(∀y : Y, P (baz X Y y)) →
(∀f1 : nat → foo X Y,
(∀n : nat, P (f1 n)) → P (quux X Y f1)) →
∀f2 : foo X Y, P f2
*)
Inductive foo (X : Type) (Y : Type) :=
| bar : X -> foo X Y
| baz : Y -> foo X Y
| quux : (nat -> foo X Y) -> foo X Y.
Check foo_ind.
(*
foo_ind
: forall (X Y : Type) (P : foo X Y -> Prop),
(forall x : X, P (bar X Y x)) ->
(forall y : Y, P (baz X Y y)) ->
(forall f1 : nat -> foo X Y,
(forall n : nat, P (f1 n)) -> P (quux X Y f1)) ->
forall f2 : foo X Y, P f2
*)
Inductive foo' (X:Type) : Type :=
| C1 : list X -> foo' X -> foo' X
| C2 : foo' X.
(*
foo'_ind :
forall (X : Type) (P : foo' X -> Prop),
(forall (l : list X) (f : foo' X), P f -> P (C1 X l f)) ->
P (C2 X) ->
forall f : foo' X, P f.
*)
Check foo'_ind.
(*
foo'_ind
: forall (X : Type) (P : foo' X -> Prop),
(forall (l : list X) (f : foo' X), P f -> P (C1 X l f)) ->
P (C2 X) -> forall f1 : foo' X, P f1
*)
Theorem plus_assoc' :
forall n m p, n + (m + p) = n + m + p.
Proof.
intros.
induction n as [| n'].
reflexivity.
simpl. rewrite IHn'. reflexivity.
Qed.
Theorem plus_comm' : forall n m : nat,
n + m = m + n.
Proof.
induction n as [| n'].
intros. rewrite plus_0_r. reflexivity.
intros. simpl. rewrite -> IHn'.
rewrite plus_n_Sm. reflexivity.
Qed.
Definition P_pa : nat -> nat -> nat -> Prop :=
fun n => fun m p => n + (m + p) = n + m + p.
Theorem plus_assoc'' :
forall m, forall p, forall n, P_pa n m p.
Proof.
intros m p.
apply nat_ind. reflexivity.
unfold P_pa. intros. simpl. rewrite H. reflexivity.
Qed.
Definition P_pc (n : nat) (m : nat) : Prop :=
n + m = m + n.
Theorem plus_comm'' :
forall m n, P_pc n m.
Proof.
intro. apply nat_ind.
unfold P_pc. rewrite plus_0_r. reflexivity.
unfold P_pc. intros. simpl. rewrite -> H.
rewrite plus_n_Sm. reflexivity.
Qed.
(*
Inductive beautiful : nat -> Prop :=
| b_0 : beautiful 0
| b_3 : beautiful 3
| b_5 : beautiful 5
| b_sum : forall m n : nat,
beautiful m -> beautiful n ->
beautiful (m + n).
*)
Lemma one_not_beautiful_FAILED: ~ beautiful 1.
Proof.
intro H.
remember 1.
induction H; inversion Heqn.
destruct m.
destruct n.
inversion H2.
simpl in H2. apply IHbeautiful2 in H2. inversion H2.
destruct n.
rewrite plus_0_r in H2. apply IHbeautiful1 in H2. inversion H2.
inversion H2. rewrite NPeano.Nat.add_succ_r in H3. inversion H3.
Qed.
Goal forall n m o, n <= m -> m <= o -> n <= o.
Proof.
intros.
induction H.
assumption.