-
Notifications
You must be signed in to change notification settings - Fork 13
/
seminar09.v
187 lines (122 loc) · 4.23 KB
/
seminar09.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
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div seq path.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Axiom replace_with_your_solution_here : forall {A : Type}, A.
Section Exercise1.
Definition impl_distr (A B C : Prop) :
(A -> (B -> C)) <-> ((A -> B) -> (A -> C))
:= replace_with_your_solution_here.
End Exercise1.
Section Exercise2.
Variable DNE : forall A : Prop, ~ ~ A -> A.
Lemma drinker_paradox (P : nat -> Prop) :
exists x, P x -> forall y, P y.
Proof.
Admitted.
End Exercise2.
Section Exercise3.
Lemma min_plus_minus m n p :
minn n m + minn (n - m) p = minn n (m + p).
Proof.
Admitted.
End Exercise3.
Section Exercise4.
(** Continuation-passing style list sum function
See https://en.wikipedia.org/wiki/Continuation-passing_style *)
(** Recursive helper function *)
Fixpoint sumn_cont' {A} (l : seq nat) (k : nat -> A) : A :=
if l is (x :: xs) then sumn_cont' xs (fun answer => k (x + answer))
else k 0.
(** The main definition *)
Definition sumn_cont (l : seq nat) : nat :=
sumn_cont' l (fun x => x).
Lemma sumn_cont'_correct A l (k : nat -> A) :
sumn_cont' l k = k (sumn l).
Admitted.
(** Prove that the continuation-passing style list sum function is correct w.r.t
the standard [sumn] function *)
Lemma sumn_cont_correct l :
sumn_cont l = sumn l.
Proof.
Admitted.
End Exercise4.
Section Exercise5.
(* Prove [8x = 6y + 1] has no solutions in [nat] *)
Lemma no_solution x y :
8*x != 6*y + 1.
Proof.
Admitted.
End Exercise5.
Section Exercise6.
Lemma exercise n :
~~ odd n ->
(n.-1 %/ 2) = (n %/ 2 - 1).
Proof.
Admitted.
End Exercise6.
(*** Extra topics *)
(** * Strict positivity *)
Unset Positivity Checking.
Inductive prop :=
RemoveNegation of (prop -> False).
Set Positivity Checking.
Print Assumptions prop.
Definition not_prop (p : prop) : False :=
let '(RemoveNegation not_p) := p in not_p p.
Check RemoveNegation not_prop : prop.
Definition yet_another_proof_of_False : False :=
not_prop (RemoveNegation not_prop).
Print Assumptions yet_another_proof_of_False.
(** * Russel's Paradox in Prop *)
Module RusselInProp.
(* the universe of all sets *)
Inductive U : Prop :=
set (L : Prop) (i : L -> U) (P : L -> Prop).
(* L -- labels for elements of the universe *)
(* i -- function interpreting labels into sets (the elements of the universe) *)
(* P -- the predicate on labels corresponding to a set we want to define *)
(* Membership relation: x \in A *)
Fail Definition In (x A : U) : Prop :=
match A with
| set L i P => exists lx, (x = (i lx)) /\ (P lx)
end.
End RusselInProp.
(** * Russel's Paradox in Type (Using Type-In-Type) *)
Module RusselInType.
(* a bit of logic in Type (as opposed to Prop) *)
Inductive And (A B : Type) : Type :=
and_ : A -> B -> And A B.
Inductive Exists {A : Type} (P : A -> Type) : Type :=
exists_ : forall (a : A), (P a) -> Exists P.
Inductive Eq {A : Type} (x : A) : A -> Type :=
eq_refl_ : Eq x x.
Inductive FalseT : Type := .
(* the universe of all sets, now in Type *)
Inductive U : Type :=
set (L : Type) (i : L -> U) (P : L -> Type).
(* L -- labels for elements of the universe *)
(* i -- function interpreting labels into sets (the elements of the universe) *)
(* P -- the predicate on labels corresponding to a set we want to define *)
(* Membership relation: x \in A *)
(* if an element x belongs to a set A, this means there exists a labels for x,
such that the interpretation of the label is the same as x and
the predicate underlying X holds on x *)
(* notice that we work in an essentially untyped setting *)
Definition In (x A : U) : Type :=
(* if we worked in Prop, we wouldn't be able to pattern-match here
as large elimination is prohibited for Prop *)
match A with
| set L i P => Exists (fun (lx : L) => And (Eq x (i lx)) (P lx))
end.
Definition proper (X : U) : Type := In X X -> FalseT.
Unset Universe Checking.
Definition ps : U := set U (fun l => l) proper.
Set Universe Checking.
Lemma proper_ps : proper ps.
Proof. by move=> p; case: (p)=> l [<-]; apply. Qed.
Lemma not_proper_ps : proper ps -> FalseT.
Proof. by apply; exists ps; split=>//; apply: proper_ps. Qed.
Lemma inconsistency : FalseT.
Proof. exact: (not_proper_ps proper_ps). Qed.
End RusselInType.