Repository navigation
factorization(n) and primefactors(n): a prime factorisation as a node - #2471
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2471 +/- ##
==========================================
- Coverage 86.97% 86.96% -0.01%
==========================================
Files 324 324
Lines 71849 71984 +135
Branches 20955 20977 +22
==========================================
+ Hits 62492 62603 +111
- Misses 5024 5044 +20
- Partials 4333 4337 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…tors(n)
factorization(n) is the map from each prime to its exponent in n,
mathlib's Nat.factorization: a node of its own, PrimeFactorizationf, that
stays as written at a positive integer and holds the map in Factors,
computed once by the factoriser MathS.NumberTheory.Factorize uses. It is not
the held product 2^3 * 3^2 * 5, which evaluates to 360, and not the number,
so factorization(360) = 360 is left undecided. primefactors(n), the set
node PrimeFactorsf, is its support and lists { 2, 3, 5 }. With valuation
(#1453) and the product over a set (#2467),
product(p ^ valuation(n, p), p in primefactors(n)) is n, measured at 1, a
prime, 360, 2^64 + 1 and 3^40 * 7^3.
Both are NaN at a number that is not a positive integer, as primenu and
the other functions of a factorisation are: 0 has none and a negative
integer is -1 times one (#2466 refuses both in Factorize). A symbol, or an
integer with a factor neither proven prime nor split, is left as written.
Codomain Any, as a matrix, a transpose and a set have, being no number.
Printed factorization(360), and 2^{3} \cdot 3^{2} \cdot 5 in LaTeX once
the map is known (1 for factorization(1)); primefactors(n) prints as
written. SymPy: sympy.factorint(n), the dict that is the map, and
FiniteSet(*primefactors(n)); refused for an argument with a variable,
where SymPy raises. Both compilers refuse each, naming it, since
evaluating gives no number to compile. factorize(360) is still refused,
and its message now names factorization(n).
Grammar: two rules, factorization( and primefactors(, after valuation(;
the factorize( action's message. The unmodified grammar regenerated to an
empty diff first.
Part of #2449
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Rebased onto 73b77bf after #2470 (shader source) merged. Both PRs had changed |
Rafael-SOWNet
force-pushed
the
feature/factorization-node
branch
from
November 16, 2026 01:39
22f4356 to
4e10913
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The second half of #2449, built from the design note (the first half, a product over a set, is #2467).
factorization(n)is the prime factorisation of a positive integer: the finitely supported map from each prime to its exponent inn, mathlib'sNat.factorization. It is its own node,PrimeFactorizationf, rather than a held product, sinceSimplifywould fold2^3 * 3^2 * 5back to360and a factorisation is not the number; its pairs are cached inFactors, computed by the same factoriserFactorizeuses (Pollard rho, past the longs).primefactors(n)is its support, a finite set.factorization(360)factorization * 360factorization(360),Factors= (2,3), (3,2), (5,1)factorization(1)/(97)/(2^64+1)factorization(0),(-12),(1/2)0, productsNaN, asprimenu,primeomega,mobiusanddivisorsigmagive at 0 and −12factorization(n)n in ZZ+primefactors(360)/(1)primefactors * 360{ 2, 3, 5 }/{ }product(p ^ valuation(n, p), p in primefactors(n))n, at 1, 2, 97, 360, 1024, 9699690, 2^64+1 and 3^40·7^3factorize(360)factorization(n)Anyfor both, as matrices,transpose,cross, sets andpowersethave: no domain of numbers.MathS.NumberTheory.Factorization(Entity)andMathS.NumberTheory.PrimeFactors(Entity).2^{3} \cdot 3^{2} \cdot 5(1for the empty map,\operatorname{factorization}(n)for a symbol). CSharpMath reads that back as the number 360, not as the node: that is the notation, since a factorisation written as a product cannot be told from the product, so there is nothing for CSharpMath to change.sympy.factorint(n), the dict, which is the map itself, andsympy.FiniteSet(*sympy.primefactors(n)); refused with a variable, where SymPy raises.'valuation(', and'factorize('changes only its message.Recorded in
BREAKING-CHANGES.md(Was measured on the 2.7.0 package).PrimeFactorizationNodeTest: 46 cases. Full check: 20,574 unit tests, 0 failed; MCP 448, Terminal 69, F# 134, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines.Closes #2449.
🤖 Generated with Claude Code