Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lean-dojo/LeanDojo-v2/llms.txt
Use this file to discover all available pages before exploring further.
BaseProver is the foundation every concrete prover in LeanDojo v2 builds on. It inherits from Pantograph’s Agent and Python’s ABC, providing a complete depth-first search loop, a default goal-prioritization heuristic, and a path-finding utility that extracts the shortest winning tactic chain from the search graph. Subclasses only need to implement two abstract methods — next_tactic() and generate_whole_proof() — while getting the entire search infrastructure for free.
Class
lean_dojo_v2.prover.
Constructor
BaseProver takes no parameters. Subclasses call super().__init__() to initialize the internal theorem state holder used during a search run.
Abstract Methods
next_tactic
search() on every step of the DFS loop.
The current Pantograph
GoalState object, which contains all open goals at this point in the proof.Zero-based index of the specific goal within
state.goals that the prover should target next.A Pantograph
Tactic string to apply to the goal, or None to signal that the prover has no suggestion and the search should backtrack.generate_whole_proof
theorem in a single inference call, without running the DFS search loop. This method is used by scripts that want a whole-proof output (e.g., for training data generation) rather than tactic-by-tactic search.
A
lean_dojo_v2.database.models.theorems.Theorem object whose theorem_statement field holds the full theorem … := by declaration.A Lean 4 proof string. The exact format depends on the concrete implementation; typically the tactic block body only (no
theorem header).Core Method: search
networkx search graph, and tactic bookkeeping.
Search algorithm
- Resolves the goal string: if
theoremis provided, it callsserver.env_inspect(theorem.full_name)to retrieve the pretty-printed goal. Otherwise it usesgoaldirectly. - Calls
server.goal_start(goal)to obtain the initialGoalState. - Runs a DFS loop for up to 100 steps, attempting up to 5 tactics per goal (
max_trials_per_goal=5) before backtracking. - Builds a
networkx.DiGraphwhere nodes areSearchStateobjects and edges carry the tactic string, goal ID, and step number. Failed tactics are stored as failure-labelled edges so the full search tree is preserved. - On success, calls
_find_shortest_path_to_solved()to extract the minimal tactic chain and returns it.
Parameters
A running Pantograph
Server instance. The server must be in automatic mode (server.is_automatic() == True).A raw Lean 4 goal string to prove, e.g.
"∀ {p q : Prop}, p ∧ q → q ∧ p". Exactly one of goal or theorem must be provided.A
Theorem object. When provided, the goal string is looked up automatically via server.env_inspect. Exactly one of goal or theorem must be provided.When
True, prints step-by-step progress including the current stack depth, the tactic being attempted, and the goal it targets.Return value
A Pantograph
SearchResult containing success (bool), steps (int), duration (float), and n_goals_root (int).The ordered list of tactics on the shortest path from the initial state to the solved state. Returns
None if the search failed.guidance
state. Higher weights cause the search to tackle that goal earlier in the DFS ordering.
Default implementation assigns 1.0 / (len(goal.variables) + 1) to each goal — goals with fewer bound variables are prioritized, as they tend to be simpler to close.
The current goal state whose goals should be scored.
A list of float weights, one per goal in
state.goals, in the same order.guidance() to implement custom heuristics such as learned value functions or embedding-based similarity scores.
_find_shortest_path_to_solved
search() when a proof is found. Uses networkx.shortest_path to walk from node 0 (the root) to solved_node_id through the search graph and collect the tactic sequence.
The directed graph built during the search run.
The node ID of the solved
SearchState.A list of
(node_id, tactic, goal_id) tuples representing each edge on the shortest path. Returns None if no path exists (logged as a warning).Example
The following example is adapted directly fromexamples/theorem_proving/generate_tactics.py:
Writing a Custom Prover
Any custom prover must inherit from
BaseProver and implement both next_tactic() and generate_whole_proof(). The search loop, graph construction, and path extraction are provided automatically — only the tactic generation logic needs to be supplied.See Also
- HFProver — local HuggingFace model tactic generator
- ExternalProver — HF Inference API tactic generator
- RetrievalProver — RAG-based tactic generator