-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.html
6653 lines (5956 loc) · 324 KB
/
commands.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>
<html lang="en">
<head>
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/style.css">
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/pygments.css">
<link rel="stylesheet" href="https://pygae.github.io/lean-ga-docs/pygments-dark.css">
<link rel="shortcut icon" href="https://pygae.github.io/lean-ga-docs/favicon.ico">
<title>Commands - mathlib3 docs</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Commands provide a way to interact with and modify a Lean environment outside of the context of a proof. Familiar commands from core Lean include `#check`, `#eval`, and `run_cmd`." />
<link rel="canonical" href="https://leanprover-community.github.io/mathlib_docs/commands.html" />
<meta property="og:title" content="Commands - mathlib3 docs">
<meta property="og:site_name" content="mathlib for Lean 3 - API documentation">
<meta property="og:description" content="Commands provide a way to interact with and modify a Lean environment outside of the context of a proof. Familiar commands from core Lean include `#check`, `#eval`, and `run_cmd`.">
<meta property="og:image" content="https://pygae.github.io/lean-ga-docs/meta-og.png">
<meta name="twitter:card" content="summary">
<script src="https://pygae.github.io/lean-ga-docs/color_scheme.js"></script>
</head>
<body>
<input id="nav_toggle" type="checkbox">
<header>
<h1><label for="nav_toggle"></label><a href="https://leanprover-community.github.io/lean3">mathlib3</a>
<span>documentation</span></h1>
<p class="header_filename break_within">Commands</p>
<form action="https://google.com/search" method="get" id="search_form">
<input type="hidden" name="sitesearch" value="https://leanprover-community.github.io/mathlib_docs">
<input type="text" name="q" autocomplete="off">
<button>Google site search</button>
</form>
</header>
<nav class="internal_nav">
<h3><a href="#top">Commands</a></h3>
<details class="tagfilter-div">
<summary>Filter by tag</summary>
<label><input type="checkbox" id="tagfilter-selectall" name="tagfilter-selectall">Select/deselect all</label>
<br><hr>
<label><input type="checkbox" class="tagfilter" name="arithmetic" value="arithmetic">arithmetic</label>
<br>
<label><input type="checkbox" class="tagfilter" name="category-theory" value="category-theory">category theory</label>
<br>
<label><input type="checkbox" class="tagfilter" name="core" value="core">core</label>
<br>
<label><input type="checkbox" class="tagfilter" name="debugging" value="debugging">debugging</label>
<br>
<label><input type="checkbox" class="tagfilter" name="decision-procedure" value="decision-procedure">decision procedure</label>
<br>
<label><input type="checkbox" class="tagfilter" name="documentation" value="documentation">documentation</label>
<br>
<label><input type="checkbox" class="tagfilter" name="environment" value="environment">environment</label>
<br>
<label><input type="checkbox" class="tagfilter" name="linting" value="linting">linting</label>
<br>
<label><input type="checkbox" class="tagfilter" name="logic" value="logic">logic</label>
<br>
<label><input type="checkbox" class="tagfilter" name="notation" value="notation">notation</label>
<br>
<label><input type="checkbox" class="tagfilter" name="parsing" value="parsing">parsing</label>
<br>
<label><input type="checkbox" class="tagfilter" name="proof-display" value="proof-display">proof display</label>
<br>
<label><input type="checkbox" class="tagfilter" name="renaming" value="renaming">renaming</label>
<br>
<label><input type="checkbox" class="tagfilter" name="search" value="search">search</label>
<br>
<label><input type="checkbox" class="tagfilter" name="simplification" value="simplification">simplification</label>
<br>
<label><input type="checkbox" class="tagfilter" name="type-classes" value="type-classes">type classes</label>
<br>
<label><input type="checkbox" class="tagfilter" name="widgets" value="widgets">widgets</label>
<br>
</details>
<div class="taclink proof-display widgets"><a href="##explode / #explode_widget">#explode / #explode_widget</a></div>
<div class="taclink search"><a href="##find">#find</a></div>
<div class="taclink core widgets"><a href="##html">#html</a></div>
<div class="taclink simplification arithmetic decision-procedure"><a href="##norm_num">#norm_num</a></div>
<div class="taclink logic"><a href="##push_neg">#push_neg</a></div>
<div class="taclink simplification"><a href="##simp">#simp</a></div>
<div class="taclink environment"><a href="##where">#where</a></div>
<div class="taclink documentation"><a href="#add_decl_doc">add_decl_doc</a></div>
<div class="taclink search"><a href="#add_hint_tactic">add_hint_tactic</a></div>
<div class="taclink documentation"><a href="#add_tactic_doc">add_tactic_doc</a></div>
<div class="taclink renaming"><a href="#alias">alias</a></div>
<div class="taclink documentation"><a href="#copy_doc_string">copy_doc_string</a></div>
<div class="taclink environment renaming"><a href="#def_replacer">def_replacer</a></div>
<div class="taclink renaming"><a href="#import_private">import_private</a></div>
<div class="taclink simplification"><a href="#initialize_simps_projections">initialize_simps_projections</a></div>
<div class="taclink documentation"><a href="#library_note">library_note</a></div>
<div class="taclink linting"><a href="#linting commands">linting commands</a></div>
<div class="taclink notation type-classes"><a href="#localized notation">localized notation</a></div>
<div class="taclink logic environment"><a href="#mk_iff_of_inductive_prop">mk_iff_of_inductive_prop</a></div>
<div class="taclink simplification"><a href="#mk_simp_attribute">mk_simp_attribute</a></div>
<div class="taclink search environment debugging"><a href="#print_sorry_in">print_sorry_in</a></div>
<div class="taclink category-theory"><a href="#reassoc_axiom">reassoc_axiom</a></div>
<div class="taclink renaming environment"><a href="#restate_axiom">restate_axiom</a></div>
<div class="taclink parsing"><a href="#run_parser">run_parser</a></div>
<div class="taclink parsing notation"><a href="#setup_tactic_parser">setup_tactic_parser</a></div>
</nav>
<main>
<a id="top"></a>
<div class="docfile">
<h1>Commands</h1>
<p>Commands provide a way to interact with and modify a Lean environment outside of the context of a proof.
Familiar commands from core Lean include <code>#check</code>, <code>#eval</code>, and <code>run_cmd</code>.</p>
<p>Mathlib provides a number of commands that offer customized behavior. These commands fall into two
categories:</p>
<ul>
<li>
<p><em>Transient</em> commands are used to query the environment for information, but do not modify it,
and have no effect on the following proofs. These are useful as a user to get information from Lean.
They should not appear in "finished" files.
Transient commands typically begin with the symbol <code>#</code>.
<code>#check</code> is a standard example of a transient command.</p>
</li>
<li>
<p><em>Permanent</em> commands modify the environment. Removing a permanent command from a file may affect
the following proofs. <code>set_option class.instance_max_depth 500</code> is a standard example of a
permanent command.</p>
</li>
</ul>
<p>User-defined commands can have unintuitive interactions with the parser. For the most part, this is
not something to worry about. However, you may occasionally see strange error messages when using
mathlib commands: for instance, running these commands immediately after <code>import file.name</code> will
produce an error. An easy solution is to run a built-in no-op command in between, for example:</p>
<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="n">data.nat.basic</span>
<span class="kd">run_cmd</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic.skip">tactic.skip</a></span> <span class="c1">-- this serves as a "barrier" between `import` and `#find`</span>
<span class="bp">#</span><span class="n">find</span> <span class="n">_</span> <span class="bp">+</span> <span class="n">_</span> <span class="bp">=</span> <span class="n">_</span> <span class="bp">+</span> <span class="n">_</span>
</code></pre></div>
<div class="tactic proof-display widgets">
<h2 id="#explode / #explode_widget"><a href="##explode / #explode_widget">#explode / #explode_widget</a></h2>
<p><code>#explode decl_name</code> displays a proof term in a line-by-line format somewhat akin to a Fitch-style
proof or the Metamath proof style.
<code>#explode_widget decl_name</code> renders a widget that displays an <code>#explode</code> proof.</p>
<p><code>#explode <a href="https://pygae.github.io/lean-ga-docs/init/logic.html#iff_true_intro">iff_true_intro</a></code> produces</p>
<div class="codehilite"><pre><span></span><code><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#iff_true_intro">iff_true_intro</a></span> <span class="o">:</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">a</span> <span class="o">:</span> <span class="kt">Prop</span><span class="o">},</span> <span class="n">a</span> <span class="bp">→</span> <span class="o">(</span><span class="n">a</span> <span class="bp">↔</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span><span class="o">)</span>
<span class="mi">0</span><span class="bp">│</span> <span class="bp">│</span> <span class="n">a</span> <span class="bp">├</span> <span class="kt">Prop</span>
<span class="mi">1</span><span class="bp">│</span> <span class="bp">│</span> <span class="n">h</span> <span class="bp">├</span> <span class="n">a</span>
<span class="mi">2</span><span class="bp">│</span> <span class="bp">│</span> <span class="n">hl</span> <span class="bp">│</span> <span class="bp">┌</span> <span class="n">a</span>
<span class="mi">3</span><span class="bp">│</span> <span class="bp">│</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#trivial">trivial</a></span> <span class="bp">│</span> <span class="bp">│</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span>
<span class="mi">4</span><span class="bp">│</span><span class="mi">2</span><span class="o">,</span><span class="mi">3</span><span class="bp">│</span> <span class="bp">∀</span><span class="n">I</span> <span class="bp">│</span> <span class="n">a</span> <span class="bp">→</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span>
<span class="mi">5</span><span class="bp">│</span> <span class="bp">│</span> <span class="n">hr</span> <span class="bp">│</span> <span class="bp">┌</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span>
<span class="mi">6</span><span class="bp">│</span><span class="mi">5</span><span class="o">,</span><span class="mi">1</span><span class="bp">│</span> <span class="bp">∀</span><span class="n">I</span> <span class="bp">│</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span> <span class="bp">→</span> <span class="n">a</span>
<span class="mi">7</span><span class="bp">│</span><span class="mi">4</span><span class="o">,</span><span class="mi">6</span><span class="bp">│</span> <span class="n">iff.intro</span> <span class="bp">│</span> <span class="n">a</span> <span class="bp">↔</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span>
<span class="mi">8</span><span class="bp">│</span><span class="mi">1</span><span class="o">,</span><span class="mi">7</span><span class="bp">│</span> <span class="bp">∀</span><span class="n">I</span> <span class="bp">│</span> <span class="n">a</span> <span class="bp">→</span> <span class="o">(</span><span class="n">a</span> <span class="bp">↔</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span><span class="o">)</span>
<span class="mi">9</span><span class="bp">│</span><span class="mi">0</span><span class="o">,</span><span class="mi">8</span><span class="bp">│</span> <span class="bp">∀</span><span class="n">I</span> <span class="bp">│</span> <span class="bp">∀</span> <span class="o">{</span><span class="n">a</span> <span class="o">:</span> <span class="kt">Prop</span><span class="o">},</span> <span class="n">a</span> <span class="bp">→</span> <span class="o">(</span><span class="n">a</span> <span class="bp">↔</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></span><span class="o">)</span>
</code></pre></div>
<p>In more detail:</p>
<p>The output of <code>#explode</code> is a Fitch-style proof in a four-column diagram modeled after Metamath
proof displays like <a href="http://us.metamath.org/mpeuni/ru.html">this</a>. The headers of the columns are
"Step", "Hyp", "Ref", "Type" (or "Expression" in the case of Metamath):</p>
<ul>
<li>Step: An increasing sequence of numbers to number each step in the proof, used in the Hyp field.</li>
<li>Hyp: The direct children of the current step. Most theorems are implications like <code>A -> B -> C</code>,
and so on the step proving <code>C</code> the Hyp field will refer to the steps that prove <code>A</code> and <code>B</code>.</li>
<li>Ref: The name of the theorem being applied. This is well-defined in Metamath, but in Lean there
are some special steps that may have long names because the structure of proof terms doesn't
exactly match this mold.
<ul>
<li>If the theorem is <code>foo (x y : Z) : A x -> B y -> C x y</code>:
<ul>
<li>the Ref field will contain <code>foo</code>,</li>
<li><code>x</code> and <code>y</code> will be suppressed, because term construction is not interesting, and</li>
<li>the Hyp field will reference steps proving <code>A x</code> and <code>B y</code>. This corresponds to a proof term
like <code>@foo x y pA pB</code> where <code>pA</code> and <code>pB</code> are subproofs.</li>
</ul>
</li>
<li>If the head of the proof term is a local constant or lambda, then in this case the Ref will
say <code>∀E</code> for forall-elimination. This happens when you have for example <code>h : A -> B</code> and
<code>ha : A</code> and prove <code>b</code> by <code>h ha</code>; we reinterpret this as if it said <code>∀E h ha</code> where <code>∀E</code> is
(n-ary) modus ponens.</li>
<li>If the proof term is a lambda, we will also use <code>∀I</code> for forall-introduction, referencing the
body of the lambda. The indentation level will increase, and a bracket will surround the proof
of the body of the lambda, starting at a proof step labeled with the name of the lambda variable
and its type, and ending with the <code>∀I</code> step. Metamath doesn't have steps like this, but the
style is based on Fitch proofs in first-order logic.</li>
</ul>
</li>
<li>Type: This contains the type of the proof term, the theorem being proven at the current step.
This proof layout differs from <code>#print</code> in using lots of intermediate step displays so that you
can follow along and don't have to see term construction steps because they are implicitly in the
intermediate step displays.</li>
</ul>
<p>Also, it is common for a Lean theorem to begin with a sequence of lambdas introducing local
constants of the theorem. In order to minimize the indentation level, the <code>∀I</code> steps at the end of
the proof will be introduced in a group and the indentation will stay fixed. (The indentation
brackets are only needed in order to delimit the scope of assumptions, and these assumptions
have global scope anyway so detailed tracking is not necessary.)</p>
<div class="tags">Tags:
<ul>
<li>proof display</li>
<li>widgets</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/explode.html#tactic.explode_cmd">tactic.explode_cmd</a></li>
<li>tactic.explode_widget_cmd</li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.explode</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic search">
<h2 id="#find"><a href="##find">#find</a></h2>
<p>The <code>find</code> command from <code>tactic.find</code> allows to find definitions lemmas using
pattern matching on the type. For instance:</p>
<div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="n">tactic.find</span>
<span class="kd">run_cmd</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic.skip">tactic.skip</a></span>
<span class="bp">#</span><span class="n">find</span> <span class="n">_</span> <span class="bp">+</span> <span class="n">_</span> <span class="bp">=</span> <span class="n">_</span> <span class="bp">+</span> <span class="n">_</span>
<span class="bp">#</span><span class="n">find</span> <span class="o">(</span><span class="n">_</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span> <span class="bp">+</span> <span class="n">_</span> <span class="bp">=</span> <span class="n">_</span> <span class="bp">+</span> <span class="n">_</span>
<span class="bp">#</span><span class="n">find</span> <span class="n">ℕ</span> <span class="bp">→</span> <span class="n">ℕ</span>
</code></pre></div>
<p>The tactic <code>library_search</code> is an alternate way to find lemmas in the library.</p>
<div class="tags">Tags:
<ul>
<li>search</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/find.html#find_cmd">find_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.find</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic core widgets">
<h2 id="#html"><a href="##html">#html</a></h2>
<p>Accepts terms with the type <code>component <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic_state">tactic_state</a> <a href="https://pygae.github.io/lean-ga-docs/init/data/string/basic.html#string">string</a></code> or <code>html <a href="https://pygae.github.io/lean-ga-docs/init/core.html#empty">empty</a></code> and
renders them interactively.
Requires a compatible version of the vscode extension to view the resulting widget.</p>
<h3 id="example" class="markdown-heading">Example: <a class="hover-link" href="#example">#</a></h3>
<div class="codehilite"><pre><span></span><code><span class="sd">/-- A simple counter that can be incremented or decremented with some buttons. -/</span>
<span class="kd">meta</span> <span class="kd">def</span> <span class="n">counter_widget</span> <span class="o">{</span><span class="n">π</span> <span class="n">α</span> <span class="o">:</span> <span class="kt">Type</span><span class="o">}</span> <span class="o">:</span> <span class="n">component</span> <span class="n">π</span> <span class="n">α</span> <span class="o">:=</span>
<span class="n">component.ignore_props</span> <span class="bp">$</span> <span class="n">component.mk_simple</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/data/int/basic.html#int">int</a></span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/data/int/basic.html#int">int</a></span> <span class="mi">0</span> <span class="o">(</span><span class="bp">λ</span> <span class="n">_</span> <span class="n">x</span> <span class="n">y</span><span class="o">,</span> <span class="o">(</span><span class="n">x</span> <span class="bp">+</span> <span class="n">y</span><span class="o">,</span> <span class="n">none</span><span class="o">))</span> <span class="o">(</span><span class="bp">λ</span> <span class="n">_</span> <span class="n">s</span><span class="o">,</span>
<span class="n">h</span> <span class="s2">"div"</span> <span class="o">[]</span> <span class="o">[</span>
<span class="n">button</span> <span class="s2">"+"</span> <span class="o">(</span><span class="mi">1</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/data/int/basic.html#int">int</a></span><span class="o">),</span>
<span class="n">html.of_string</span> <span class="bp">$</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/data/to_string.html#to_string">to_string</a></span> <span class="bp">$</span> <span class="n">s</span><span class="o">,</span>
<span class="n">button</span> <span class="s2">"-"</span> <span class="o">(</span><span class="bp">-</span><span class="mi">1</span><span class="o">)</span>
<span class="o">]</span>
<span class="o">)</span>
<span class="bp">#</span><span class="n">html</span> <span class="n">counter_widget</span>
<span class="bp">```</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>core</li>
<li>widgets</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/init/meta/widget/html_cmd.html#show_widget_cmd">show_widget_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>imported by default</li></ul></details>
</div>
<div class="tactic simplification arithmetic decision-procedure">
<h2 id="#norm_num"><a href="##norm_num">#norm_num</a></h2>
<p>The basic usage is <code>#norm_num e</code>, where <code>e</code> is an expression,
which will print the <code>norm_num</code> form of <code>e</code>.</p>
<p>Syntax: <code>#norm_num</code> (<code>only</code>)? (<code>[</code> simp lemma list <code>]</code>)? (<code>with</code> simp sets)? <code>:</code>? expression</p>
<p>This accepts the same options as the <code>#simp</code> command.
You can specify additional simp lemmas as usual, for example using
<code>#norm_num [f, g] : e</code>, or <code>#norm_num with attr : e</code>.
(The colon is optional but helpful for the parser.)
The <code>only</code> restricts <code>norm_num</code> to using only the provided lemmas, and so
<code>#norm_num only : e</code> behaves similarly to <code>norm_num1</code>.</p>
<p>Unlike <code>norm_num</code>, this command does not fail when no simplifications are made.</p>
<p><code>#norm_num</code> understands local variables, so you can use them to
introduce parameters.</p>
<div class="tags">Tags:
<ul>
<li>simplification</li>
<li>arithmetic</li>
<li>decision procedure</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/norm_num.html#tactic.norm_num_cmd">tactic.norm_num_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.norm_num</li>
<li>import tactic</li></ul></details>
</div>
<div class="tactic logic">
<h2 id="#push_neg"><a href="##push_neg">#push_neg</a></h2>
<p>The syntax is <code>#push_neg e</code>, where <code>e</code> is an expression,
which will print the <code>push_neg</code> form of <code>e</code>.</p>
<p><code>#push_neg</code> understands local variables, so you can use them to
introduce parameters.</p>
<div class="tags">Tags:
<ul>
<li>logic</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/push_neg.html#tactic.push_neg_cmd">tactic.push_neg_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.push_neg</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic simplification">
<h2 id="#simp"><a href="##simp">#simp</a></h2>
<p>The basic usage is <code>#simp e</code>, where <code>e</code> is an expression,
which will print the simplified form of <code>e</code>.</p>
<p>You can specify additional simp lemmas as usual for example using
<code>#simp [f, g] : e</code>, or <code>#simp with attr : e</code>.
(The colon is optional, but helpful for the parser.)</p>
<p><code>#simp</code> understands local variables, so you can use them to
introduce parameters.</p>
<div class="tags">Tags:
<ul>
<li>simplification</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/simp_command.html#tactic.simp_cmd">tactic.simp_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.simp_command</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic environment">
<h2 id="#where"><a href="##where">#where</a></h2>
<p>When working in a Lean file with namespaces, parameters, and variables, it can be confusing to
identify what the current "parser context" is. The command <code>#where</code> identifies and prints
information about the current location, including the active namespace, open namespaces, and
declared variables.</p>
<p>It is a bug for <code>#where</code> to incorrectly report this information (this was not formerly the case);
please file an issue on GitHub if you observe a failure.</p>
<div class="tags">Tags:
<ul>
<li>environment</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/where.html#where.where_cmd">where.where_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.where</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic documentation">
<h2 id="add_decl_doc"><a href="#add_decl_doc">add_decl_doc</a></h2>
<p>The <code>add_decl_doc</code> command is used to add a doc string to an existing declaration.</p>
<div class="codehilite"><pre><span></span><code><span class="kd">def</span> <span class="n">foo</span> <span class="o">:=</span> <span class="mi">5</span>
<span class="sd">/--</span>
<span class="sd">Doc string for foo.</span>
<span class="sd">-/</span>
<span class="n">add_decl_doc</span> <span class="n">foo</span>
<span class="bp">```</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>documentation</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#add_decl_doc_command">add_decl_doc_command</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.doc_commands</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic search">
<h2 id="add_hint_tactic"><a href="#add_hint_tactic">add_hint_tactic</a></h2>
<p><code>add_hint_tactic t</code> runs the tactic <code>t</code> whenever <code>hint</code> is invoked.
The typical use case is <code>add_hint_tactic "foo"</code> for some interactive tactic <code>foo</code>.</p>
<div class="tags">Tags:
<ul>
<li>search</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/hint.html#tactic.hint.add_hint_tactic">tactic.hint.add_hint_tactic</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.hint</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic documentation">
<h2 id="add_tactic_doc"><a href="#add_tactic_doc">add_tactic_doc</a></h2>
<p>A command used to add documentation for a tactic, command, hole command, or attribute.</p>
<p>Usage: after defining an interactive tactic, command, or attribute,
add its documentation as follows.</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/--</span>
<span class="sd">describe what the command does here</span>
<span class="sd">-/</span>
<span class="n">add_tactic_doc</span>
<span class="o">{</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/meta/name.html#name">name</a></span> <span class="o">:=</span> <span class="s2">"display name of the tactic"</span><span class="o">,</span>
<span class="n">category</span> <span class="o">:=</span> <span class="n">cat</span><span class="o">,</span>
<span class="n">decl_names</span> <span class="o">:=</span> <span class="o">[</span><span class="bp">`</span><span class="n">dcl_1</span><span class="o">,</span> <span class="bp">`</span><span class="n">dcl_2</span><span class="o">],</span>
<span class="n">tags</span> <span class="o">:=</span> <span class="o">[</span><span class="s2">"tag_1"</span><span class="o">,</span> <span class="s2">"tag_2"</span><span class="o">]</span> <span class="o">}</span>
</code></pre></div>
<p>The argument to <code>add_tactic_doc</code> is a structure of type <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#tactic_doc_entry">tactic_doc_entry</a></code>.</p>
<ul>
<li><code><a href="https://pygae.github.io/lean-ga-docs/init/meta/name.html#name">name</a></code> refers to the display name of the tactic; it is used as the header of the doc entry.</li>
<li><code>cat</code> refers to the category of doc entry.
Options: <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#doc_category.tactic">doc_category.tactic</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#doc_category.cmd">doc_category.cmd</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#doc_category.hole_cmd">doc_category.hole_cmd</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#doc_category.attr">doc_category.attr</a></code></li>
<li><code>decl_names</code> is a list of the declarations associated with this doc. For instance,
the entry for <code>linarith</code> would set <code>decl_names := [`tactic.interactive.linarith]</code>.
Some entries may cover multiple declarations.
It is only necessary to list the interactive versions of tactics.</li>
<li><code>tags</code> is an optional list of strings used to categorize entries.</li>
<li>The doc string is the body of the entry. It can be formatted with markdown.
What you are reading now is the description of <code>add_tactic_doc</code>.</li>
</ul>
<p>If only one related declaration is listed in <code>decl_names</code> and if this
invocation of <code>add_tactic_doc</code> does not have a doc string, the doc string of
that declaration will become the body of the tactic doc entry. If there are
multiple declarations, you can select the one to be used by passing a name to
the <code>inherit_description_from</code> field.</p>
<p>If you prefer a tactic to have a doc string that is different then the doc entry,
you should write the doc entry as a doc string for the <code>add_tactic_doc</code> invocation.</p>
<p>Note that providing a badly formed <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#tactic_doc_entry">tactic_doc_entry</a></code> to the command can result in strange error
messages.</p>
<div class="tags">Tags:
<ul>
<li>documentation</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#add_tactic_doc_command">add_tactic_doc_command</a></li>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#tactic.add_tactic_doc">tactic.add_tactic_doc</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.doc_commands</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic renaming">
<h2 id="alias"><a href="#alias">alias</a></h2>
<p>The <code>alias</code> command can be used to create copies
of a theorem or definition with different names.</p>
<p>Syntax:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/-- doc string -/</span>
<span class="n">alias</span> <span class="n">my_theorem</span> <span class="bp">←</span> <span class="n">alias1</span> <span class="n">alias2</span> <span class="bp">...</span>
</code></pre></div>
<p>This produces defs or theorems of the form:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/-- doc string -/</span>
<span class="kd">@[alias]</span> <span class="kd">theorem</span> <span class="n">alias1</span> <span class="o">:</span> <span class="bp"><</span><span class="n">type</span> <span class="n">of</span> <span class="n">my_theorem</span><span class="bp">></span> <span class="o">:=</span> <span class="n">my_theorem</span>
<span class="sd">/-- doc string -/</span>
<span class="kd">@[alias]</span> <span class="kd">theorem</span> <span class="n">alias2</span> <span class="o">:</span> <span class="bp"><</span><span class="n">type</span> <span class="n">of</span> <span class="n">my_theorem</span><span class="bp">></span> <span class="o">:=</span> <span class="n">my_theorem</span>
</code></pre></div>
<p>Iff alias syntax:</p>
<div class="codehilite"><pre><span></span><code><span class="n">alias</span> <span class="n">A_iff_B</span> <span class="bp">↔</span> <span class="n">B_of_A</span> <span class="n">A_of_B</span>
<span class="n">alias</span> <span class="n">A_iff_B</span> <span class="bp">↔</span> <span class="bp">..</span>
</code></pre></div>
<p>This gets an existing biconditional theorem <code>A_iff_B</code> and produces
the one-way implications <code>B_of_A</code> and <code>A_of_B</code> (with no change in
implicit arguments). A blank <code>_</code> can be used to avoid generating one direction.
The <code>..</code> notation attempts to generate the 'of'-names automatically when the
input theorem has the form <code>A_iff_B</code> or <code>A_iff_B_left</code> etc.</p>
<div class="tags">Tags:
<ul>
<li>renaming</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/alias.html#tactic.alias.alias_cmd">tactic.alias.alias_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.alias</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic documentation">
<h2 id="copy_doc_string"><a href="#copy_doc_string">copy_doc_string</a></h2>
<p><code>copy_doc_string source → target_1 target_2 ... target_n</code> copies the doc string of the
declaration named <code>source</code> to each of <code>target_1</code>, <code>target_2</code>, ..., <code>target_n</code>.</p>
<div class="tags">Tags:
<ul>
<li>documentation</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#copy_doc_string_cmd">copy_doc_string_cmd</a></li>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#tactic.copy_doc_string">tactic.copy_doc_string</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.doc_commands</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic environment renaming">
<h2 id="def_replacer"><a href="#def_replacer">def_replacer</a></h2>
<p><code>def_replacer foo</code> sets up a stub definition <code>foo : <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a></code>, which can
effectively be defined and re-defined later, by tagging definitions with <code>@[foo]</code>.</p>
<ul>
<li><code>@[foo] meta def foo_1 : <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a> := ...</code> replaces the current definition of <code>foo</code>.</li>
<li><code>@[foo] meta def foo_2 (old : <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a>) : <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a> := ...</code> replaces the current
definition of <code>foo</code>, and provides access to the previous definition via <code>old</code>.
(The argument can also be an <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#option">option</a> (<a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> <a href="https://pygae.github.io/lean-ga-docs/init/core.html#unit">unit</a>)</code>, which is provided as <code>none</code> if
this is the first definition tagged with <code>@[foo]</code> since <code>def_replacer</code> was invoked.)</li>
</ul>
<p><code>def_replacer foo : α → β → <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> γ</code> allows the specification of a replacer with
custom input and output types. In this case all subsequent redefinitions must have the
same type, or the type <code>α → β → <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> γ → <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> γ</code> or
<code>α → β → <a href="https://pygae.github.io/lean-ga-docs/init/core.html#option">option</a> (<a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> γ) → <a href="https://pygae.github.io/lean-ga-docs/init/meta/tactic.html#tactic">tactic</a> γ</code> analogously to the previous cases.</p>
<div class="tags">Tags:
<ul>
<li>environment</li>
<li>renaming</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/replacer.html#tactic.def_replacer_cmd">tactic.def_replacer_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.replacer</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic renaming">
<h2 id="import_private"><a href="#import_private">import_private</a></h2>
<p><code>import_private foo from bar</code> finds a private declaration <code>foo</code> in the same file as <code>bar</code>
and creates a local notation to refer to it.</p>
<p><code>import_private foo</code> looks for <code>foo</code> in all imported files.</p>
<p>When possible, make <code>foo</code> non-private rather than using this feature.</p>
<div class="tags">Tags:
<ul>
<li>renaming</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/core.html#tactic.import_private_cmd">tactic.import_private_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.core</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic simplification">
<h2 id="initialize_simps_projections"><a href="#initialize_simps_projections">initialize_simps_projections</a></h2>
<p>This command specifies custom names and custom projections for the simp attribute <code><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#simps_attr">simps_attr</a></code>.</p>
<ul>
<li>You can specify custom names by writing e.g.
<code>initialize_simps_projections <a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a> (to_fun → apply, inv_fun → symm_apply)</code>.</li>
<li>See <a id="noteref1" href="https://pygae.github.io/lean-ga-docs/notes.html#custom simps projection">Note [custom simps projection]</a> and the examples below for information how to declare custom
projections.</li>
<li>If no custom projection is specified, the projection will be <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe_fn">coe_fn</a></code>/<code>⇑</code> if a <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code>
instance has been declared, or the notation of a notation class (like <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_mul">has_mul</a></code>) if such an
instance is available. If none of these cases apply, the projection itself will be used.</li>
<li>You can disable a projection by default by running
<code>initialize_simps_projections <a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a> (-inv_fun)</code>
This will ensure that no simp lemmas are generated for this projection,
unless this projection is explicitly specified by the user.</li>
<li>If you want the projection name added as a prefix in the generated lemma name, you can add the
<code>as_prefix</code> modifier:
<code>initialize_simps_projections <a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a> (to_fun → <a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a> as_prefix)</code>
Note that this does not influence the parsing of projection names: if you have a declaration
<code>foo</code> and you want to apply the projections <code>snd</code>, <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a></code> (which is a prefix) and <code>fst</code>, in that
order you can run <code>@[simps snd_coe_fst] def foo ...</code> and this will generate a lemma with the
name <code>coe_foo_snd_fst</code>.
<ul>
<li>Run <code>initialize_simps_projections?</code> (or <code>set_option trace.simps.verbose <a href="https://pygae.github.io/lean-ga-docs/init/core.html#true">true</a></code>)
to see the generated projections.</li>
</ul>
</li>
<li>You can declare a new name for a projection that is the composite of multiple projections, e.g.
<div class="codehilite"><pre><span></span><code> <span class="kd">structure</span> <span class="n">A</span> <span class="o">:=</span> <span class="o">(</span><span class="n">proj</span> <span class="o">:</span> <span class="n">ℕ</span><span class="o">)</span>
<span class="kd">structure</span> <span class="n">B</span> <span class="kd">extends</span> <span class="n">A</span>
<span class="n">initialize_simps_projections</span><span class="bp">?</span> <span class="n">B</span> <span class="o">(</span><span class="n">to_A_proj</span> <span class="bp">→</span> <span class="n">proj</span><span class="o">,</span> <span class="bp">-</span><span class="n">to_A</span><span class="o">)</span>
</code></pre></div>
You can also make your custom projection that is definitionally equal to a composite of
projections. In this case, coercions and notation classes are not automatically recognized, and
should be manually given by giving a custom projection.
This is especially useful when extending a structure (without <code>old_structure_cmd</code>).
In the above example, it is desirable to add <code>-to_A</code>, so that <code>@[simps]</code> doesn't automatically
apply the <code>B.to_A</code> projection and then recursively the <code>A.proj</code> projection in the lemmas it
generates. If you want to get both the <code>foo_proj</code> and <code>foo_to_A</code> simp lemmas, you can use
<code>@[simps, simps to_A]</code>.</li>
<li>Running <code>initialize_simps_projections my_struc</code> without arguments is not necessary, it has the
same effect if you just add <code>@[simps]</code> to a declaration.</li>
<li>If you do anything to change the default projections, make sure to call either <code>@[simps]</code> or
<code>initialize_simps_projections</code> in the same file as the structure declaration. Otherwise, you might
have a file that imports the structure, but not your custom projections.</li>
</ul>
<p>Some common uses:</p>
<ul>
<li>If you define a new homomorphism-like structure (like <code><a href="https://pygae.github.io/lean-ga-docs/algebra/hom/group.html#mul_hom">mul_hom</a></code>) you can just run
<code>initialize_simps_projections</code> after defining the <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> instance
<div class="codehilite"><pre><span></span><code> <span class="kd">instance</span> <span class="o">{</span><span class="n">mM</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_mul">has_mul</a></span> <span class="n">M</span><span class="o">}</span> <span class="o">{</span><span class="n">mN</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/core.html#has_mul">has_mul</a></span> <span class="n">N</span><span class="o">}</span> <span class="o">:</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></span> <span class="o">(</span><span class="n">M</span> <span class="bp">→ₙ*</span> <span class="n">N</span><span class="o">)</span> <span class="o">:=</span> <span class="bp">...</span>
<span class="n">initialize_simps_projections</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/algebra/hom/group.html#mul_hom">mul_hom</a></span> <span class="o">(</span><span class="n">to_fun</span> <span class="bp">→</span> <span class="n">apply</span><span class="o">)</span>
</code></pre></div>
This will generate <code>foo_apply</code> lemmas for each declaration <code>foo</code>.</li>
<li>If you prefer <code>coe_foo</code> lemmas that state equalities between functions, use
<code>initialize_simps_projections <a href="https://pygae.github.io/lean-ga-docs/algebra/hom/group.html#mul_hom">mul_hom</a> (to_fun → <a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a> as_prefix)</code>
In this case you have to use <code>@[simps {fully_applied := ff}]</code> or equivalently <code>@[simps <a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#as_fn">as_fn</a>]</code>
whenever you call <code>@[simps]</code>.</li>
<li>You can also initialize to use both, in which case you have to choose which one to use by default,
by using either of the following
<div class="codehilite"><pre><span></span><code> <span class="n">initialize_simps_projections</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/algebra/hom/group.html#mul_hom">mul_hom</a></span> <span class="o">(</span><span class="n">to_fun</span> <span class="bp">→</span> <span class="n">apply</span><span class="o">,</span> <span class="n">to_fun</span> <span class="bp">→</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a></span><span class="o">,</span> <span class="bp">-</span><span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a></span> <span class="n">as_prefix</span><span class="o">)</span>
<span class="n">initialize_simps_projections</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/algebra/hom/group.html#mul_hom">mul_hom</a></span> <span class="o">(</span><span class="n">to_fun</span> <span class="bp">→</span> <span class="n">apply</span><span class="o">,</span> <span class="n">to_fun</span> <span class="bp">→</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a></span> <span class="n">as_prefix</span><span class="o">,</span> <span class="bp">-</span><span class="n">apply</span><span class="o">)</span>
</code></pre></div>
In the first case, you can get both lemmas using <code>@[simps, simps <a href="https://pygae.github.io/lean-ga-docs/init/coe.html#coe">coe</a> <a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#as_fn">as_fn</a>]</code> and in the second
case you can get both lemmas using <code>@[simps as_fn, simps apply]</code>.</li>
<li>If your new homomorphism-like structure extends another structure (without <code>old_structure_cmd</code>)
(like <code><a href="https://pygae.github.io/lean-ga-docs/order/rel_iso/basic.html#rel_embedding">rel_embedding</a></code>), then you have to specify explicitly that you want to use a coercion
as a custom projection. For example
<div class="codehilite"><pre><span></span><code> <span class="kd">def</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/order/rel_iso/basic.html#rel_embedding.simps.apply">rel_embedding.simps.apply</a></span> <span class="o">(</span><span class="n">h</span> <span class="o">:</span> <span class="n">r</span> <span class="bp">↪</span><span class="n">r</span> <span class="n">s</span><span class="o">)</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">→</span> <span class="n">β</span> <span class="o">:=</span> <span class="n">h</span>
<span class="n">initialize_simps_projections</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/order/rel_iso/basic.html#rel_embedding">rel_embedding</a></span> <span class="o">(</span><span class="n">to_embedding_to_fun</span> <span class="bp">→</span> <span class="n">apply</span><span class="o">,</span> <span class="bp">-</span><span class="n">to_embedding</span><span class="o">)</span>
</code></pre></div>
</li>
<li>If you have an isomorphism-like structure (like <code><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a></code>) you often want to define a custom
projection for the inverse:
<div class="codehilite"><pre><span></span><code> <span class="kd">def</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv.simps.symm_apply">equiv.simps.symm_apply</a></span> <span class="o">(</span><span class="n">e</span> <span class="o">:</span> <span class="n">α</span> <span class="bp">≃</span> <span class="n">β</span><span class="o">)</span> <span class="o">:</span> <span class="n">β</span> <span class="bp">→</span> <span class="n">α</span> <span class="o">:=</span> <span class="n">e.symm</span>
<span class="n">initialize_simps_projections</span> <span class="n"><a href="https://pygae.github.io/lean-ga-docs/logic/equiv/defs.html#equiv">equiv</a></span> <span class="o">(</span><span class="n">to_fun</span> <span class="bp">→</span> <span class="n">apply</span><span class="o">,</span> <span class="n">inv_fun</span> <span class="bp">→</span> <span class="n">symm_apply</span><span class="o">)</span>
</code></pre></div>
</li>
</ul>
<div class="tags">Tags:
<ul>
<li>simplification</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/simps.html#initialize_simps_projections_cmd">initialize_simps_projections_cmd</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.simps</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic documentation">
<h2 id="library_note"><a href="#library_note">library_note</a></h2>
<p>At various places in mathlib, we leave implementation notes that are referenced from many other
files. To keep track of these notes, we use the command <code><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#library_note">library_note</a></code>. This makes it easy to
retrieve a list of all notes, e.g. for documentation output.</p>
<p>These notes can be referenced in mathlib with the syntax <code>Note [note <a href="https://pygae.github.io/lean-ga-docs/init/logic.html#id">id</a>]</code>.
Often, these references will be made in code comments (<code>--</code>) that won't be displayed in docs.
If such a reference is made in a doc string or module doc, it will be linked to the corresponding
note in the doc display.</p>
<p>Syntax:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/--</span>
<span class="sd">note message</span>
<span class="sd">-/</span>
<span class="n"><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#library_note">library_note</a></span> <span class="s2">"note id"</span>
</code></pre></div>
<p>An example from <code>meta.expr</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="sd">/--</span>
<span class="sd">Some declarations work with open expressions, i.e. an expr that has free variables.</span>
<span class="sd">Terms will free variables are not well-typed, and one should not use them in tactics like</span>
<span class="sd">`infer_type` or `unify`. You can still do syntactic analysis/manipulation on them.</span>
<span class="sd">The reason for working with open types is for performance: instantiating variables requires</span>
<span class="sd">iterating through the expression. In one performance test `pi_binders` was more than 6x</span>
<span class="sd">quicker than `mk_local_pis` (when applied to the type of all imported declarations 100x).</span>
<span class="sd">-/</span>
<span class="n"><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#library_note">library_note</a></span> <span class="s2">"open expressions"</span>
</code></pre></div>
<p>This note can be referenced near a usage of <code>pi_binders</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="c1">-- See <a id="noteref2" href="https://pygae.github.io/lean-ga-docs/notes.html#open expressions">Note [open expressions]</a></span>
<span class="sd">/-- behavior of f -/</span>
<span class="kd">def</span> <span class="n">f</span> <span class="o">:=</span> <span class="n">pi_binders</span> <span class="bp">...</span>
</code></pre></div>
<div class="tags">Tags:
<ul>
<li>documentation</li>
</ul>
</div>
<details class="rel_decls"><summary>Related declarations</summary>
<ul>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#library_note">library_note</a></li>
<li><a href="https://pygae.github.io/lean-ga-docs/tactic/doc_commands.html#tactic.add_library_note">tactic.add_library_note</a></li>
</ul>
</details>
<details class="imports"><summary>Import using</summary><ul><li>import tactic.doc_commands</li>
<li>import tactic.basic</li></ul></details>
</div>
<div class="tactic linting">
<h2 id="linting commands"><a href="#linting commands">linting commands</a></h2>
<p>User commands to spot common mistakes in the code</p>
<ul>
<li><code>#lint</code>: check all declarations in the current file</li>
<li><code>#lint_mathlib</code>: check all declarations in mathlib (so excluding core or other projects,
and also excluding the current file)</li>
<li><code>#lint_all</code>: check all declarations in the environment (the current file and all
imported files)</li>
</ul>
<p>The following linters are run by default:</p>
<ol>
<li><code>unused_arguments</code> checks for unused arguments in declarations.</li>
<li><code>def_lemma</code> checks whether a declaration is incorrectly marked as a def/lemma.</li>
<li><code>dup_namespce</code> checks whether a namespace is duplicated in the name of a declaration.</li>
<li><code>ge_or_gt</code> checks whether ≥/> is used in the declaration.</li>
<li><code>instance_priority</code> checks that instances that always apply have priority below default.</li>
<li><code>doc_blame</code> checks for missing doc strings on definitions and constants.</li>
<li><code>has_nonempty_instance</code> checks whether every type has an associated <code><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#inhabited">inhabited</a></code>, <code><a href="https://pygae.github.io/lean-ga-docs/logic/unique.html#unique">unique</a></code>
or <code><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#nonempty">nonempty</a></code> instance.</li>
<li><code>impossible_instance</code> checks for instances that can never fire.</li>
<li><code>incorrect_type_class_argument</code> checks for arguments in [square brackets] that are not classes.</li>
<li><code>dangerous_instance</code> checks for instances that generate type-class problems with metavariables.</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/type_classes.html#fails_quickly">fails_quickly</a></code> tests that type-class inference ends (relatively) quickly when applied to
variables.</li>
<li><code>has_coe_variable</code> tests that there are no instances of type <code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe">has_coe</a> α t</code> for a variable <code>α</code>.</li>
<li><code>inhabited_nonempty</code> checks for <code><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#inhabited">inhabited</a></code> instance arguments that should be changed to
<code><a href="https://pygae.github.io/lean-ga-docs/init/logic.html#nonempty">nonempty</a></code>.</li>
<li><code>simp_nf</code> checks that the left-hand side of simp lemmas is in simp-normal form.</li>
<li><code>simp_var_head</code> checks that there are no variables as head symbol of left-hand sides of
simp lemmas.</li>
<li><code>simp_comm</code> checks that no commutativity lemmas (such as <code><a href="https://pygae.github.io/lean-ga-docs/algebra/group/defs.html#add_comm">add_comm</a></code>) are marked simp.</li>
<li><code>decidable_classical</code> checks for <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> hypotheses that are used in the proof of a
proposition but not in the statement, and could be removed using <code>classical</code>.
Theorems in the <code><a href="https://pygae.github.io/lean-ga-docs/init/core.html#decidable">decidable</a></code> namespace are exempt.</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> checks that every type that coerces to a function has a direct
<code><a href="https://pygae.github.io/lean-ga-docs/init/coe.html#has_coe_to_fun">has_coe_to_fun</a></code> instance.</li>
<li><code><a href="https://pygae.github.io/lean-ga-docs/tactic/lint/misc.html#check_type">check_type</a></code> checks that the statement of a declaration is well-typed.</li>