/
qoc_jisuanji_ends.html
563 lines (463 loc) · 11.2 KB
/
qoc_jisuanji_ends.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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<!--
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, April 26, 2019, 22:22:00
<br/> OOO1337777 , COQ , 鸡算计 , mathematics , 数学 - ends , 鸡算计.在线 - 目的们 , http://鸡算计.在线
<br/> http://鸡算计.在线
<br/> https://www.bilibili.com/video/av50587460/
</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 .
(**
短 : “鸡算计.在线”的目的是让每个人都能读写数学。在未来5年到10年,这可以用于国民教育。
Short :the objective of the "鸡算计.在线" is to enable everyone to read and write mathematics . In the next 5 years to 10 years , this could be used in the national education .
Outline ::
* PART 1 : ENDS . 第1部分 : 目的们
* PART 2 : MORE TACTICS . 第2部分:更多战术们
*)
(** * PART 1 : ENDS . 第1部分 : 目的们 *)
(**
http://鸡算计.在线
http://xn--lzzm24a52n.xn--3ds443g/
短 : “鸡算计.在线”的目的是让每个人都能读写数学。在未来5年到10年,这可以用于国民教育。
Short :the objective of the "鸡算计.在线" is to enable everyone to read and write mathematics . In the next 5 years to 10 years , this could be used in the national education .
*)
(** * PART 2 : MORE TACTICS . 第2部分:更多战术们 *)
(**cs3110 *)
(** 假设 *)
论点 p_implies_p : forall P : Prop,
P -> P.
证明.
移动外 P P_holds.
假设.
据证实.
(** 同一 , 对称 , transitivity *)
论点 forty_two : 41 + 1 = 42.
证明.
同一. 复原.
对称. 同一. 复原 2.
外传递. 确切 (eq_refl (3 + (38 + 1))).
同一.
退出.
(** 琐细 *)
论点 p_implies_p' : forall P : Prop,
P -> P .
证明.
琐细.
据证实.
(** 自动 *)
论点 modus_tollens: forall (P Q : Prop),
(P -> Q) -> ~Q -> ~P.
证明.
自动.
据证实.
(** 辨析 *)
论点 false_implies_anything : forall P : Prop,
0 = 1 -> P.
证明.
移动外 P zero_equals_one.
辨析.
据证实.
(** 确切 *)
论点 everything : 42 = 42.
证明.
确切 (eq_refl 42).
据证实.
(** 矛盾 *)
论点 law_of_矛盾 : forall (P Q : Prop),
P -> ~P -> Q.
证明.
移动外 P Q P_and_not_P.
矛盾.
据证实.
(** Transforming goals *)
(** 移动外 *)
论点 my移动外 : forall A B C D : Prop, D .
证明.
移动外 A B C .
退出.
(** 简化 *)
论点 switch_to_honors : 10 + 2 = 12.
证明.
计时了 简化.
计时了 同一.
退出.
(** 展开 *)
定义 plus_two (x : nat) : nat :=
x + 2.
论点 switch_to_honors_again :
plus_two 10 = 12.
证明.
展开 plus_two.
同一.
据证实.
(** 应用 *)
论点 modus_ponens : forall (P Q : Prop),
(P -> Q) -> P -> Q.
证明.
移动外 P Q P_implies_Q P_holds.
应用 P_implies_Q.
退出.
论点 modus_ponens'' : forall (P Q : Prop),
P -> (P -> Q) -> Q.
证明.
自动.
据证实.
论点 double_negation : forall (P : Prop),
P -> ~~P.
证明.
展开 not. 移动外个 P.
应用 modus_ponens''.
据证实.
(** rewrite *)
论点 add_comm : forall (x y : nat),
x + y = y + x.
证明.
移动外. 归纳 x 如 [ | x' IHx' ].
- 琐细.
- 简化. 改写 -> IHx'.
琐细.
据证实.
(** 逆温 *)
论点 succ_eq_implies_eq : forall (x y : nat),
S x = S y -> x = y.
证明.
移动外 x y succ_eq.
逆温 succ_eq.
琐细.
据证实.
(** 左 , 右 *)
论点 or_左 : forall (P Q : Prop),
P -> P \/ Q.
证明.
移动外 P Q P_holds.
左.
退出.
论点 or_右 : forall (P Q : Prop),
Q -> P \/ Q.
证明.
移动外 P Q Q_holds.
右.
退出.
(** 更换 *)
论点 one_x_one : forall (x : nat),
1 + x + 1 = 2 + x.
证明.
移动外个. 简化.
更换 (x + 1) 与 (S x).
退出.
(** 分裂 *)
论点 implies_and : forall (P Q R : Prop),
P -> (P -> Q) -> (P -> R) -> (Q /\ R).
证明.
移动外 P Q R P_holds.
移动外 P_implies_Q P_implies_R.
分裂. 复原. 构造函数.
- 应用 P_implies_Q . 假设 .
- 应用 P_implies_R . 假设 .
据证实.
论点 and_左 : forall (P Q : Prop),
(P /\ Q) -> P.
证明.
移动外 P Q P_and_Q.
解构 P_and_Q 如 [P_holds Q_holds].
假设.
据证实.
论点 or_comm : forall (P Q : Prop),
P \/ Q -> Q \/ P.
证明.
移动外 P Q P_or_Q.
解构 P_or_Q 如 [P_holds | Q_holds].
- 右. 复原. 构造函数 2. 假设.
- 左. 复原. 构造函数 1. 假设.
据证实.
归纳的 element :=
| grass : element
| fire : element
| water : element.
定义 weakness (e : element) : element :=
匹配 e 与
| grass => fire
| fire => water
| water => grass
结束.
论点 never_weak_to_self : forall (e : element),
weakness e <> e.
证明.
解构 e.
- 简化. 辨析.
- 简化. 辨析.
- 简化. 辨析.
退出.
论点 n_plus_n : forall (n : nat),
n + n = n * 2.
证明.
归纳 n 如 [| x IH].
- 同一.
- 简化. 改写 <- IH. 自动.
据证实.
(** 自动 *)
(** logical t自动 *)
论点 demorgan : forall (P Q : Prop),
~(P \/ Q) -> ~P /\ ~Q.
证明.
同义反复.
据证实.
从 Coq 要求 进口 Lia.
论点 dfoil : forall a ,
(a + 2) * (1 + 2) = a*1 + 2*1 + a*2 + 2*2.
证明.
移动外. lia.
据证实.
从 Coq 要求 进口 Arith.
(** algebraic rihg *)
论点 foil : forall a b c d,
(a + b) * (c + d) = a*c + b*c + a*d + b*d.
证明.
移动外. ring.
据证实.
(** ** alt
----------------------------------------------------------------------------- *)
Reset p_implies_p.
(** assumption *)
Lemma p_implies_p : forall P : Prop,
P -> P.
Proof.
intros P P_holds.
assumption.
Qed.
(** reflexivity , symmetry , transitivity *)
Lemma forty_two : 41 + 1 = 42.
Proof.
reflexivity. Undo.
symmetry. reflexivity. Undo 2.
etransitivity. exact (eq_refl (3 + (38 + 1))).
reflexivity.
Abort.
(** trivial *)
Lemma p_implies_p' : forall P : Prop,
P -> P .
Proof.
trivial.
Qed.
(** auto *)
Lemma modus_tollens: forall (P Q : Prop),
(P -> Q) -> ~Q -> ~P.
Proof.
auto.
Qed.
(** discriminate *)
Lemma false_implies_anything : forall P : Prop,
0 = 1 -> P.
Proof.
intros P zero_equals_one.
discriminate.
Qed.
(** exact *)
Lemma everything : 42 = 42.
Proof.
exact (eq_refl 42).
Qed.
(** contradiction *)
Lemma law_of_contradiction : forall (P Q : Prop),
P -> ~P -> Q.
Proof.
intros P Q P_and_not_P.
contradiction.
Qed.
(** Transforming goals *)
(** intros *)
Lemma myintros : forall A B C D : Prop, D .
Proof.
intros A B C .
Abort.
(** simpl *)
Lemma switch_to_honors : 10 + 2 = 12.
Proof.
Time simpl.
Time reflexivity.
Abort.
(** unfold *)
Definition plus_two (x : nat) : nat :=
x + 2.
Lemma switch_to_honors_again :
plus_two 10 = 12.
Proof.
unfold plus_two.
reflexivity.
Qed.
(** apply *)
Lemma modus_ponens : forall (P Q : Prop),
(P -> Q) -> P -> Q.
Proof.
intros P Q P_implies_Q P_holds.
apply P_implies_Q.
Abort.
Lemma modus_ponens'' : forall (P Q : Prop),
P -> (P -> Q) -> Q.
Proof.
auto.
Qed.
Lemma double_negation : forall (P : Prop),
P -> ~~P.
Proof.
unfold not. intro P.
apply modus_ponens''.
Qed.
(** rewrite *)
Lemma add_comm : forall (x y : nat),
x + y = y + x.
Proof.
intros. induction x as [ | x' IHx' ].
- trivial.
- simpl. rewrite -> IHx'.
trivial.
Qed.
(** inversion *)
Lemma succ_eq_implies_eq : forall (x y : nat),
S x = S y -> x = y.
Proof.
intros x y succ_eq.
inversion succ_eq.
trivial.
Qed.
(** left , right *)
Lemma or_left : forall (P Q : Prop),
P -> P \/ Q.
Proof.
intros P Q P_holds.
left.
Abort.
Lemma or_right : forall (P Q : Prop),
Q -> P \/ Q.
Proof.
intros P Q Q_holds.
right.
Abort.
(** replace *)
Lemma one_x_one : forall (x : nat),
1 + x + 1 = 2 + x.
Proof.
intro. simpl.
replace (x + 1) with (S x).
Abort.
(** split *)
Lemma implies_and : forall (P Q R : Prop),
P -> (P -> Q) -> (P -> R) -> (Q /\ R).
Proof.
intros P Q R P_holds.
intros P_implies_Q P_implies_R.
split. Undo. constructor.
- apply P_implies_Q . assumption .
- apply P_implies_R . assumption .
Qed.
Lemma and_left : forall (P Q : Prop),
(P /\ Q) -> P.
Proof.
intros P Q P_and_Q.
destruct P_and_Q as [P_holds Q_holds].
assumption.
Qed.
Lemma or_comm : forall (P Q : Prop),
P \/ Q -> Q \/ P.
Proof.
intros P Q P_or_Q.
destruct P_or_Q as [P_holds | Q_holds].
- right. Undo. constructor 2. assumption.
- left. Undo. constructor 1. assumption.
Qed.
Inductive element :=
| grass : element
| fire : element
| water : element.
Definition weakness (e : element) : element :=
match e with
| grass => fire
| fire => water
| water => grass
end.
Lemma never_weak_to_self : forall (e : element),
weakness e <> e.
Proof.
destruct e.
- simpl. discriminate.
- simpl. discriminate.
- simpl. discriminate.
Abort.
Lemma n_plus_n : forall (n : nat),
n + n = n * 2.
Proof.
induction n as [| x IH].
- reflexivity.
- simpl. rewrite <- IH. auto.
Qed.
(** auto *)
(** logical tauto *)
Lemma demorgan : forall (P Q : Prop),
~(P \/ Q) -> ~P /\ ~Q.
Proof.
tauto.
Qed.
From Coq Require Import Lia.
Lemma dfoil : forall a ,
(a + 2) * (1 + 2) = a*1 + 2*1 + a*2 + 2*2.
Proof.
intros. lia.
Qed.
From Coq Require Import Arith.
(** algebraic rihg *)
Lemma foil : forall a b c d,
(a + b) * (c + d) = a*c + b*c + a*d + b*d.
Proof.
intros. ring.
Qed.
</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>