---
title: "NProduct"
language: "en"
type: "Symbol"
summary: "NProduct[f, {i, imin, imax}] gives a numerical approximation to the product \\[Product]i = imin imax f. NProduct[f, {i, imin, imax, di}] uses a step di in the product."
keywords: 
- numerical product
- products
- sequence acceleration
- Wynn epsilon
- extrapolation method
- Euler-Maclaurin
- EulerMaclaurin
- WynnEpsilon
canonical_url: "https://reference.wolfram.com/language/ref/NProduct.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Discrete Calculus"
    link: "https://reference.wolfram.com/language/guide/DiscreteCalculus.en.md"
related_functions: 
  - 
    title: "Product"
    link: "https://reference.wolfram.com/language/ref/Product.en.md"
  - 
    title: "NSum"
    link: "https://reference.wolfram.com/language/ref/NSum.en.md"
related_tutorials: 
  - 
    title: "Numerical Sums, Products and Integrals"
    link: "https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#3848"
  - 
    title: "Numerical Mathematics"
    link: "https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#20411"
  - 
    title: "Numerical Evaluation of Sums and Products"
    link: "https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#10980"
---
# NProduct

NProduct[f, {i, imin, imax}] gives a numerical approximation to the product $\prod _{i=i_{\min }}^{i_{\max }} f$.

NProduct[f, {i, imin, imax, di}] uses a step di in the product.

## Details and Options

* ``NProduct`` can be used for products with both finite and infinite limits.

* ``NProduct[f, {i, …}, {j, …}, …]`` can be used to evaluate multidimensional products.

* The following options can be given:

|                    |                  |                                                 |
| :----------------- | :--------------- | :---------------------------------------------- |
| AccuracyGoal       | Infinity         | number of digits of final accuracy sought       |
| EvaluationMonitor  | None             | expression to evaluate whenever f is evaluated  |
| Method             | Automatic        | method to use                                   |
| PrecisionGoal      | Automatic        | number of digits of final precision sought      |
| VerifyConvergence  | True             | whether to explicitly test for convergence      |
| WorkingPrecision   | MachinePrecision | the precision used in internal computations     |

* Possible settings for the ``Method`` option include:

|                  |                                   |
| ---------------- | --------------------------------- |
| "EulerMaclaurin" | Euler–Maclaurin summation method  |
| "WynnEpsilon"    | Wynn epsilon extrapolation method |

* With the Euler–Maclaurin method, the options ``AccuracyGoal`` and ``PrecisionGoal`` can be used to specify the accuracy and precision to try and get in the final answer. ``NProduct`` stops when the error estimates it gets imply that either the accuracy or precision sought has been reached.

* You should realize that in sufficiently pathological cases, the algorithms used by ``NProduct`` can give wrong answers. In most cases, you can test the answer by looking at its sensitivity to changes in the setting of options for ``NProduct``.

* ``VerifyConvergence`` is only used for products with infinite limits.

* ``N[Product[…]]`` calls ``NProduct``.

* ``NProduct`` first localizes the values of all variables, then evaluates ``f`` with the variables being symbolic, and then repeatedly evaluates the result numerically.

* ``NProduct`` has attribute ``HoldAll``, and effectively uses ``Block`` to localize variables.

---

## Examples (20)

### Basic Examples (1)

Approximate an infinite product numerically:

```wl
In[1]:= NProduct[(1 + 1 / i ^ 2), {i, 1, ∞}]

Out[1]= 3.67608
```

The error versus the exact value of $\frac{\sinh (\pi )}{\pi }$ :

```wl
In[2]:= % - Sinh[π] / π

Out[2]= -3.164117856613302`*^-10
```

### Scope (5)

Approximate the value of a finite product:

```wl
In[1]:= NProduct[1 + (-1) ^ i / i ^ 2, {i, 100, 10 ^ 4}]

Out[1]= 1.00005
```

This is effectively the ratio of two infinite products:

```wl
In[2]:= NProduct[1 + (-1) ^ i / i ^ 2, {i, 100, ∞}]  / NProduct[1 + (-1) ^ i / i ^ 2, {i,   10 ^ 4, ∞}]

Out[2]= 1.00005
```

---

Approximate a multidimensional product:

```wl
In[1]:= NProduct[1 + (-1) ^ n(2 / n) ^ k / k ^ 2, {n, 2, ∞}, {k, 1, ∞}]

Out[1]= 0.812331
```

---

Approximate a multidimensional product with the second index depending on the first:

```wl
In[1]:= NProduct[1 + (-1) ^ n(2 / n) ^ k / k ^ 2, {n, 2, ∞}, {k, 1, n}]

