Welcome to PyPolyhedralCubature’s documentation!

This package allows to evaluate the integral of a multivariate function over a convex polytope, given by the linear combinations of the variables defining the bounds of the integrals.

See the README file for usage examples.

Indices and tables

Members functions

polyhedralcubature.getAb(inequalities, symbols)

Get the matrix-vector representation of a set of linear inequalities.

Parameters:
  • inequalities (list) – list of symbolic inequalities

  • symbols (list) – list of symbols

Returns:

  • matrix – The matrix of the coefficients of the inequalities.

  • vector – The vector made of the bounds of the inequalities.

Examples

>>> from pypolyhedralcubature.polyhedralcubature import getAb
>>> from sympy.abc import x, y, z
>>> # linear inequalities
>>> i1 = (x >= -5) & (x <= 4)
>>> i2 = (y >= -5) & (y <= 3 - x)
>>> i3 = (z >= -10) & (z <= 6 - x - y)
>>> # get matrix-vector representation of these inequalities
>>> A, b = getAb([i1, i2, i3], [x, y, z])
polyhedralcubature.integrateOnPolytope(f, A, b, dim=1, maxEvals=10000, absError=0.0, tol=1e-05, rule=3)

Integration a function over a convex polytope.

Parameters:
  • f (function) – The function to be integrated.

  • A (array-like) – matrix of the coefficients of the linear inequalities (see README for an example)

  • b (vector-like) – vector of the upper bounds of the linear inequalities

  • dim (integer) – The dimension of the values of f.

  • maxEvals (integer) – Maximum number of calls to f.

  • absError (number) – Desired absolute error.

  • tol (number) – Desired relative error.

  • rule (integer) – Integer between 1 and 4 corresponding to the integration rule; a 2*rule+1 degree rule will be applied.

Returns:

The value of the integral is in the field “integral” of the returned value.

Return type:

dictionary

Examples

>>> from pypolyhedralcubature.polyhedralcubature import *
>>> from sympy.abc import x, y, z
>>> # integral bounds
>>> i1 = (x >= -5) & (x <= 4)
>>> i2 = (y >= -5) & (y <= 3 - x)
>>> i3 = (z >= -10) & (z <= 6 - x - y)
>>> # get matrix-vector representation of these inequalities
>>> A, b = getAb([i1, i2, i3], [x, y, z])
>>> # function to integrate
>>> f = lambda x, y, z : x*(x+1) - y*z**2
>>> # integral of f on the polytope defined by the bounds
>>> g = lambda v : f(v[0], v[1], v[2])
>>> I_f = integrateOnPolytope(g, A, b)
>>> I_f["integral"]
polyhedralcubature.integratePolynomialOnPolytope(P, A, b)

Integration a polynomial over a convex polytope.

Parameters:
  • P (function) – The function to be integrated.

  • A (array-like) – matrix of the coefficients of the linear inequalities (see README for an example)

  • b (vector-like) – vector of the upper bounds of the linear inequalities

Returns:

The exact value of the integral of P over the polytope defined by A and b.

Return type:

number

Examples

>>> from pypolyhedralcubature.polyhedralcubature import *
>>> from sympy import Poly
>>> from sympy.abc import x, y, z
>>> # integral bounds
>>> i1 = (x >= -5) & (x <= 4)
>>> i2 = (y >= -5) & (y <= 3 - x)
>>> i3 = (z >= -10) & (z <= 6 - x - y)
>>> # get matrix-vector representation of these inequalities
>>> A, b = getAb([i1, i2, i3], [x, y, z])
>>> # polynomial to integrate
>>> P = Poly(x*(x+1) - y*z**2, domain = "RR")
>>> # integral of P over the polytope defined by the bounds
>>> integratePolynomialOnPolytope(P, A, b)