Skip to main content

A package for computing Riemann summations in n-dimensional space

Project description

riemann

Repository Logo

Riemann is a pure-Python package for computing Riemann sums of functions in $n$-dimensional space.

GitHub GitHub Pipenv locked Python version PyPI - Python Version GitHub tag (latest SemVer)


Basic Usage

Riemann provides an intuitive syntax for calculating the Riemann sum of a function over a closed interval. The below code snippet computes the Riemann sum of $f(x) = x^{2}$ over the interval $[0, 2]$ using 10 partitions along the $x$ axis.

>>> import riemann
>>> from riemann import Dimension
>>> f = lambda x: x ** 2
>>> dim_x = Dimension(0, 2, 10, riemann.LOWER)
>>> dim_x
Dimension(a=0, b=2, n=10, method=Method(name='lower'))
>>> riemann.rsum(f, dim_x)
Decimal('2.28')

However, Riemann is not restricted to computing Riemann sums only over one dimension. A similar syntax can be used to calculate the Riemann sum of a function of several real variables over a closed multi-dimensional interval. The below code snippet computes the Riemann sum of $f(x, y) = x^{2} y^{2}$ over the interval $x \in [0, 2], y \in [0, 4]$ using 10 partitions along the $x$ axis and 10 partitions along the $y$ axis.

>>> import riemann
>>> from riemann import Dimension
>>> f = lambda x, y: (x ** 2) * (y ** 2)
>>> dim_x = Dimension(0, 2, 10, riemann.MIDDLE)
>>> dim_x
Dimension(a=0, b=2, n=10, method=Method(name='middle'))
>>> dim_y = Dimension(0, 4, 10, riemann.MIDDLE)
>>> dim_y
Dimension(a=0, b=4, n=10, method=Method(name='middle'))
>>> riemann.rsum(f, dim_x, dim_y)
Decimal('56.6048')

The sole requirement is that the number of parameters taken by the function passed as the func argument to riemann.rsum equals the number of riemann.Dimension objects passed.

Features

  • Fast computation of Riemann sum.
  • Support for computation of multi-dimensional Riemann sum.
  • Built-in support for left, middle, and right Riemann sum methods.
  • Support for custom Riemann sum methods (using the :py:class:riemann.Method class).

Requirements

Riemann requires Python 3.7+. This project does not require any additional dependencies.

Installation

$ pip install riemann

Documentation

Documentation Status

The documentation for this project is available on Read the Docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

riemann-0.9.0.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

riemann-0.9.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page