Skip to content

feat(Tactic/NormNum): norm_num extension for Squarefree - #44427

Open
xroblot wants to merge 12 commits into
leanprover-community:masterfrom
xroblot:norm-num-squarefree
Open

xroblot wants to merge 12 commits into
leanprover-community:masterfrom
xroblot:norm-num-squarefree

Conversation

@xroblot

@xroblot xroblot commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Add a norm_num extension deciding Squarefree n for numerals n in ℕ and ℤ.

If n is not squarefree, the proof uses a witness a > 1 with a * a ∣ n, found with Nat.minSqFac. If n is squarefree, the proof is a trial division of n by the odd numbers k = 3, 5, 7, …, keeping the invariant that every prime divisor of the cofactor is at least k.

This is adapted from the Mathlib 3 extension by Mario Carneiro (mathlib#11666), which was left commented out in Mathlib.Data.Nat.Squarefree during the port. This commented-out code is removed, and the corresponding tests are restored.

As for the Nat.Prime extension, the proof is a certificate rather than a kernel evaluation of Nat.minSqFac via Nat.squarefree_iff_minSqFac. The certificate is also faster to check, but, as for Nat.Prime, large numbers need a higher maxRecDepth.

Note. I have read and checked the ordinary Lean statements and their proofs, but I am not familiar with metaprogramming, so I cannot really vouch for the meta code itself, which was written with the help of an LLM (although it looks reasonable to me). A review by someone who is comfortable with norm_num extensions would be very welcome.

Created with Claude Code 🤖


@github-actions github-actions Bot added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

PR summary 82f6ec79af

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Tactic 1
Mathlib.Tactic.NormNum.Squarefree (new file) 1123

Declarations diff (regex)

+ evalIntSquarefree
+ evalNatSquarefree
+ evalSquarefreeLit
+ isInt_not_squarefree
+ isInt_squarefree
+ isNat_not_squarefree
+ isNat_squarefree
+ proveSquarefree
+ squarefree_of_odd
+ squarefree_two_mul
- squarefreeHelper_4
- squarefree_bit1
- squarefree_bit10
- squarefree_helper_0

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 82f6ec7).

  • +16 new declarations
  • −0 removed declarations
+Mathlib.Meta.NormNum.SquarefreeHelper
+Mathlib.Meta.NormNum.evalIntSquarefree
+Mathlib.Meta.NormNum.evalNatSquarefree
+Mathlib.Meta.NormNum.evalSquarefreeLit
+Mathlib.Meta.NormNum.isInt_not_squarefree
+Mathlib.Meta.NormNum.isInt_squarefree
+Mathlib.Meta.NormNum.isNat_not_squarefree
+Mathlib.Meta.NormNum.isNat_squarefree
+Mathlib.Meta.NormNum.not_squarefree_mul
+Mathlib.Meta.NormNum.proveSquarefree
+Mathlib.Meta.NormNum.proveSquarefreeHelper
+Mathlib.Meta.NormNum.squarefreeHelper_1
+Mathlib.Meta.NormNum.squarefreeHelper_2
+Mathlib.Meta.NormNum.squarefreeHelper_3
+Mathlib.Meta.NormNum.squarefree_of_odd
+Mathlib.Meta.NormNum.squarefree_two_mul

Decrease in strong tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (strong)
407 -1 porting notes
No changes to weak technical debt.

Current commit 82f6ec79af
Reference commit 13152f691c

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).

@grunweg grunweg added the t-meta Tactics, attributes or user commands label Oct 3, 2026
@xroblot xroblot added LLM-generated PRs with substantial input from LLMs - review accordingly WIP Work in progress and removed WIP Work in progress labels Oct 7, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@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 Nov 10, 2026
# Conflicts:
#	Mathlib/Data/Nat/Squarefree.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 Nov 12, 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 Nov 30, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@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 Dec 1, 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 t-meta Tactics, attributes or user commands tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants