-
Notifications
You must be signed in to change notification settings - Fork 1
/
exercise6.html
347 lines (281 loc) · 9.02 KB
/
exercise6.html
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="jscoq/node_modules/bootstrap/dist/css/bootstrap.min.css" />
<title>Machine-Checked Mathematics</title>
<link rel="stylesheet" href="local.css" />
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML'
async></script>
<script src="Blob.js" type="text/javascript"></script>
<script src="FileSaver.js" type="text/javascript"></script>
</head>
<body>
<div id="ide-wrapper" class="toggled">
<div id="code-wrapper">
<div id="document">
<p>
Use ALT-(up-arrow) and ALT-(down-arrow) to process this document inside your browser, line-by-line.
Use ALT-(right-arrow) to go to the cursor.
You can
<span class="save-button" onClick="save_coq_snippets()">save your edits</span>
inside your browser and
<span class="save-button" onClick="load_coq_snippets()">load them back</span>.
<!-- (edits are also saved when you close the window) -->
Finally, you can
<span class="save-button" onClick="download_coq_snippets()">download</span>
your working copy of the file, e.g., for sending it to teachers.
<hl />
</p>
<div><textarea id='coq-ta-1'>
From mathcomp Require Import mini_ssreflect.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
</textarea></div>
<div><p>
<hr/>
<div class="slide">
<p>
<h2>
Exercise 1:
</h2>
<p>
<ul class="doclist">
<li> Extend the definitions introduced in Lesson 6, so that
the proof of the <tt>test1</tt> lemma succeeds without changing
the proof script.
</li>
</ul>
<div>
</div>
<div><textarea id='coq-ta-2'>
Section PosNat.
Variable P : nat -> Prop.
Record pos_nat : Set := PosNat {val : nat; pos_val : 1 <= val}.
Coercion val : pos_nat >-> nat.
Hypothesis posP : forall x : pos_nat, P x.
Lemma pos_S (x : nat) : 1 <= S x.
Proof. by []. Qed.
Definition pos_nat_S (n : nat) : pos_nat := PosNat (pos_S n).
Canonical pos_nat_S.
Lemma pos_add (x y : pos_nat) : 1 <= x + y.
Proof. by rewrite addn_gt0; case: x => x ->. Qed.
Definition pos_nat_add (x y : pos_nat) : pos_nat := PosNat (pos_add x y).
Canonical pos_nat_add.
(* Something goes here *)
Lemma test1 x y : P ((S x) * (3 + (S y))).
Proof.
exact: posP.
Qed.
End PosNat.
</textarea></div>
<div><p>
</div>
<hr/>
<div class="slide">
<p>
Exercise 2.
We define a type <tt>tuple</tt> for polymorphic lists with a prescribed length, given
as a parameter. This type is a dependent pair.
This condition is expressed as a (boolean) constraint
on the size of a list, coerced to Prop via the usual <tt>is_true</tt> coercion.
The infix <tt>==</tt> notation refers to the notation available on instances of
the <tt>eqType</tt> structure, as defined by the library loaded in this section.
This structure is isomorphic to the one we used in Lesson 6. In particular, it is endowed with a reflection lemma <tt>eqP</tt>, relating the boolean test with
equality.
<p>
Fill the missing parts so that the <tt>test</tt> lemmas are proved without
changing their script.
<p>
<div>
</div>
<div><textarea id='coq-ta-3'>
About size.
About map.
Section Def.
Variables (n : nat) (T : Type).
Record tuple : Type := Tuple {tval : list T; valP : size tval == n}.
Coercion tval : tuple >-> list.
Lemma size_tuple (t : tuple) : size t = n.
(* Something goes here *)
Qed.
End Def.
(* Something goes here, two things actually. *)
Section TupleTest.
Variable P : list nat -> Prop.
Variable hP : forall n, forall t : tuple (S n) nat, P t.
Lemma test2 : P (cons 2 nil).
Proof. apply: hP. Qed.
End TupleTest.
Section MapTuple.
Variables (T1 T2 : Type) (n : nat) (f : T1 -> T2).
Lemma map_tupleP (t : tuple n T1) : size (map f t) == n.
Proof.
(* Finish the proof, and may be more *)
Qed.
End MapTuple.
Section TupleTest.
Variable P : list bool -> Prop.
Variable hP : forall n, forall t : tuple (S n) bool, P t.
Lemma test3 (f : nat -> bool) : P (map f (cons 2 nil)).
Proof. apply: hP. Qed.
End TupleTest.
</textarea></div>
<script type="text/javascript">
var coqdoc_ids = ['coq-ta-1', 'coq-ta-2', 'coq-ta-3'];
</script>
<hr />
<script type="text/javascript">
function load_coq_snippets() {
for (i = 0; i < coqdoc_ids.length; ++i) {
document.getElementById(coqdoc_ids[i]).nextSibling.CodeMirror.setValue(
localStorage.getItem('coq-snippet-' + coqdoc_ids[i]));
}
}
function save_coq_snippets() {
for (i = 0; i < coqdoc_ids.length; ++i) {
localStorage.setItem('coq-snippet-' + coqdoc_ids[i], document.getElementById(coqdoc_ids[i]).nextSibling.CodeMirror.getValue());
}
alert("Coq snippets saved.");
}
function download_coq_snippets() {
var chunks = []
for (i = 0; i < coqdoc_ids.length; ++i) {
chunks.push(document.getElementById(coqdoc_ids[i]).nextSibling.CodeMirror.getValue())
}
var data = new Blob(chunks, { type: "text/plain;charset=utf-8" });
saveAs(data, 'source.v');
}
alignWithTop = true;
current = 0;
slides = [];
function select_current() {
for (var i = 0; i < slides.length; i++) {
var s = document.getElementById('slideno' + i);
if (i == current) {
s.setAttribute('class', 'slideno selected');
} else {
s.setAttribute('class', 'slideno');
}
}
}
function mk_tooltip(label, text) {
var t = document.createElement("div");
t.setAttribute('class', 'slide-tooltip');
t.innerHTML = label;
var s = document.createElement("span");
s.setAttribute('class', 'slide-tooltiptext slide-tooltip-left');
s.innerHTML = text;
t.appendChild(s);
return t;
}
function find_hx(e) {
for (var i = 0; i < e.children.length; i++) {
var x = e.children[i];
if (x.tagName == "H1" ||
x.tagName == "H2" ||
x.tagName == "H3" ||
x.tagName == "H4") return x.textContent;
}
return null;
}
function init_slides() {
var toolbar = document.getElementById('document');
if (toolbar) {
var tools = document.createElement("div");
var tprev = document.createElement("div");
var tnext = document.createElement("div");
tools.setAttribute('id', 'tools');
tprev.setAttribute('id', 'prev');
tprev.setAttribute('onclick', 'prev_slide();');
tnext.setAttribute('id', 'next');
tnext.setAttribute('onclick', 'next_slide();');
toolbar.prepend(tools);
tools.appendChild(tprev);
tools.appendChild(tnext);
slides = document.getElementsByClassName('slide');
for (var i = 0; i < slides.length; i++) {
var s = document.createElement("div");
s.setAttribute('id', 'slideno' + i);
s.setAttribute('class', 'slideno');
s.setAttribute('onclick', 'goto_slide(' + i + ');');
var title = find_hx(slides[i]);
if (title == null) {
title = "goto slide " + i;
}
var t = mk_tooltip(i, title);
s.appendChild(t)
tools.appendChild(s);
}
select_current();
} else {
//retry later
setTimeout(init_slides, 100);
}
}
function on_screen(rect) {
return (
rect.top >= 0 &&
rect.top <= (window.innerHeight || document.documentElement.clientHeight)
);
}
function update_scrolled() {
for (var i = slides.length - 1; i >= 0; i--) {
var rect = slides[i].getBoundingClientRect();
if (on_screen(rect)) {
current = i;
select_current();
}
}
}
function goto_slide(n) {
current = n;
var element = slides[current];
console.log(element);
element.scrollIntoView(alignWithTop);
select_current();
}
function next_slide() {
current++;
if (current >= slides.length) { current = slides.length - 1; }
var element = slides[current];
console.log(element);
element.scrollIntoView(alignWithTop);
select_current();
}
function prev_slide() {
current--;
if (current < 0) { current = 0; }
var element = slides[current];
element.scrollIntoView(alignWithTop);
select_current();
}
window.onload = init_slides;
window.onbeforeunload = save_coq_snippets;
window.onscroll = update_scrolled;
</script>
</div> <!-- /#document -->
</div> <!-- /#code-wrapper -->
</div> <!-- /#ide-wrapper -->
<script src="./jscoq/ui-js/jscoq-loader.js" type="text/javascript"></script>
<script type="text/javascript">
var coq;
loadJsCoq('./jscoq/')
.then(loadJs("./jscoq/node_modules/codemirror/addon/runmode/runmode"))
.then(loadJs("./jscoq/node_modules/codemirror/addon/runmode/colorize"))
.then(function () {
var coqInline = document.getElementsByClassName("inline-coq");
CodeMirror.colorize(coqInline);
})
.then(function () {
coq = new CoqManager(coqdoc_ids,
{ base_path: './jscoq/',
init_pkgs: ['init'],
all_pkgs: ['init','math-comp']
}
);
});
</script>
</body>
</html>