aesop - Automated Proof Search
aesop is a proof search tactic from Mathlib. It explores small proof steps such as introductions, case splits, simplifications, and lemma applications to close goals automatically.
aesop lives in Mathlib. Use import Mathlib.Tactic before calling it.Basic Usage
Use aesop as a finishing tactic after you introduce variables or simplify the goal. It is most effective when the necessary facts are already in the local context.
1import Mathlib.Tactic23example (P Q R : Prop) (hP : P) (hPQ : P -> Q) (hQR : Q -> R) : R := by4 aesop56example (P Q R : Prop) : (P -> Q) -> (Q -> R) -> P -> R := by7 intro hPQ hQR hP8 aesop910example (P Q : Prop) (h : P \/ Q) (hp : P -> Q) : Q := by11 aesopWhen aesop Works Best
Think of aesop as a searcher for small logical steps. It performs best when a short chain of applications and simplifications can finish the goal.
- The goal is propositional and does not require heavy computation.
- The context already contains the lemmas or hypotheses you need.
- The remaining proof is a short chain of introductions and applications.
What aesop Tries
At a high level, aesop builds a search tree. It introduces hypotheses, splits cases, runs simplification, and applies lemmas it considers safe. If a branch fails, it backtracks and tries a different path until the goal is solved or the search budget runs out.
1import Mathlib.Tactic23example (n : Nat) : n + 0 = n := by4 aesop56example (h : P /\ Q) : Q := by7 aesopaesop is best used as a finishing tactic after you set up the right facts with intro, have, and simp.Common Workflows
Finish After Setup
Open the goal with a few explicit steps, then let aesopclose the remaining details.
1import Mathlib.Tactic23example (P Q R : Prop) : (P -> Q) -> (Q -> R) -> P -> R := by4 intro hPQ hQR hP5 aesopSplit and Solve
If you already know the main case split, do it yourself and letaesop finish each branch.
1import Mathlib.Tactic23example (P Q R : Prop) (h : P \/ Q) (hP : P -> R) (hQ : Q -> R) : R := by4 cases h with5 | inl hp => aesop6 | inr hq => aesopGuiding the Search
If aesop does not solve the goal, simplify first, add the missing lemma to the context, or break the goal into smaller parts. The clearer the proof state, the easier the search.
1import Mathlib.Tactic23example (n : Nat) (h : n = 3) : n + 1 = 4 := by4 simp [h]5 aesopRegistering aesop Rules
If you use a lemma frequently, register it so aesopcan apply it automatically.
1import Mathlib.Tactic23def Even (n : Nat) : Prop := Exists fun k => n = 2 * k45@[aesop]6lemma even_zero : Even 0 := by7 exact Exists.intro 0 (by simp)89example : Even 0 := by10 aesopaesop? for Proof Scripts
Use aesop? when you want a concrete proof script. It runs the same search and prints a suggestion you can paste into your file.
1import Mathlib.Tactic23example (P Q R : Prop) (hP : P) (hPQ : P -> Q) (hQR : Q -> R) : R := by4 aesop?5 -- The messages window shows a suggested tactic script.Set up a short proof and let aesop finish it.
1import Mathlib.Tactic23example (P Q R : Prop) (hP : P) (hPQ : P → Q) (hQR : Q → R) : R := by4 aesopDeep Dive: When Not to Use aesop
aesop can be slower on large goals or when the search space explodes. In those cases, prefer targeted tactics likerw, simp, linarith, or omega.
If aesop feels slow, reduce the goal first or add a missing lemma so the search has fewer branches.