forked from TurtlePU/Coq-2025
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLecture1.html
1256 lines (1009 loc) · 98.7 KB
/
Lecture1.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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="common/css/sf.css" rel="stylesheet" type="text/css" />
<title>Lecture1</title>
<link href="common/jquery-ui/jquery-ui.css" rel="stylesheet">
<script src="common/jquery-ui/external/jquery/jquery.js"></script>
<script src="common/jquery-ui/jquery-ui.js"></script>
<script src="common/toggleproofs.js"></script>
<link href="common/css/lf.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="common/slides.js"></script>
<link href="common/css/slides.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page">
<div id="header">
<div id='logoinheader'><a href='https://softwarefoundations.cis.upenn.edu'>
<img src='common/media/image/sf_logo_sm.png' alt='Software Foundations Logo'></a></div>
<div class='booktitleinheader'><a href='index.html'>Volume 1: Logical Foundations</a></div>
<ul id='menu'>
<li class='section_name'><a href='toc.html'>Table of Contents</a></li>
<li class='section_name'><a href='coqindex.html'>Index</a></li>
<li class='section_name'><a href='deps.html'>Roadmap</a></li>
</ul>
</div>
<div id="main">
<h1 class="libtitle">Lecture1</h1>
<div class="doc">
<a id="lab1"></a><h1 class="section">Основы: Функциональное программмирование на Coq</h1>
</div>
<div class="doc">
<a id="lab2"></a><h1 class="section">Типы данных и функции</h1>
<div class="paragraph"> </div>
<a id="lab3"></a><h2 class="section">Типы-перечисления</h2>
<div class="paragraph"> </div>
В Coq практически всё можно выстроить с нуля...
</div>
<div class="code">
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab4"></a><h2 class="section">Дни недели</h2>
<div class="paragraph"> </div>
Определение типа данных:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">day</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">monday</span><br/>
| <span class="id" title="var">tuesday</span><br/>
| <span class="id" title="var">wednesday</span><br/>
| <span class="id" title="var">thursday</span><br/>
| <span class="id" title="var">friday</span><br/>
| <span class="id" title="var">saturday</span><br/>
| <span class="id" title="var">sunday</span>.<br/>
</div>
<div class="doc">
<a id="lab5"></a><h3 class="section"> </h3>
Функция на днях недели:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">next_working_day</span> (<span class="id" title="var">d</span>:<span class="id" title="var">day</span>) : <span class="id" title="var">day</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">d</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">monday</span> ⇒ <span class="id" title="var">tuesday</span><br/>
| <span class="id" title="var">tuesday</span> ⇒ <span class="id" title="var">wednesday</span><br/>
| <span class="id" title="var">wednesday</span> ⇒ <span class="id" title="var">thursday</span><br/>
| <span class="id" title="var">thursday</span> ⇒ <span class="id" title="var">friday</span><br/>
| <span class="id" title="var">friday</span> ⇒ <span class="id" title="var">monday</span><br/>
| <span class="id" title="var">saturday</span> ⇒ <span class="id" title="var">monday</span><br/>
| <span class="id" title="var">sunday</span> ⇒ <span class="id" title="var">monday</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
<a id="lab6"></a><h3 class="section"> </h3>
Во-первых, мы можем упрощать:
</div>
<div class="code">
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">next_working_day</span> <span class="id" title="var">friday</span>).<br/>
<span class="comment">(* ==> monday : day *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">next_working_day</span> (<span class="id" title="var">next_working_day</span> <span class="id" title="var">saturday</span>)).<br/>
<span class="comment">(* ==> tuesday : day *)</span><br/>
</div>
<div class="doc">
Во-вторых, мы можем записать _ожидаемый_ результат в виде примера Coq:
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_next_working_day</span>:<br/>
(<span class="id" title="var">next_working_day</span> (<span class="id" title="var">next_working_day</span> <span class="id" title="var">saturday</span>)) = <span class="id" title="var">tuesday</span>.<br/>
</div>
<div class="doc">
Далее, мы можем выписать _скрипт доказательства_, подтверждающий
утверждение:
</div>
<div class="code">
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
В-третьих, мы можем попросить Coq извлечь из нашего <span class="inlinecode">Определения</span> программу
на более традиционном языке программирования (OCaml, Scheme или Haskell) с
помощью высокопроизводительного компилятора. Это средство очень полезно,
поскольку оно прокладывает нам путь от корректных-по-построению алгоритмов,
написанных на Gallina, к эффективному машинному коду.
<div class="paragraph"> </div>
(Конечно, мы доверяем корректности компилятора OCaml/Haskell/Scheme и
средствам извлечения Coq самим по себе, но это все равно большой шаг вперед
по сравнению с тем, как сегодня разрабатывается большинство программ!)
<div class="paragraph"> </div>
Действительно, это одно из основных применений, для которых был разработан
Coq. Мы вернемся к этой теме в следующих главах.
</div>
<div class="code">
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab7"></a><h2 class="section">Логические значения</h2>
<div class="paragraph"> </div>
Другой знакомый тип-перечисление:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">bool</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">true</span><br/>
| <span class="id" title="var">false</span>.<br/>
</div>
<div class="doc">
Логические значения также доступны в стандартной библиотеке Coq's, но
в этом курсе мы будем определять всё с нуля для наглядности. <a id="lab8"></a><h3 class="section"> </h3>
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">negb</span> (<span class="id" title="var">b</span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">b</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">true</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">false</span> ⇒ <span class="id" title="var">true</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">andb</span> (<span class="id" title="var">b<sub>1</sub></span>:<span class="id" title="var">bool</span>) (<span class="id" title="var">b<sub>2</sub></span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">b<sub>1</sub></span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">true</span> ⇒ <span class="id" title="var">b<sub>2</sub></span><br/>
| <span class="id" title="var">false</span> ⇒ <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">orb</span> (<span class="id" title="var">b<sub>1</sub></span>:<span class="id" title="var">bool</span>) (<span class="id" title="var">b<sub>2</sub></span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">b<sub>1</sub></span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">true</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">false</span> ⇒ <span class="id" title="var">b<sub>2</sub></span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
Обратите внимание на синтаксис для определения функций с несколькими
аргументами (<span class="inlinecode"><span class="id" title="var">andb</span></span> и <span class="inlinecode"><span class="id" title="var">orb</span></span>). <a id="lab9"></a><h3 class="section"> </h3>
</div>
<div class="code">
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_orb1</span>: (<span class="id" title="var">orb</span> <span class="id" title="var">true</span> <span class="id" title="var">false</span>) = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_orb2</span>: (<span class="id" title="var">orb</span> <span class="id" title="var">false</span> <span class="id" title="var">false</span>) = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_orb3</span>: (<span class="id" title="var">orb</span> <span class="id" title="var">false</span> <span class="id" title="var">true</span>) = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_orb4</span>: (<span class="id" title="var">orb</span> <span class="id" title="var">true</span> <span class="id" title="var">true</span>) = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Мы можем ввести новую нотацию для существующих определений.
</div>
<div class="code">
<span class="id" title="keyword">Notation</span> "x && y" := (<span class="id" title="var">andb</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>).<br/>
<span class="id" title="keyword">Notation</span> "x || y" := (<span class="id" title="var">orb</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>).<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_orb5</span>: <span class="id" title="var">false</span> || <span class="id" title="var">false</span> || <span class="id" title="var">true</span> = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab10"></a><h3 class="section"> </h3>
Эти примеры также дают повод показать еще одну маленькую особенность
Gallina: условные выражения...
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">negb'</span> (<span class="id" title="var">b</span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">if</span> <span class="id" title="var">b</span> <span class="id" title="keyword">then</span> <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">else</span> <span class="id" title="var">true</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">andb'</span> (<span class="id" title="var">b<sub>1</sub></span>:<span class="id" title="var">bool</span>) (<span class="id" title="var">b<sub>2</sub></span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">if</span> <span class="id" title="var">b<sub>1</sub></span> <span class="id" title="keyword">then</span> <span class="id" title="var">b<sub>2</sub></span><br/>
<span class="id" title="keyword">else</span> <span class="id" title="var">false</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">orb'</span> (<span class="id" title="var">b<sub>1</sub></span>:<span class="id" title="var">bool</span>) (<span class="id" title="var">b<sub>2</sub></span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">if</span> <span class="id" title="var">b<sub>1</sub></span> <span class="id" title="keyword">then</span> <span class="id" title="var">true</span><br/>
<span class="id" title="keyword">else</span> <span class="id" title="var">b<sub>2</sub></span>.<br/>
</div>
<div class="doc">
Это работает для всех типов данных с двумя конструкторами:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">bw</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">bw_black</span><br/>
| <span class="id" title="var">bw_white</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">invert</span> (<span class="id" title="var">x</span>: <span class="id" title="var">bw</span>) : <span class="id" title="var">bw</span> :=<br/>
<span class="id" title="keyword">if</span> <span class="id" title="var">x</span> <span class="id" title="keyword">then</span> <span class="id" title="var">bw_white</span><br/>
<span class="id" title="keyword">else</span> <span class="id" title="var">bw_black</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">invert</span> <span class="id" title="var">bw_black</span>).<br/>
<span class="comment">(* ==> bw_white : bw *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">invert</span> <span class="id" title="var">bw_white</span>).<br/>
<span class="comment">(* ==> bw_black : bw *)</span><br/>
</div>
<div class="doc">
<a id="lab11"></a><h3 class="section"> </h3>
<a id="lab12"></a><h4 class="section">Exercise: 1 star, standard (nandb)</h4>
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">nandb</span> (<span class="id" title="var">b<sub>1</sub></span>:<span class="id" title="var">bool</span>) (<span class="id" title="var">b<sub>2</sub></span>:<span class="id" title="var">bool</span>) : <span class="id" title="var">bool</span><br/>
<span class="comment">(* ЗАМЕНИТЕ ЭТУ СТРОКУ НА ":= _ваше_определение_ ." *)</span>. <span class="id" title="var">Admitted</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_nandb1</span>: (<span class="id" title="var">nandb</span> <span class="id" title="var">true</span> <span class="id" title="var">false</span>) = <span class="id" title="var">true</span>.<br/>
<span class="comment">(* ЗАПОЛНИТЕ ЗДЕСЬ *)</span> <span class="id" title="var">Admitted</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_nandb2</span>: (<span class="id" title="var">nandb</span> <span class="id" title="var">false</span> <span class="id" title="var">false</span>) = <span class="id" title="var">true</span>.<br/>
<span class="comment">(* ЗАПОЛНИТЕ ЗДЕСЬ *)</span> <span class="id" title="var">Admitted</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_nandb3</span>: (<span class="id" title="var">nandb</span> <span class="id" title="var">false</span> <span class="id" title="var">true</span>) = <span class="id" title="var">true</span>.<br/>
<span class="comment">(* ЗАПОЛНИТЕ ЗДЕСЬ *)</span> <span class="id" title="var">Admitted</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_nandb4</span>: (<span class="id" title="var">nandb</span> <span class="id" title="var">true</span> <span class="id" title="var">true</span>) = <span class="id" title="var">false</span>.<br/>
<span class="comment">(* ЗАПОЛНИТЕ ЗДЕСЬ *)</span> <span class="id" title="var">Admitted</span>.<br/>
<font size=-2>☐</font>
</div>
<div class="doc">
<div class="paragraph"> </div>
Далее, большинство упражнений будут опущены в лекционных материалах.
<div class="paragraph"> </div>
Полная версия содержит как более подробные объяснения, так и все упражнения.
</div>
<div class="code">
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab13"></a><h2 class="section">Типы</h2>
<div class="paragraph"> </div>
Каждое выражение в Coq имеет тип, описывающий, что именно оно вычисляет.
Команда <span class="inlinecode"><span class="id" title="keyword">Check</span></span> просит Coq распечатать тип выражения.
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <span class="id" title="var">true</span>.<br/>
<span class="comment">(* ===> true : bool *)</span><br/>
</div>
<div class="doc">
Если после <span class="inlinecode"><span class="id" title="keyword">Check</span></span> следует двоеточие и объявление типа, Coq проверит,
соответствует ли тип выражения заданному типу и остановится с ошибкой, если
это не так.
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <span class="id" title="var">true</span><br/>
: <span class="id" title="var">bool</span>.<br/>
<span class="id" title="keyword">Check</span> (<span class="id" title="var">negb</span> <span class="id" title="var">true</span>)<br/>
: <span class="id" title="var">bool</span>.<br/>
</div>
<div class="doc">
Функции, подобные <span class="inlinecode"><span class="id" title="var">negb</span></span>, сами по себе также являются значениями, как <span class="inlinecode"><span class="id" title="var">true</span></span>
и <span class="inlinecode"><span class="id" title="var">false</span></span>. Их типы называются _типами функций_ и пишутся со стрелками.
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <span class="id" title="var">negb</span><br/>
: <span class="id" title="var">bool</span> → <span class="id" title="var">bool</span>.<br/><hr class='doublespaceincode'/>
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab14"></a><h2 class="section">Новые типы из старых</h2>
<div class="paragraph"> </div>
Более интересное определение типа:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">rgb</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="tactic">red</span><br/>
| <span class="id" title="var">green</span><br/>
| <span class="id" title="var">blue</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">color</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">black</span><br/>
| <span class="id" title="var">white</span><br/>
| <span class="id" title="var">primary</span> (<span class="id" title="var">p</span> : <span class="id" title="var">rgb</span>).<br/>
</div>
<div class="doc">
Давайте изучим его более подробно.
<div class="paragraph"> </div>
<span class="inlinecode">Индуктивное</span> определение выполняет две функции:
<div class="paragraph"> </div>
<ul class="doclist">
<li> Оно определяет набор новых _конструкторов_. Например, <span class="inlinecode"><span class="id" title="tactic">red</span></span>, <span class="inlinecode"><span class="id" title="var">primary</span></span>,
<span class="inlinecode"><span class="id" title="var">true</span></span>, <span class="inlinecode"><span class="id" title="var">false</span></span>, <span class="inlinecode"><span class="id" title="var">monday</span></span> и т.д. являются конструкторами.
<div class="paragraph"> </div>
</li>
<li> Оно группирует их в новый именованный тип, например <span class="inlinecode"><span class="id" title="var">bool</span></span>, <span class="inlinecode"><span class="id" title="var">rgb</span></span> или
<span class="inlinecode"><span class="id" title="var">color</span></span>.
</li>
</ul>
<div class="paragraph"> </div>
_Конструкторные выражения_ формируются с помощью применения конструктора к
некоторому (0 или более) количеству других конструкторов или конструкторных
выражений, соблюдая заявленное количество и типы аргументов конструктора.
Например, это правильные конструкторные выражения...
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="tactic">red</span></span>
</li>
<li> <span class="inlinecode"><span class="id" title="var">true</span></span>
</li>
<li> <span class="inlinecode"><span class="id" title="var">primary</span></span> <span class="inlinecode"><span class="id" title="tactic">red</span></span>
</li>
<li> и т.д.
</li>
</ul>
... а эти -- нет:
<ul class="doclist">
<li> <span class="inlinecode"><span class="id" title="tactic">red</span></span> <span class="inlinecode"><span class="id" title="var">primary</span></span>
</li>
<li> <span class="inlinecode"><span class="id" title="var">true</span></span> <span class="inlinecode"><span class="id" title="tactic">red</span></span>
</li>
<li> <span class="inlinecode"><span class="id" title="var">primary</span></span> <span class="inlinecode">(<span class="id" title="var">primary</span></span> <span class="inlinecode"><span class="id" title="tactic">red</span>)</span>
</li>
<li> и т.д.
</li>
</ul>
<div class="paragraph"> </div>
<a id="lab15"></a><h3 class="section"> </h3>
<div class="paragraph"> </div>
Мы можем определить функции на цветах, используя сопоставление с образцом,
точно так же, как мы это делали для <span class="inlinecode"><span class="id" title="var">day</span></span> и <span class="inlinecode"><span class="id" title="var">bool</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">monochrome</span> (<span class="id" title="var">c</span> : <span class="id" title="var">color</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">c</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">black</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">white</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">primary</span> <span class="id" title="var">p</span> ⇒ <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
Раз конструктор <span class="inlinecode"><span class="id" title="var">primary</span></span> принимает аргумент, то образец, соответствующий
<span class="inlinecode"><span class="id" title="var">primary</span></span>, должен содержать либо переменную, как мы только что сделали
(обратите внимание, что мы можем свободно выбирать ее имя), либо константу
соответствующего типа (как показано ниже).
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">isred</span> (<span class="id" title="var">c</span> : <span class="id" title="var">color</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">c</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">black</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">white</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">primary</span> <span class="id" title="tactic">red</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">primary</span> <span class="id" title="var">_</span> ⇒ <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
Шаблон "<span class="inlinecode"><span class="id" title="var">primary</span></span> <span class="inlinecode"><span class="id" title="var">_</span></span>" здесь является сокращением для обозначения
"конструктора <span class="inlinecode"><span class="id" title="var">primary</span></span>, применяемого к любому конструктору <span class="inlinecode"><span class="id" title="var">rgb</span></span>, кроме
<span class="inlinecode"><span class="id" title="tactic">red</span></span>".
</div>
<div class="code">
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab16"></a><h2 class="section">Модули</h2>
<div class="paragraph"> </div>
Объявления <span class="inlinecode"><span class="id" title="keyword">Module</span></span> создают отдельные пространства имён.
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <span class="id" title="var">Playground</span>.<br/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">foo</span> : <span class="id" title="var">rgb</span> := <span class="id" title="var">blue</span>.<br/>
<span class="id" title="keyword">End</span> <span class="id" title="var">Playground</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">foo</span> : <span class="id" title="var">bool</span> := <span class="id" title="var">true</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> <span class="id" title="var">Playground.foo</span> : <span class="id" title="var">rgb</span>.<br/>
<span class="id" title="keyword">Check</span> <span class="id" title="var">foo</span> : <span class="id" title="var">bool</span>.<br/><hr class='doublespaceincode'/>
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab17"></a><h2 class="section">Кортежи</h2>
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <span class="id" title="var">TuplePlayground</span>.<br/>
</div>
<div class="doc">
Ниббл -- это половина байта, т.е. четыре бита.
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">bit</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">B<sub>1</sub></span><br/>
| <span class="id" title="var">B<sub>0</sub></span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">nybble</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">bits</span> (<span class="id" title="var">b<sub>0</sub></span> <span class="id" title="var">b<sub>1</sub></span> <span class="id" title="var">b<sub>2</sub></span> <span class="id" title="var">b<sub>3</sub></span> : <span class="id" title="var">bit</span>).<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> (<span class="id" title="var">bits</span> <span class="id" title="var">B<sub>1</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>1</sub></span> <span class="id" title="var">B<sub>0</sub></span>)<br/>
: <span class="id" title="var">nybble</span>.<br/>
</div>
<div class="doc">
<a id="lab18"></a><h3 class="section"> </h3>
Мы деконструируем ниббл с помощью сопоставления с образцом.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">all_zero</span> (<span class="id" title="var">nb</span> : <span class="id" title="var">nybble</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">nb</span> <span class="id" title="keyword">with</span><br/>
| (<span class="id" title="var">bits</span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span>) ⇒ <span class="id" title="var">true</span><br/>
| (<span class="id" title="var">bits</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span> <span class="id" title="var">_</span>) ⇒ <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">all_zero</span> (<span class="id" title="var">bits</span> <span class="id" title="var">B<sub>1</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>1</sub></span> <span class="id" title="var">B<sub>0</sub></span>)).<br/>
<span class="comment">(* ===> false : bool *)</span><br/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">all_zero</span> (<span class="id" title="var">bits</span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span> <span class="id" title="var">B<sub>0</sub></span>)).<br/>
<span class="comment">(* ===> true : bool *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <span class="id" title="var">TuplePlayground</span>.<br/><hr class='doublespaceincode'/>
<span class="comment">(* ================================================================= *)</span><br/>
</div>
<div class="doc">
<a id="lab19"></a><h2 class="section">Числа</h2>
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <span class="id" title="var">NatPlayground</span>.<br/>
</div>
<div class="doc">
Есть множество различных представлений натуральных чисел. Наверняка
вы знакомы с десятичной, шестнадцатеричной, восьмеричной и двоичной
системами счисления. Для простоты доказательств же используют унарную: <span class="inlinecode"><span class="id" title="var">O</span></span>
представляет 0, а <span class="inlinecode"><span class="id" title="var">S</span></span> представляет добавление единицы. Так, <span class="inlinecode"><span class="id" title="var">S</span></span> это операция
взятия "последователя", которая, будучи применённой к представлению числа n,
возвращает представление числа n+1.
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">nat</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> (<span class="id" title="var">n</span> : <span class="id" title="var">nat</span>).<br/>
</div>
<div class="doc">
В таком определении, 0 представляется как <span class="inlinecode"><span class="id" title="var">O</span></span>, 1 -- как <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span></span>, 2 -- как
<span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>)</span> и т.д.
<div class="paragraph"> </div>
Опять же, давайте изучим это определение более подробно. В определении
<span class="inlinecode"><span class="id" title="var">nat</span></span> говорится о том, какие выражения в множестве <span class="inlinecode"><span class="id" title="var">nat</span></span> мы можем построить:
<div class="paragraph"> </div>
<ul class="doclist">
<li> конструкторное выражение <span class="inlinecode"><span class="id" title="var">O</span></span> принадлежит множеству <span class="inlinecode"><span class="id" title="var">nat</span></span>;
</li>
<li> если <span class="inlinecode"><span class="id" title="var">n</span></span> является конструкторным выражением, принадлежащим множеству
<span class="inlinecode"><span class="id" title="var">nat</span></span>, то <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> также является конструкторным выражением, принадлежащим
набору <span class="inlinecode"><span class="id" title="var">nat</span></span>; и
</li>
<li> конструкторные выражения, сформированные этими двумя способами, являются
единственными конструкторными выражениями, принадлежащими множеству
<span class="inlinecode"><span class="id" title="var">nat</span></span>.
</li>
</ul>
<div class="paragraph"> </div>
<a id="lab20"></a><h3 class="section"> </h3>
<div class="paragraph"> </div>
Важное замечание: это объявление задаёт _представление_ чисел --
унарную нотацию для их записи.
<div class="paragraph"> </div>
Имена <span class="inlinecode"><span class="id" title="var">O</span></span> и <span class="inlinecode"><span class="id" title="var">S</span></span> совершенно произвольны. Это просто две различных "пометки"
безо всякого значения самого по себе.
<div class="paragraph"> </div>
Мы точно так же могли использовать совершенно другие метки:
</div>
<div class="code">
<span class="id" title="keyword">Inductive</span> <span class="id" title="var">otherNat</span> : <span class="id" title="keyword">Type</span> :=<br/>
| <span class="id" title="var">stop</span><br/>
| <span class="id" title="var">tick</span> (<span class="id" title="var">foo</span> : <span class="id" title="var">otherNat</span>).<br/>
</div>
<div class="doc">
Уже _интерпретация_ этих меток зависит от того, как мы пользуемся ими при
вычислениях.
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">pred</span> (<span class="id" title="var">n</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">nat</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span> ⇒ <span class="id" title="var">n'</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <span class="id" title="var">NatPlayground</span>.<br/>
</div>
<div class="doc">
<a id="lab21"></a><h3 class="section"> </h3>
Ради удобства, стандартную десятичную запись можно использовать
вместо последовательностей применений <span class="inlinecode"><span class="id" title="var">S</span></span> к <span class="inlinecode"><span class="id" title="var">O</span></span>; Coq использует аналогичное
сокращение при печати:
</div>
<div class="code">
<span class="id" title="keyword">Check</span> (<span class="id" title="var">S</span> (<span class="id" title="var">S</span> (<span class="id" title="var">S</span> (<span class="id" title="var">S</span> <span class="id" title="var">O</span>)))).<br/>
<span class="comment">(* ===> 4 : nat *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Definition</span> <span class="id" title="var">minustwo</span> (<span class="id" title="var">n</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">nat</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">O</span> ⇒ <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> (<span class="id" title="var">S</span> <span class="id" title="var">n'</span>) ⇒ <span class="id" title="var">n'</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">minustwo</span> 4).<br/>
<span class="comment">(* ===> 2 : nat *)</span><br/>
</div>
<div class="doc">
<a id="lab22"></a><h3 class="section"> </h3>
Рекурсивные функции вводятся с помощью ключевого слова <span class="inlinecode"><span class="id" title="keyword">Fixpoint</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">even</span> (<span class="id" title="var">n</span>:<span class="id" title="var">nat</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">O</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">S</span> (<span class="id" title="var">S</span> <span class="id" title="var">n'</span>) ⇒ <span class="id" title="var">even</span> <span class="id" title="var">n'</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
<a id="lab23"></a><h3 class="section"> </h3>
Мы могли бы определить <span class="inlinecode"><span class="id" title="var">odd</span></span> с помощью аналогичного объявления <span class="inlinecode"><span class="id" title="keyword">Fixpoint</span></span>,
но вот более простой способ:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <span class="id" title="var">odd</span> (<span class="id" title="var">n</span>:<span class="id" title="var">nat</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="var">negb</span> (<span class="id" title="var">even</span> <span class="id" title="var">n</span>).<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_odd1</span>: <span class="id" title="var">odd</span> 1 = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_odd2</span>: <span class="id" title="var">odd</span> 4 = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab24"></a><h3 class="section"> </h3>
Рекурсивная функция от нескольких аргументов.
</div>
<div class="code">
<span class="id" title="keyword">Module</span> <span class="id" title="var">NatPlayground2</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">plus</span> (<span class="id" title="var">n</span> : <span class="id" title="var">nat</span>) (<span class="id" title="var">m</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">nat</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">m</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span> ⇒ <span class="id" title="var">S</span> (<span class="id" title="var">plus</span> <span class="id" title="var">n'</span> <span class="id" title="var">m</span>)<br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Compute</span> (<span class="id" title="var">plus</span> 3 2).<br/>
<span class="comment">(* ===> 5 : nat *)</span><br/><hr class='doublespaceincode'/>
<span class="comment">(* <span class="inlinecode"><span class="id" title="var">plus</span></span> <span class="inlinecode">3</span> <span class="inlinecode">2</span><br/>
т.е. <span class="inlinecode"><span class="id" title="var">plus</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>)))</span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>))</span><br/>
==> <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">plus</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>))</span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>)))</span><br/>
по второй клозе в <span class="inlinecode"><span class="id" title="keyword">match</span></span><br/>
==> <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">plus</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>)</span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>))))</span><br/>
по второй клозе в <span class="inlinecode"><span class="id" title="keyword">match</span></span><br/>
==> <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">plus</span></span> <span class="inlinecode"><span class="id" title="var">O</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>)))))</span><br/>
по второй клозе в <span class="inlinecode"><span class="id" title="keyword">match</span></span><br/>
==> <span class="inlinecode"><span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode">(<span class="id" title="var">S</span></span> <span class="inlinecode"><span class="id" title="var">O</span>))))</span><br/>
по первой клозе в <span class="inlinecode"><span class="id" title="keyword">match</span></span><br/>
т.е. <span class="inlinecode">5</span> *)</span><br/>
</div>
<div class="doc">
<a id="lab25"></a><h3 class="section"> </h3>
Ещё одна:
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">mult</span> (<span class="id" title="var">n</span> <span class="id" title="var">m</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">nat</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span> ⇒ <span class="id" title="var">plus</span> <span class="id" title="var">m</span> (<span class="id" title="var">mult</span> <span class="id" title="var">n'</span> <span class="id" title="var">m</span>)<br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_mult1</span>: (<span class="id" title="var">mult</span> 3 3) = 9.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab26"></a><h3 class="section"> </h3>
Мы можем сопоставить с образцом два выражения за раз, поставив запятую
между ними:
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">minus</span> (<span class="id" title="var">n</span> <span class="id" title="var">m</span>:<span class="id" title="var">nat</span>) : <span class="id" title="var">nat</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span>, <span class="id" title="var">m</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> , <span class="id" title="var">_</span> ⇒ <span class="id" title="var">O</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">_</span> , <span class="id" title="var">O</span> ⇒ <span class="id" title="var">n</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span>, <span class="id" title="var">S</span> <span class="id" title="var">m'</span> ⇒ <span class="id" title="var">minus</span> <span class="id" title="var">n'</span> <span class="id" title="var">m'</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">End</span> <span class="id" title="var">NatPlayground2</span>.<br/>
</div>
<div class="doc">
<a id="lab27"></a><h3 class="section"> </h3>
Опять же, мы можем упростить чтение и запись числовых выражений,
введя обозначения для сложения, вычитания и умножения.
</div>
<div class="code">
<span class="id" title="keyword">Notation</span> "x + y" := (<span class="id" title="var">plus</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>)<br/>
(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 50, <span class="id" title="tactic">left</span> <span class="id" title="keyword">associativity</span>)<br/>
: <span class="id" title="var">nat_scope</span>.<br/>
<span class="id" title="keyword">Notation</span> "x - y" := (<span class="id" title="var">minus</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>)<br/>
(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 50, <span class="id" title="tactic">left</span> <span class="id" title="keyword">associativity</span>)<br/>
: <span class="id" title="var">nat_scope</span>.<br/>
<span class="id" title="keyword">Notation</span> "x * y" := (<span class="id" title="var">mult</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>)<br/>
(<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 40, <span class="id" title="tactic">left</span> <span class="id" title="keyword">associativity</span>)<br/>
: <span class="id" title="var">nat_scope</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> ((0 + 1) + 1) : <span class="id" title="var">nat</span>.<br/>
</div>
<div class="doc">
<a id="lab28"></a><h3 class="section"> </h3>
Когда мы говорим, что в Coq практически ничего не встроено, мы действительно
имеем это в виду: даже проверка равенства -- это операция, определяемая
пользователем!
<div class="paragraph"> </div>
Вот функция <span class="inlinecode"><span class="id" title="var">eqb</span></span>, которая проверяет натуральные числа на
равенство (<span class="inlinecode"><span class="id" title="var">eq</span></span>), возвращающая логическое значение (<span class="inlinecode"><span class="id" title="var">b</span></span>). Обратите внимание
на использование вложенных сопоставлений с образцом (мы также могли бы
сопоставить с образцом оба аргумента вместе, как в определении <span class="inlinecode"><span class="id" title="var">minus</span></span>).
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">eqb</span> (<span class="id" title="var">n</span> <span class="id" title="var">m</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="keyword">match</span> <span class="id" title="var">m</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">m'</span> ⇒ <span class="id" title="var">false</span><br/>
<span class="id" title="keyword">end</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span> ⇒ <span class="id" title="keyword">match</span> <span class="id" title="var">m</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">m'</span> ⇒ <span class="id" title="var">eqb</span> <span class="id" title="var">n'</span> <span class="id" title="var">m'</span><br/>
<span class="id" title="keyword">end</span><br/>
<span class="id" title="keyword">end</span>.<br/>
</div>
<div class="doc">
<a id="lab29"></a><h3 class="section"> </h3>
Аналогично, функция <span class="inlinecode"><span class="id" title="var">leb</span></span> проверяет, является ли ее первый аргумент меньшим
или равным второму, и возвращает логическое значение.
</div>
<div class="code">
<span class="id" title="keyword">Fixpoint</span> <span class="id" title="var">leb</span> (<span class="id" title="var">n</span> <span class="id" title="var">m</span> : <span class="id" title="var">nat</span>) : <span class="id" title="var">bool</span> :=<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">n</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">true</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">n'</span> ⇒<br/>
<span class="id" title="keyword">match</span> <span class="id" title="var">m</span> <span class="id" title="keyword">with</span><br/>
| <span class="id" title="var">O</span> ⇒ <span class="id" title="var">false</span><br/>
| <span class="id" title="var">S</span> <span class="id" title="var">m'</span> ⇒ <span class="id" title="var">leb</span> <span class="id" title="var">n'</span> <span class="id" title="var">m'</span><br/>
<span class="id" title="keyword">end</span><br/>
<span class="id" title="keyword">end</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_leb1</span>: <span class="id" title="var">leb</span> 2 2 = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_leb2</span>: <span class="id" title="var">leb</span> 2 4 = <span class="id" title="var">true</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_leb3</span>: <span class="id" title="var">leb</span> 4 2 = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab30"></a><h3 class="section"> </h3>
Мы будем часто использовать эти функции (особенно <span class="inlinecode"><span class="id" title="var">eqb</span></span>), поэтому давайте
определим для них инфиксную нотацию.
</div>
<div class="code">
<span class="id" title="keyword">Notation</span> "x =? y" := (<span class="id" title="var">eqb</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>) (<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 70) : <span class="id" title="var">nat_scope</span>.<br/>
<span class="id" title="keyword">Notation</span> "x <=? y" := (<span class="id" title="var">leb</span> <span class="id" title="var">x</span> <span class="id" title="var">y</span>) (<span class="id" title="tactic">at</span> <span class="id" title="keyword">level</span> 70) : <span class="id" title="var">nat_scope</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Example</span> <span class="id" title="var">test_leb3'</span>: (4 <=? 2) = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Теперь у нас есть два "равенства":
<div class="paragraph"> </div>
<ul class="doclist">
<li> <span class="inlinecode">=</span> как логическое _утверждение_, которое можно _доказать_.
<div class="paragraph"> </div>
</li>
<li> <span class="inlinecode">=?</span> как _выражение_ типа <span class="inlinecode"><span class="id" title="var">bool</span></span>, которое Coq _вычисляет_.
</li>
</ul>
</div>
<div class="doc">
<a id="lab31"></a><h1 class="section">Доказательство через упрощения</h1>
<div class="paragraph"> </div>
Общее свойство натуральных чисел:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_O_n</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> : <span class="id" title="var">nat</span>, 0 + <span class="id" title="var">n</span> = <span class="id" title="var">n</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">simpl</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Тактика <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> здесь, на самом деле, не нужна, т.к. <span class="inlinecode"><span class="id" title="tactic">reflexivity</span></span>
уже производит некоторые упрощения за нас:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_O_n'</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> : <span class="id" title="var">nat</span>, 0 + <span class="id" title="var">n</span> = <span class="id" title="var">n</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Любой другой (новый) идентификатор можно было бы использовать вместо <span class="inlinecode"><span class="id" title="var">n</span></span>:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_O_n''</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> : <span class="id" title="var">nat</span>, 0 + <span class="id" title="var">n</span> = <span class="id" title="var">n</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">m</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab32"></a><h3 class="section"> </h3>
Другие подобные теоремы могут быть доказаны по той же схеме.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_1_l</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span>:<span class="id" title="var">nat</span>, 1 + <span class="id" title="var">n</span> = <span class="id" title="var">S</span> <span class="id" title="var">n</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">mult_0_l</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span>:<span class="id" title="var">nat</span>, 0 × <span class="id" title="var">n</span> = 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab33"></a><h1 class="section">Доказательства с помощью переписывания</h1>
<div class="paragraph"> </div>
Следующая теорема немного интереснее тех, что мы видели ранее:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_id_example</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span>:<span class="id" title="var">nat</span>,<br/>
<span class="id" title="var">n</span> = <span class="id" title="var">m</span> →<br/>
<span class="id" title="var">n</span> + <span class="id" title="var">n</span> = <span class="id" title="var">m</span> + <span class="id" title="var">m</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="comment">(* переместим оба квантора в контекст: *)</span><br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span> <span class="id" title="var">m</span>.<br/>
<span class="comment">(* перенесём гипотезу в контекст: *)</span><br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">H</span>.<br/>
<span class="comment">(* перепишем цель, используя гипотезу: *)</span><br/>
<span class="id" title="tactic">rewrite</span> → <span class="id" title="var">H</span>.<br/>
<span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="tactic">intros</span></span> называет гипотезу, когда она перемещается в контекст.
<span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> нужно знать, какое равенство используется -- и в каком направлении
чтобы выполнить замену.
<div class="paragraph"> </div>
<a id="lab34"></a><h3 class="section"> </h3>
<div class="paragraph"> </div>
Команду <span class="inlinecode"><span class="id" title="keyword">Check</span></span> также можно использовать для проверки утверждений ранее
объявленных лемм и теорем. Два примера ниже -- леммы о умножении, которые
доказаны в стандартной библиотеке. (Мы увидим, как доказать их самим, во
второй части занятия.)
</div>
<div class="code">
<span class="id" title="keyword">Check</span> <span class="id" title="var">mult_n_O</span>.<br/>
<span class="comment">(* ===> forall n : nat, 0 = n * 0 *)</span><br/><hr class='doublespaceincode'/>
<span class="id" title="keyword">Check</span> <span class="id" title="var">mult_n_Sm</span>.<br/>
<span class="comment">(* ===> forall n m : nat, n * m + n = n * S m *)</span><br/>
</div>
<div class="doc">
<a id="lab35"></a><h3 class="section"> </h3>
Мы можем использовать тактику <span class="inlinecode"><span class="id" title="tactic">rewrite</span></span> не только с гипотезами из контекста,
но и используя ранее доказанные теоремы. Если утверждение ранее доказанной
теоремы включает переменные под кванторами, как в примере ниже, Coq
попытается подставить вместо них соответствующие значения, сопоставив текст
утверждения теоремы с текущей целью.
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">mult_n_0_m_0</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">p</span> <span class="id" title="var">q</span> : <span class="id" title="var">nat</span>,<br/>
(<span class="id" title="var">p</span> × 0) + (<span class="id" title="var">q</span> × 0) = 0.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">p</span> <span class="id" title="var">q</span>.<br/>
<span class="id" title="tactic">rewrite</span> <- <span class="id" title="var">mult_n_O</span>.<br/>
<span class="id" title="tactic">rewrite</span> <- <span class="id" title="var">mult_n_O</span>.<br/>
<span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab36"></a><h1 class="section">Доказательство разбором случаев</h1>
<div class="paragraph"> </div>
Иногда просто вычислений и переписываний недостаточно...
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_1_neq_0_firsttry</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> : <span class="id" title="var">nat</span>,<br/>
(<span class="id" title="var">n</span> + 1) =? 0 = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>.<br/>
<span class="id" title="tactic">simpl</span>. <span class="comment">(* ничего не делает! *)</span><br/>
<span class="id" title="keyword">Abort</span>.<br/>
</div>
<div class="doc">
Мы можем использовать <span class="inlinecode"><span class="id" title="tactic">destruct</span></span> для разбора случаев:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">plus_1_neq_0</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">n</span> : <span class="id" title="var">nat</span>,<br/>
(<span class="id" title="var">n</span> + 1) =? 0 = <span class="id" title="var">false</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">n</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">n</span> <span class="id" title="keyword">as</span> [| <span class="id" title="var">n'</span>] <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
- <span class="id" title="tactic">reflexivity</span>.<br/>
- <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
Обратите внимание на буллеты, маркирующие доказательства двух
подцелей.
<div class="paragraph"> </div>
<a id="lab37"></a><h3 class="section"> </h3>
Ещё пример (с использованием логических значений):
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">negb_involutive</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">b</span> : <span class="id" title="var">bool</span>,<br/>
<span class="id" title="var">negb</span> (<span class="id" title="var">negb</span> <span class="id" title="var">b</span>) = <span class="id" title="var">b</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">b</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">b</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">E</span>.<br/>
- <span class="id" title="tactic">reflexivity</span>.<br/>
- <span class="id" title="tactic">reflexivity</span>. <span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab38"></a><h3 class="section"> </h3>
Доказательства подцелей можно вкладывать (используя уже другие
буллеты для внутренних подцелей):
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">andb_commutative</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span>, <span class="id" title="var">andb</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> = <span class="id" title="var">andb</span> <span class="id" title="var">c</span> <span class="id" title="var">b</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">b</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Eb</span>.<br/>
- <span class="id" title="tactic">destruct</span> <span class="id" title="var">c</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Ec</span>.<br/>
+ <span class="id" title="tactic">reflexivity</span>.<br/>
+ <span class="id" title="tactic">reflexivity</span>.<br/>
- <span class="id" title="tactic">destruct</span> <span class="id" title="var">c</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Ec</span>.<br/>
+ <span class="id" title="tactic">reflexivity</span>.<br/>
+ <span class="id" title="tactic">reflexivity</span>.<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">
<a id="lab39"></a><h3 class="section"> </h3>
Кроме <span class="inlinecode">-</span> и <span class="inlinecode">+</span>, мы можем использовать <span class="inlinecode">×</span> (астериск, звёздочку), а также
любой повтор буллета (например, <span class="inlinecode">--</span> либо <span class="inlinecode">***</span>) в качестве буллета. Также
мы можем заключать под-доказательства в фигурные скобки:
</div>
<div class="code">
<span class="id" title="keyword">Theorem</span> <span class="id" title="var">andb_commutative'</span> : <span class="id" title="keyword">∀</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span>, <span class="id" title="var">andb</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span> = <span class="id" title="var">andb</span> <span class="id" title="var">c</span> <span class="id" title="var">b</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">b</span> <span class="id" title="var">c</span>. <span class="id" title="tactic">destruct</span> <span class="id" title="var">b</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Eb</span>.<br/>
{ <span class="id" title="tactic">destruct</span> <span class="id" title="var">c</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Ec</span>.<br/>
{ <span class="id" title="tactic">reflexivity</span>. }<br/>
{ <span class="id" title="tactic">reflexivity</span>. } }<br/>
{ <span class="id" title="tactic">destruct</span> <span class="id" title="var">c</span> <span class="id" title="var">eqn</span>:<span class="id" title="var">Ec</span>.<br/>
{ <span class="id" title="tactic">reflexivity</span>. }<br/>
{ <span class="id" title="tactic">reflexivity</span>. } }<br/>
<span class="id" title="keyword">Qed</span>.<br/>
</div>
<div class="doc">