forked from jamiepg1/software-foundations-coq-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prop.v
332 lines (276 loc) · 6.01 KB
/
Prop.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
324
325
326
327
328
329
330
331
332
(* ix: 3Nv *)
Require Export Poly.
Inductive beautiful : nat -> Prop :=
| b_0 : beautiful 0
| b_3 : beautiful 3
| b_5 : beautiful 5
| b_sum : forall (n m : nat), beautiful n -> beautiful m -> beautiful (n + m).
Theorem beautiful_3 : beautiful 3.
apply b_3.
Qed.
Theorem beautiful_8 : beautiful 8.
apply b_sum with (n:=3) (m:=5).
apply b_3.
apply b_5.
Qed.
Theorem eight_is_beautiful': beautiful 8.
apply (b_sum 3 5 b_3 b_5).
Qed.
Theorem eight_is_beautiful'': beautiful 8.
Proof.
Show Proof.
apply b_sum with (n:=3) (m:=5).
Show Proof.
apply b_3.
Show Proof.
apply b_5.
Show Proof.
Qed.
Definition eight_is_beautiful''' : beautiful 8 :=
b_sum 3 5 b_3 b_5.
Theorem six_is_beautiful :
beautiful 6.
Proof.
apply b_sum with (n:=3) (m:=3).
apply b_3.
apply b_3.
Qed.
Definition six_is_beautiful' : beautiful 6 :=
b_sum 3 3 b_3 b_3.
Theorem nine_is_beautiful :
beautiful 9.
Proof.
apply b_sum with (n:=6) (m:=3).
apply six_is_beautiful.
apply b_3.
Qed.
Theorem b_plus3: forall n, beautiful n -> beautiful (3+n).
Proof.
intro n.
intro H.
apply b_sum.
apply b_3.
apply H.
Qed.
Definition b_plus3' : forall n, beautiful n -> beautiful (3+n) :=
fun (n:nat) => fun (H : beautiful n) => b_sum 3 n b_3 H.
Definition b_plus3'' (n : nat) (H : beautiful n) : beautiful (3+n) :=
b_sum 3 n b_3 H.
Theorem b_times2: forall n, beautiful n -> beautiful (2*n).
Proof.
intros n H.
simpl.
apply b_sum.
apply H.
apply b_sum.
apply H.
apply b_0.
Qed.
Theorem b_timesm: forall n m, beautiful n -> beautiful (m*n).
Proof.
intros n m H.
induction m as [| m'].
apply b_0.
simpl.
apply b_sum.
apply H.
apply IHm'.
Qed.
Fixpoint b_timesm' (n m :nat) (H : beautiful n) : beautiful (m*n) :=
match m return beautiful (m * n) with
| O => b_0
| S m' => b_sum n (m' * n) H (b_timesm' n m' H)
end.
Inductive gorgeous : nat -> Prop :=
g_0 : gorgeous 0
| g_plus3 : forall n, gorgeous n -> gorgeous (3+n)
| g_plus5 : forall n, gorgeous n -> gorgeous (5+n).
Theorem gorgeous__beautiful : forall n,
gorgeous n -> beautiful n.
Proof.
intros.
(*
gorgeous_ind
: forall P : nat -> Prop,
P 0 ->
(forall n : nat, gorgeous n -> P n -> P (3 + n)) ->
(forall n : nat, gorgeous n -> P n -> P (5 + n)) ->
forall n : nat, gorgeous n -> P n
*)
induction H as [| n' | n'].
apply b_0.
apply b_sum.
apply b_3.
apply IHgorgeous.
apply b_sum.
apply b_5.
apply IHgorgeous.
Qed.
Theorem gorgeous_plus13: forall n,
gorgeous n -> gorgeous (13+n).
Proof.
intros n H.
apply g_plus5 with (n := (8+n)).
apply g_plus5 with (n := (3+n)).
apply g_plus3.
apply H.
Show Proof.
Qed.
Theorem gorgeous_sum : forall n m,
gorgeous n -> gorgeous m -> gorgeous (n + m).
Proof.
intros n m Gn Gm.
induction Gn as [ | n' | n'].
apply Gm.
apply g_plus3 with (n:=(n'+m)).
apply IHGn.
apply g_plus5 with (n:=(n'+m)).
apply IHGn.
Qed.
Theorem beautiful__gorgeous : forall n, beautiful n -> gorgeous n.
Proof.
intros n B.
induction B.
apply g_0.
apply g_plus3 with (n:=0).
apply g_0.
apply g_plus5 with (n:=0).
apply g_0.
apply gorgeous_sum.
apply IHB1.
apply IHB2.
Qed.
Definition even (n:nat) : Prop :=
evenb n = true.
Inductive ev : nat -> Prop :=
| ev_0 : ev O
| ev_SS : forall n:nat, ev n -> ev (S (S n)).
Theorem ev_4 : ev 4.
apply ev_SS.
apply ev_SS.
apply ev_0.
Qed.
Theorem double_even : forall n, ev (double n).
Proof.
induction n as [| n'].
apply ev_0.
simpl.
apply ev_SS.
apply IHn'.
Qed.
Definition double_even' : forall n, ev (double n) :=
nat_ind
(fun n => ev (double n))
ev_0
(fun n' => fun IHn' => (ev_SS (double n') IHn')).
Theorem ev_minus2: forall n,
ev n -> ev (pred (pred n)).
Proof.
intros n E.
destruct E as [| n' E'].
simpl.
apply ev_0.
simpl.
apply E'.
Qed.
Theorem ev__even : forall n,
ev n -> even n.
intros n E.
induction E as [| n' E IHE].
unfold even.
simpl.
reflexivity.
Print even.
unfold even.
simpl.
unfold even in IHE.
apply IHE.
Qed.
Theorem ev_sum : forall n m,
ev n -> ev m -> ev (n+m).
Proof.
intros n m En Em.
induction En as [| n' En' EIHn'].
simpl.
apply Em.
simpl.
apply ev_SS.
apply EIHn'.
Qed.
Theorem SSev_ev : forall n,
ev (S (S n)) -> ev n.
Proof.
intros n H.
inversion H as [| n' H'].
apply H'.
Qed.
Theorem SSSSev__even : forall n,
ev (S (S (S (S n)))) -> ev n.
Proof.
intros n H.
inversion H.
inversion H1.
apply H3.
Qed.
Theorem even5_nonsense :
ev 5 -> 2 + 2 = 9.
Proof.
intros contra.
inversion contra.
inversion H0.
inversion H2.
Qed.
Theorem ev_ev__ev : forall n m,
ev (n+m) -> ev n -> ev m.
Proof.
intros n m Enplusm En.
induction En as [| n' IHn'].
simpl in Enplusm.
apply Enplusm.
simpl in Enplusm.
inversion Enplusm.
apply IHIHn'.
apply H0.
Qed.
Theorem ev_plus_plus : forall n m p,
ev (n+m) -> ev (n+p) -> ev (m+p).
Proof.
intros n m p Enm Enp.
apply ev_sum with (n:=n+m) (m:=n+p) in Enm.
(* (n + m) + (n + p) *)
replace ((n+m) + (n+p)) with ((n + n) + (m + p)) in Enm.
replace (n+n) with (double n) in Enm.
apply ev_ev__ev with (m:=m+p) in Enm.
apply Enm.
replace (double n + (m + p) + (m + p)) with (double n + ((m + p) + (m + p))).
replace (m + p + (m + p)) with (double (m + p)).
apply ev_sum.
apply double_even.
apply double_even.
apply double_plus with (n:=m+p).
apply plus_assoc with (n:=double n).
apply double_plus.
rewrite <- plus_assoc.
replace (n+(m+p)) with (m+(n+ p)).
rewrite plus_assoc.
reflexivity.
apply plus_swap'.
apply Enp.
Qed.
Theorem ev_plus_plus' : forall n m p,
ev (n+m) -> ev (n+p) -> ev (m+p).
Proof.
intros n m p Hm Hp.
apply ev_sum with (n:=n+m) (m:=n+p) in Hm.
replace (n + m + (n + p)) with ((n+n)+(m+p)) in Hm.
apply ev_ev__ev with (n:=n+n) in Hm.
apply Hm.
rewrite <- double_plus.
apply double_even.
rewrite <- plus_assoc.
replace (n + (m + p)) with (m + (n + p)).
rewrite <- plus_assoc.
reflexivity.
apply plus_swap'.
apply Hp.
Qed.