pysimplicialcubature


Namepysimplicialcubature JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/stla/PySimplicialCubature
SummaryIntegration on simplices.
upload_time2023-05-10 20:25:23
maintainer
docs_urlNone
authorStéphane Laurent
requires_python>=3.9,<4.0
licenseGPL-3.0-only
keywords integration simplex
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pysimplicialcubature

<!-- badges: start -->
[![Documentation status](https://readthedocs.org/projects/pysimplicialcubature/badge/)](http://pysimplicialcubature.readthedocs.io)
<!-- badges: end -->

This package is a port of a part of the R package **SimplicialCubature**, 
written by John P. Nolan, and which contains R translations of 
some Matlab and Fortran code written by Alan Genz. In addition it 
provides a function for the exact computation of the integral of a 
polynomial over a simplex.

___

A simplex is a triangle in dimension 2, a tetrahedron in dimension 3. 
This package provides two main functions: `integrateOnSimplex`, to integrate 
an arbitrary function on a simplex, and `integratePolynomialOnSimplex`, to 
get the exact value of the integral of a multivariate polynomial on a 
simplex.

Suppose for example you want to evaluate the following integral:

$$\int\_0^1\int\_0^x\int\_0^y \exp(x + y + z) \text{d}z \text{d}y \text{d}x.$$

```python
from pysimplicialcubature.simplicialcubature import integrateOnSimplex
from math import exp

# simplex vertices
v1 = [0.0, 0.0, 0.0] 
v2 = [1.0, 1.0, 1.0] 
v3 = [0.0, 1.0, 1.0] 
v4 = [0.0, 0.0, 1.0]
# simplex
S = [v1, v2, v3, v4]
# function to integrate
f = lambda x : exp(x[0] + x[1] + x[2])
# integral of f on S
I_f = integrateOnSimplex(f, S)
I_f["integral"]
```

Now let's turn to a polynomial example. You have to define the polynomial with 
`sympy.Poly`.

```python
from pysimplicialcubature.simplicialcubature import integratePolynomialOnSimplex
from sympy import Poly
from sympy.abc import x, y, z

# simplex vertices
v1 = [1.0, 1.0, 1.0] 
v2 = [2.0, 2.0, 3.0] 
v3 = [3.0, 4.0, 5.0] 
v4 = [3.0, 2.0, 1.0]
# simplex
S = [v1, v2, v3, v4]
# polynomial to integrate
P = Poly(x**4 + y + 2*x*y**2 - 3*z, x, y, z, domain = "RR")
# integral of P on S
integratePolynomialOnSimplex(P, S)
```


## References

- A. Genz and R. Cools. 
*An adaptive numerical cubature algorithm for simplices.* 
ACM Trans. Math. Software 29, 297-308 (2003).

- Jean B. Lasserre.
*Simple formula for the integration of polynomials on a simplex.* 
BIT Numerical Mathematics 61, 523-533 (2021).
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/stla/PySimplicialCubature",
    "name": "pysimplicialcubature",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "integration,simplex",
    "author": "St\u00e9phane Laurent",
    "author_email": "laurent_step@outlook.fr",
    "download_url": "https://files.pythonhosted.org/packages/7d/a7/9273577c7757b0e593c84aae3c31d7af875e6db38dce83fd79a7d6cebb66/pysimplicialcubature-0.1.0.tar.gz",
    "platform": null,
    "description": "# pysimplicialcubature\n\n<!-- badges: start -->\n[![Documentation status](https://readthedocs.org/projects/pysimplicialcubature/badge/)](http://pysimplicialcubature.readthedocs.io)\n<!-- badges: end -->\n\nThis package is a port of a part of the R package **SimplicialCubature**, \nwritten by John P. Nolan, and which contains R translations of \nsome Matlab and Fortran code written by Alan Genz. In addition it \nprovides a function for the exact computation of the integral of a \npolynomial over a simplex.\n\n___\n\nA simplex is a triangle in dimension 2, a tetrahedron in dimension 3. \nThis package provides two main functions: `integrateOnSimplex`, to integrate \nan arbitrary function on a simplex, and `integratePolynomialOnSimplex`, to \nget the exact value of the integral of a multivariate polynomial on a \nsimplex.\n\nSuppose for example you want to evaluate the following integral:\n\n$$\\int\\_0^1\\int\\_0^x\\int\\_0^y \\exp(x + y + z) \\text{d}z \\text{d}y \\text{d}x.$$\n\n```python\nfrom pysimplicialcubature.simplicialcubature import integrateOnSimplex\nfrom math import exp\n\n# simplex vertices\nv1 = [0.0, 0.0, 0.0] \nv2 = [1.0, 1.0, 1.0] \nv3 = [0.0, 1.0, 1.0] \nv4 = [0.0, 0.0, 1.0]\n# simplex\nS = [v1, v2, v3, v4]\n# function to integrate\nf = lambda x : exp(x[0] + x[1] + x[2])\n# integral of f on S\nI_f = integrateOnSimplex(f, S)\nI_f[\"integral\"]\n```\n\nNow let's turn to a polynomial example. You have to define the polynomial with \n`sympy.Poly`.\n\n```python\nfrom pysimplicialcubature.simplicialcubature import integratePolynomialOnSimplex\nfrom sympy import Poly\nfrom sympy.abc import x, y, z\n\n# simplex vertices\nv1 = [1.0, 1.0, 1.0] \nv2 = [2.0, 2.0, 3.0] \nv3 = [3.0, 4.0, 5.0] \nv4 = [3.0, 2.0, 1.0]\n# simplex\nS = [v1, v2, v3, v4]\n# polynomial to integrate\nP = Poly(x**4 + y + 2*x*y**2 - 3*z, x, y, z, domain = \"RR\")\n# integral of P on S\nintegratePolynomialOnSimplex(P, S)\n```\n\n\n## References\n\n- A. Genz and R. Cools. \n*An adaptive numerical cubature algorithm for simplices.* \nACM Trans. Math. Software 29, 297-308 (2003).\n\n- Jean B. Lasserre.\n*Simple formula for the integration of polynomials on a simplex.* \nBIT Numerical Mathematics 61, 523-533 (2021).",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "Integration on simplices.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://pysimplicialcubature.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/stla/PySimplicialCubature"
    },
    "split_keywords": [
        "integration",
        "simplex"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a8394655233d96eca3417d3a91bf9de2827456fe212510b21873e3972e2c2a8",
                "md5": "b18540029e1f012bdc0389c4b3807454",
                "sha256": "c1f6eacb816bbcf8db89c268d4e0e8675fae2a6243cca4e75ff4684be4b361ca"
            },
            "downloads": -1,
            "filename": "pysimplicialcubature-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b18540029e1f012bdc0389c4b3807454",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 20644,
            "upload_time": "2023-05-10T20:25:20",
            "upload_time_iso_8601": "2023-05-10T20:25:20.997774Z",
            "url": "https://files.pythonhosted.org/packages/6a/83/94655233d96eca3417d3a91bf9de2827456fe212510b21873e3972e2c2a8/pysimplicialcubature-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7da79273577c7757b0e593c84aae3c31d7af875e6db38dce83fd79a7d6cebb66",
                "md5": "1b4ecdd0a4dd6d05cf00b1033f1a611c",
                "sha256": "263a4929a3be047548fdf3401d1b4c966a773650464008e90ccadd3d2a092968"
            },
            "downloads": -1,
            "filename": "pysimplicialcubature-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1b4ecdd0a4dd6d05cf00b1033f1a611c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 20839,
            "upload_time": "2023-05-10T20:25:23",
            "upload_time_iso_8601": "2023-05-10T20:25:23.552644Z",
            "url": "https://files.pythonhosted.org/packages/7d/a7/9273577c7757b0e593c84aae3c31d7af875e6db38dce83fd79a7d6cebb66/pysimplicialcubature-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-10 20:25:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stla",
    "github_project": "PySimplicialCubature",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pysimplicialcubature"
}
        
Elapsed time: 0.54936s