The areas / V34. The tactics of Mathlib
Mathlib.Tactic.TacticAnalysis.Declarations
46 declarations. Mathlib docs · Source
Tactic linters
This file defines passes to run from the tactic analysis framework.
def Mathlib.TacticAnalysis.terminalReplacement E1 #
String →
String →
Lean.SyntaxNodeKind →
(Lean.Elab.ContextInfo →
Lean.Elab.TacticInfo → Lean.Syntax → Lean.Elab.Command.CommandElabM (Lean.TSyntax `tactic)) →
optParam Bool true →
optParam Bool false → optParam Bool false → optParam Float 1 → Mathlib.TacticAnalysis.Config
Define a pass that tries replacing one terminal tactic with another.
newTacticName is a human-readable name for the tactic, for example "linarith".
This can be used to group messages together, so that ring, ring_nf, ring1, ...
all produce the same message.
oldTacticKind is the SyntaxNodeKind for the tactic's main parser,
for example Mathlib.Tactic.linarith.
newTactic stx goal selects the new tactic to try, which may depend on the old tactic invocation
in stx and the current goal.
def Mathlib.TacticAnalysis.grindReplacementWith E1 #
String →
Lean.SyntaxNodeKind →
(optParam (Lean.Syntax → Option (Lean.Syntax.TSepArray `term ",")) fun x ↦ none) →
optParam Bool true → optParam Bool false → optParam Bool false → optParam Float 1 → Mathlib.TacticAnalysis.Config
Define a pass that tries replacing a specific tactic with grind.
tacticName is a human-readable name for the tactic, for example "linarith".
This can be used to group messages together, so that ring, ring_nf, ring1, ...
all produce the same message.
tacticKind is the SyntaxNodeKind for the tactic's main parser,
for example Mathlib.Tactic.linarith.
If extractArgs is provided, it extracts term arguments from the original tactic
(e.g., linarith [X, Y]) and passes them to grind (e.g., grind [X, Y]).
Local hypotheses are filtered out since grind uses them automatically.
opaque linter.tacticAnalysis.regressions.linarithToGrind E1 #
Lean.Option Bool
Debug grind by identifying places where it does not yet supersede linarith.
def linarithToGrindRegressions E1 #
Mathlib.TacticAnalysis.Config
Debug grind by identifying places where it does not yet supersede linarith.
opaque linter.tacticAnalysis.regressions.ringToGrind E1 #
Lean.Option Bool
Debug grind by identifying places where it does not yet supersede ring.
def ringToGrindRegressions E1 #
Mathlib.TacticAnalysis.Config
Debug grind by identifying places where it does not yet supersede ring.
opaque linter.tacticAnalysis.regressions.omegaToLia E1 #
Lean.Option Bool
Debug lia by identifying places where it does not yet supersede omega.
def omegaToLiaRegressions E1 #
Mathlib.TacticAnalysis.Config
Debug lia by identifying places where it does not yet supersede omega.
opaque linter.tacticAnalysis.omegaToLia E1 #
Lean.Option Bool
Report places where omega can be replaced by lia.
def omegaToLia E1 #
Mathlib.TacticAnalysis.Config
Report places where omega can be replaced by lia.
opaque linter.tacticAnalysis.rwaSuggestion E1 #
Lean.Option Bool
Suggest rwa for rw followed by assumption.
def Mathlib.TacticAnalysis.rwaSuggestion E1 #
Mathlib.TacticAnalysis.Config
Suggest rwa for rw followed by assumption.
opaque linter.tacticAnalysis.rwMerge E1 #
Lean.Option Bool
Suggest merging two adjacent rw tactics if that also solves the goal.
def Mathlib.TacticAnalysis.rwMerge E1 #
Mathlib.TacticAnalysis.Config
Suggest merging two adjacent rw tactics if that also solves the goal.
opaque linter.tacticAnalysis.mergeWithGrind E1 #
Lean.Option Bool
Suggest merging tac; grind into just grind if that also solves the goal.
def Mathlib.TacticAnalysis.mergeWithGrind E1 #
Mathlib.TacticAnalysis.Config
Suggest merging tac; grind into just grind if that also solves the goal.
opaque linter.tacticAnalysis.terminalToGrind E1 #
Lean.Option Bool
Suggest replacing a sequence of tactics with grind if that also solves the goal.
def Mathlib.TacticAnalysis.terminalToGrind E1 #
Mathlib.TacticAnalysis.Config
Suggest replacing a sequence of tactics with grind if that also solves the goal.
opaque linter.tacticAnalysis.tryAtEachStep.fraction E1 #
Lean.Option ℕ
When running the "tryAtEachStep" tactic analysis linters,
only run on a fraction 1/n of the goals found in the library.
This is useful for running quick benchmarks.
opaque linter.tacticAnalysis.tryAtEachStep.showTiming E1 #
Lean.Option Bool
Whether to show timing information in "tryAtEachStep" tactic analysis output.
When true (default), messages include elapsed time like (23ms).
Set to false in tests to avoid non-deterministic output.
opaque linter.tacticAnalysis.tryAtEachStep.selfReplacements E1 #
Lean.Option Bool
Whether to report when a tactic can be replaced with itself.
When true (default), all successful replacements are reported, including when the suggested tactic matches the existing proof. When false, self-replacements are suppressed.
def Mathlib.TacticAnalysis.tryAtEachStepCore E1 #
(Lean.Syntax → Lean.MVarId → Lean.Elab.Command.CommandElabM (Lean.TSyntax `tactic)) →
optParam (Option String) none → Mathlib.TacticAnalysis.Config
Run a tactic at each proof step, with optional timing.
label is an optional human-readable name for output. If none, the tactic syntax is used.
Reports elapsed time in milliseconds for each successful replacement
when linter.tacticAnalysis.tryAtEachStep.showTiming is true.
When linter.tacticAnalysis.tryAtEachStep.selfReplacements is false, cases where
the suggested tactic matches the existing proof are suppressed.
def Mathlib.TacticAnalysis.tryAtEachStep E1 #
(Lean.Syntax → Lean.MVarId → Lean.Elab.Command.CommandElabM (Lean.TSyntax `tactic)) → Mathlib.TacticAnalysis.Config
Run a tactic at each proof step. See tryAtEachStepCore for details.
def Mathlib.TacticAnalysis.tryAtEachStepFromStrings E1 #
String → String → Mathlib.TacticAnalysis.Config
Run a tactic (given as a string) at each proof step, with optional timing.
label is the human-readable name shown in output (e.g., "grind").
tacticStr is the tactic syntax as a string (e.g., "grind").
Tactic sequences like "simp; grind" are also supported.
Reports elapsed time in milliseconds for each successful replacement
when linter.tacticAnalysis.tryAtEachStep.showTiming is true.
To limit tactic runtime, use set_option maxHeartbeats N in the build command.
When linter.tacticAnalysis.tryAtEachStep.selfReplacements is false, cases where
the suggested tactic matches the existing proof are suppressed.
def Mathlib.TacticAnalysis.tryAtEachStepFromEnvImpl E1 #
Mathlib.TacticAnalysis.Config
Run a custom tactic at each proof step, configured via environment variables.
Reads from environment variables:
TRY_AT_EACH_STEP_TACTIC: Tactic syntax to try (e.g., "grind") - requiredTRY_AT_EACH_STEP_LABEL: Human-readable label for output (optional, defaults to tactic)
If TRY_AT_EACH_STEP_TACTIC is missing, this linter does nothing.
To enable, add to the mathlibOnlyLinters array in lakefile.lean:
⟨`linter.tacticAnalysis.tryAtEachStepFromEnv, true⟩,
Then run with the environment variable:
TRY_AT_EACH_STEP_TACTIC="grind" lake build Mathlib
This generic entry point is used by the hammer-bench benchmarking tool (https://github.com/leanprover-community/hammer-bench) to test arbitrary tactics without requiring Mathlib code changes for each new tactic variant.
opaque linter.tacticAnalysis.tryAtEachStepGrind E1 #
Lean.Option Bool
Run grind at every step in proofs, reporting where it succeeds.
def tryAtEachStepGrind E1 #
Mathlib.TacticAnalysis.Config
Run grind at every step in proofs, reporting where it succeeds.
opaque linter.tacticAnalysis.tryAtEachStepSimpAll E1 #
Lean.Option Bool
Run simp_all at every step in proofs, reporting where it succeeds.
def tryAtEachStepSimpAll E1 #
Mathlib.TacticAnalysis.Config
Run simp_all at every step in proofs, reporting where it succeeds.
opaque linter.tacticAnalysis.tryAtEachStepAesop E1 #
Lean.Option Bool
Run aesop at every step in proofs, reporting where it succeeds.
def tryAtEachStepAesop E1 #
Mathlib.TacticAnalysis.Config
Run aesop at every step in proofs, reporting where it succeeds.
opaque linter.tacticAnalysis.tryAtEachStepGrindSuggestions E1 #
Lean.Option Bool
Run grind +suggestions at every step in proofs, reporting where it succeeds.
def tryAtEachStepGrindSuggestions E1 #
Mathlib.TacticAnalysis.Config
Run grind +suggestions at every step in proofs, reporting where it succeeds.
opaque linter.tacticAnalysis.tryAtEachStepSimpAllSuggestions E1 #
Lean.Option Bool
Run simp_all? +suggestions at every step in proofs, reporting where it succeeds.
def tryAtEachStepSimpAllSuggestions E1 #
Mathlib.TacticAnalysis.Config
Run simp_all? +suggestions at every step in proofs, reporting where it succeeds.
opaque linter.tacticAnalysis.tryAtEachStepFromEnv E1 #
Lean.Option Bool
Run a custom tactic at every step in proofs, configured via environment variables.
Set TRY_AT_EACH_STEP_TACTIC to the tactic syntax to try (required).
Set TRY_AT_EACH_STEP_LABEL to the label for output messages (optional, defaults to tactic).
def tryAtEachStepFromEnv E1 #
Mathlib.TacticAnalysis.Config
Run a custom tactic at every step in proofs, configured via environment variables.
Set TRY_AT_EACH_STEP_TACTIC to the tactic syntax to try (required).
Set TRY_AT_EACH_STEP_LABEL to the label for output messages (optional, defaults to tactic).
opaque linter.tacticAnalysis.introMerge E1 #
Lean.Option Bool
Suggest merging adjacent intro-like tactics whose effect is equivalent to a single intro.
def Mathlib.TacticAnalysis.introMerge E1 #
Mathlib.TacticAnalysis.Config
Suggest merging adjacent intro-like tactics whose effect is equivalent to a single intro.
def Mathlib.TacticAnalysis.verifyTryThisSuggestions E1 #
(Lean.Syntax → Lean.MVarId → Lean.Elab.Command.CommandElabM (Option (Lean.TSyntax `tactic))) →
String → Mathlib.TacticAnalysis.Config
Verify that TryThis suggestions from a tactic actually work.
Runs the given tactic at each proof step, captures any "Try this:" suggestions, then re-runs the suggested tactic to verify it succeeds. Only reports failures (where the suggestion doesn't close the goal).
opaque linter.tacticAnalysis.verifyGrind E1 #
Lean.Option Bool
Verify that grind? suggestions actually work.
def verifyGrind E1 #
Mathlib.TacticAnalysis.Config
Verify that grind? suggestions actually work.
opaque linter.tacticAnalysis.verifyGrindSuggestions E1 #
Lean.Option Bool
Verify that grind? +suggestions suggestions actually work.
def verifyGrindSuggestions E1 #
Mathlib.TacticAnalysis.Config
Verify that grind? +suggestions suggestions actually work.
opaque linter.tacticAnalysis.verifyGrindOnly E1 #
Lean.Option Bool
Verify that replacing grind with grind? produces a valid grind only suggestion.
def verifyGrindOnly E1 #
Mathlib.TacticAnalysis.Config
Verify that replacing grind with grind? produces a valid grind only suggestion.