Skip to content

fix(Tactic/Linarith): attribute linarith? suggestions to the correct hypotheses - #42588

Open
sharky564 wants to merge 7 commits into
leanprover-community:masterfrom
sharky564:SK_fix_linarith
Open

sharky564 wants to merge 7 commits into
leanprover-community:masterfrom
sharky564:SK_fix_linarith

Conversation

@sharky564

@sharky564 sharky564 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

runLinarith returned indices into the post-preprocessing fact list, but linarithUsedHyps applies them to the pre-preprocessing hypothesis list, so linarith? could suggest the wrong hypotheses or fail outright. Fixed this by tagging each fact with the indices of the original hypotheses it was derived from (TaggedProof), threaded through all preprocessors.


This addresses and closes the issue raised in #41471.

This was broken because the old code passed indices of a list around, without updating when the list was modified by preprocessor dropped, split or synthesised facts. No index-fix could recover this, besides just carrying through the index. Keeping the Origin a set rather than a single index is necessary since preprocessors can combine hypotheses. However this does mean the preprocessors no longer act on Exprs but rather TaggedProofs - I'm not the greatest fan of this, but I couldn't come up with an easy solution that preserved this behaviour. I've also provided additional tests which highlight the issues that would've previously arisen.

AI disclosure:

I did have AI assistance (Claude Opus/Fable) with this, but this was for me to learn more Lean syntax not typically seen in writing proofs. The diagnosis and idea for the solution was mine, and debugging and documentation was with AI assistance.

Open in Gitpod

@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

PR summary f610de377b

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ Origin
+ TaggedProof
+ partitionByType
+ proveFalseByLinarithTagged
- partitionByTypeIdx

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit f610de3).

  • +19 new declarations
  • −1 removed declarations
+Mathlib.Tactic.Linarith.Origin
+Mathlib.Tactic.Linarith.TaggedProof
+Mathlib.Tactic.Linarith.TaggedProof.casesOn
+Mathlib.Tactic.Linarith.TaggedProof.ctorIdx
+Mathlib.Tactic.Linarith.TaggedProof.mk
+Mathlib.Tactic.Linarith.TaggedProof.mk.inj
+Mathlib.Tactic.Linarith.TaggedProof.mk.injEq
+Mathlib.Tactic.Linarith.TaggedProof.mk.noConfusion
+Mathlib.Tactic.Linarith.TaggedProof.mk.sizeOf_spec
+Mathlib.Tactic.Linarith.TaggedProof.noConfusion
+Mathlib.Tactic.Linarith.TaggedProof.noConfusionType
+Mathlib.Tactic.Linarith.TaggedProof.origin
+Mathlib.Tactic.Linarith.TaggedProof.proof
+Mathlib.Tactic.Linarith.TaggedProof.rec
+Mathlib.Tactic.Linarith.TaggedProof.recOn
+Mathlib.Tactic.Linarith.instInhabitedTaggedProof
+Mathlib.Tactic.Linarith.instInhabitedTaggedProof.default
+Mathlib.Tactic.Linarith.partitionByType
-Mathlib.Tactic.Linarith.partitionByTypeIdx
+Mathlib.Tactic.Linarith.proveFalseByLinarithTagged

No changes to strong technical debt.
No changes to weak technical debt.

Current commit f610de377b
Reference commit c85646e3ac

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

✅ PR Title Formatted Correctly

The title of this PR has been updated to match our commit style conventions.
Thank you!

@github-actions github-actions Bot added the t-meta Tactics, attributes or user commands label Aug 9, 2026
@sharky564 sharky564 changed the title fix(Tactic/Linarith): attribute linarith? suggestions to the correct hypotheses. fix(Tactic/Linarith): attribute linarith? suggestions to the correct hypotheses Aug 9, 2026
@kbuzzard

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Aug 10, 2026 •

Copy link
Copy Markdown

Benchmark results for 433a341 against b2933a1 are in. No significant results found. @kbuzzard

  • ✅ build//instructions: -129.5G (-0.09%)

