├── .gitignore ├── LICENSE ├── lean-tactics.pdf └── lean-tactics.tex /.gitignore: -------------------------------------------------------------------------------- 1 | ## Core latex/pdflatex auxiliary files: 2 | *.aux 3 | *.lof 4 | *.log 5 | *.lot 6 | *.fls 7 | *.out 8 | *.toc 9 | *.fmt 10 | *.fot 11 | *.cb 12 | *.cb2 13 | .*.lb 14 | 15 | ## Intermediate documents: 16 | *.dvi 17 | *.xdv 18 | *-converted-to.* 19 | # these rules might exclude image files for figures etc. 20 | # *.ps 21 | # *.eps 22 | # *.pdf 23 | 24 | ## Generated if empty string is given at "Please type another file name for output:" 25 | .pdf 26 | 27 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 28 | *.bbl 29 | *.bcf 30 | *.blg 31 | *-blx.aux 32 | *-blx.bib 33 | *.run.xml 34 | 35 | ## Build tool auxiliary files: 36 | *.fdb_latexmk 37 | *.synctex 38 | *.synctex(busy) 39 | *.synctex.gz 40 | *.synctex.gz(busy) 41 | *.pdfsync 42 | 43 | ## Build tool directories for auxiliary files 44 | # latexrun 45 | latex.out/ 46 | 47 | ## Auxiliary and intermediate files from other packages: 48 | # algorithms 49 | *.alg 50 | *.loa 51 | 52 | # achemso 53 | acs-*.bib 54 | 55 | # amsthm 56 | *.thm 57 | 58 | # beamer 59 | *.nav 60 | *.pre 61 | *.snm 62 | *.vrb 63 | 64 | # changes 65 | *.soc 66 | 67 | # comment 68 | *.cut 69 | 70 | # cprotect 71 | *.cpt 72 | 73 | # elsarticle (documentclass of Elsevier journals) 74 | *.spl 75 | 76 | # endnotes 77 | *.ent 78 | 79 | # fixme 80 | *.lox 81 | 82 | # feynmf/feynmp 83 | *.mf 84 | *.mp 85 | *.t[1-9] 86 | *.t[1-9][0-9] 87 | *.tfm 88 | 89 | #(r)(e)ledmac/(r)(e)ledpar 90 | *.end 91 | *.?end 92 | *.[1-9] 93 | *.[1-9][0-9] 94 | *.[1-9][0-9][0-9] 95 | *.[1-9]R 96 | *.[1-9][0-9]R 97 | *.[1-9][0-9][0-9]R 98 | *.eledsec[1-9] 99 | *.eledsec[1-9]R 100 | *.eledsec[1-9][0-9] 101 | *.eledsec[1-9][0-9]R 102 | *.eledsec[1-9][0-9][0-9] 103 | *.eledsec[1-9][0-9][0-9]R 104 | 105 | # glossaries 106 | *.acn 107 | *.acr 108 | *.glg 109 | *.glo 110 | *.gls 111 | *.glsdefs 112 | *.lzo 113 | *.lzs 114 | 115 | # uncomment this for glossaries-extra (will ignore makeindex's style files!) 116 | # *.ist 117 | 118 | # gnuplottex 119 | *-gnuplottex-* 120 | 121 | # gregoriotex 122 | *.gaux 123 | *.gtex 124 | 125 | # htlatex 126 | *.4ct 127 | *.4tc 128 | *.idv 129 | *.lg 130 | *.trc 131 | *.xref 132 | 133 | # hyperref 134 | *.brf 135 | 136 | # knitr 137 | *-concordance.tex 138 | # TODO Comment the next line if you want to keep your tikz graphics files 139 | *.tikz 140 | *-tikzDictionary 141 | 142 | # listings 143 | *.lol 144 | 145 | # luatexja-ruby 146 | *.ltjruby 147 | 148 | # makeidx 149 | *.idx 150 | *.ilg 151 | *.ind 152 | 153 | # minitoc 154 | *.maf 155 | *.mlf 156 | *.mlt 157 | *.mtc[0-9]* 158 | *.slf[0-9]* 159 | *.slt[0-9]* 160 | *.stc[0-9]* 161 | 162 | # minted 163 | _minted* 164 | *.pyg 165 | 166 | # morewrites 167 | *.mw 168 | 169 | # nomencl 170 | *.nlg 171 | *.nlo 172 | *.nls 173 | 174 | # pax 175 | *.pax 176 | 177 | # pdfpcnotes 178 | *.pdfpc 179 | 180 | # sagetex 181 | *.sagetex.sage 182 | *.sagetex.py 183 | *.sagetex.scmd 184 | 185 | # scrwfile 186 | *.wrt 187 | 188 | # sympy 189 | *.sout 190 | *.sympy 191 | sympy-plots-for-*.tex/ 192 | 193 | # pdfcomment 194 | *.upa 195 | *.upb 196 | 197 | # pythontex 198 | *.pytxcode 199 | pythontex-files-*/ 200 | 201 | # tcolorbox 202 | *.listing 203 | 204 | # thmtools 205 | *.loe 206 | 207 | # TikZ & PGF 208 | *.dpth 209 | *.md5 210 | *.auxlock 211 | 212 | # todonotes 213 | *.tdo 214 | 215 | # vhistory 216 | *.hst 217 | *.ver 218 | 219 | # easy-todo 220 | *.lod 221 | 222 | # xcolor 223 | *.xcp 224 | 225 | # xmpincl 226 | *.xmpi 227 | 228 | # xindy 229 | *.xdy 230 | 231 | # xypic precompiled matrices and outlines 232 | *.xyc 233 | *.xyd 234 | 235 | # endfloat 236 | *.ttt 237 | *.fff 238 | 239 | # Latexian 240 | TSWLatexianTemp* 241 | 242 | ## Editors: 243 | # WinEdt 244 | *.bak 245 | *.sav 246 | 247 | # Texpad 248 | .texpadtmp 249 | 250 | # LyX 251 | *.lyx~ 252 | 253 | # Kile 254 | *.backup 255 | 256 | # gummi 257 | .*.swp 258 | 259 | # KBibTeX 260 | *~[0-9]* 261 | 262 | # TeXnicCenter 263 | *.tps 264 | 265 | # auto folder when using emacs and auctex 266 | ./auto/* 267 | *.el 268 | 269 | # expex forward references with \gathertags 270 | *-tags.tex 271 | 272 | # standalone packages 273 | *.sta 274 | 275 | # Makeindex log files 276 | *.lpz 277 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /lean-tactics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madvorak/lean4-cheatsheet/6ff882bb743ddb52bd066d0e76054b819072d4cd/lean-tactics.pdf -------------------------------------------------------------------------------- /lean-tactics.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper]{article} 2 | \usepackage[T1]{fontenc} 3 | \usepackage[utf8]{inputenc} 4 | \usepackage[english]{babel} 5 | 6 | %\usepackage[urw-garamond,expert,uppercase=upright,greeklowercase=upright]{mathdesign} 7 | %\usepackage[osf,swashQ]{garamondx} 8 | % 9 | %\usepackage{microtype} 10 | 11 | \usepackage[textwidth=17cm, textheight=27cm]{geometry} 12 | \usepackage{booktabs, xspace} 13 | \usepackage{amsmath,amsfonts,amssymb} 14 | 15 | \newcommand{\lean}[1]{{\tt #1}} 16 | \newcommand{\nv}{\textit{new\_name} } 17 | \newcommand{\nom}{\textit{name} } 18 | \newcommand{\expr}{\textit{expr} } 19 | \newcommand{\proposition}{\textit{proposition} } 20 | \newcommand{\hyp}{\textit{hyp}\xspace} 21 | 22 | % Original authors (Lean 3 version): Patrick Massot and Johan Commelin 23 | % https://github.com/leanprover-community/lftcm2020/blob/master/lean-tactics.tex 24 | 25 | \usepackage{makecell} 26 | \usepackage{xcolor} 27 | 28 | \begin{document} 29 | \pagestyle{empty} 30 | \begin{center} 31 | \large\textsc{Lean 4 Cheatsheet} 32 | \end{center} 33 | 34 | In the following tables, 35 | \nom always refers to a name already known to Lean 36 | while \nv is a new name provided by the user; 37 | \expr means an expression, 38 | for example the name of an object in the context, 39 | an arithmetic expression that is a function of such objects, 40 | a hypothesis in the context, 41 | or a lemma applied to any of these; 42 | \proposition is an expression of the type \lean{Prop} (e.g. \lean{0 < x}) 43 | When one of these words appears twice in the same cell, 44 | the appearances do not designate the same name or 45 | the same expression. 46 | 47 | \begin{center} 48 | \setlength\tabcolsep{5mm} 49 | \def\arraystretch{1.3} 50 | \begin{tabular}{@{}lll@{}} 51 | \toprule 52 | Logical symbol & Appears in goal & Appears in hypothesis \\ 53 | \midrule 54 | $\exists$ (there exists) & \makecell[lt]{\lean{use} \expr} & \makecell[lt]{ 55 | \lean{obtain} $\langle$\nv, \nv$\!\!\rangle$ \lean{:=} \expr 56 | } \\ 57 | $\forall$ (for all) & \lean{intro} \nv & \lean{apply} \expr or \lean{specialize} \nom \expr \\ 58 | $\lnot$ (not) & \lean{intro} \nv & \lean{apply} \expr or \lean{specialize} \nom \expr \\ 59 | $\to$ (implies) & \lean{intro} \nv & \lean{apply} \expr or \lean{specialize} \nom \expr \\ 60 | $\leftrightarrow$ (if and only if)~~ & \lean{constructor} & \lean{rw [}\expr\lean{]} or \lean{rw [←} \expr\lean{]}\\ 61 | $\land$ (and) & \lean{constructor} & \makecell[lt]{ 62 | \lean{obtain} $\langle$\nv, \nv$\!\!\rangle$ \lean{:=} \expr 63 | } \\ 64 | $\lor$ (or) & \makecell[lt]{\lean{left} or \lean{right}} & \makecell[lt]{ 65 | \lean{cases} \expr \lean{with} \\ 66 | \lean{| inl }\nv \lean{=> ...} \\ 67 | \lean{| inr }\nv \lean{=> ...} 68 | } \\ 69 | \bottomrule 70 | \end{tabular} 71 | \end{center} 72 | 73 | \medskip 74 | In the left-hand column of the following table, 75 | the parts in parentheses are optional. 76 | The effect of these parts is also in parentheses in the right-hand column. 77 | 78 | \begin{center} 79 | \setlength\tabcolsep{5mm} 80 | \def\arraystretch{1.3} 81 | \begin{tabular}{@{}lp{10cm}@{}} 82 | \toprule 83 | Tactic & Effect \\ 84 | \midrule 85 | \lean{exact} \expr & the goal is satisfied by \expr \\ 86 | \lean{refine} \expr & similar to \lean{exact} but allows to leave any number of \lean{?\_} in the \expr to denote holes that will be filled later (creates goals) \\ 87 | \makecell[lt]{\lean{convert} \expr} & prove the goal by transforming it to an existing fact \expr and create goals for propositions used in the transformation that were not proved automatically \\ 88 | \makecell[lt]{\lean{convert\_to} \proposition} & transform the goal into the goal \proposition and create additional goals for propositions used in the transformation that were not proved automatically \\ 89 | \makecell[lt]{\lean{have} \nv : \proposition} & introduce a name \nv asserting that \proposition is true; at the same time, create and focus a goal for \proposition \\ 90 | \lean{unfold} \nom (\lean{at} \hyp) & unfold the definition \nom in the goal 91 | (or in the hypothesis \hyp) \\ 92 | \lean{rw [} (\lean{←}) \expr\lean{]} (\lean{at} \hyp) & in the goal (or in the 93 | hypothesis \hyp), replace (all occurrences of) the left-hand side 94 | (or the right-hand side, if \lean{←} is present) 95 | of the equality or equivalence \expr by its other side \\ 96 | \lean{rw [} \expr\lean{,} \expr\lean{,} \expr\lean{]} (\lean{at} \hyp) & do more rewrites in the given order (any number of \lean{←} possible) \\ 97 | \lean{calc} & start a proof by calculation (uses transitivity) \\ 98 | \lean{by\_cases} \nv : \proposition & split the proof into two cases 99 | depending on whether \proposition is true or false, 100 | using \nv as name for this hypothesis \\ 101 | \makecell[lt]{\lean{exfalso}} & apply the rule ``False implies anything'' a.k.a.~``ex falso quodlibet'' (replaces the current goal by \lean{False}) \\ 102 | \makecell[lt]{\lean{by\_contra} \nv} & start a proof by contradiction, 103 | using \nv as name for the hypothesis that is the negation of the goal \\ 104 | \makecell[lt]{\lean{push\_neg} (\lean{at} \hyp)} & push negations in the goal 105 | (or in the hypothesis \hyp); e.g.~change $\neg\;\forall$ x, \proposition to $\exists$ x, $\neg\;$\proposition \\ 106 | \makecell[lt]{\lean{linarith}} & prove the goal by a linear combination of hypotheses \\ 107 | \makecell[lt]{\lean{ring}} & prove the goal by combining the axioms of a (semi)ring \\ 108 | \makecell[lt]{\lean{simp} (\lean{at} \hyp)} & simplify the goal (or the hypothesis \hyp) using standard equalities \\ 109 | \makecell[lt]{\lean{exact?}} & search for a single existing lemma which closes the goal, also using local hypotheses \\ 110 | \makecell[lt]{\lean{apply?}} & search for lemmas whose conclusion matches the goal; suggest those that may be used with \lean{apply} or \lean{refine} \\ 111 | \makecell[lt]{\lean{aesop}} & try to solve the goal using magic \\ 112 | \bottomrule 113 | \end{tabular} 114 | \end{center} 115 | 116 | \end{document} 117 | --------------------------------------------------------------------------------