forked from srbmiy/ssreflect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nat01.v
259 lines (221 loc) · 8.2 KB
/
nat01.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
Require Import ssreflect ssrbool ssrnat.
Definition nand_b (b0 : bool) (b1 : bool) : bool :=
match b0 with
| true => (~~ b1)
| false => true
end.
Lemma nand_lemma : forall (b0 b1 : bool), (nand_b b0 b1) = (~~(b0 && b1)).
Proof.
move=> b0 b1.
case b0.
simpl; reflexivity.
simpl; reflexivity.
Qed.
(* Software Foundation 練習問題: ★★, recommended (basic_induction) *)
Lemma ゼロを掛けるとゼロになる : forall (n:nat), n*0 = 0.
Proof.
move=> n.
induction n as [| m].
trivial. (* 0*0 == 0 *)
rewrite mulSnr. (* m.+1 * 0 ~~~> m * 0 + 0 *)
rewrite -> IHm. (* apply IHm : m * 0 == 0 *)
reflexivity.
Qed.
Axiom SET : Type.
Axiom membership : SET -> SET -> Prop.
Notation "x ∈ y" := (membership x y) (at level 100) : type_scope.
Axiom Extensionality : forall (x y: SET), (forall (z : SET), ((z ∈ x) <-> (z ∈ y))) <-> (x = y).
Axiom emptyset : SET.
Axiom EmptySetAxiom : (forall (z: SET), ~(z ∈ emptyset)).
Axiom pair : SET -> SET -> SET.
Notation "{ x , y }" := (pair x y) (at level 50) : type_scope.
Axiom PairingAxiom : forall (x y : SET), forall (z : SET), (z ∈ { x , y }) <-> (x = z) \/ (y = z).
Notation "{{ x }}" := (pair x x) (at level 49) : type_scope.
Axiom union : SET -> SET.
Notation "∪ x" := (union x) (at level 40) : type_scope.
Axiom UnionAxiom : forall (x : SET), forall (z : SET), (z ∈ (∪ x)) <-> (exists (y : SET), (y ∈ x) /\ (z ∈ y)).
Notation "x ∪ y" := (union (pair x y)) (at level 39) : type_scope.
Definition subset_of (x y : SET) : Prop :=
forall (z : SET), (membership z x) -> (membership z y).
Notation "x ⊆ y" := (subset_of x y) (at level 101) : type_scope.
Axiom P : SET -> SET.
Axiom PowerSetAxiom : forall (x : SET), forall (z : SET), (z ⊆ x) <-> (z ∈ P x).
Axiom Comprehension : forall (phi : SET -> SET-> Prop), forall (param : SET), forall (x : SET), exists (y : SET), forall (z : SET), (z ∈ y) <-> (z ∈ x) /\ (phi z param).
Axiom ω : SET.
Definition inductive_set (x : SET) : Prop :=
(emptyset ∈ x) /\ forall (y : SET), (y ∈ x) -> ((y ∪ {{ y }}) ∈ x).
Axiom InfinityAxiom : (inductive_set ω) /\ (forall (x : SET), (inductive_set x) -> (ω ⊆ x)).
Lemma 補題_0と1は異なる : ~(emptyset = {{ emptyset }}).
Proof.
assert (emptyset ∈ {{emptyset}}) as H1.
apply PairingAxiom.
left; exact. (* assertion succeeded. *)
assert (~(emptyset ∈ emptyset)) as H0.
apply EmptySetAxiom. (* assertion succeeded. *)
rewrite <- Extensionality.
move => Habs.
destruct H0.
rewrite (Habs emptyset).
exact.
Qed.
(*-----------------------------------------------------------------*)
(*--- Kuratowski's Definition of ordered-pairs ---*)
Definition ordered_pair (x y : SET) : SET :=
{ {{x}} , { x , y } }.
Notation "\( x , y \)" := (ordered_pair x y) (at level 35).
Lemma 補題_Singletonのequality : forall (x y z : SET), {{x}} = {y, z} -> x = y.
Proof.
move=> y x z; move.
case=> Hsingleton.
assert ( x ∈ {x, z} ) as Hxinx.
apply (PairingAxiom x z x); left; reflexivity.
assert ( x ∈ {{y}} ) as Hyinx.
rewrite -> Hsingleton; exact.
assert (y = x \/ y = x) as Htmp.
apply (PairingAxiom y y x).
exact.
destruct Htmp.
exact.
exact.
Qed.
Lemma 補題_非順序対は交換可能 : forall (x y : SET), {x , y} = {y , x}.
Proof.
move=> x y.
rewrite <- (Extensionality ({x , y}) ({y , x})).
move=> z.
move; split.
move=> Hleft.
apply (PairingAxiom y x z).
assert ((x = z) \/ (y = z)).
apply (PairingAxiom x y z); exact.
destruct H.
move: H; auto.
move: H; auto.
move=> Hleft.
apply (PairingAxiom x y z).
assert ((y = z) \/ (x = z)).
apply (PairingAxiom y x z); exact.
destruct H.
move: H; auto.
move: H; auto.
Qed.
Lemma 補題_順序対のequality : forall (x0 x1 y0 y1 : SET), (x0 = x1) /\ (y0 = y1) <-> ( \( x0, y0 \) = \(x1 , y1\) ).
Proof.
move => x y z w.
(* 片方ずつ示すこととします *)
assert ((x = y) /\ (z = w) -> \(x, z\) = \(y, w\)) as Hright.
case=> Hxy Hzw.
rewrite <- Hxy; rewrite <- Hzw; exact.
(* もう片方の難しい方を示す *)
assert ( \(x, z\) = \(y, w\) -> (x=y)/\(z=w) ) as Hleft.
case=> Hpair. (* 仮定の導入 *)
(* Proof x=y Start. *)
assert (x = y) as Hxy.
assert ({{x}} ∈ \(x, z \)) as Hx.
apply (PairingAxiom ({{x}}) ({x , z})).
left; exact.
assert ({{x}} ∈ \(y, w\)) as Hxinyw.
rewrite <- Hpair; assumption.
assert (({{y}} = {{x}}) \/ ({y,w} = {{x}})) as Hdicotomy.
apply (PairingAxiom ({{y}}) ({y,w}) ({{x}})); assumption.
destruct Hdicotomy. (* Dicotomiyの場合分け. *)
(* どちらの場合でも x=y でて来るはず *)
assert (y= x) as Hxeqy.
apply (補題_Singletonのequality y x x); exact.
rewrite -> Hxeqy; reflexivity.
assert ({{x}} = {y, w}) as Hprev.
rewrite <- H; reflexivity.
apply (補題_Singletonのequality x y w); exact.
(* Proof x=y End. *)
(* Proof z=w Start. Simply a symmetric argument. *)
assert (z = w) as Hzw.
assert ({x , z} ∈ \(x, z \)) as Hxz.
apply (PairingAxiom ({{x}}) ({x,z}) ({x , z})).
right; exact.
assert ({x , z} ∈ \(y, w \)) as Hxzinyw.
rewrite <- Hpair; assumption.
assert ({{y}} = ({x ,z}) \/ ({y , w} = {x , z})) as Hdicotomy.
apply (PairingAxiom ({{y}}) ({y , w}) ({x , z})); assumption.
destruct Hdicotomy. (* Dicotomiyの場合分け. *)
(* どちらの場合でも z=w でて来るはず *)
(*apply (補題_Singletonのequality y x z); exact.*)
assert ({{y}} = {z,x} ) as HH.
rewrite -> (補題_非順序対は交換可能 z x); exact.
assert (y = z) as Hyz.
apply (補題_Singletonのequality y z x); exact.
assert (x = z) as Hxeqz.
rewrite <- Hyz; exact.
assert ({y, w} ∈ \(x , z \)) as Hyw.
assert ({y, w} ∈ \(y , w \)).
apply (PairingAxiom ({{y}}) ({y , w}) ({y , w})); right; reflexivity.
rewrite -> Hpair; exact.
assert ({y , w} = {{x}}).
assert (({{x}} = {y , w}) \/ ({x , z} = {y , w})).
apply (PairingAxiom ({{x}}) ({x , z}) ({y , w})); exact.
case: H0; auto.
rewrite <- Hxeqz; auto.
assert ({{x}} = {y, w}) as Hprev.
auto.
move: Hprev.
rewrite <- Hxeqz.
rewrite <- Hxy.
move=> Hprev.
assert (w ∈ {x , w}).
apply (PairingAxiom x w w); right; reflexivity.
move: H1.
rewrite <- Hprev.
move=> Hprev2.
assert (x = w \/ x = w).
apply (PairingAxiom x x w); exact.
case H1; exact.
assert (x = w \/ x <> w) as EMxz.
Hypothesis EM : forall p : Prop, p \/ ~p.
apply (EM (x = w)).
case: EMxz.
move=> Hxeqw.
assert ({{x}} = {x , z}).
rewrite <- H.
rewrite <- Hxy.
rewrite <- Hxeqw; reflexivity.
assert ({{x}} = {z , x}).
rewrite -> (補題_非順序対は交換可能 z x); exact.
assert (x = z).
apply (補題_Singletonのequality x z x); exact.
rewrite <- H2; exact.
move=> Hxneqw.
assert (w ∈ {x , z}).
assert (w ∈ {y , w}).
apply (PairingAxiom y w w); right; reflexivity.
rewrite <- H; exact.
assert ((x = w) \/ (z = w)).
apply (PairingAxiom x z w); exact.
case: H1.
move=> H2.
contradiction.
trivial.
move: Hxy Hzw; auto.
move.
auto.
Qed.
(*-------------------------------------------------------------------*)
Definition is_Relation (R : SET) : Prop :=
forall z, (z ∈ R) -> (exists (x y :SET), z = \(x , y \)).
Definition is_WellDefined (R : SET) : Prop :=
forall (x0 y0 x1 y1: SET), ( (\(x0 , y0 \) ∈ R) /\ (\(x1 , y1\) ∈ R) ) -> x0 = x1 -> y0 = y1.
Definition is_Function (R : SET) : Prop :=
(is_Relation R) /\ (is_WellDefined R).
Definition is_OneToOne (R : SET) : Prop :=
forall (x0 y0 x1 y1 : SET), ( (\(x0 , y0 \) ∈ R) /\ (\(x1 , y1\) ∈ R) ) -> y0 = y1 -> x0 = x1.
Definition is_Injection (R : SET) : Prop :=
(is_Function R) /\ (is_OneToOne R).
(*=====================================================================*)
Definition is_Reflexive_Relation (R : SET) : Prop :=
(is_Relation R) /\ forall (x y: SET), (\(x , y \) ∈ R) -> (\( x , x \) ∈ R).
Definition is_Symmetric_Relation (R : SET) : Prop :=
(is_Relation R) /\ forall (x y: SET), (\(x , y\) ∈ R) -> (\(y , x\) ∈ R).
Definition is_Transitive_Relation (R : SET) : Prop :=
(is_Relation R) /\ forall (x y z : SET), (\(x , y \) ∈ R) -> (\(y , z\) ∈ R) -> (\(x , z\) ∈ R).
Definition is_Transitive (x : SET) : Prop :=
forall (y z : SET), (y ∈ x) -> (z ∈ y) -> (z ∈ x).
Definition is_Ordinal : (x : SET) : Prop :=
(is_Transitive x) /\ (is_Transitive_Relation