Skip to content

prime(n) is the n-th prime, and valuation(n, p) the p-adic valuation - #1453

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
nth-prime
Sep 21, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
nth-prime

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

The two functions #1450's questions come down to, beside the set #1452 added.

prime(n) — the n-th prime, SymPy's spelling: prime(1) is 2, prime(25) is 97, prime(1000) is 7919; NaN off 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 on PP, which carries no order; its codomain is Domain.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) — the p-adic valuation, the exponent of the prime p in n: valuation(12, 2) is 2, valuation(12, 5) is 0, valuation(-40, 2) is 3, +oo at n = 0 by the convention every text uses, 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 — the product(f, p in S) binder itself is the multiplicative twin of #1435's union and 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 in PrimeSetTest, Syntax.md and BREAKING-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

Rafael-SOWNet and others added 2 commits September 21, 2026 16:27
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
@Rafael-SOWNet
Rafael-SOWNet merged commit f050d4e into master Sep 21, 2026
32 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the nth-prime branch September 21, 2026 16:59
@Rafael-SOWNet Rafael-SOWNet mentioned this pull request Nov 15, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant