-
Notifications
You must be signed in to change notification settings - Fork 13
/
hw05.v
224 lines (160 loc) · 4.71 KB
/
hw05.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
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(** Use SSReflect tactics.
DO NOT use automation like [tauto], [intuition], [firstorder], etc.,
except for [by], [done], [exact] tactic(al)s. *)
(** * Exercise *)
Lemma nlem (A : Prop):
~ (A \/ ~ A) -> A.
Proof.
Admitted.
(** Hint: you might want to use a separate lemma here to make progress.
Or, use the `have` tactic: `have: statement` creates a new subgoal and asks
you to prove the statement. This is like a local lemma. *)
(** * Exercise *)
Lemma weak_Peirce (A B : Prop) :
((((A -> B) -> A) -> A) -> B) -> B.
Proof.
Admitted.
(** * Exercise *)
(* Prove that having a general fixed-point combinator in Coq would be incosistent *)
Definition FIX := forall A : Type, (A -> A) -> A.
Lemma fix_inconsistent :
FIX -> False.
Proof.
Admitted.
Section Boolean.
(** * Exercise *)
Lemma negbNE b : ~~ ~~ b -> b.
Proof.
Admitted.
(** * Exercise *)
Lemma negbK : involutive negb.
Proof.
Admitted.
(** * Exercise *)
Lemma negb_inj : injective negb.
Proof.
Admitted.
End Boolean.
(** * Exercise *)
Fixpoint triple (n : nat) : nat :=
if n is n'.+1 then (triple n').+3
else n.
Lemma triple_mul3 n :
triple n = 3 * n.
Proof.
Admitted.
(** Hints:
- use the /= action to simplify your goal: e.g. move=> /=.
- use `Search (<pattern>)` to find a useful lemma about multiplication
*)
(** * Exercise
Prove by it induction: you may re-use the addnS and addSn lemmas only *)
Lemma double_inj m n :
m + m = n + n -> m = n.
Proof.
Admitted.
(* This is a harder exercise than the previous ones but
the tactics you already know are sufficient *)
(** * Optional exercise
[negb \o odd] means "even".
The expression here says, informally,
the sum of two numbers is even if the summands have the same "evenness",
or, equivalently, "even" is a morphism from [nat] to [bool] with respect
to addition and equivalence correspondingly.
Hint: [Unset Printing Notations.] and [rewrite /definition] are your friends :)
*)
Lemma even_add :
{morph (negb \o odd) : x y / x + y >-> x == y}.
Proof.
Admitted.
(** * Optional exercise *)
Lemma DNE_iff_nppp :
(forall P, ~ ~ P -> P) <-> (forall P, (~ P -> P) -> P).
Proof.
Admitted.
(** * Optional exercise *)
Lemma leq_add1l p m n :
m <= n -> m <= p + n.
Proof.
Search (_ <= _ + _).
Admitted.
(** Hint: this lemmas does not require induction, just look for a couple lemmas *)
(* ================================================ *)
(*
More fun with functions, OPTIONAL
*)
Section PropertiesOfFunctions.
Section SurjectiveEpic.
Context {A B : Type}.
(* https://en.wikipedia.org/wiki/Surjective_function *)
(** Note: This definition is too strong in Coq's setting, see [epic_surj] below *)
Definition surjective (f : A -> B) :=
exists g : B -> A, f \o g =1 id.
(** This is a category-theoretical counterpart of surjectivity:
https://en.wikipedia.org/wiki/Epimorphism *)
Definition epic (f : A -> B) :=
forall C (g1 g2 : B -> C), g1 \o f =1 g2 \o f -> g1 =1 g2.
(** * Optional exercise *)
Lemma surj_epic f : surjective f -> epic f.
Proof.
Admitted.
(** * Optional exercise *)
Lemma epic_surj f : epic f -> surjective f.
(** Why is this not provable? *)
Abort.
End SurjectiveEpic.
Section EpicProperties.
Context {A B C : Type}.
(** * Optional exercise *)
Lemma epic_comp (f : B -> C) (g : A -> B) :
epic f -> epic g -> epic (f \o g).
Admitted.
(** * Optional exercise *)
Lemma comp_epicl (f : B -> C) (g : A -> B) :
epic (f \o g) -> epic f.
Admitted.
(** * Optional exercise *)
Lemma retraction_epic (f : B -> A) (g : A -> B) :
(f \o g =1 id) -> epic f.
Admitted.
End EpicProperties.
(** The following section treats some properties of injective functions:
https://en.wikipedia.org/wiki/Injective_function *)
Section InjectiveMonic.
Context {B C : Type}.
(** This is a category-theoretical counterpart of injectivity:
https://en.wikipedia.org/wiki/Monomorphism *)
Definition monic (f : B -> C) :=
forall A (g1 g2 : A -> B), f \o g1 =1 f \o g2 -> g1 =1 g2.
(** * Optional exercise *)
Lemma inj_monic f : injective f -> monic f.
Proof.
Admitted.
(** * Optional exercise *)
Lemma monic_inj f : monic f -> injective f.
Proof.
Admitted.
End InjectiveMonic.
Section MonicProperties.
Context {A B C : Type}.
(** * Optional exercise *)
Lemma monic_comp (f : B -> C) (g : A -> B) :
monic f -> monic g -> monic (f \o g).
Proof.
Admitted.
(** * Optional exercise *)
Lemma comp_monicr (f : B -> C) (g : A -> B) :
monic (f \o g) -> monic g.
Proof.
Admitted.
(** * Optional exercise *)
Lemma section_monic (f : B -> A) (g : A -> B) :
(g \o f =1 id) -> monic f.
Proof.
Admitted.
End MonicProperties.
End PropertiesOfFunctions.