Repository navigation
A product over a set: product(f, x in S) - #2467
Merged
Merged
Conversation
product took a range and nothing else, so product(f, x in S) threw an arity
error where sum(f, x in S) worked. ProductOverSetf is the sum over a set's
counterpart: the variable is bound over the factor and the set (FreeVariables,
Substitute, DomainCondition scoping), it prints product(f, x in S) and
\prod_{x \in S} f, MathS.Product(f, x, S) builds it, and the compilers refuse
it as they refuse the sum. Its factors are multiplied out exactly where the sum
adds its terms up -- a listed set of numbers distinct by value, the roots of a
polynomial the solver writes all of, numerically the Durand-Kerner roots, and
the interval evaluator's enclosed roots -- and it is left as written where the
sum is. The empty product is 1. SymPy export as a Mul over the listed members or
the CRootOf roots of the square-free part. product(p, p in PP /\ [1; 30]) is
6469693230 and product(1 - 1/p^2, p in {2, 3, 5}) is 16/25.
The derivative is the product rule over the set,
sum(f'(m) product(f(n), n in S \ { m }), m in S), which holds where a factor
is zero. For that to evaluate over roots, a set of roots with listed members
taken out is now read by the sum and the product alike: a member taken out is
found as written, a number whose value is none of them takes nothing out, and
anything else is undecided. That changes sum(x, x in { w : w^2 - 2 = 0 } \
{ sqrt(2) }) from unevaluated to -sqrt(2); recorded in BREAKING-CHANGES.md
with the parse error that became an answer, as #2455 recorded its refusals.
Grammar: one action, the product( rule, takes the sum( rule's two-argument
branch; the unmodified grammar regenerated to an empty diff first.
Part of #2449
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2467 +/- ##
==========================================
- Coverage 86.96% 86.92% -0.04%
==========================================
Files 320 320
Lines 71398 71457 +59
Branches 20847 20864 +17
==========================================
+ Hits 62090 62116 +26
- Misses 4992 5020 +28
- Partials 4316 4321 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
product(f, p in S)threw an arity error whilesum(f, k in S)worked. It is now the nodeProductOverSetf(Expression, Var, Over), built the waySumOverSetfwas in #1624, and it multiplies its factors exactly where the sum adds its terms, so it is left unevaluated wherever the sum is.product(p, p in PP /\ [1; 30])6469693230(29#)product(1 - 1/p^2, p in {2, 3, 5})16/25product(x, x in {})1, as the empty sum is0product(w, w in {w : w^2 - 3 = 0})-3product(w, w in {w : (w-1)^2 (w-2) = 0})2: a set, so the double root counts onceproduct(w, w in {w : w^5+w+3=0}),.Evaled-3, over the numeric rootsproduct(x, x in {a, b}), overZZ,PP,[0; 1]product(w+y, w in {w : w^3+w+1=0})iny, aty = 14Wired as the sum over a set is: the binding (
Binding.Of(Var).In(Over), soFreeVariables,DomainConditionandSubstituteread the index as bound), the codomain, JSON serialisation, the sort hash, the interval evaluator, printing (product(f, x in S),\prod_{x \in S} f, with a round-trip test), a compile refusal naming it, SymPy export (asympy.Mulover the members or overall_roots(), run in SymPy 1.14), andMathS.Product(f, x, S). The grammar changes by one action:'product('takes the same two-argument branch as'sum('.The derivative is the product rule,
sum(f'(m) product(f(n), n in S \ {m}), m in S), which holds where a factor is zero. To evaluate it over polynomial roots,S \ {m}is now read from a set of roots: a member taken out is found as written, a number equal to none takes nothing out, and anything else stays undecided. That also changes one sum, silently:sum(x, x in {w : w^2-2=0} \ {sqrt(2)})was unevaluated and is now-sqrt(2). Both are recorded inBREAKING-CHANGES.md.The other half of #2449, a node for integer factorisation, is a design for a later PR; measuring for it found #2466 (
Factorize(0)andFactorize(-12)answer[], the factorisation of 1).Full check: 20,119 unit tests, 0 failed; MCP 444, Terminal 69, F# 134, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, PropCheck 1355/0, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines.
Part of #2449.
🤖 Generated with Claude Code