Out[1]= 0.564097
```

---

Complex infinite product approximation:

```wl
In[1]:= NProduct[1 + E ^ (I n 2 / 3) / n ^ 2, {n, 1, Infinity}]

Out[1]= 1.43706 + 1.07945 I
```

---

Multiply the even factors of an infinite product:

```wl
In[1]:= NProduct[1 + 1 / 2 ^ i, {i, 0, ∞, 2}]

Out[1]= 2.71182
```

An equivalent way of specifying the same multiplication:

```wl
In[2]:= NProduct[1 + 1 / 2 ^ (2j), {j, 0, ∞}]

Out[2]= 2.71182
```

### Options (8)

#### AccuracyGoal and PrecisionGoal (1)

Approximate a product with the default tolerances:

```wl
In[1]:= p = NProduct[1 + 1 / n ^ 2, {n, 1, ∞}]

Out[1]= 3.67608
```

Find the error versus the exact value:

```wl
In[2]:= exact = Product[1 + 1 / n ^ 2, {n, 1, ∞}]

Out[2]= (Sinh[π]/π)

In[3]:= p - exact

Out[3]= -3.164117856613302`*^-10
```

The error with smaller absolute and relative tolerances:

```wl
In[4]:= NProduct[1 + 1 / n ^ 2, {n, 1, ∞}, AccuracyGoal -> 4, PrecisionGoal -> 4] - exact

Out[4]= 1.2599136445246018`*^-7
```

The error with larger absolute and relative tolerances:

```wl
In[5]:= NProduct[1 + 1 / n ^ 2, {n, 1, ∞}, AccuracyGoal -> 8, PrecisionGoal -> 8] - exact

Out[5]= 3.772093748466432`*^-12
```

#### EvaluationMonitor (3)

Get the number of evaluation points used in a product approximation:

```wl
In[1]:= Block[{k = 0}, {NProduct[1 + (1/(2 n + 1)^2), {n, 1, ∞}, EvaluationMonitor :> k++], k}]

Out[1]= {1.25459, 114}
```

---

The evaluation points used in a product approximated by an integration method:

```wl
In[1]:= ListPlot[Reap[NProduct[1 + (1/(n + 1)^2), {n, 0, ∞}, EvaluationMonitor :> Sow[n]]][[2, 1]]]

Out[1]= [image]
```

---

The evaluation points used in a product approximated by a sequence extrapolation method:

```wl
In[1]:= ListPlot[Reap[NProduct[1 + ((-1)^n/(n + 1)^2), {n, 0, ∞}, EvaluationMonitor :> Sow[n]]][[2, 1]]]

Out[1]= [image]
```

#### Method (1)

Use the Wynn epsilon method to approximate an infinite product:

```wl
In[1]:= p = NProduct[1 + (1/(n + 1)^2), {n, 0, ∞}, Method -> "WynnEpsilon"]

Out[1]= 3.67334
```

Compare to the exact value:

```wl
In[2]:= exact = Product[1 + (1/(n + 1)^2), {n, 0, ∞}]

Out[2]= (Sinh[π]/π)

In[3]:= p - exact

Out[3]= -0.00274252
```

The error is smaller with the default method:

```wl
In[4]:= NProduct[1 + (1/(n + 1)^2), {n, 0, ∞}] - exact

Out[4]= -3.164117856613302`*^-10
```

#### NProductFactors (1)

By default ``NProduct`` uses 15 factors at the beginning before approximating the tail:

```wl
In[1]:= p = NProduct[1 + 1 / (1 + (k - 20) ^ 2), {k, 0, ∞}]

Out[1]= 12.8567
```

The error for this example is large because the factors peak at 20:

```wl
In[2]:= exact = Product[1 + 1 / (1 + (k - 20) ^ 2), {k, 0, ∞}]

Out[2]= (Gamma[-20 - I] Gamma[-20 + I]/Gamma[-20 - I Sqrt[2]] Gamma[-20 + I Sqrt[2]])

In[3]:= p - exact

Out[3]= -0.044583 + 0. I

In[4]:= ListPlot[Table[1 + 1 / (1 + (k - 20) ^ 2), {k, 1, 40}], PlotRange -> All]

Out[4]= [image]
```

Increasing ``NProductFactors`` to include this feature improves the approximation:

```wl
In[5]:= NProduct[1 + 1 / (1 + (k - 20) ^ 2), {k, 0, ∞}, NProductFactors -> 30]

Out[5]= 12.9013

In[6]:= % - exact

Out[6]= 3.353797239924461`*^-10 + 0. I
```

#### VerifyConvergence (1)

By default the factor's convergence is verified:

```wl
In[1]:= NProduct[1 + BesselJ[k, 3], {k, 1, ∞}]//Timing

Out[1]= {0.157, 3.12064}
```

