Repository navigation
prime(n) is the n-th prime, and valuation(n, p) the p-adic valuation - #1453
Merged
Merged
Conversation
A function of its own -- PP carries no order -- with SymPy's spelling: prime(1) is 2, prime(25) is 97, NaN off the positive whole numbers, and left as written for a symbol or an index past a million, where the table would be built towards it. Its codomain is Domain.Prime. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
The exponent of the prime p in n: valuation(12, 2) is 2, valuation(12, 5) is 0, +oo at n = 0 by the convention, NaN where p is not prime. Sullivan and Mackey's Ex 5.5.1 writes n = 2^m (2 l + 1) with m the 2-adic valuation, and n = product(p^valuation(n, p), p in PP) is what a factorisation says over the set of primes. v_p(n) in LaTeX, sympy.multiplicity in SymPy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Closed
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 16, 2026
…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>
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 16, 2026
…tors(n) (#2471) 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>
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 two functions #1450's questions come down to, beside the set #1452 added.
prime(n)— then-th prime, SymPy's spelling:prime(1)is2,prime(25)is97,prime(1000)is7919;NaNoff the positive whole numbers; left as written for a symbol or an index past a million, where the table would be built towards it. A function of its own rather than an operation onPP, which carries no order; its codomain isDomain.Prime. The table behind it,Primes.GetPrime, existed already for the continued-fraction code — this exposes it.\operatorname{prime}(n)in LaTeX,sympy.prime(n).valuation(n, p)— thep-adic valuation, the exponent of the primepinn:valuation(12, 2)is2,valuation(12, 5)is0,valuation(-40, 2)is3,+ooatn = 0by the convention every text uses,NaNwherepis not prime. Sullivan and Mackey's Ex 5.5.1 writesn = 2^m (2 l + 1)withmthe 2-adic valuation, andn = product(p^valuation(n, p), p in PP)is what a factorisation says over the set — theproduct(f, p in S)binder itself is the multiplicative twin of #1435'sunionand waits for #1019's indexed-family convention.v_p(n)in LaTeX,sympy.multiplicity(p, n).Both are nodes through every pipeline (
WritingARule.md's buildable count goes 48 → 50), with 22 rows inPrimeSetTest,Syntax.mdandBREAKING-CHANGES.md. Full suite 12499 passed; the allocation gate passes on all 19 gated benchmarks —ParseHard+0.7%, which is #1441's ~12 KB per'name('token, twice.Part of #1450.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura