-
Notifications
You must be signed in to change notification settings - Fork 21
/
lecture_tactics.html
1293 lines (991 loc) · 86.2 KB
/
lecture_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
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="coqdoc.css" rel="stylesheet" type="text/css" />
<title>lecture_tactics</title>
</head>
<body>
<div id="page">
<div id="header">
</div>
<div id="main">
<h1 class="libtitle">Library lecture_tactics</h1>
<div class="code">
</div>
<div class="doc">
<a id="lab1"></a><h1 class="section">Lecture 4: Tactics in UniMath</h1>
by Ralph Matthes, IRIT, Université de Toulouse, CNRS, Toulouse INP, UT3, Toulouse, France
<div class="paragraph"> </div>
My employer is the CNRS, my lab is the IRIT, but the above affiliation is obligatory for
any scientific production I release.
<div class="paragraph"> </div>
This is material for presentation at the UniMath school
2022 in Cortona; an extended version for self-study
and for exploring the UniMath library is available as
<span class="inlinecode"><span class="id" title="var">lecture_tactics_long_version.v</span></span>.
<div class="paragraph"> </div>
It grew out of the presentations at the UniMath schools
2017 and 2019 in Birmingham.
<div class="paragraph"> </div>
Works with current UniMath (as of July 15, 2022, but also the Coq platform of April '22).
<div class="paragraph"> </div>
Compiles with the command
<br/>
<span class="inlinecode"><span class="id" title="var">coqc</span> <span class="id" title="var">lecture_tactics.v</span>
<div class="paragraph"> </div>
</span>when Coq is set up according to the instructions for this school and the associated coqc executable
has priority in the path. However, you do not need to compile this file. Moreover, your own developments
will need the Coq options configured through the installation instructions, most notably -type-in-type.
<div class="paragraph"> </div>
Can be transformed into HTML documentation with the command
<br/>
<span class="inlinecode"><span class="id" title="var">coqdoc</span> -<span class="id" title="var">utf8</span> <span class="id" title="var">lecture_tactics.v</span>
<div class="paragraph"> </div>
</span> (If internal links in the generated lecture_tactics.html are desired, compilation with coqc is needed.)
<div class="paragraph"> </div>
In Coq, one can define concepts by directly giving well-typed
terms (see Part 2), but one can also be helped in the construction by the
interactive mode.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Require</span> <span class="id" title="keyword">Import</span> <span class="id" title="library">UniMath.Foundations.Preamble</span>.<br/>
<br/>
</div>
<div class="doc">
<a id="lab2"></a><h2 class="section">define a concept interactively:</h2>
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> <span class="id" title="var">bool</span>. </div>
<div class="doc">
a separate definition - <span class="inlinecode"><span class="id" title="var">Init.Datatypes.bool</span></span> is in the Coq library,
not available for UniMath
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Definition</span> <a id="myfirsttruthvalue" class="idref" href="#myfirsttruthvalue"><span class="id" title="definition">myfirsttruthvalue</span></a>: <span class="id" title="inductive">bool</span>.<br/>
</div>
<div class="doc">
only the identifier and its type given, not the definiens
<div class="paragraph"> </div>
This opens the interactive mode.
<div class="paragraph"> </div>
The <a href="https://github.com/UniMath/UniMath/tree/master/UniMath/README.md#unimath-coding-style">UniMath
style guide</a> asks us to start what follows with <span class="inlinecode"><span class="id" title="keyword">Proof</span>.</span> in a separate line.
In vanilla Coq, this would be optional (it is anyway a "nop").
</div>
<div class="code">
<span class="id" title="keyword">Proof</span>.<br/>
</div>
<div class="doc">
Now we still have to give the term, but we are in interactive mode. If you want to see everything in the currently loaded part of the UniMath library
that *involves* booleans, then do
</div>
<div class="code">
<span class="id" title="keyword">Search</span> <span class="id" title="inductive">bool</span>.<br/>
</div>
<div class="doc">
If you only want to find library elements that *yield* booleans, then try
</div>
<div class="code">
<span class="id" title="keyword">Search</span><span class="id" title="var">Pattern</span> <span class="id" title="inductive">bool</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="var">true</span></span> does not take an argument, and it is already a term we can take as definiens.
</div>
<div class="code">
<span class="id" title="tactic">exact</span> <span class="id" title="constructor">true</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="tactic">exact</span></span> is a tactic which takes the term as argument and informs Coq in the proof mode to
finish the current goal with that term.
<div class="paragraph"> </div>
We see in the response buffer: "No more subgoals."
Hence, there is nothing more to do, except for leaving the proof mode properly.
</div>
<div class="code">
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="keyword">Defined</span>.</span> instructs Coq to complete the whole interactive construction of a term,
verify it and to associate it with the given identifer, here <span class="inlinecode"><span class="id" title="var">myfirsttruthvalue</span></span>.
</div>
<div class="code">
<span class="id" title="keyword">Search</span> <span class="id" title="inductive">bool</span>.<br/>
</div>
<div class="doc">
The new definition appears at the beginning of the list.
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#myfirsttruthvalue"><span class="id" title="definition">myfirsttruthvalue</span></a>. </div>
<div class="doc">
or just point to the identifier and hit the
key combination mentioned in Part 2
<div class="paragraph"> </div>
<a id="lab3"></a><h3 class="section">a more compelling example</h3>
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="mysecondtruthvalue" class="idref" href="#mysecondtruthvalue"><span class="id" title="definition">mysecondtruthvalue</span></a>: <span class="id" title="inductive">bool</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Search</span> <span class="id" title="inductive">bool</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="definition">negb</span>.<br/>
</div>
<div class="doc">
applies the function <span class="inlinecode"><span class="id" title="var">negb</span></span> to obtain the required boolean,
thus the system has to ask for its argument
</div>
<div class="code">
<span class="id" title="tactic">exact</span> <a class="idref" href="lecture_tactics.html#myfirsttruthvalue"><span class="id" title="definition">myfirsttruthvalue</span></a>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#mysecondtruthvalue"><span class="id" title="definition">mysecondtruthvalue</span></a>.<br/>
</div>
<div class="doc">
<br/>
<span class="inlinecode"><span class="id" title="var">mysecondtruthvalue</span> = <span class="id" title="var">negb</span> <span class="id" title="var">myfirsttruthvalue</span><br/>
: <span class="id" title="var">bool</span>
<div class="paragraph"> </div>
</span>
<div class="paragraph"> </div>
the definition is "as is", evaluation can be done subsequently:
</div>
<div class="code">
<span class="id" title="keyword">Eval</span> <span class="id" title="tactic">compute</span> <span class="id" title="tactic">in</span> <a class="idref" href="lecture_tactics.html#mysecondtruthvalue"><span class="id" title="definition">mysecondtruthvalue</span></a>.<br/>
</div>
<div class="doc">
<br/>
<span class="inlinecode"> = <span class="id" title="var">false</span><br/>
: <span class="id" title="var">bool</span>
<div class="paragraph"> </div>
</span>
<div class="paragraph"> </div>
Again, not much has been gained by the interactive mode.
<div class="paragraph"> </div>
Here, we see a copy of the definition from the Coq library:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="andb" class="idref" href="#andb"><span class="id" title="definition">andb</span></a> (<a id="b1:1" class="idref" href="#b1:1"><span class="id" title="binder">b1</span></a> <a id="b2:2" class="idref" href="#b2:2"><span class="id" title="binder">b2</span></a>: <span class="id" title="inductive">bool</span>) : <span class="id" title="inductive">bool</span> := <span class="id" title="keyword">if</span> <a class="idref" href="lecture_tactics.html#b1:1"><span class="id" title="variable">b1</span></a> <span class="id" title="keyword">then</span> <a class="idref" href="lecture_tactics.html#b2:2"><span class="id" title="variable">b2</span></a> <span class="id" title="keyword">else</span> <span class="id" title="constructor">false</span>.<br/>
</div>
<div class="doc">
only for illustration purposes - it would be better to define
it according to UniMath style
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Definition</span> <a id="mythirdtruthvalue" class="idref" href="#mythirdtruthvalue"><span class="id" title="definition">mythirdtruthvalue</span></a>: <span class="id" title="inductive">bool</span>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="keyword">Search</span> <span class="id" title="inductive">bool</span>.<br/>
<span class="id" title="tactic">apply</span> <a class="idref" href="lecture_tactics.html#andb"><span class="id" title="definition">andb</span></a>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">andb</span>.</span> applies the function <span class="inlinecode"><span class="id" title="var">andb</span></span> to obtain the required boolean,
thus the system has to ask for its TWO arguments, one by one.
<div class="paragraph"> </div>
This follows the proof pattern of "backward chaining" that tries to
attack goals instead of building up evidence. In the course of action,
more goals can be generated. The proof effort is over when no more
goal remains.
<div class="paragraph"> </div>
UniMath coding style asks you to use proof structuring syntax,
while vanilla Coq would allow you to write formally verified
"spaghetti code".
<div class="paragraph"> </div>
We tell Coq that we start working on the first subgoal.
</div>
<div class="code">
-<br/>
</div>
<div class="doc">
only the "focused" subgoal is now on display
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <a class="idref" href="lecture_tactics.html#andb"><span class="id" title="definition">andb</span></a>.<br/>
</div>
<div class="doc">
this again spawns two subgoals
<div class="paragraph"> </div>
we tell Coq that we start working on the first subgoal
</div>
<div class="code">
+<br/>
</div>
<div class="doc">
normally, one would not leave the "bullet symbol" isolated in a line
</div>
<div class="code">
<span class="id" title="tactic">exact</span> <a class="idref" href="lecture_tactics.html#mysecondtruthvalue"><span class="id" title="definition">mysecondtruthvalue</span></a>.<br/>
+ <span class="id" title="tactic">exact</span> <a class="idref" href="lecture_tactics.html#myfirsttruthvalue"><span class="id" title="definition">myfirsttruthvalue</span></a>.<br/>
</div>
<div class="doc">
The response buffer signals:
<br/>
<span class="inlinecode"><span class="id" title="var">There</span> <span class="id" title="var">are</span> <span class="id" title="var">unfocused</span> <span class="id" title="keyword">goals</span>.
<div class="paragraph"> </div>
</span> ProofGeneral would give more precise instructions as how to proceed.
But we know what we are doing...
</div>
<div class="code">
- <span class="id" title="tactic">exact</span> <span class="id" title="constructor">true</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
</div>
<div class="doc">
The usual "UniMath bullet order" is -, +, *, --, ++, **, ---, +++, ***,
and so on (all the ones shown are being used).
<div class="paragraph"> </div>
Coq does not impose any order, so one can start with, e.g., *****,
if need be for the sake of experimenting with a proof.
<div class="paragraph"> </div>
Reuse of bullets even on one branch is possible by enclosing subproofs
in curly braces {}.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#mythirdtruthvalue"><span class="id" title="definition">mythirdtruthvalue</span></a>.<br/>
<span class="id" title="keyword">Eval</span> <span class="id" title="tactic">compute</span> <span class="id" title="tactic">in</span> <a class="idref" href="lecture_tactics.html#mythirdtruthvalue"><span class="id" title="definition">mythirdtruthvalue</span></a>.<br/>
<br/>
</div>
<div class="doc">
You only saw the tactics <span class="inlinecode"><span class="id" title="tactic">exact</span></span> and <span class="inlinecode"><span class="id" title="tactic">apply</span></span> at work, and there was no context.
<div class="paragraph"> </div>
<a id="lab4"></a><h2 class="section">doing Curry-Howard logic</h2>
<div class="paragraph"> </div>
Interactive mode is more wide-spread when it comes to carrying out proofs
(the command <span class="inlinecode"><span class="id" title="keyword">Proof</span>.</span> is reminiscent of that).
<div class="paragraph"> </div>
Disclaimer: this section has a logical flavour, but the "connectives"
are not confined to the world of propositional or predicate logic.
In particular, there is no reference to the sort Prop of Coq.
Prop is not used at all in UniMath!
<div class="paragraph"> </div>
On first reading, it is useful to focus on the logical meaning.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "->". </div>
<div class="doc">
non-dependent product, can be seen as implication
</div>
<div class="code">
<span class="id" title="keyword">Locate</span> "∅".<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="inductive">empty</span>. </div>
<div class="doc">
an inductive type that has no constructor
</div>
<div class="code">
<span class="id" title="keyword">Locate</span> "¬". </div>
<div class="doc">
we need to refer to the UniMath library more explicitly
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Require</span> <span class="id" title="keyword">Import</span> <span class="id" title="library">UniMath.Foundations.PartA</span>.<br/>
</div>
<div class="doc">
Do not write the import statements in the middle of a vernacular file.
Here, it is done to show the order of appearance, but this is only for
reasons of pedagogy.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "¬".<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="definition">neg</span>.<br/>
</div>
<div class="doc">
Negation is not a native concept; it is reduced to implication,
as is usual in constructive logic.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "×".<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="definition">dirprod</span>. </div>
<div class="doc">
non-dependent sum, can be seen as conjunction
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Definition</span> <a id="combinatorS" class="idref" href="#combinatorS"><span class="id" title="definition">combinatorS</span></a> (<a id="A:3" class="idref" href="#A:3"><span class="id" title="binder">A</span></a> <a id="B:4" class="idref" href="#B:4"><span class="id" title="binder">B</span></a> <a id="C:5" class="idref" href="#C:5"><span class="id" title="binder">C</span></a>: <span class="id" title="definition">UU</span>): <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:3"><span class="id" title="variable">A</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#B:4"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:5"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:3"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:4"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#A:3"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:5"><span class="id" title="variable">C</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
</div>
<div class="doc">
how to infer an implication?
</div>
<div class="code">
<span class="id" title="tactic">intro</span> <span class="id" title="var">Hyp123</span>.<br/>
<span class="id" title="tactic">set</span> (<span class="id" title="var">Hyp1</span> := <span class="id" title="projection">pr1</span> <span class="id" title="var">Hyp123</span>).<br/>
</div>
<div class="doc">
This is already a bit of "forward chaining" which is a fact-building process.
</div>
<div class="code">
<span class="id" title="tactic">set</span> (<span class="id" title="var">Hyp23</span> := <span class="id" title="projection">pr2</span> <span class="id" title="var">Hyp123</span>).<br/>
<span class="id" title="var">cbn</span> <span class="id" title="tactic">in</span> <span class="id" title="var">Hyp23</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="var">cbn</span></span> simplifies a goal, and <span class="inlinecode"><span class="id" title="var">cbn</span></span> <span class="inlinecode"><span class="id" title="tactic">in</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> does this for hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span>;
note that <span class="inlinecode"><span class="id" title="tactic">simpl</span></span> has the same high-level description but should better
be avoided in new developments.
</div>
<div class="code">
<span class="id" title="tactic">set</span> (<span class="id" title="var">Hyp2</span> := <span class="id" title="projection">pr1</span> <span class="id" title="var">Hyp23</span>).<br/>
<span class="id" title="tactic">set</span> (<span class="id" title="var">Hyp3</span> := <span class="id" title="projection">pr2</span> <span class="id" title="var">Hyp23</span>).<br/>
<span class="id" title="var">cbn</span> <span class="id" title="tactic">in</span> <span class="id" title="var">Hyp3</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">Hyp1</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="constructor">tpair</span>. </div>
<div class="doc">
more advanced users will use the tactic split
</div>
<div class="code">
- <span class="id" title="tactic">exact</span> <span class="id" title="var">Hyp3</span>.<br/>
- <span class="id" title="tactic">apply</span> <span class="id" title="var">Hyp2</span>.<br/>
<span class="id" title="tactic">exact</span> <span class="id" title="var">Hyp3</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#combinatorS"><span class="id" title="definition">combinatorS</span></a>.<br/>
<span class="id" title="keyword">Eval</span> <span class="id" title="tactic">compute</span> <span class="id" title="tactic">in</span> <a class="idref" href="lecture_tactics.html#combinatorS"><span class="id" title="definition">combinatorS</span></a>.<br/>
<br/>
</div>
<div class="doc">
a more comfortable variant:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="combinatorS_induction" class="idref" href="#combinatorS_induction"><span class="id" title="definition">combinatorS_induction</span></a> (<a id="A:6" class="idref" href="#A:6"><span class="id" title="binder">A</span></a> <a id="B:7" class="idref" href="#B:7"><span class="id" title="binder">B</span></a> <a id="C:8" class="idref" href="#C:8"><span class="id" title="binder">C</span></a>: <span class="id" title="definition">UU</span>): <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:6"><span class="id" title="variable">A</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#B:7"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:8"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:6"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:7"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#A:6"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:8"><span class="id" title="variable">C</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intro</span> <span class="id" title="var">Hyp123</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">Hyp123</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">Hyp1</span> <span class="id" title="var">Hyp23</span>].<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">Hyp1</span>.<br/>
<span class="id" title="tactic">induction</span> <span class="id" title="var">Hyp23</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">Hyp2</span> <span class="id" title="var">Hyp3</span>].<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="constructor">tpair</span>.<br/>
- <span class="id" title="tactic">exact</span> <span class="id" title="var">Hyp3</span>.<br/>
- <span class="id" title="tactic">apply</span> <span class="id" title="var">Hyp2</span>.<br/>
<span class="id" title="tactic">exact</span> <span class="id" title="var">Hyp3</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#combinatorS_induction"><span class="id" title="definition">combinatorS_induction</span></a>.<br/>
<span class="id" title="keyword">Eval</span> <span class="id" title="tactic">compute</span> <span class="id" title="tactic">in</span> <a class="idref" href="lecture_tactics.html#combinatorS_induction"><span class="id" title="definition">combinatorS_induction</span></a>.<br/>
</div>
<div class="doc">
the comfort for the user does not change the normal form of the constructed proof
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Definition</span> <a id="combinatorS_curried" class="idref" href="#combinatorS_curried"><span class="id" title="definition">combinatorS_curried</span></a> (<a id="A:9" class="idref" href="#A:9"><span class="id" title="binder">A</span></a> <a id="B:10" class="idref" href="#B:10"><span class="id" title="binder">B</span></a> <a id="C:11" class="idref" href="#C:11"><span class="id" title="binder">C</span></a>: <span class="id" title="definition">UU</span>): <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:9"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:10"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:11"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:9"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:10"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#A:9"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:11"><span class="id" title="variable">C</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
</div>
<div class="doc">
use <span class="inlinecode"><span class="id" title="tactic">intro</span></span> three times or rather <span class="inlinecode"><span class="id" title="tactic">intros</span></span> once; reasonable coding style
gives names to all hypotheses that are not already present
in the goal formula, see also the next definition
</div>
<div class="code">
<span class="id" title="tactic">intros</span> <span class="id" title="var">H1</span> <span class="id" title="var">H2</span> <span class="id" title="var">H3</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">H1</span>.<br/>
- <span class="id" title="tactic">exact</span> <span class="id" title="var">H3</span>.<br/>
- <span class="id" title="tactic">set</span> (<span class="id" title="var">proofofB</span> := <span class="id" title="var">H2</span> <span class="id" title="var">H3</span>).<br/>
</div>
<div class="doc">
set up abbreviations that can make use of the current context
</div>
<div class="code">
<span class="id" title="tactic">exact</span> <span class="id" title="var">proofofB</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
<span class="id" title="keyword">Print</span> <a class="idref" href="lecture_tactics.html#combinatorS_curried"><span class="id" title="definition">combinatorS_curried</span></a>.<br/>
</div>
<div class="doc">
We see that <span class="inlinecode"><span class="id" title="tactic">set</span></span> gives rise to <span class="inlinecode"><span class="id" title="keyword">let</span></span>-expressions that are known
from functional programming languages, in other words: the use of
<span class="inlinecode"><span class="id" title="tactic">set</span></span> is not a "macro" facility to ease typing.
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="keyword">let</span></span>-bindings disappear when computing the normal form of a term:
</div>
<div class="code">
<span class="id" title="keyword">Eval</span> <span class="id" title="tactic">compute</span> <span class="id" title="tactic">in</span> <a class="idref" href="lecture_tactics.html#combinatorS_curried"><span class="id" title="definition">combinatorS_curried</span></a>.<br/>
<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="tactic">set</span></span> can only be used if the term of the desired type is provided,
but we can also work interactively as follows:
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="combinatorS_curried_with_assert" class="idref" href="#combinatorS_curried_with_assert"><span class="id" title="definition">combinatorS_curried_with_assert</span></a> (<a id="A:12" class="idref" href="#A:12"><span class="id" title="binder">A</span></a> <a id="B:13" class="idref" href="#B:13"><span class="id" title="binder">B</span></a> <a id="C:14" class="idref" href="#C:14"><span class="id" title="binder">C</span></a>: <span class="id" title="definition">UU</span>):<br/>
<span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:12"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:13"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:14"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:12"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:13"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#A:12"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:14"><span class="id" title="variable">C</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">H1</span> <span class="id" title="var">H2</span> <span class="id" title="var">H3</span>.<br/>
</div>
<div class="doc">
we can momentarily forget about our goal and build up knowledge:
</div>
<div class="code">
<span class="id" title="tactic">assert</span> (<span class="id" title="var">proofofB</span> : <span class="id" title="var">B</span>).<br/>
</div>
<div class="doc">
the current goal <span class="inlinecode"><span class="id" title="var">C</span></span> becomes the second sub-goal, and the new current goal is <span class="inlinecode"><span class="id" title="var">B</span></span>
<div class="paragraph"> </div>
It is not wise to handle this situation by "bullets" since many assertions
can appear in a linearly thought argument. It would pretend a tree structure
although it would rather be a comb. The proof of the assertion should
be packaged by enclosing it in curly braces like so:
</div>
<div class="code">
{ <span class="id" title="tactic">apply</span> <span class="id" title="var">H2</span>.<br/>
<span class="id" title="tactic">exact</span> <span class="id" title="var">H3</span>.<br/>
}<br/>
</div>
<div class="doc">
Now, <span class="inlinecode"><span class="id" title="var">proofofB</span></span> is in the context with type <span class="inlinecode"><span class="id" title="var">B</span></span>.
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <span class="id" title="var">H1</span>.<br/>
- <span class="id" title="tactic">exact</span> <span class="id" title="var">H3</span>.<br/>
- <span class="id" title="tactic">exact</span> <span class="id" title="var">proofofB</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
<br/>
</div>
<div class="doc">
the wildcard <span class="inlinecode">?</span> for <span class="inlinecode"><span class="id" title="tactic">intros</span></span>
</div>
<div class="code">
<span class="id" title="keyword">Definition</span> <a id="combinatorS_curried_variant" class="idref" href="#combinatorS_curried_variant"><span class="id" title="definition">combinatorS_curried_variant</span></a> (<a id="A:15" class="idref" href="#A:15"><span class="id" title="binder">A</span></a> <a id="B:16" class="idref" href="#B:16"><span class="id" title="binder">B</span></a> <a id="C:17" class="idref" href="#C:17"><span class="id" title="binder">C</span></a>: <span class="id" title="definition">UU</span>):<br/>
<span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:15"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:16"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#C:17"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:15"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#B:16"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <span class="id" title="keyword">∀</span> <a id="H7:18" class="idref" href="#H7:18"><span class="id" title="binder">H7</span></a>: <a class="idref" href="lecture_tactics.html#A:15"><span class="id" title="variable">A</span></a>, <a class="idref" href="lecture_tactics.html#C:17"><span class="id" title="variable">C</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span> <span class="id" title="var">H1</span> <span class="id" title="var">H2</span> ?.<br/>
</div>
<div class="doc">
a question mark instructs Coq to use the corresponding identifier
from the goal formula
</div>
<div class="code">
<span class="id" title="tactic">exact</span> (<span class="id" title="var">H1</span> <span class="id" title="var">H7</span> (<span class="id" title="var">H2</span> <span class="id" title="var">H7</span>)).<br/>
<span class="id" title="keyword">Defined</span>.<br/>
</div>
<div class="doc">
the wildcard <span class="inlinecode"><span class="id" title="var">_</span></span> for <span class="inlinecode"><span class="id" title="tactic">intros</span></span> forgets the respective hypothesis
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "⨿". </div>
<div class="doc">
this symbol is typed as \amalg when the recommended extension
packages for VSCode are loaded
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="inductive">coprod</span>. </div>
<div class="doc">
defined in UniMath preamble as inductive type,
can be seen as disjunction
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "∏".<br/>
<br/>
<span class="id" title="keyword">Locate</span> "=". </div>
<div class="doc">
the identity type of UniMath
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="inductive">paths</span>.<br/>
<br/>
</div>
<div class="doc">
<a id="lab5"></a><h3 class="section">How to decompose formulas</h3>
<div class="paragraph"> </div>
In "Coq in a Hurry", Yves Bertot gives recipes for decomposing the usual logical
connectives. Crucially, one has to distinguish between decomposition of the goal
or decomposition of a hypothesis in the context.
<div class="paragraph"> </div>
Here, we do it alike.
<div class="paragraph"> </div>
<a id="lab6"></a><h4 class="section">Decomposition of goal formulas:</h4>
<div class="paragraph"> </div>
A1,...,An -> B: tactic <span class="inlinecode"><span class="id" title="tactic">intro</span></span> or <span class="inlinecode"><span class="id" title="tactic">intros</span></span>
<div class="paragraph"> </div>
<span class="inlinecode">¬</span> <span class="inlinecode"><span class="id" title="var">A</span></span>: idem (negation is defined through implication)
<div class="paragraph"> </div>
Π-type: idem (implication is a special case of product)
<div class="paragraph"> </div>
<span class="inlinecode">×</span>: <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">dirprodpair</span></span>, less specifically <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">tpair</span></span>
<div class="paragraph"> </div>
Σ-type: <span class="inlinecode"><span class="id" title="var">use</span></span> <span class="inlinecode"><span class="id" title="var">tpair</span></span> or <span class="inlinecode"><span class="id" title="tactic">∃</span></span>, see explanations below
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">⨿</span> <span class="inlinecode"><span class="id" title="var">B</span></span>: <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">ii1</span></span> or <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">ii2</span></span>, but this constitutes a choice
of which way to go
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">B</span></span>: <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">idpath</span></span>, however this only works when the expressions
are convertible
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">nat</span></span>: <span class="inlinecode"><span class="id" title="tactic">exact</span></span> <span class="inlinecode">1000</span>, for example (a logical reading is not
useful for this type); beware that UniMath knows only 27 numerals
<div class="paragraph"> </div>
<a id="lab7"></a><h4 class="section">Decomposition of formula of hypothesis <span class="inlinecode"><span class="id" title="var">H</span></span>:</h4>
<div class="paragraph"> </div>
<span class="inlinecode">∅</span>: <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span>
<div class="paragraph"> </div>
This terminates a goal. (It corresponds to ex falso quodlibet.)
<div class="paragraph"> </div>
There is naturally no recipe for getting rid of <span class="inlinecode">∅</span> in the conclusion.
But <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">fromempty</span></span> allows to replace any goal by <span class="inlinecode">∅</span>.
<div class="paragraph"> </div>
A1,...,An -> B: <span class="inlinecode"><span class="id" title="tactic">apply</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span>, but the formula has to fit with the goal
<div class="paragraph"> </div>
<span class="inlinecode">×</span>: <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[<span class="id" title="var">H1</span></span> <span class="inlinecode"><span class="id" title="var">H2</span>]</span>
<div class="paragraph"> </div>
As seen above, this introduces names of hypotheses for the two components.
<div class="paragraph"> </div>
Σ-type: idem, but rather more asymmetric as <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[<span class="id" title="var">x</span></span> <span class="inlinecode"><span class="id" title="var">H'</span>]</span>
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">⨿</span> <span class="inlinecode"><span class="id" title="var">B</span></span>: <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[<span class="id" title="var">H1</span></span> <span class="inlinecode">|</span> <span class="inlinecode"><span class="id" title="var">H2</span>]</span>
<div class="paragraph"> </div>
This introduces names for the hypotheses in the two branches.
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">A</span></span> <span class="inlinecode">=</span> <span class="inlinecode"><span class="id" title="var">B</span></span>: <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">H</span></span>
<div class="paragraph"> </div>
The supposedly equal <span class="inlinecode"><span class="id" title="var">A</span></span> and <span class="inlinecode"><span class="id" title="var">B</span></span> become the same <span class="inlinecode"><span class="id" title="var">A</span></span> in the goal.
<div class="paragraph"> </div>
This is the least intuitive rule for the non-expert in type theory.
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">nat</span></span>: <span class="inlinecode"><span class="id" title="tactic">induction</span></span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode"><span class="id" title="keyword">as</span></span> <span class="inlinecode">[</span> <span class="inlinecode">|</span> <span class="inlinecode"><span class="id" title="var">n</span></span> <span class="inlinecode"><span class="id" title="var">IH</span>]</span>
<div class="paragraph"> </div>
Here, we assume that the hypothesis has the name <span class="inlinecode"><span class="id" title="var">n</span></span> which
is more idiomatic than <span class="inlinecode"><span class="id" title="var">H</span></span>, and there is no extra name in
the base case, while in the step case, the preceding number
is now given the name <span class="inlinecode"><span class="id" title="var">n</span></span> and the induction hypothesis is
named <span class="inlinecode"><span class="id" title="var">IH</span></span>.
<div class="paragraph"> </div>
<a id="lab8"></a><h2 class="section">Working with holes in proofs</h2>
<div class="paragraph"> </div>
Our previous proofs were particularly clear because the goal formulas
and all hypotheses were fully given by the system.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="definition">pathscomp0</span>.<br/>
</div>
<div class="doc">
This is the UniMath proof of transitivity of equality.
<div class="paragraph"> </div>
The salient feature of transitivity is that the intermediate
expression cannot be deduced from the equation to be proven.
</div>
<div class="code">
<span class="id" title="keyword">Lemma</span> <a id="badex" class="idref" href="#badex"><span class="id" title="lemma">badex</span></a> (<a id="A:19" class="idref" href="#A:19"><span class="id" title="binder">A</span></a> <a id="B:20" class="idref" href="#B:20"><span class="id" title="binder">B</span></a> <a id="C:21" class="idref" href="#C:21"><span class="id" title="binder">C</span></a> <a id="D:22" class="idref" href="#D:22"><span class="id" title="binder">D</span></a>: <span class="id" title="definition">UU</span>) : <span class="id" title="notation">(</span><span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:19"><span class="id" title="variable">A</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#B:20"><span class="id" title="variable">B</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#C:21"><span class="id" title="variable">C</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#D:22"><span class="id" title="variable">D</span></a><span class="id" title="notation">)</span><span class="id" title="notation">)</span> <span class="id" title="notation">=</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#A:19"><span class="id" title="variable">A</span></a> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><a class="idref" href="lecture_tactics.html#B:20"><span class="id" title="variable">B</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#C:21"><span class="id" title="variable">C</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#D:22"><span class="id" title="variable">D</span></a><span class="id" title="notation">)</span>.<br/>
</div>
<div class="doc">
Notice that the outermost parentheses are needed here.
</div>
<div class="code">
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="var">Fail</span> <span class="id" title="tactic">apply</span> <span class="id" title="definition">pathscomp0</span>.<br/>
</div>
<div class="doc">
<br/>
<span class="inlinecode"><span class="id" title="var">The</span> <span class="id" title="var">command</span> <span class="id" title="var">has</span> <span class="id" title="var">indeed</span> <span class="id" title="var">failed</span> <span class="id" title="keyword">with</span> <span class="id" title="var">message</span>:<br/>
<span class="id" title="var">Cannot</span> <span class="id" title="var">infer</span> <span class="id" title="var">the</span> <span class="id" title="var">implicit</span> <span class="id" title="var">parameter</span> <span class="id" title="var">b</span> <span class="id" title="keyword">of</span> <span class="id" title="var">pathscomp0</span> <span class="id" title="var">whose</span> <span class="id" title="keyword">type</span> <span class="id" title="keyword">is</span><br/>
"Type" <span class="id" title="tactic">in</span> <span class="id" title="var">environment</span>:<br/>
<span class="id" title="var">A</span>, <span class="id" title="var">B</span>, <span class="id" title="var">C</span>, <span class="id" title="var">D</span> : <span class="id" title="var">UU</span>
<div class="paragraph"> </div>
</span>
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="var">Fail</span></span> announces failure and therefore allows to continue with
the interpretation of the vernacular file.
<div class="paragraph"> </div>
We need to help Coq with the argument <span class="inlinecode"><span class="id" title="var">b</span></span> to <span class="inlinecode"><span class="id" title="var">pathscomp0</span></span>.
</div>
<div class="code">
<span class="id" title="tactic">apply</span> (<span class="id" title="definition">pathscomp0</span> (<span class="id" title="var">b</span> := <span class="id" title="var">A</span> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><span class="id" title="var">B</span> <span class="id" title="notation">×</span> <span class="id" title="notation">(</span><span class="id" title="var">C</span> <span class="id" title="notation">×</span> <span class="id" title="var">D</span><span class="id" title="notation">))</span>)).<br/>
- </div>
<div class="doc">
is this not just associativity with third argument <span class="inlinecode"><span class="id" title="var">C</span></span> <span class="inlinecode">×</span> <span class="inlinecode"><span class="id" title="var">D</span></span>?
</div>
<div class="code">
<span class="id" title="keyword">SearchPattern</span> (<span class="id" title="var">_</span> <span class="id" title="notation">×</span> <span class="id" title="var">_</span> <span class="id" title="notation">=</span> <span class="id" title="var">_</span> <span class="id" title="notation">×</span> <span class="id" title="var">_</span>).<br/>
</div>
<div class="doc">
Nothing for our equation - we can only hope for weak equivalence ≃,
see the exercises.
</div>
<div class="code">
<span class="id" title="keyword">Abort</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="var">badex</span></span> is not in the symbol table.
<div class="paragraph"> </div>
<span class="inlinecode"><span class="id" title="keyword">Abort</span>.</span> is a way of documenting a problem with proving a result.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Lemma</span> <a id="sumex" class="idref" href="#sumex"><span class="id" title="lemma">sumex</span></a> (<a id="A:23" class="idref" href="#A:23"><span class="id" title="binder">A</span></a>: <span class="id" title="definition">UU</span>) (<a id="P:24" class="idref" href="#P:24"><span class="id" title="binder">P</span></a> <a id="Q:25" class="idref" href="#Q:25"><span class="id" title="binder">Q</span></a>: <a class="idref" href="lecture_tactics.html#A:23"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <span class="id" title="definition">UU</span>):<br/>
<span class="id" title="notation">(</span><span class="id" title="notation">∑</span> <a id="x:26" class="idref" href="#x:26"><span class="id" title="binder">x</span></a>: <a class="idref" href="lecture_tactics.html#A:23"><span class="id" title="variable">A</span></a><span class="id" title="notation">,</span> <a class="idref" href="lecture_tactics.html#P:24"><span class="id" title="variable">P</span></a> <a class="idref" href="lecture_tactics.html#x:26"><span class="id" title="variable">x</span></a> <span class="id" title="notation">×</span> <a class="idref" href="lecture_tactics.html#Q:25"><span class="id" title="variable">Q</span></a> <a class="idref" href="lecture_tactics.html#x:26"><span class="id" title="variable">x</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">→</span> <span class="id" title="notation">(</span><span class="id" title="notation">∑</span> <a id="x:27" class="idref" href="#x:27"><span class="id" title="binder">x</span></a>: <a class="idref" href="lecture_tactics.html#A:23"><span class="id" title="variable">A</span></a><span class="id" title="notation">,</span> <a class="idref" href="lecture_tactics.html#P:24"><span class="id" title="variable">P</span></a> <a class="idref" href="lecture_tactics.html#x:27"><span class="id" title="variable">x</span></a><span class="id" title="notation">)</span> <span class="id" title="notation">×</span> <span class="id" title="notation">∑</span> <a id="x:28" class="idref" href="#x:28"><span class="id" title="binder">x</span></a>:<a class="idref" href="lecture_tactics.html#A:23"><span class="id" title="variable">A</span></a><span class="id" title="notation">,</span> <a class="idref" href="lecture_tactics.html#Q:25"><span class="id" title="variable">Q</span></a> <a class="idref" href="lecture_tactics.html#x:28"><span class="id" title="variable">x</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
</div>
<div class="doc">
decompose the implication:
</div>
<div class="code">
<span class="id" title="tactic">intro</span> <span class="id" title="var">H</span>.<br/>
</div>
<div class="doc">
decompose the Σ-type:
</div>
<div class="code">
<span class="id" title="tactic">induction</span> <span class="id" title="var">H</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">x</span> <span class="id" title="var">H'</span>].<br/>
</div>
<div class="doc">
decompose the pair:
</div>
<div class="code">
<span class="id" title="tactic">induction</span> <span class="id" title="var">H'</span> <span class="id" title="keyword">as</span> [<span class="id" title="var">H1</span> <span class="id" title="var">H2</span>].<br/>
</div>
<div class="doc">
decompose the pair in the goal
</div>
<div class="code">
<span class="id" title="tactic">apply</span> <span class="id" title="constructor">tpair</span>.<br/>
- <span class="id" title="var">Fail</span> (<span class="id" title="tactic">apply</span> <span class="id" title="constructor">tpair</span>).<br/>
</div>
<div class="doc">
<br/>
<span class="inlinecode"><span class="id" title="var">The</span> <span class="id" title="var">command</span> <span class="id" title="var">has</span> <span class="id" title="var">indeed</span> <span class="id" title="var">failed</span> <span class="id" title="keyword">with</span> <span class="id" title="var">message</span>:<br/>
<span class="id" title="var">Unable</span> <span class="id" title="var">to</span> <span class="id" title="var">find</span> <span class="id" title="var">an</span> <span class="id" title="var">instance</span> <span class="id" title="keyword">for</span> <span class="id" title="var">the</span> <span class="id" title="var">variable</span> <span class="id" title="var">pr1</span>.
<div class="paragraph"> </div>
</span> A simple way out, by providing the first component:
</div>
<div class="code">
<span class="id" title="tactic">∃</span> <span class="id" title="var">x</span>.<br/>
<span class="id" title="tactic">exact</span> <span class="id" title="var">H1</span>.<br/>
- </div>
<div class="doc">
or use <span class="inlinecode"><span class="id" title="var">use</span></span>
</div>
<div class="code">
<span class="id" title="var">use</span> <span class="id" title="constructor">tpair</span>.<br/>
+ <span class="id" title="tactic">exact</span> <span class="id" title="var">x</span>.<br/>
+ <span class="id" title="var">cbn</span>. </div>
<div class="doc">
is given only for better readability
</div>
<div class="code">
<span class="id" title="tactic">exact</span> <span class="id" title="var">H2</span>.<br/>
<span class="id" title="keyword">Defined</span>.<br/>
</div>
<div class="doc">
<span class="inlinecode"><span class="id" title="var">use</span></span> is not generally available in Coq but defined in the
preamble of the UniMath library.
<div class="paragraph"> </div>
<a id="lab9"></a><h2 class="section">a bit more on equational reasoning</h2>
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Section</span> <a id="homot" class="idref" href="#homot"><span class="id" title="section">homot</span></a>.<br/>
</div>
<div class="doc">
A section allows to introduce local variables/parameters
that will be bound outside of the section.
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Locate</span> "~".<br/>
<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="definition">homot</span>. </div>
<div class="doc">
this is just pointwise equality
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="definition">idfun</span>. </div>
<div class="doc">
the identity function
</div>
<div class="code">
<span class="id" title="keyword">Locate</span> "∘". </div>
<div class="doc">
exchanges the arguments of <span class="inlinecode"><span class="id" title="var">funcomp</span></span>
</div>
<div class="code">
<span class="id" title="keyword">Print</span> <span class="id" title="definition">funcomp</span>.<br/>
</div>
<div class="doc">
plain function composition in diagrammatic order, i.e.,
first the first argument, then the second argument
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Context</span> (<a id="A:29" class="idref" href="#A:29"><span class="id" title="binder">A</span></a> <a id="B:30" class="idref" href="#B:30"><span class="id" title="binder">B</span></a>: <span class="id" title="definition">UU</span>).<br/>
</div>
<div class="doc">
makes good sense in a section, can be put in curly braces to indicate
they will be implicit arguments for every construction in the section
</div>
<div class="code">
<br/>
<span class="id" title="keyword">Definition</span> <a id="interestingstatement" class="idref" href="#interestingstatement"><span class="id" title="definition">interestingstatement</span></a> : <span class="id" title="definition">UU</span> :=<br/>
<span class="id" title="notation">∏</span> <span class="id" title="notation">(</span><a id="v:31" class="idref" href="#v:31"><span class="id" title="binder">v</span></a> <a id="w:32" class="idref" href="#w:32"><span class="id" title="binder">w</span></a> : <a class="idref" href="lecture_tactics.html#homot.A"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#homot.B"><span class="id" title="variable">B</span></a>) (<a id="v':33" class="idref" href="#v':33"><span class="id" title="binder">v'</span></a> <a id="w':34" class="idref" href="#w':34"><span class="id" title="binder">w'</span></a> : <a class="idref" href="lecture_tactics.html#homot.B"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#homot.A"><span class="id" title="variable">A</span></a><span class="id" title="notation">),</span><br/>
<a class="idref" href="lecture_tactics.html#w:32"><span class="id" title="variable">w</span></a> <span class="id" title="notation">∘</span> <a class="idref" href="lecture_tactics.html#w':34"><span class="id" title="variable">w'</span></a> <span class="id" title="notation">~</span> <span class="id" title="definition">idfun</span> <a class="idref" href="lecture_tactics.html#homot.B"><span class="id" title="variable">B</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#v':33"><span class="id" title="variable">v'</span></a> <span class="id" title="notation">∘</span> <a class="idref" href="lecture_tactics.html#v:31"><span class="id" title="variable">v</span></a> <span class="id" title="notation">~</span> <span class="id" title="definition">idfun</span> <a class="idref" href="lecture_tactics.html#homot.A"><span class="id" title="variable">A</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#v':33"><span class="id" title="variable">v'</span></a> <span class="id" title="notation">~</span> <a class="idref" href="lecture_tactics.html#w':34"><span class="id" title="variable">w'</span></a> <span class="id" title="notation">→</span> <a class="idref" href="lecture_tactics.html#v:31"><span class="id" title="variable">v</span></a> <span class="id" title="notation">~</span> <a class="idref" href="lecture_tactics.html#w:32"><span class="id" title="variable">w</span></a>.<br/>
<br/>
<span class="id" title="keyword">Check</span> (<span class="id" title="definition">isinjinvmap'</span>: <a class="idref" href="lecture_tactics.html#interestingstatement"><span class="id" title="definition">interestingstatement</span></a>).<br/>
<br/>
<span class="id" title="keyword">Lemma</span> <a id="ourisinjinvmap'" class="idref" href="#ourisinjinvmap'"><span class="id" title="lemma">ourisinjinvmap'</span></a>: <a class="idref" href="lecture_tactics.html#interestingstatement"><span class="id" title="definition">interestingstatement</span></a>.<br/>
<span class="id" title="keyword">Proof</span>.<br/>
<span class="id" title="tactic">intros</span>. </div>
<div class="doc">
is a nop since the formula structure is not analyzed
</div>
<div class="code">
<span class="id" title="tactic">unfold</span> <a class="idref" href="lecture_tactics.html#interestingstatement"><span class="id" title="definition">interestingstatement</span></a>. </div>
<div class="doc">
<span class="inlinecode"><span class="id" title="tactic">unfold</span></span> unfolds a definition
</div>
<div class="code">
<span class="id" title="tactic">intros</span> ? ? ? ? <span class="id" title="var">homoth1</span> <span class="id" title="var">homoth2</span> <span class="id" title="var">hyp</span> <span class="id" title="var">a</span>.<br/>
</div>
<div class="doc">
the extra element <span class="inlinecode"><span class="id" title="var">a</span></span> triggers Coq to unfold the formula further;
<span class="inlinecode"><span class="id" title="tactic">unfold</span></span> <span class="inlinecode"><span class="id" title="var">interestingstatement</span></span> was there only for illustration!
<div class="paragraph"> </div>
we want to use transitivity that is expressed by <span class="inlinecode"><span class="id" title="var">pathscomp0</span></span> and
instruct Coq to take a specific intermediate term; for this, there
is a "convenience tactic" in UniMath: <span class="inlinecode"><span class="id" title="var">intermediate_path</span></span>
</div>
<div class="code">
<span class="id" title="var">intermediate_path</span> (<span class="id" title="var">w</span> (<span class="id" title="var">w'</span> (<span class="id" title="var">v</span> <span class="id" title="var">a</span>))).<br/>
- <span class="id" title="tactic">apply</span> <span class="id" title="definition">pathsinv0</span>. </div>
<div class="doc">
apply symmetry of equality
</div>
<div class="code">
<span class="id" title="tactic">unfold</span> <span class="id" title="definition">homot</span> <span class="id" title="tactic">in</span> <span class="id" title="var">homoth1</span>.<br/>
<span class="id" title="tactic">unfold</span> <span class="id" title="definition">funcomp</span> <span class="id" title="tactic">in</span> <span class="id" title="var">homoth1</span>.<br/>
<span class="id" title="tactic">unfold</span> <span class="id" title="definition">idfun</span> <span class="id" title="tactic">in</span> <span class="id" title="var">homoth1</span>.<br/>
<span class="id" title="tactic">apply</span> <span class="id" title="var">homoth1</span>. </div>
<div class="doc">
all the <span class="inlinecode"><span class="id" title="tactic">unfold</span></span> were only for illustration!
</div>
<div class="code">
-<br/>
<span class="id" title="keyword">Print</span> <span class="id" title="definition">maponpaths</span>.<br/>