<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.math.integration.simpson" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.math.integration.simpson

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/math/integration/simpson.py">View source</a>



Evaluates definite integral using composite Simpson's 1/3 rule.

```python
tf_quant_finance.math.integration.simpson(
    func, lower, upper, num_points=1001, dtype=None, name=None
)
```



<!-- Placeholder for "Used in" -->

Integrates `func` using composite Simpson's 1/3 rule [1].

Evaluates function at points of evenly spaced grid of `num_points` points,
then uses obtained values to interpolate `func` with quadratic polynomials
and integrates these polynomials.

#### References
[1] Weisstein, Eric W. "Simpson's Rule." From MathWorld - A Wolfram Web
    Resource. http://mathworld.wolfram.com/SimpsonsRule.html

#### Example
```python
  f = lambda x: x*x
  a = tf.constant(0.0)
  b = tf.constant(3.0)
  simpson(f, a, b, num_points=1001) # 9.0
```

#### Args:


* <b>`func`</b>: Represents a function to be integrated. It must be a callable of a
  single `Tensor` parameter and return a `Tensor` of the same shape and
  dtype as its input. It will be called with a `Tensor` of shape
  `lower.shape + [n]` (where n is integer number of points) and of the same
  `dtype` as `lower`.
* <b>`lower`</b>: Represents the lower limits of integration. `func` will be integrated
  between each pair of points defined by `lower` and `upper`.
* <b>`upper`</b>: Same shape and dtype as `lower` representing the upper limits of
  intergation.
* <b>`num_points`</b>: Number of points at which function `func` will be evaluated.
  Must be odd and at least 3. Default value: 1001.
* <b>`dtype`</b>: If supplied, the dtype for the `lower` and `upper`. Result will have
  the same dtype.
  Default value: None which maps to dtype of `lower`.
* <b>`name`</b>: The name to give to the ops created by this function.
  Default value: None which maps to 'integrate_simpson_composite'.


#### Returns:

`Tensor` of shape `func_batch_shape + limits_batch_shape`, containing
  value of the definite integral.