Generally, if the convergence is not verified the computation is faster:

```wl
In[2]:= NProduct[1 + BesselJ[k, 3], {k, 1, ∞}, VerifyConvergence -> False]//Timing

Out[2]= {0., 3.12064}
```

#### WorkingPrecision (1)

Use higher precision to get a better approximation:

```wl
In[1]:= pa = NProduct[E^-(1/2 n) (1 + (1/2 n)), {n, 1, ∞}, WorkingPrecision -> 25]

Out[1]= 0.84550128163352918
```

Find the error versus the exact value:

```wl
In[2]:= pe = Product[E^-(1/2 n) (1 + (1/2 n)), {n, 1, ∞}]

Out[2]= (2 E^-EulerGamma / 2/Sqrt[π])

In[3]:= pe - pa

Out[3]= 0``17.279205200864016
```

### Applications (2)

Estimate the infinite product of a ``BesselJ`` sequence:

```wl
In[1]:= NProduct[BesselJ[0, 1 / n], {n, 1, ∞}]

Out[1]= 0.650397
```

---

Use a product representation to approximate the ``Sin`` function:

```wl
In[1]:= Block[{x = 1 / 2}, x NProduct[1 - x ^ 2 / (Pi ^ 2 k ^ 2), {k, 1, Infinity}]]

Out[1]= 0.479426

In[2]:= Sin[1 / 2.]

Out[2]= 0.479426
```

### Properties & Relations (2)

Use ``Product`` to compute exact formulas:

```wl
In[1]:= exact = Product[1 + (1/x^2 + 5), {x, 0, ∞}]

Out[1]= Sqrt[(6/5)] Csch[Sqrt[5] π] Sinh[Sqrt[6] π]
```

The results of ``Product`` and ``NProduct`` agree closely:

```wl
In[2]:= NProduct[1 + (1/x^2 + 5), {x, 0, ∞}] - exact

Out[2]= -2.3680124527913904`*^-10
```

---

A product is equivalent to the exponential of a sum of logarithms of factors:

```wl
In[1]:= Exp[NSum[Log[(4n ^ 2) / (4n ^ 2 - 1)], {n, 1, ∞}]]

Out[1]= 1.5708

In[2]:= NProduct[(4n ^ 2) / (4n ^ 2 - 1), {n, 1, ∞}]

Out[2]= 1.5708
```

### Possible Issues (2)

``NProduct`` may not detect divergence for some infinite products:

```wl
In[1]:= NProduct[1 + 1 / k, {k, 1, ∞}]
```

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in k near {k} = {6.13224\*10^28}. NIntegrate obtained 23229.329407159807\` and 19751.299458866175\` for the integral and error estimates.

```wl
Out[1]= 3.86364619832005298969852037746224`15.954589770191005*^10089
```

Convergence verification is based on a ratio test that is inconclusive when equal to 1:

```wl
In[2]:= Limit[(1 + 1 / (k + 1) - 1) / (1 + 1 / k - 1), k -> ∞]

Out[2]= 1
```

---

You should realize that in sufficiently pathological cases, the algorithms used by ``NProduct`` can give wrong answers:

```wl
In[1]:= NProduct[Exp[99 ^ k (Log[99] - HarmonicNumber[k]) / 100 ^ (k + 1)], {k, 1, Infinity}]

Out[1]= 1.61999
```

Compare to the result from ``Product`` :

```wl
In[2]:= Product[Exp[99 ^ k (Log[99] - HarmonicNumber[k]) / 100 ^ (k + 1)], {k, 1, Infinity}]//N

Out[2]= 0.945538
```

One option is increasing the ``WorkingPrecision`` and ``NProductFactors`` :

```wl
In[3]:=
NProduct[
  Exp[99 ^ k (Log[99] - HarmonicNumber[k]) / 100 ^ (k + 1)], {k, 1, Infinity}, 
     WorkingPrecision -> 20, NProductFactors -> 4000] // AbsoluteTiming

Out[3]= {0.327039, 0.9455376850989528}
```

## See Also

* [`Product`](https://reference.wolfram.com/language/ref/Product.en.md)
* [`NSum`](https://reference.wolfram.com/language/ref/NSum.en.md)

## Tech Notes

* [Numerical Sums, Products and Integrals](https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#3848)
* [Numerical Mathematics](https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#20411)
* [Numerical Evaluation of Sums and Products](https://reference.wolfram.com/language/tutorial/NumericalOperationsOnFunctions.en.md#10980)

## Related Guides

* [Discrete Calculus](https://reference.wolfram.com/language/guide/DiscreteCalculus.en.md)

## History

* Introduced in 1988 (1.0) \| Updated in 2003 (5.0)