-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathExam2-Review.lean
378 lines (263 loc) · 8.06 KB
/
Exam2-Review.lean
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/-
You need to understand the following
elements of automated predicate logic
for Exam 2
Suppose P and Q are arbitrary propositions
(i.e., P Q : Prop) and T and V are arbitrary
types (i.e., T V : Type).
Know the following forms, how to prove them,
how to use proofs of them, and how to do these
things in Lean.
To know how to prove them and how to use proofs
of them, you need an intuitive understanding of
the introduction and elimination rules for each
form, and how to use them in Lean.
* true : Prop
* false : Prop
* = -- equality
* P ∧ Q : Prop
* (∀ p : P, Q) : Prop -- Q can involve p
* T → V : Type -- function type)
* P → Q : Prop -- implication)
* ¬ P : Prop
* P ↔ Q : Prop
* P ∨ Q : Prop
* (∃ p : P, Q) : Prop -- Q can involve p
* T → Prop -- a property of Ts
* T → V → Prop -- a T-V binary relation
Knowing this material, you are also expected to be
able to combine these reasoning rules to prove more
interesting propositions. In general, such a proof
first applies elimination rules to obtain additional
useful elements from given assumptions, and then uses
introduction rules to combine the elements obtained
into proofs of desired conclusions.
You should have an intuitive understanding of the
meaning of each form and how to use each form in
logical reasoning. In particular, understand (1)
the introduction rules for each -- how to construct
proofs in these forms -- and (2) the elimination
rules for each form -- how to use proofs in these
forms to obtain additional facts to be used in
constructing proofs of other propositions.
For extra credit, be able to work in Lean with
(1) propositions and proofs involving combinations
of quantifiers, such as (∀ x : X, ∃ y : Y, Z) and
(∃ x : X, ∀ y : Y, Z), and with (2) negations of
quantified propositions, such as ¬ (∃ p : P, Q)
and ¬ (∀ p : P, Q).
The test will be structured to help you to know and
to show how far you've gotten and where you still
have some work to do.
Here are exercises for each form.
-/
/- ***************************************** -/
/- ***************** true ****************** -/
/- ***************************************** -/
/-
(1)
Use "example" in Lean to prove that there
is a proof of true. Be sure that after the :=
you can provide a proof using both an expression
and a tactic script.
-/
/- ***************************************** -/
/- ***************** false ***************** -/
/- ***************************************** -/
/-
(2)
Use "def" in Lean to define a function, fq,
that proves that if P and Q are propositions
and if Q is true then false → ¬ Q.
-/
/-
(3)
Use "example" in Lean to prove that if 0 = 1
then 0 ≠ 1.
-/
/-
(4) Use "example" to prove that for any two
natural numbers, a and b if a = b then if
b ≠ a then a ≠ b.
-/
/- ***************************************** -/
/- ***************** and ******************* -/
/- ***************************************** -/
/-
(5)
Use "example" to prove that if P, Q, and R
are propositions, P → Q → R → (P ∧ Q) ∧ R
-/
/-
(6)
Use "example" to prove that if P, Q, and R
are propositions, (P ∧ Q) ∧ R → P ∧ R.
-/
/- ***************************************** -/
/- *************** functions *************** -/
/- ***************************************** -/
/-
(7) Use example to prove that if S and T
are arbitrary types and if there is a value,
t : T, then S → T. Remember that a proof of
S → T has to be a function that if given any
value of type S returns some value of type T.
Present this proof as a Python-style function
definition, isFun, then using a tactic script.
The Π you can read and treast as ∀, for now.
-/
/-
(8) use def to define comp to be a function
that takes as its argments, the types S, T,
and R, along with a function of type S → T
and a function of type T → R and that returns
a function of type S → R. It should take S,
T, and R implicitly and st and tr explicitly.
-/
/-
(9) Define square to be a function that
takes a natural number and returns its
square, and inc to be a function that
takes a nat, n, and returns n + 1. Now
use def and comp to define incSquare to
be a function that takes a nat, n, as an
argument and that returns one more than
n^2. Use #reduce to check that the value
of (incSquare 5) is 26.
-/
/-
(10)
Consider the function, sum4, below. What
is the type of (sum4 3 7)? What function is
(sum4 3 7)? Answer the second question
with a lambda abstraction.
-/
/- ***************************************** -/
/- ************** implication ************** -/
/- ***************************************** -/
/-
(11)
Use several "examples" to prove (1) false → false,
(2) false → true, (3) ¬ (true → false).
-/
/-
(12)
Use example to prove that for any two
propositions, P, Q, if P ∧ Q is true
then if ¬ (P ∨ Q) is true, then you
can derive a proof of false.
-/
/- ***************************************** -/
/- *************** forall (∀) ************** -/
/- ***************************************** -/
/-
(13)
Use example to prove that for all proposition,
P, Q, and R, if P → Q → R then P → R.
-/
/-
(14)
Prove that for any type, T, for any a : T,
and for any property, (P : T → Prop), if
(∀ t : T, P t), then P a.
-/
/- ***************************************** -/
/- *************** negation **************** -/
/- ***************************************** -/
/-
(15)
Show that for any propositions, P and Q,
¬ ((P ∧ Q) ∧ ((P ∧ Q) → (¬ Q ∧ P)).
-/
/-
(16)
Prove that for any propositions, P and R,
if P → R and ¬ P → R, then R. You might
need to use the law of the excluded middle.
-/
/- ***************************************** -/
/- ************* bi-implication ************ -/
/- ***************************************** -/
/-
(17)
Prove that for any propositions P and Q,
(P -> Q) ∧ (Q → P) → (P ↔ Q).
-/
/-
(18)
Prove that for propositions P and Q,
((P ↔ Q) ∧ P) → Q.
-/
/- ***************************************** -/
/- ************** disjunction ************** -/
/- ***************************************** -/
/-
(19)
Prove that if you eat donuts or if you eat
candy you will get cavities. The proposition
you prove should build in the assumptions
that if you eat donuts you will get cavities
and if you eat candy you will get cavities.
We start the proof for you. You complete it.
Start your proof like this:
example : ∀ donut candy cavity : Prop, ...
-/
/-
(20)
Prove that if P and Q are any propositions, and
if you have a proof of ¬(P ∨ Q) then you can
construct a proof of ¬ P.
-/
/-
(21)
Show, without using em explicitly, that if
for any proposition, P, P ∨ ¬ P, then for any
proposition, Q, ¬ ¬ Q → Q. The proposition to
prove is (∀ P : Prop, P ∨ ¬ P) → (∀ Q, ¬¬ Q → Q).
Remember that a proof of (∀ P, S) can be applied
to a value of type P to get a value of type S.
-/
/- ***************************************** -/
/- **************** predicates ************* -/
/- ***************************************** -/
/-
(22)
Define notZero(n) to be a predicate on
natural numbers that is true when 0 ≠ n
(and false otherwise). Then prove two facts
using "example." First, ¬ (notZero 0). When
doing this proof, remember what (notZero 0)
means, and remember what negation means.
Second, prove (notZero 1).
-/
/-
(23)
Define eqString(s, t) to be a predicate on
values of type string, that is true when
s = t (and not true otherwise). Then prove:
eqString "Hello Lean" ("Hello " ++ "Lean")
-/
/- ***************************************** -/
/- **************** exists ***************** -/
/- ***************************************** -/
/-
(24)
Prove that ∃ n : ℕ, n = 13.
-/
/-
(25)
Prove ∀ s : string, ∃ n, n = string.length s.
-/
/-
(26)
Prove exists m : ℕ, exists n: ℕ, m * n = 100.
Remember that you can apply exists.intro to a
witness, leaving the proof to be constructed
interactively.
-/
/-
(27)
Prove that if P and S are properties of
natural numbers, and if (∃ n : ℕ, P n ∧ S n),
then (∃ n : ℕ, P n ∨ S n).
-/