-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC2_ex.v
229 lines (168 loc) · 3.87 KB
/
C2_ex.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
Section C2_1.
Parameter (A : Type) (R : A -> A -> Prop) (f : A -> A) (a : A).
Hypothesis Hf : forall x y, R x y -> R x (f y).
Hypothesis R_refl : forall x, R x x.
(* Variables x : A. *)
Lemma Lf : forall x, R x (f (f (f x))).
Proof.
(* intro x.
apply Hf.
apply Hf.
apply Hf.
apply R_refl. *)
intro; repeat apply Hf; apply R_refl.
Qed.
End C2_1.
Require Import Arith.
Section C2_2.
Check lt_n_Sn.
Check lt_trans.
Lemma lt_n_SSn : forall i, i < S (S i).
Proof.
intro i.
do 1 apply lt_trans with (2 := lt_n_Sn _).
apply lt_n_Sn.
Qed.
Lemma greater : forall n, exists p, n < p.
Proof.
intros n.
exists (S (S n)).
apply lt_n_SSn.
Qed.
Print greater.
Section absurd.
Hypothesis H : exists n, forall p, p < n.
Lemma absurd : False.
Proof.
destruct H as [ m Hm ].
apply (lt_irrefl m).
apply Hm.
Qed.
End absurd.
Lemma L36 : 9 * 4 = 3 * 12.
Proof.
reflexivity.
Qed.
Variable (A : Type).
Lemma eq_trans_on_A (x y z : A) : x = y -> y = z -> x = z.
Proof.
intros H1 H2.
(* rewrite H1, <- H2; reflexivity. *)
(* now rewrite H1. (* is the same as rewrite H1; easy. *) *)
(* subst; reflexivity. *)
(* symmetry; transitivity y; symmetry; trivial. *)
replace z with y; trivial.
Qed.
Lemma L1 : forall x y : nat,
x = S (S y) -> 2 <= x * x.
Proof.
intros x y H.
pattern x at 1.
rewrite H.
Admitted.
End C2_2.
Section C2_3.
Variable f : nat -> nat -> nat.
Hypothesis f_comm : forall x y, f x y = f y x.
Lemma L : forall x y z, f (f x y) z = f z (f y x).
Proof.
intros x y z.
rewrite (f_comm x y).
rewrite (f_comm _ z).
reflexivity.
Qed.
End C2_3.
Require Import Omega Lia.
Lemma L' : forall n, n < 2 -> n = 0 \/ n = 1.
Proof.
intros; lia.
Qed.
Lemma L2 : forall i, i < 2 -> i*i = i.
Proof.
intros i H.
destruct L' with (1 := H); subst i; trivial.
Qed.
Lemma or_comm : forall P Q : Prop, P \/ Q -> Q \/ P.
Proof.
intros ? ? []; [ right | left ]; assumption.
Qed.
Lemma not_ex_all_not : forall (A : Type) (P : A -> Prop),
(~ exists a:A, P a) -> forall a, ~ P a.
Proof.
intros A P H a H1.
unfold not in *.
apply H.
exists a.
trivial.
Qed.
Lemma all_not_not_ex (A : Type) (P : A -> Prop) :
(forall a, ~ P a) -> ~ exists a:A, P a.
Proof.
intros H (x & Hx).
apply (H x), Hx.
Qed.
Lemma test_students : exists P : nat -> Prop, P 0 /\ ~ P 1.
Proof.
(* exists (fun x => x < 1); lia. *)
exists (fun x : nat => 0 = x); lia.
(* split.
+ reflexivity.
+ discriminate. *)
Qed.
Fixpoint factorial n :=
match n with
| 0 => 1
| S n => (S n) * factorial n
end.
Lemma factorial_prop n : forall p, 0 < p <= n -> exists q, factorial n = q * p.
Proof.
induction n as [ | n IHn ].
Admitted.
Lemma exf : exists f : nat -> nat,
forall n p, 0 < p -> p <= n -> exists q, f n = q * p.
Proof.
exists (fun _ => 0).
intros n p _ _.
exists 0.
simpl.
reflexivity.
Qed.
Section HO.
Variables (A : Type) (f : A -> A)
(f_self_inverse : forall a, f (f a) = a).
Lemma f_onto : forall b, exists a, b = f a.
Proof.
intros b.
exists (f b).
rewrite f_self_inverse.
reflexivity.
Qed.
End HO.
Require Import ZArith Ring.
Open Scope Z_scope.
Section Z_sect.
Variable f : Z -> Z -> Z -> Z.
Goal forall x y z, f (x+y) z 0 = f (y+x+0) (z*(1+0)) (x-x).
Proof.
intros x y z.
f_equal; ring.
(*
replace (x+y) with (y+x+0).
replace z with (z*(1+0)) at 1.
replace 0 with (x-x) at 3.
reflexivity. *)
Qed.
End Z_sect.
Require Import Setoid.
Section rewrite_equivalence.
Variable (A : Type) (P Q : A -> Prop).
Hypothesis E : forall a : A, P a <-> ~ Q a.
Goal (exists a, P a) -> ~ (forall x, Q x).
Proof.
intros (x & Hx) H1.
rewrite E in Hx.
apply Hx, H1.
Qed.
Print L2.
Check N.
Print Lf.