Zulip Chat Archive
Stream: general
Topic: tactic cheat sheet examples
Mark Ettinger (Sep 29 2025 at 18:11):
As I learn Lean, I've found this tactic cheatsheet very helpful: https://raw.githubusercontent.com/fpvandoorn/LeanCourse24/master/lean-tactics.pdf
However it would be super useful if there were a single document ( in contrast to spread out over the standard intro texts) which showed the use of each of these tactics in an example. Does such a thing exist already (or similar)?
Kevin Buzzard (Sep 29 2025 at 18:21):
The course notes for Imperial's Lean course https://b-mehta.github.io/formalising-mathematics-notes/Part_2/Part_2.html have tactic documentation written for mathematician beginners.
Anthony Wang (Sep 29 2025 at 19:42):
Mark Ettinger said:
As I learn Lean, I've found this tactic cheatsheet very helpful: https://raw.githubusercontent.com/fpvandoorn/LeanCourse24/master/lean-tactics.pdf
By the way, I think the canonical URL for that cheatsheet is https://leanprover-community.github.io/papers/lean-tactics.pdf which is slightly more up-to-date.
Martin Dvořák (Sep 29 2025 at 19:45):
I am fascinated by how many versions this document has!
Jovan Gerbscheid (Sep 29 2025 at 23:12):
Maybe an entry on grw should be added :)
Asei Inoue (Sep 30 2025 at 00:45):
How about https://lean-ja.github.io/lean-by-example/ ? (Japanese only)
Aaron Liu (Sep 30 2025 at 00:47):
unfortunately not everyone knows Japanese
Aaron Liu (Sep 30 2025 at 00:48):
This seems like a whole book not just a tactic cheat sheet
Floris van Doorn (Sep 30 2025 at 13:44):
Jovan Gerbscheid said:
Maybe an entry on
grwshould be added :)
leanprover-community/leanprover-community.github.io#692
Jovan Gerbscheid (Sep 30 2025 at 14:00):
Should push_neg be entirely removed from the list?
Relatedly, should push_neg be deprecated from Mathlib in favor of push ¬ _?
Floris van Doorn (Sep 30 2025 at 14:04):
I don't want the cheat sheet to be comprehensive (that would be too much), so I'm happy to leave it off. And I think knowing about push/pull is much nicer for new(ish) people to Lean, especially once we have tagged a whole lot more push-lemmas.
Floris van Doorn (Sep 30 2025 at 14:05):
I don't have a strong opinion of deprecating push_neg from Mathlib. Maybe not now, but maybe later, once push/pull is widely used for other operations?
Patrick Massot (Sep 30 2025 at 14:24):
I’m in favor of not having many ways of doing the same thing. If push ¬ is equivalent (or better) than push_neg then we can deprecate push_neg in Mathlib (especially if we can do that without triggering deprecation warning in projects depending on Mathlib).
Jovan Gerbscheid (Sep 30 2025 at 15:03):
The current syntax is push ¬ _ or push Not (and these are equivalent to push_neg). Do you think it would be good to have a macro to allow writing push ¬?
Patrick Massot (Sep 30 2025 at 15:27):
Sorry, that was a typo. push Not is fine.
Sorrachai Yingchareonthawornchai (Sep 30 2025 at 21:28):
Jovan Gerbscheid said:
Maybe an entry on
grwshould be added :)
Also, maybe an entry on suffices and wlog can be added?
Mark Ettinger (Sep 30 2025 at 23:24):
@Kevin Buzzard Thanks for these notes. I feel they fill an important gap in the ramp-up docs, especially the tactics section but also the tips section.
Jovan Gerbscheid (Oct 16 2025 at 14:57):
Should tauto be removed from the cheat sheet now that grind supersedes it?
Jovan Gerbscheid (Oct 16 2025 at 15:00):
Also I was surprised that the sheet contains pick_goal n but not on_goal n =>. Isn't on_goal is the preferred form?
Floris van Doorn (Oct 16 2025 at 15:45):
Jovan Gerbscheid said:
Should
tautobe removed from the cheat sheet now thatgrindsupersedes it?
If grind is now preferred, I'm happy to remove tauto
Jovan Gerbscheid said:
Also I was surprised that the sheet contains
pick_goal nbut noton_goal n =>. Isn'ton_goalis the preferred form?
I'm happy to change this!
Please PR fixes.
Kim Morrison (Oct 16 2025 at 22:07):
Floris van Doorn said:
If
grindis now preferred, I'm happy to removetauto
No, there are many places where tauto can not be replaced with grind (yet? :-). Perhaps you are thinking of cc.
Kim Morrison (Oct 16 2025 at 22:16):
#30619 adds the (off by default) linters:
linter.tacticAnalysis.tautoToGrindwhich reports all uses oftautothat can be replaced bygrindlinter.tacticAnalysis.regressions.tautoToGrindwhich reports all uses oftautothat can not be replaced bygrind
Kim Morrison (Oct 16 2025 at 22:19):
(tauto, or rather its constituent parts, e.g. assumption, contradiction, solve_by_elim, rfl, and constructorMatching is much more willing to unfold definitions than grind is)
Jovan Gerbscheid (Oct 31 2025 at 12:25):
I also noticed that contrapose/contrapose! isn't on the cheat sheet. (nor is absurd, which can be used together with exfalso to emulate contrapose)
Mirek Olšák (Oct 31 2025 at 13:14):
It is hard to be comprehensive, and to select representative tactics... this is my attempt
https://git.olsak.net/mirek/lean-teaching/src/branch/master/LeanTeaching/Lecture4_TacticZoo.lean
Mirek Olšák (Oct 31 2025 at 16:32):
If we could make the list of tactics produced by this meta-code hoverable, it would be nice! I have not yet figured out if it is possible to give MessageData a custom hover, or I need to fit into the Lean data categories (maybe DocElabInfo?)
import Batteries
open Lean Meta Elab Tactic Command in
def listStx (stx : Name) : CommandElabM Unit := do
let cat := (Parser.parserExtension.getState (← getEnv)).categories.find! stx
let env ← getEnv
let mut tactics := #[]
for (k, _) in cat.kinds do
if let some tk := do
Batteries.Tactic.getHeadTk (← (← env.find? k).value?) then
let tk := tk.trim
tactics := tactics.push tk
tactics := tactics.qsort
logInfo <| "\n".intercalate tactics.toList
run_cmd listStx `tactic
Damiano Testa (Oct 31 2025 at 16:50):
It seems like #help tactic could be useful.
Mirek Olšák (Oct 31 2025 at 16:57):
I know #help tactic but that is extremely messy. I want only the list, but see what the tactic does once I hover over it.
Mirek Olšák (Oct 31 2025 at 17:03):
Ideally with correctly displayed markdown... :slight_smile: am I asking too much?
Damiano Testa (Oct 31 2025 at 17:05):
If you are happy to hover over the parser name, you can get the ConstantInfo from the environment, but instead of the value, extract the name. Then MessageData.ofConstName will print the parser name with the hover.
Mirek Olšák (Oct 31 2025 at 17:05):
Actually, you are right -- #help tactic has the syntax element hoverable... so it might be possible to replace the string inside
Mirek Olšák (Oct 31 2025 at 17:07):
I would prefer if it was clean -- without parser names (users do not care about them).
Mirek Olšák (Oct 31 2025 at 17:08):
But thanks, I have another direction to investigate...
Mirek Olšák (Oct 31 2025 at 19:20):
Here we go :tada: List tactics
François G. Dorais (Oct 31 2025 at 21:14):
The #help command suite could use some sprucing up: PRs welcome!
Mirek Olšák (Oct 31 2025 at 22:33):
To make it a library version, I would be happy to remove the Lean.ParserDescr header, but I am not sure if it is feasible...
Asei Inoue (Oct 31 2025 at 23:10):
you may want https://seasawher.github.io/mathlib4-help/ ?
Last updated: Dec 20 2025 at 21:32 UTC