-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab1.v
354 lines (280 loc) · 6.6 KB
/
lab1.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
(** This file contains some lemmas you will have to prove, i.e. replacing
the "Admitted" joker with a sequence of tactic calls, terminated with a
"Qed" command.
Each lemma could be proved several times using various combinations
of tactics.
Notice that, if you want to keep all solutions, you may use various
identifiers like in the given example : imp_dist, imp_dist' share
the same statement, with different interactive proofs.
*)
(* Une seule étoile *)
Section Minimal_propositional_logic.
(** Propositional Intuitionistic logic restricted to the [->] fragment *)
Variables P Q R S : Prop.
(* Prove the lemmas using the following tactics
intro[s], exact, apply, assumption, trivial
*)
(** The I combinator *)
Proposition I_P : P -> P.
Proof.
intro p.
exact p. (* assumption or trivial *)
Qed.
Check I_P.
Print I_P.
(** The K combinator *)
Lemma K_PQ : P -> Q -> P.
Proof.
intros p q.
exact p.
(* intros; trivial or trivial or auto *)
Qed.
Print K_PQ.
(** The S combinator *)
Lemma S_PQR : (P -> Q -> R) -> (P -> Q) -> P -> R.
Proof.
intros H1 H2 H3.
apply H1.
+ apply H3.
+ apply H2, H3.
(*
apply H1; try apply H2; apply H3.
or
apply H1; [ apply H3 | apply H2, H3 ].
or
apply H1; repeat (apply H2 || apply H3).
*)
Qed.
Print S_PQR.
(** The B combinator *)
Lemma B_PQR : (Q -> R) -> (P -> Q) -> P -> R.
Proof.
intros H1 H2 ?.
apply H1, H2; assumption.
Qed.
(** The C combinator *)
Lemma C_PQR : (P -> Q -> R) -> Q -> P -> R.
Proof.
intros H ? ?.
apply H; assumption.
Qed.
Lemma imp_trans : (P -> Q) -> (Q -> R) -> P -> R.
Proof.
intros H1 H2 H3.
apply H2, H1, H3.
Qed.
Lemma ignore_Q : (P -> R) -> P -> Q -> R.
Proof.
(* intros ? H _; revert H; assumption. *)
intros H1 H2 H3.
clear H3.
(* apply H1, H2. *)
revert H2.
assumption.
Qed.
Print ignore_Q.
Definition delta_imp : (P -> P -> Q) -> P -> Q.
Proof.
intros H ?; apply H; assumption.
(* refine (fun H1 H2 => H1 H2 _); trivial. *)
Qed.
Lemma delta_impR : (P -> Q) -> P -> P -> Q.
Proof.
intros H a b.
apply H, a.
Qed.
Print delta_impR.
Lemma diamond : (P -> Q) -> (P -> R) -> (Q -> R -> S) -> P -> S.
Proof.
intros H1 H2 H3 H4.
apply H3; [ apply H1 | apply H2 ]; apply H4.
(*
apply H3.
+ apply H1, H4.
+ apply H2, H4. *)
Qed.
Lemma weak_peirce : ((((P -> Q) -> P) -> P) -> Q) -> Q.
Proof.
intros H; apply H.
intros H1; apply H1.
intros H2; apply H.
intros _; apply H2.
Qed.
Print weak_peirce.
Lemma natural_number : (P -> P) -> (P -> P).
Proof.
intros H p.
do 8 apply H.
exact p.
Qed.
Print natural_number.
End Minimal_propositional_logic.
Section propositional_logic.
(** Propositional Intuitionistic logic *)
Variables P Q R S T : Prop.
(* Prove the lemmas using the following tactics
intro[s], exact, apply, assumption, trivial
destruct, left/right, split
try use tactic composition
*)
Lemma and_assoc : P /\ (Q /\ R) -> (P /\ Q) /\ R.
Proof.
intros [ p [ q r ] ].
split.
+ split.
* exact p.
* exact q.
+ exact r.
(* intro H. destruct H as (p & [ q r ]). *)
(* destruct H as [ p qr ].
destruct qr as [ q r ]. *)
(* destruct H as [ p [ q r ] ]. *)
Qed.
Print and_assoc.
Lemma and_imp_dist : (P -> Q) /\ (R -> S) -> P /\ R -> Q /\ S.
Proof.
intros (H1 & H2) (H3 & H4).
split.
+ apply H1, H3.
+ apply H2, H4.
Qed.
(* ~P (not P) is defined as P -> False *)
Lemma not_contrad : (P /\ (P -> Q)) -> Q.
Proof.
(* unfold not *)
intros (p & np).
apply np, p.
Qed.
Lemma not_contrad' : ~(P /\ ~P).
Proof.
intros (p & np).
destruct np.
exact p.
Qed.
Print not_contrad.
Print not_contrad'.
Print True.
Lemma or_and_not : (P \/ Q) /\ ~P -> Q.
Proof.
(*
intros ([ H | H ] & np).
+ destruct np.
exact H.
+ exact H. *)
intros ([|] & np); [ destruct np | idtac ]; assumption.
(* intros (pq & np).
destruct pq as [ p | q ]. *)
Admitted.
Lemma not_not_exm : ~ ~ (P \/ ~ P).
Proof.
intros H.
apply H.
right.
intros p.
apply H.
left.
exact p.
Qed.
Lemma de_morgan_1 : ~(P \/ Q) -> ~P /\ ~Q.
Proof.
intros H.
split.
+ contradict H.
left.
assumption.
+ intros q.
apply H.
right.
assumption.
Qed.
Lemma de_morgan_2 : ~P /\ ~Q -> ~(P \/ Q).
Proof.
intros (np & nq) [ p | q ].
+ apply np, p.
+ apply nq, q.
Qed.
Lemma de_morgan_3 : ~P \/ ~Q -> ~(P /\ Q).
Proof.
intros [ np | nq ] (p & q).
+ apply np, p.
+ apply nq, q.
Qed.
Lemma or_to_imp : P \/ Q -> ~ P -> Q.
Proof.
intros [ p | q ] np.
+ destruct np.
apply p.
+ apply q.
Qed.
Lemma destruct_before_left_right : (P \/ Q) -> (P -> R) -> (Q -> T) -> R \/ T.
Proof.
intros [ p | q ] H1 H2.
+ left.
apply H1, p.
+ right.
apply H2, q.
Qed.
Lemma imp_to_not_not_or : (P -> Q) -> ~~(~P \/ Q).
Proof.
intros H1 H2.
assert (~ Q) as H3. (** State intermediate lemma *)
+ contradict H2; right; assumption.
+ apply H2.
left.
intros H4.
apply H3, H1, H4.
Qed.
Lemma contraposition : (P -> Q) -> (~Q -> ~P).
Proof.
intros H1 H2.
contradict H2.
apply H1, H2.
Qed.
(** A <-> B is defined as (A -> B) /\ (B -> A) *)
Lemma contraposition' : (~P -> ~Q) <-> (~~Q -> ~~P).
Proof.
(* unfold iff. *)
split.
+ intros H1 H2.
contradict H2.
apply H1, H2.
+ intros H1 H2 H3.
apply H1; trivial.
intros C; apply C, H3.
Qed.
Lemma contraposition'' : (~P -> ~Q) <-> ~~(Q -> P).
Proof.
split.
+ intros H1 H2.
apply H2.
intros H3.
destruct H1.
* contradict H2; intros _; assumption.
* assumption.
+ intros H1 H2 H3.
apply H1.
intros H4.
apply H2, H4, H3.
Qed.
Section weak_XM.
Hypothesis H0 : P -> R.
Hypothesis H1 : ~P -> R.
Lemma weak_XM : ~~R.
Proof.
intros nr.
apply nr, H1.
intros p.
apply nr, H0, p.
Qed.
Check weak_XM.
End weak_XM.
Check weak_XM.
(* Now, you may invent and solve your own exercises !
Note that you can trust the tactic tauto, based on
Dyckhoff's LJT calculus: if it fails, then your formula
is probably not (intuitionnistically) provable *)
Lemma contraposition''' : (~P -> ~Q) <-> (Q -> P).
Proof.
(* tauto. *) (* Not provable in Intuitionistic Logic *)
Admitted.
End propositional_logic.