/
qoc_jisuanji_tactics.html
412 lines (341 loc) · 12.1 KB
/
qoc_jisuanji_tactics.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!--
This sample contains two very simple introductory exercises of
interactive proofs in Coq, one with natural numbers and one with lists.
It can be used as a gentle landing page, which requires no knowledge
of math-comp.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="An Online IDE for the Coq Theorem Prover" />
<title>Use Coq in Your Browser: The Js Coq Theorem Prover Online IDE!</title>
</head>
<body>
<div id="ide-wrapper" class="toggled">
<div id="code-wrapper">
<div id="document">
<p>
+ Friday, March 29, 2019, 23:00:00
<br/> OOO1337777 , COQ , 鸡算计 , mathematics , 数学 - tactic , suffice - 战术 , 满足
<br/> https://bilibili.com/video/av47713482
</p>
<p>
Alt+↑/↓ – move through proof; Alt+→ or Alt+⏎ – go to cursor. <br/>
Alt+hover executed sentences to watch intermediate steps. <br/>
Hover identifiers in goals to view their types. Alt+hover to view definitions.<br/>
<i style="color: rgb(51, 51, 150)">Company-coq</i> addon is enabled: it will auto-complete names of tactics and lemmas
from the standard library, and also show types of lemmas in the right pane.
</p>
<p>
“Alt +↑/↓” : 通过证明。 “Alt +→”或“Alt +⏎” : 转到光标。
<br/> “Alt +”悬停执行句子以观察中间步骤。
<br/> 将目标中的标识符悬停在其中以查看其类型。 “Alt +”悬停以查看定义。
<br/> 启用“Company-coq”加载项:它将自动完成标准库中的策略和引理名称,并在右侧窗格中显示引导类型。
</p>
<textarea id="workspace">
From Qoc Require Import Jisuanji .
Import ssreflect .
(**MEMO:
短 :: 为了从“A”到“E”的目标,搜索/猜测某些“S”从“A”到“S”然后从“S”变为“E”可能更明智/更具策略性“。
Short :: for the goal of going from "A" to "E" , it may be more sensible/tactical to search/guess some "S" such to go from "A" to "S" then to go from "S" to "E" .
It may be more-sensible to refine/start/open the top of some deduction/proof of some end/goal [A |- E] by sequencing this deduction into two more-sensible parts/halves [A |- S] and [A |- S -> E] , where oneself shall search/guess/devine the mediator [S] by using the contextual sense of the end/goal .
In the most general text , [E] is the END/goal . And [S] is some SEARCHED/guessed/devined weaker SUB-end/goal which suffices ( expressed as [ S -> E ] ) for the end/goal [E] .
In the less general text , [W] is some searched/guessed/devined WEAKENER which defines this particular sub-end/goal [ S := (W -> E) ] ( the end UNDER [W] ) , which suffices ( [ (W -> E) -> E ] ) for the end/goal [E] . Alternatively , oneself may transpose this precedent result and view the sufficiency expression as [ W -> E ] and the sub-end/goal as [ S := ( (W -> E) -> E ) ] ( the RELATIVE [W] , which is some style of double negation of [W] above the end [E] not the bottom [False] )
Everythere , the identifier [p] is some outer-argument/parameter and [x] is some (varying) inner-argument . And the sense for the identifier [x] is not binary , possible senses are : [simultaneous] identifier , [parametric]/singly/pointwise identifier , [none] identifier .
-----
+ simultaneous have s_ , s_x : x / S p x
1(instance): x |- S p x
2(generalized): x ; s_ : (forall x , S p x) ; s_x : S x |- E p x
* have s : S
1(instance): |- S
2(generalized): s : S |- E
+ simultaneous suffices s_ : x / S p x
1(generalized): x ; s_ : (forall x , S p x) |- E p x
2(instance): x |- S p x
* suffices s : S
1(generalized): s : S |- E
2(instance): |- S
+ parametric have_relatively w : x / W p x
1(instance): x |- (forall x , W p x -> E p x) -> E p x
2(generalized): x ; w : W p x |- E p x
* have_relatively w : W
1(instance): |- (W -> E) -> E
2(generalized): w : W |- E
* have_under m : W
1(instance): |- W -> E
2(generalized): m : (W -> E) |- E
+ parametric suffices_relatively w : x / W p x
1(generalized): x ; w : W p x |- E p x
2(instance): x |- (forall x , W p x -> E p x) -> E p x
* suffices_relatively w : W
1(generalized): w : W |- E
2(instance): |- (W -> E) -> E
* suffices_under m : W
1(generalized): m : (W -> E) |- E
2(instance): |- W -> E
-----
+ simultaneous have s_ , s_x : x / S p x
:= gen have s_ , s_x : x / S p x
* have s : S
:= have s : S
+ simultaneous suffices s_ : x / S p x
:= wlog suff s_ : x / S p x
* suffices s : S
:= suff s : S
+ parametric have_relatively w : x / W p x
:= wlog w : x / W a x
* have_relatively w : W
:= ??
* have_under m : W
:= have suff m : W
+ parametric suffices_relatively w : x / W p x
:= ??
* suffices_relatively w : W
:= suff have w : W
* suffices_under m : W
:= ??
*)
Module Tactics .
Module Generalization .
Parameter A : forall (p : bool) , Type .
Parameter E : forall (p : bool) (x : bool) , Type .
Parameter S : forall (p : bool) (x : bool) , Type .
Parameter W : forall (p : bool) (x : bool) , Type .
Section section1 .
Variable p : bool .
Lemma lemma1 : A p -> forall x : bool , E p x .
Proof.
intros a x .
simultaneous have s_ , s_x : x / S p x . Show 2 . Undo .
(** Tóngshí jùyǒu *)
同时 具有 s_ , s_x : x / S p x . Show 2 . Undo .
(** 1(instance): x |- S p x
2(generalized): x ; s_ : (forall x , S p x) ; s_x : S x |- E p x *)
have s : S p x . Show 2. Undo.
(** Jùyǒu *)
具有 s : S p x . Show 2. Undo.
(** 1(instance): |- S
2(generalized): s : S |- E *)
Abort .
Lemma lemma1 : A p -> forall x : bool , E p x .
Proof.
intros a x .
simultaneous suffices s_ : x / S p x . Show 2 . Undo .
(** Tóngshí mǎnzú *)
同时 满足 s_ : x / S p x . Show 2 . Undo .
(** 1(generalized): x ; s_ : (forall x , S p x) |- E p x
2(instance): x |- S p x *)
suffices s : S p x . Show 2 . Undo .
(** mǎnzú *)
满足 s : S p x . Show 2 . Undo .
(** 1(generalized): s : S |- E
2(instance): |- S *)
Abort .
Lemma lemma1 : A p -> forall x : bool , E p x .
Proof.
intros a x .
parametric have_relatively w : x / W p x . Show 2 . Undo .
(** Cān jùyǒu_xiāngduì *)
参 具有_相对 w : x / W p x . Show 2 . Undo .
(** 1(instance): x |- (forall x , W p x -> E p x) -> E p x
2(generalized): x ; w : W p x |- E p x *)
have_relatively w : W p x . Show 2 . Undo .
(** Cān jùyǒu_xiāngduì *)
具有_相对 w : W p x . Show 2 . Undo .
(** 1(instance): |- (W -> E) -> E
2(generalized): w : W |- E *)
have_under m : W p x . Show 2 . Undo .
(** Jùyǒu_xià *)
具有_下 m : W p x . Show 2 . Undo .
(** 1(instance): |- W -> E
2(generalized): m : (W -> E) |- E *)
Abort .
Lemma lemma1 : A p -> forall x : bool , E p x .
Proof.
intros a x .
parametric suffices_relatively w : x / W p x . Show 2 . Undo .
(** Cān mǎnzú_xiāngduì *)
参 满足_相对 w : x / W p x . Show 2 . Undo .
(** 1(generalized): x ; w : W p x |- E p x
2(instance): x |- (forall x , W p x -> E p x) -> E p x *)
suffices_relatively w : W p x . Show 2 . Undo .
(** Mǎnzú_xiāngduì *)
满足_相对 w : W p x . Show 2 . Undo .
(** 1(generalized): w : W |- E
2(instance): |- (W -> E) -> E *)
suffices_under m : W p x . Show 2 . Undo .
(** Mǎnzú_xià *)
满足_下 m : W p x . Show 2 . Undo .
(** 1(generalized): m : (W -> E) |- E
2(instance): |- W -> E *)
Abort.
End section1.
Section Generalization_example .
Lemma quo_rem_unicity ( d : nat) :
forall ( q1 q2 r1 r2 : nat ) ,
q1*d + r1 = q2*d + r2 ->
r1 < d -> r2 < d ->
(pair q1 r1) = (pair q2 r2) .
Proof .
intros q1 q2 r1 r2 .
wlog: q1 q2 r1 r2 / q1 <= q2 . Show 2 . Undo .
parametric have_relatively w : q1 q2 r1 r2 / q1 <= q2 . Show 2 . Undo .
(** Cān jùyǒu_xiāngduì *)
参 具有_相对 w : q1 q2 r1 r2 / q1 <= q2 . Show 2 . Undo .
(** 1(instance): (用 q3 q4 r3 r4 : nat, q3 <= q4 ->
q3 * d + r3 = q4 * d + r4 -> r3 < d -> r4 < d -> (q3, r3) = (q4, r4))
-> q1 * d + r1 = q2 * d + r2 -> r1 < d -> r2 < d -> (q1, r1) = (q2, r2)
2(generalized): w : q1 <= q2 |- q1 * d + r1 = q2 * d + r2 -> r1 < d -> r2 < d -> (q1, r1) = (q2, r2) *)
Abort .
End Generalization_example .
End Generalization .
Definition tactics_move_apply_exact_elim_case
: forall n : nat , nat .
Proof .
move => m . Undo .
(** Yídòng *)
移动 => m .
apply : m . Undo .
(** Yìngyòng *)
应用 : m . Undo .
exact : m . Undo .
(** Quèqiè *)
确切 : m . Undo .
elim : m . Undo .
(** Xiāochú *)
消除 : m . Undo .
case : m . Undo .
(** Lìzi *)
例子 : m . Undo .
Abort.
(**TODO: solve this *)
Lemma tactics_abstract (n m : nat) : True.
have [:Sm] @plus_n_Sm : nat .
{ apply: (plus n).
abstract: Sm.
{ exact: (S m).
}
}
Restart .
(** Jùyǒu *)
具有 [:Sm] @plus_n_Sm : nat .
{ (** Yìngyòng *)
应用: (plus n).
(** Chōuxiàng *)
抽象: Sm.
{ (** Quèqiè *)
确切: (S m).
}
}
Abort.
Definition tactics_rewrite : forall n m : nat , n = m -> m = n .
Proof .
intros n m H.
rewrite H . Undo .
(** Gǎixiě *)
改写 H . Undo .
Abort.
Lemma tactic_pose : True.
pose f x y := x + y . Undo .
(** Bǎi *)
摆 f x y := x + y. Undo .
pose fix f (x y : nat) {struct x} : nat :=
if x is S p then S (f p y) else 0 .
Undo .
(** Bǎi gùdìng *)
摆 固定 f (x y : nat) {struct x} : nat :=
if x is S p then S (f p y) else 0 .
Undo .
Abort .
Lemma tactic_set (x y z : nat) : x + y = z.
set t := _ x. Undo .
(** Bǎiliè *)
摆列 t := _ x . Undo .
Abort .
Lemma tactic_lock n m : (S n) + m = match (S n) with
S p => m + (S p)
| 0 => m + 0
end.
rewrite {1}[S]lock .
rewrite -lock. Undo.
unlock .
move: (S n) . Restart .
(** Gǎixiě *)
改写 {1}[S]lock .
(** Kāisuǒ *)
开锁 .
(** Yídòng *)
移动: (S n).
Abort.
Definition add :=
( 固定 add (n m : nat) {构 n} : nat := 匹配 n 与
| 0 => m
| S p => S (add p m)
结束 ) .
(** Bù jiǎnhuà *)
Definition addn := 不简化 add .
Lemma notation_nosimpl : forall n m,
( if (addn (S n) (S m))
is (S p ) then p
else 0 )
= (addn (S m) n) .
intros n m .
simpl . fold addn .
move: (S m).
Abort.
Lemma tactic_congr x y :
x + (y * (y + x - x)) = (x * 1) + (y + 0) * y.
congr plus . Undo .
(** Cítóu *)
词头 plus . Undo .
congr ( _ + (_ * _)) . Undo .
(** Cítóu *)
词头 ( _ + (_ * _)) . Undo .
Abort .
Inductive test : nat -> Prop :=
| C1 : forall n , n = 1 -> test n
| C2 : forall n , n = 2 -> test n
| C3 : forall n , n = 3 -> test n
| C4 : forall n , n = 4 -> test n
| C5 : forall n , n = 5 -> test n .
Lemma tactic_last n (t : test n) : True.
case : t ;
last 2 [ move => k3
| move => k4 ] . Undo .
(** Lìzi *)
例子 : t ;
(** Hòu *)
后 2 [ (** Yídòng *) 移动 => k3
| (** Yídòng *) 移动 => k4 ] . Undo .
case : t ;
first last . Undo .
(** Lìzi *)
例子 : t ;
(** Qián hòu *)
前 后 .
Abort.
End Tactics .
Print Tactics .
</textarea>
</div> <!-- /#document -->
</div> <!-- /#code-wrapper -->
</div> <!-- /#ide-wrapper -->
<script src="../ui-js/jscoq-loader.js" type="text/javascript"></script>
<script type="text/javascript">
var jscoq_ids = ['workspace'];
var jscoq_opts = {
prelude: true,
base_path: '../',
init_pkgs: ['init', 'qoc'],
all_pkgs: ['init', 'qoc', 'coq-base', 'coq-collections', 'coq-arith', 'coq-reals', 'math-comp'],
implicit_libs: true,
editor: { mode: { 'company-coq': true }, keyMap: 'default' }
};
/* Global reference */
var coq;
loadJsCoq(jscoq_opts.base_path)
.then( () => coq = new CoqManager(jscoq_ids, jscoq_opts) );
</script>
</body>
</html>