Skip to content

A product over a set: product(f, x in S) - #2467

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
feature/product-over-a-set
Nov 15, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
feature/product-over-a-set

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

product(f, p in S) threw an arity error while sum(f, k in S) worked. It is now the node ProductOverSetf(Expression, Var, Over), built the way SumOverSetf was in #1624, and it multiplies its factors exactly where the sum adds its terms, so it is left unevaluated wherever the sum is.

input was now
product(p, p in PP /\ [1; 30]) throws 6469693230 (29#)
product(1 - 1/p^2, p in {2, 3, 5}) throws 16/25
product(x, x in {}) throws 1, as the empty sum is 0
product(w, w in {w : w^2 - 3 = 0}) throws -3
product(w, w in {w : (w-1)^2 (w-2) = 0}) throws 2: a set, so the double root counts once
product(w, w in {w : w^5+w+3=0}), .Evaled throws -3, over the numeric roots
product(x, x in {a, b}), over ZZ, PP, [0; 1] throws left unevaluated, as the sum is
derivative of product(w+y, w in {w : w^3+w+1=0}) in y, at y = 1 throws 4

Wired as the sum over a set is: the binding (Binding.Of(Var).In(Over), so FreeVariables, DomainCondition and Substitute read 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 (a sympy.Mul over the members or over all_roots(), run in SymPy 1.14), and MathS.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 in BREAKING-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) and Factorize(-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

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

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.43750% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (dd5cc83) to head (17a4d10).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...nctions/Output/ToSympy/ToSympy.Calculus.Classes.cs 0.00% 8 Missing ⚠️
Sources/AngouriMath/Numerics/PreciseEvaluation.cs 25.00% 1 Missing and 2 partials ⚠️
...ources/AngouriMath/Functions/Algebra/SumOverSet.cs 88.23% 0 Missing and 2 partials ⚠️
...ngouriMath/Functions/Continuous/Differentiation.cs 75.00% 1 Missing and 1 partial ⚠️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 0.00% 1 Missing ⚠️
...AngouriMath/Functions/TreeAnalyzer/Sort.Classes.cs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.45% <73.43%> (-0.04%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 39.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 90.74% <100.00%> (+0.02%) ⬆️
...ources/AngouriMath/Core/Antlr/AngouriMathParser.cs 88.04% <100.00%> (ø)
Sources/AngouriMath/Core/Domains.Classes.cs 100.00% <100.00%> (ø)
...y/Continuous/Entity.Continuous.Calculus.Classes.cs 100.00% <100.00%> (ø)
...urces/AngouriMath/Core/Entity/Entity.Definition.cs 94.30% <100.00%> (-0.78%) ⬇️
...urces/AngouriMath/Functions/Compilation/Binders.cs 92.59% <100.00%> (+0.28%) ⬆️
...ntinuous/Evaluation.Continuous.Calculus.Classes.cs 85.97% <100.00%> (+0.26%) ⬆️
...Math/Functions/Evaluation/Evaluation.Definition.cs 91.63% <100.00%> (+0.03%) ⬆️
...h/Functions/Output/Latex/Latex.Calculus.Classes.cs 98.03% <100.00%> (+0.08%) ⬆️
...tions/Output/ToString/ToString.Calculus.Classes.cs 91.42% <100.00%> (+0.51%) ⬆️
... and 7 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 3abd4d9 into master Nov 15, 2026
37 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Nov 15, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the feature/product-over-a-set branch November 15, 2026 23:47
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

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant