-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoqt.v
283 lines (237 loc) · 4.63 KB
/
coqt.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
(* 二つの自然数の和を返す *)
Definition plus (n m : nat) : nat := n + m.
Eval compute in plus 3 5.
Definition plus' : nat -> nat -> nat := fun n m => n + m.
Eval compute in plus' 3 5.
Definition id (A : Type)(x : A) : A := x.
Eval compute in id nat 5.
Definition id' : forall (A : Type), A -> A := fun A x => x.
Eval compute in id' nat 5.
Definition prop0 : forall (A : Prop), A -> A :=
fun A x => x.
(* Haskell : (.) *)
Definition prop1 : forall (A B C : Prop), (B -> C) -> (A -> B) -> (A -> C) :=
fun A B C f g x => f (g x).
(* Haskell : flip ($) *)
Definition problem0 : forall (A B : Prop), A -> (A -> B) -> B :=
fun A B x f => f x.
(* Haskell : flip *)
Definition problem1 : forall (A B C : Prop), (A -> B -> C) -> (B -> A -> C) :=
fun A B C f g h => f h g.
Definition prop0' : forall (A : Prop), A -> A.
Proof.
intros.
apply H.
Qed.
Print prop0'.
Goal forall (P Q : Prop), (forall P : Prop, (P -> Q) -> Q) -> ((P -> Q) -> P) -> P.
Proof.
intros. (* intro. intro. intro. intro. *)
apply H0.
intro.
apply (H (P -> Q)).
apply (H P). (* apply H. *)
Qed.
Goal forall (P Q : Prop), (forall P : Prop, (P -> Q) -> Q) -> ((P -> Q) -> P) -> P.
Proof.
intros.
apply H0.
intros.
apply (H Q).
intro.
apply H2.
Qed.
Definition problem2 : forall (P Q R : Prop), (P -> Q) -> (Q -> R) -> P -> R.
Proof.
intros.
apply H0.
apply H.
apply H1.
Qed.
(* Inductive:型定義 *)
(*
Inductive list (A : Type) : Type :=
| nil : list A
| cons : A -> list A -> list A.
*)
(* Inductive False : Prop :=. *)
(* Definition:関数定義 *)
(* Definition not (A : Prop) := A -> False. *)
Goal forall (P : Prop), P -> ~~P.
Proof.
intros.
intro.
apply H0.
apply H.
Qed.
Goal forall (P : Prop), P -> ~~P.
Proof.
unfold not.
intros.
apply H0.
apply H.
Qed.
(*
Inductive or (A B : Prop) : Prop :=
| or_introl : A -> or A B
| or_intror : B -> or A B.
*)
Goal forall (P Q : Prop), P \/ Q -> Q \/ P.
Proof.
intros.
case H. (* 場合分け *)
apply or_intror.
apply or_introl.
Qed.
Goal forall (P Q : Prop), P \/ Q -> Q \/ P.
Proof.
intros.
destruct H.
right.
apply H.
left.
apply H.
Qed.
(*
Inductive and (A B : Prop) : Prop :=
conj : A -> B -> and A B.
*)
Goal forall (P Q : Prop), P /\ Q -> Q /\ P.
Proof.
intros.
destruct H.
split. (* apply conj. *)
apply H0.
apply H.
Qed.
Goal forall (P : Prop), P -> ~~P.
Proof.
auto. (* info_auto *)
Qed.
Definition problem3 : forall (P : Prop), ~(P /\ ~P).
Proof.
intros.
intro.
case H.
intros.
apply H1.
apply H0.
Qed.
Definition problem3' : forall (P : Prop), ~(P /\ ~P).
Proof.
intros.
intro.
destruct H.
apply H0.
apply H.
Qed.
Definition problem3'' : forall (P : Prop), ~(P /\ ~P).
Proof.
intro.
unfold not.
intro.
destruct H.
apply H0.
apply H.
Qed.
Definition problem4 : forall (P Q : Prop), ~P \/ ~Q -> ~(P /\ Q).
Proof.
intros.
intro.
destruct H0.
destruct H.
apply H.
apply H0.
apply H.
apply H1.
Qed.
Definition problem4' : forall (P Q : Prop), ~P \/ ~Q -> ~(P /\ Q).
Proof.
intros.
intro.
case H0.
intros.
destruct H.
apply H.
apply H1.
apply H.
apply H2.
Qed.
Definition problem5 : forall (P : Prop), (forall (P : Prop), ~~P -> P) -> P \/ ~P.
Proof.
unfold not.
intros.
apply H.
intros.
apply H0.
right.
intro.
apply H0.
left.
apply H1.
Qed.
(*
Fixpoint app (A : Type)(l l' : list A) : list A :=
match l with
| nil => l'
| cons x xs => cons x (app A xs l')
end.
*)
Require Import List.
Theorem app_nil_r : forall (A : Type)(l : list A), l ++ nil = l.
Proof.
intros.
induction l.
reflexivity.
simpl.
f_equal. (* apply (f_equal (cons a)). *)
apply IHl.
Qed.
Theorem app_assoc : forall (A : Type)(l1 l2 l3 : list A), l1 ++ (l2 ++ l3) = (l1 ++ l2) ++ l3.
Proof.
intros.
induction l1.
reflexivity.
simpl.
f_equal.
apply IHl1.
Qed.
Theorem rev_app_distr : forall (A : Type)(l1 l2 : list A), rev (l1 ++ l2) = rev l2 ++ rev l1.
Proof.
intros.
induction l1.
simpl.
rewrite app_nil_r.
reflexivity.
simpl.
rewrite app_assoc.
f_equal.
apply IHl1.
Qed.
Theorem rev_involutive : forall (A : Type)(l : list A), rev (rev l) = l.
Proof.
intros.
induction l.
reflexivity.
simpl.
rewrite rev_app_distr.
simpl.
f_equal.
apply IHl.
Qed.
(*
Fixpoint fold_right (A B : Type)(f : B -> A -> A)(a0 : A)(l : list B) : A :=
match l with
| nil => a0
| b :: t => f b (fold_right A B f a0 t)
end.
*)
Theorem fold_right_app : forall (A B : Type)(f : B -> A -> A)(l l' : list B)(i : A), fold_right f i (l ++ l') = fold_right f (fold_right f i l') l.
Proof.
intros.
induction l.
reflexivity.
simpl.
f_equal.
apply IHl.
Qed.