-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInduction.v
More file actions
364 lines (307 loc) · 6.78 KB
/
Induction.v
File metadata and controls
364 lines (307 loc) · 6.78 KB
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
From LF Require Export Basics.
From Stdlib Require Export String.
Theorem add_0_r_firsttry: forall n:nat,
n + 0 = n.
Proof.
intros n.
simpl.
Abort.
Theorem add_0_r_secondtry : forall n:nat,
n + 0 = n.
Proof.
intros n.
destruct n as [ | n'] eqn:E.
- reflexivity.
- simpl.
Abort.
Theorem add_0_r : forall n:nat, n+0 = n.
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite -> IHn'. simpl. reflexivity.
Qed.
Theorem mult_0_r : forall n:nat,
n * 0 = 0.
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite -> IHn'. reflexivity.
Qed.
Theorem plus_n_Sm : forall n m : nat,
S ( n + m) = n + (S m).
Proof.
intros n m.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite -> IHn'. reflexivity.
Qed.
Theorem add_comm : forall n m : nat,
n + m = m + n.
Proof.
intros n m.
induction m as [ | m' IHm'].
- simpl. rewrite -> add_0_r. reflexivity.
- simpl. rewrite <- plus_n_Sm. rewrite <- IHm'. simpl. reflexivity.
Qed.
Theorem add_assoc : forall n m p : nat,
n + ( m + p) = (n + m ) + p.
Proof.
intros n m p.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite <- IHn'. reflexivity.
Qed.
Fixpoint double ( n : nat) :=
match n with
| O => O
| S n' => S ( S (double n'))
end.
Lemma double_plus : forall n, double n = n + n.
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite -> IHn'. rewrite -> plus_n_Sm. simpl. reflexivity.
Qed.
Theorem eqb_refl : forall n : nat,
( n =? n ) = true.
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite -> IHn'. reflexivity.
Qed.
Theorem even_S : forall n : nat,
even ( S n) = negb ( even n).
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- rewrite -> IHn'. simpl. rewrite -> negb_involutive. reflexivity.
Qed.
(* ------------------- PROOFS WITHIN PROOFS ----------------------- *)
Theorem mult_0_plus' : forall n m : nat,
(n +0 + 0) * m = n * m.
Proof.
intros n m.
replace (n+0+0) with n.
- reflexivity.
- rewrite add_comm. simpl. rewrite add_comm. reflexivity.
Qed.
Theorem pluse_rearrange_firsttry : forall n m p q : nat,
(n + m) + ( p + q) = ( m + n)+(p + q).
Proof.
intros n m p q.
rewrite add_comm.
Abort.
Theorem plus_rearrange : forall n m p q : nat,
(n + m)+(p + q) = (m + n)+(p+q).
Proof.
intros n m p q.
replace ( n + m) with ( m + n).
- reflexivity.
- rewrite add_comm. reflexivity.
Qed.
Theorem add_shuffle3 : forall n m p : nat,
n + (m + p) = m + (n + p).
Proof.
intros n m p.
replace (n + (m + p)) with ((n + m) + p).
{
replace (n + m) with (m + n).
{
rewrite add_assoc.
reflexivity.
}
{
rewrite add_comm.
reflexivity.
}
}
{
rewrite <- add_assoc.
reflexivity.
}
Qed.
Lemma mul_succ_r : forall n m : nat,
n * (S m) = n + n * m.
Proof.
intros n m.
induction n as [| n' IHn'].
- simpl. reflexivity.
- simpl.
rewrite IHn'.
rewrite add_assoc.
rewrite add_assoc.
rewrite (add_comm m n').
reflexivity.
Qed.
Theorem mul_comm : forall m n : nat,
m*n = n*m.
Proof.
intros n m.
induction n as [ | n' IHn'].
- simpl. rewrite mult_0_r. reflexivity.
- simpl. rewrite mul_succ_r. rewrite IHn'. reflexivity.
Qed.
Theorem leb_refl : forall n : nat,
( n <=? n) = true.
Proof.
intros n.
induction n as [ | n' IHn'].
- simpl. reflexivity.
- simpl. rewrite IHn'. reflexivity.
Qed.
Theorem zero_neqb_S: forall n:nat,
0=? (S n) = false.
Proof.
intros n.
simpl.
reflexivity.
Qed.
Theorem andb_false_r : forall b : bool,
andb b false = false.
Proof.
intros b.
destruct b as [|] eqn:Eb.
- reflexivity.
- reflexivity.
Qed.
Theorem S_neqb_0: forall n:nat,
(S n) =? 0 = false.
Proof.
intros n.
simpl.
reflexivity.
Qed.
Theorem mult_1_l : forall n : nat,
1*n = n.
Proof.
intros n.
destruct n as [|n'] eqn:E.
- simpl. reflexivity.
- simpl. rewrite add_0_r. reflexivity.
Qed.
Theorem all3_spec : forall b c : bool,
orb
(andb b c)
(orb (negb b)
(negb c))
= true.
Proof.
intros b c.
destruct b eqn:Eb.
- simpl.
destruct c eqn:Ec.
+ simpl. reflexivity.
+ simpl. reflexivity.
- simpl. reflexivity.
Qed.
Theorem mult_plus_distr_r : forall n m p : nat,
(n + m)*p = (n*p)+(m*p).
Proof.
intros n m p.
induction n as [ |n' IHn'].
- simpl. reflexivity.
- simpl. rewrite IHn'. rewrite add_assoc. reflexivity.
Qed.
Theorem mult_assoc : forall n m p: nat,
n*(m*p) = (n*m)*p.
Proof.
intros n m p.
induction n as [|n' IHn'].
- simpl. reflexivity.
- simpl. rewrite IHn'. rewrite mult_plus_distr_r. reflexivity.
Qed.
Fixpoint incr ( m : bin) : bin :=
match m with
| Z => B1 Z
| B0 n' => B1 n'
| B1 n' => B0 ( incr n')
end.
Fixpoint bin_to_nat ( m : bin ) : nat :=
match m with
| Z => O
| B0 n' => plus (bin_to_nat n') (bin_to_nat n')
| B1 n' => S ( plus (bin_to_nat n') (bin_to_nat n'))
end.
Theorem bin_to_nat_pres_incr : forall b : bin,
bin_to_nat (incr b) = 1 + bin_to_nat b.
Proof.
intros b.
induction b as [| n' IHn' | n' IHn'].
- simpl.
reflexivity.
- simpl.
reflexivity.
- simpl.
rewrite IHn'.
simpl.
rewrite <- plus_n_Sm.
simpl.
reflexivity.
Qed.
Fixpoint nat_to_bin (n:nat) : bin :=
match n with
| O => Z
| S n' => incr (nat_to_bin n')
end.
Example test_nat_to_bin1 : (nat_to_bin 2) = B0 ( B1 Z).
Proof. simpl. reflexivity. Qed.
Example test_nat_to_bin2 : (nat_to_bin 3) = B1 ( B1 Z).
Proof. simpl. reflexivity. Qed.
Example test_nat_to_bin3 : (nat_to_bin O) = Z.
Proof. simpl. reflexivity. Qed.
Theorem nat_bin_nat : forall n, bin_to_nat (nat_to_bin n) = n.
Proof.
intros n.
induction n as [| n' IHn'].
- simpl.
reflexivity.
- simpl.
rewrite bin_to_nat_pres_incr.
rewrite IHn'.
reflexivity.
Qed.
Lemma double_incr : forall n : nat, double ( S n) = S ( S ( double n) ).
Proof.
intros n.
simpl.
reflexivity.
Qed.
Definition double_bin ( b : bin) : bin :=
match b with
| Z => Z
| _ => B0 b
end.
Example double_bin_zero : double_bin Z = Z.
Proof. simpl. reflexivity. Qed.
Lemma double_incr_bin : forall b,
double_bin ( incr b) = incr ( incr ( double_bin b)).
Proof.
intros b.
induction b as [| b' IHb' | b' IHb'].
- simpl. reflexivity.
- simpl. reflexivity.
- simpl. reflexivity.
Qed.
Fixpoint normalize ( b: bin) : bin :=
match b with
| Z => Z
| B1 n' => B1 ( normalize n')
| B0 n' => double_bin(normalize n')
end.
Example normalize_zero : normalize ( B0 Z) = Z.
Proof.
simpl. reflexivity.
Qed.
Example normalize_zero_deep : normalize (B0 (B0 Z)) = Z.
Proof.
simpl. reflexivity.
Qed.
Example normalize_no_op : normalize (B1 (B0 (B1 Z))) = B1 (B0 (B1 Z)).
Proof.
simpl. reflexivity.
Qed.