NProduct¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
NProduct[f, {i, imin, imax}]
gives a numerical approximation to the product of f for i from imin to imax.
NProduct[f, {i, imin, imax, di}]
uses step di. imax may be Infinity. NProduct[f, {i, ...}, {j, ...}, ...] evaluates a multidimensional product (an inner bound may depend on an outer index). The index is localised (HoldAll). Evaluated as Exp[NSum[Log[f], ...]], so the NSum engine (Euler-Maclaurin for monotone factors, Wynn's epsilon otherwise) and its convergence test carry over. Machine or arbitrary precision via WorkingPrecision.
Notes
Options: Method (Automatic | EulerMaclaurin | WynnEpsilon), WorkingPrecision (default MachinePrecision), NProductFactors (leading factors taken explicitly, default 15), NProductExtraFactors, WynnDegree, VerifyConvergence (default True; a divergent product gives ComplexInfinity), AccuracyGoal, PrecisionGoal.Examples (5)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (3)¶
In[1]:= NProduct[1 - 1/n^2, {n, 2, Infinity}]
Out[1]= 0.5
In[2]:= NProduct[(n^2)/(n^2 - 1), {n, 2, Infinity}]
Out[2]= 2.0
In[3]:= NProduct[1 + 1/n^2, {n, 1, Infinity}]
Out[3]= 3.67608
Applications (2)¶
In[4]:= NProduct[1 - 1/n^2, {n, 2, Infinity}]
Out[4]= 0.5
In[5]:= NProduct[Cos[1/n], {n, 1, Infinity}]
Out[5]= 0.388536
Algorithm¶
Strategy -------- Per Keiper 1992 ("The N functions of Mathematica", G.15), a numerical product is evaluated as the exponential of a numerical sum of logarithms:
This is exact for finite ranges (Exp inverts Log on any branch and the principal-log phases that wind by multiples of 2*pi are unwrapped by Exp) and correct for convergent infinite products (factors -> 1 => Log f -> 0 is smooth on the principal branch, and Euler-Maclaurin uses only branch-independent
Euler-Maclaurin, Wynn epsilon, Cohen-Villegas-Zagier, MPFR working precision, large-finite tail differences, and divergence detection — to the existing, tested NSum engine, and only:
- parse NProduct's own option names and map them onto NSum's;
- add guard digits on the arbitrary-precision path (Exp amplifies the
absolute error of the exponent into relative error of the product);
- handle multidimensional products by recursion (inner NProduct as body);
- special-case divergence (NSum -> ComplexInfinity).
Memory: receives res owned by the evaluator; returns a fresh Expr* on
Implementation notes¶
Algorithm. builtin_nproduct (HoldAll) parses the iterator {i, imin, imax,
di} and evaluates the product as Exp[NSum[Log[f(i)], {i, imin, imax}]]
(Keiper 1992): it forms logbody = Log[f], builds an inner NSum with the
options mapped across (NProductFactors -> NSumTerms, so the default leading
factor count is NSum's 15; NProductExtraFactors -> NSumExtraTerms; Method,
WynnDegree, VerifyConvergence, the goals and WorkingPrecision passed
through), evaluates it, and returns Exp[result]. So the whole NSum engine —
Euler–Maclaurin for monotone factors, Wynn's epsilon otherwise, and its
divergence test — carries over directly; see the NSum notes for the summation
machinery. Multidimensional products nest an inner NProduct as the factor body
(dependent inner bounds see the outer index via HoldAll). A divergent log-sum
(the inner NSum returning ComplexInfinity) makes NProduct return
ComplexInfinity; a non-numeric inner result leaves the product unevaluated.
Data structures. No numerical buffers of its own — everything is the inner
NSum's (machine double _Complex or split mpfr_t real/imag, with the Log
summand drawn through NSum's cached compiled programs). The only NProduct-
specific state is the option-remapping and the final Exp.
Complexity / limits. The cost is one NSum of Log[f] plus one Exp. The
one numerical subtlety is precision: Exp amplifies the exponent's absolute
error into the product's relative error, so the inner sum runs at
WorkingPrecision + 10 guard digits and the final Exp is renormalised back to
the requested precision with N[·, wdigits]. Options: Method (Automatic |
EulerMaclaurin | WynnEpsilon), WorkingPrecision, NProductFactors,
NProductExtraFactors, WynnDegree, VerifyConvergence (default True; a
divergent product gives ComplexInfinity), AccuracyGoal, PrecisionGoal.
NProduct is HoldAll and Protected.
Attributes: HoldAll, Protected.
References¶
See also: AccuracyGoal, PrecisionGoal, Exp
- J. B. Keiper, Numerical computation of infinite products, Wolfram Research tech. report (1992) — the Exp[NSum[Log]] reduction.
- Source:
src/numerical_calculus/nprod.c - Specification:
docs/spec/builtins/numerical-calculus.md - Tests:
tests/test_autocompile.c - Tests:
tests/test_nprod.c
Notes & additional examples¶
Notes¶
NProduct[f, {i, imin, imax}] numerically evaluates a product, with imax
allowed to be Infinity. The first case is a telescoping product:
Product[1 - 1/n^2, {n, 2, Infinity}] = 1/2 exactly. The second converges to
about 0.388536. NProduct is evaluated internally as Exp[NSum[Log[f], ...]],
so the Euler–Maclaurin / Wynn's-epsilon machinery and convergence test of NSum
carry over. With VerifyConvergence -> True (default) a divergent product gives
ComplexInfinity. Use WorkingPrecision for arbitrary precision.