-
Notifications
You must be signed in to change notification settings - Fork 13
/
seminar02.v
155 lines (107 loc) · 3.03 KB
/
seminar02.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
Section PropositionalLogic.
Variables A B C : Prop.
Definition anb1 :
A /\ B -> A
:=
Definition impl_trans :
(A -> B) -> (B -> C) -> A -> C
:=
Definition HilbertS :
(A -> B -> C) -> (A -> B) -> A -> C
:=
Definition DNE_triple_neg :
~ ~ ~ A -> ~ A
:=
Definition or_comm :
A \/ B -> B \/ A
:=
End PropositionalLogic.
Section Quantifiers.
Variable T : Type.
Variable A : Prop.
Variable P Q : T -> Prop.
Definition forall_conj_comm :
(forall x, P x /\ Q x) <-> (forall x, Q x /\ P x)
:=
Definition forall_disj_comm :
(forall x, P x \/ Q x) <-> (forall x, Q x \/ P x)
:=
Definition not_exists_forall_not :
~(exists x, P x) -> forall x, ~P x
:=
Definition exists_forall_not_ :
(exists x, A -> P x) -> (forall x, ~P x) -> ~A
:=
(** Extra exercise (feel free to skip): the dual Frobenius rule *)
Definition LEM :=
forall P : Prop, P \/ ~ P.
Definition Frobenius2 :=
forall (A : Type) (P : A -> Prop) (Q : Prop),
(forall x, Q \/ P x) <-> (Q \/ forall x, P x).
Definition lem_iff_Frobenius2 :
LEM <-> Frobenius2
:=
End Quantifiers.
Section Equality.
(** exercise: *)
Definition f_congr {A B} (f : A -> B) {x y : A} :
x = y -> f x = f y
:=
Definition f_congr' A B (f g : A -> B) (x y : A) :
f = g -> x = y -> f x = g y
:=
(** extra exercise *)
Definition congId A {x y : A} (p : x = y) :
f_congr (fun x => x) p = p :=
(* exercise *)
Definition pair_inj A B (a1 a2 : A) (b1 b2 : B) :
(a1, b1) = (a2, b2) -> (a1 = a2) /\ (b1 = b2)
:=
End Equality.
From mathcomp Require Import ssrfun.
Section ExtensionalEqualityAndComposition.
Variables A B C D : Type.
(** Exercise 2a *)
(** [\o] is a notation for function composition in MathComp, prove that it's associative *)
Definition compA (f : A -> B) (g : B -> C) (h : C -> D) :
(h \o g) \o f = h \o (g \o f)
:=
(** [=1] stands for extensional equality on unary functions,
i.e. [f =1 g] means [forall x, f x = g x].
This means it's an equivalence relation, i.e. it's reflexive, symmetric and transitive.
Let us prove a number of facts about [=1]. *)
(** Exercise: Reflexivity *)
Definition eqext_refl :
forall (f : A -> B), f =1 f
:=
(** Exercise: Symmetry *)
Definition eqext_sym :
forall (f g : A -> B), f =1 g -> g =1 f
:=
(** Exercise: Transitivity *)
Definition eqext_trans :
forall (f g h : A -> B), f =1 g -> g =1 h -> f =1 h
:=
(** Exercise: left congruence *)
Definition eq_compl :
forall (f g : A -> B) (h : B -> C),
f =1 g -> h \o f =1 h \o g
:=
(** Exercise: right congruence *)
Definition eq_compr :
forall (f g : B -> C) (h : A -> B),
f =1 g -> f \o h =1 g \o h
:=
End ExtensionalEqualityAndComposition.
From mathcomp Require Import ssreflect ssrbool eqtype.
(* After importing `eqtype` you need to either use a qualified name for
`eq_refl`: `Logic.eq_refl`, or use the `erefl` notation.
This is because `eqtype` reuses the `eq_refl` identifier for a
different lemma.
*)
Definition iff_is_if_and_only_if :
forall a b : bool, (a ==> b) && (b ==> a) = (a == b)
:=
Definition negbNE :
forall b : bool, ~~ ~~ b = true -> b = true
:=