quadax.ClenshawCurtisRule

class quadax.ClenshawCurtisRule(order: int = 32, norm: Callable | float | int = inf, batch_size: int | None = None, closed: bool = True)Source

Integrate a function from a to b using a fixed order Clenshaw-Curtis rule.

Integration is performed using an order n rule with error estimated using an embedded n//2 order rule.

Parameters:
  • order (int) – Order of integration scheme. Must be a multiple of 4 with closed=True, or any even order of at least 4 with closed=False.

  • norm (int, callable) – Norm to use for measuring error for vector valued integrands. No effect if the integrand is scalar valued. If an int, uses p-norm of the given order, otherwise should be callable.

  • batch_size (int, optional) – Maximum number of points at which to evaluate the integrand in parallel. Default is all of the rule’s nodes at once, which is fastest but makes peak memory scale with the order. Values above the number of nodes are clipped to it. A value that does not divide the number of nodes leaves a remainder, which is evaluated together in one smaller batch, so the integrand is traced twice but never evaluated at more points than the rule has nodes.

  • closed (bool, optional) – Whether the interval endpoints are among the nodes. The default closed rule uses order + 1 points and is exact to degree order. The open (Fejer-2) rule uses the same node family with the endpoints dropped, giving order - 1 points exact to degree order - 1, and never evaluates the integrand at a or b. Both nest 2:1 against an embedded order // 2 rule.

Notes

On integrands with an endpoint singularity the error estimate can under-state the true error, increasingly so at higher order, because the endpoint-clustered nodes make the two rules agree while neither has converged. An adaptive integration may then report success while missing the requested tolerance. This applies to both variants; the clustering is a property of the node family, not of the endpoints.

Which is cheaper depends on the integrand. The closed rule wins on smooth, peaked and oscillatory ones, by up to about a factor of two in evaluations; the open rule wins on endpoint singularities and by a wide margin on infinite intervals whose integrand decays algebraically.

Methods

integrate(fun, a, b, args)

Integrate a function from a to b using a nested rule.

norm(x)

Norm to use for measuring error for vector valued integrands.

Attributes

nodes_per_call

How many evaluations of the integrand one application of the rule costs.