Small changes (3🟥)

  • 🟥 build/module/Mathlib.Tactic.Linarith.Datatypes//instructions: +440.1M (+6.05%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Frontend//instructions: +683.4M (+4.86%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Preprocessing//instructions: +665.9M (+5.32%)

@kbuzzard

Copy link
Copy Markdown
Member

!bench

@leanprover-radar

leanprover-radar commented Aug 26, 2026 •

Copy link
Copy Markdown

Benchmark results for 8660a75 against c20efc8 are in. No significant results found. @kbuzzard

  • ✅ build//instructions: -16.7G (-0.01%)

Small changes (5🟥)

  • 🟥 build/module/Aesop.Script.UScriptToSScript//instructions: +25.8M (+0.63%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Datatypes//instructions: +421.5M (+5.83%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Frontend//instructions: +682.3M (+4.93%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.NNRealPreprocessor//instructions: +290.2M (+5.70%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Preprocessing//instructions: +666.6M (+5.42%)

…ses. unLinarith returned indices into the post-preprocessing fact list, but linarithUsedHyps applies them to the pre-preprocessing hypothesis list, so linarith? could suggest the wrong hypotheses or fail outright. Fixed this by tagging each fact with the indices of the original hypotheses it was derived from (TaggedProof), threaded through all preprocessors.
@sharky564

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Sep 7, 2026 •

Copy link
Copy Markdown

Benchmark results for 3edbf81 against 5aedf73 are in. No significant results found. @sharky564

  • 🟥 build//instructions: +26.7G (+0.02%)

Small changes (4🟥)

  • 🟥 build/module/Mathlib.Tactic.Linarith.Datatypes//instructions: +425.5M (+5.95%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Frontend//instructions: +659.1M (+4.79%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.NNRealPreprocessor//instructions: +296.9M (+5.88%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Preprocessing//instructions: +623.2M (+5.10%)

@sharky564

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Sep 7, 2026 •

Copy link
Copy Markdown

Benchmark results for fa937c6 against 5aedf73 are in. No significant results found. @sharky564

  • ✅ build//instructions: -6.4G (-0.00%)

Small changes (2🟥)

  • 🟥 build/module/Mathlib.Tactic.Linarith.NNRealPreprocessor//instructions: +293.3M (+5.81%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Preprocessing//instructions: +631.1M (+5.17%)

@mathlib-triage mathlib-triage Bot assigned joneugster and unassigned kim-em Sep 19, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 22, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

# Conflicts:
#	Mathlib/Tactic/Linarith/Frontend.lean
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 1, 2026
@sharky564

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Oct 5, 2026 •

Copy link
Copy Markdown

Benchmark results for ff55115 against 726a7f1 are in. No significant results found. @sharky564

  • 🟥 build//instructions: +1.3G (+0.00%)

Small changes (3🟥)

  • 🟥 build/module/Mathlib.Tactic.Linarith.Datatypes//instructions: +192.4M (+2.89%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.NNRealPreprocessor//instructions: +278.6M (+6.17%)
  • 🟥 build/module/Mathlib.Tactic.Linarith.Preprocessing//instructions: +636.2M (+5.51%) (reduced significance based on *//lines)

@JovanGerb JovanGerb added the LLM-generated PRs with substantial input from LLMs - review accordingly label Oct 15, 2026
@joneugster joneugster removed their assignment Oct 16, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 23, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

# Conflicts:
#	Mathlib/Tactic/Linarith/Frontend.lean
#	MathlibTest/Tactic/Linarith/Basic.lean
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 24, 2026

@joneugster joneugster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

The overall strategy of tagging each expression with it's origin seems reasonable to me.

maintainer merge

@joneugster joneugster self-assigned this Nov 22, 2026
@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by joneugster.

@mathlib-triage mathlib-triage Bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM-generated PRs with substantial input from LLMs - review accordingly maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants