Skip to main content

Infinite and infinitesimal numbers for JAX

Project description

infnum

infnum is a Python library that provides infinite and infinitesimal numbers using the Levi-Civita Field. It uses JAX under the hood.

Installation

You can install infnum via pip:

pip install infnum

Usage

Creating Levi-Civita Numbers

The main constructor expects a dictionary with numerical keys and values. The keys represent the exponents and the values the coefficients. In the following example, note that ε⁻³ is an infinite number.

from infnum import LeviCivitaNumber

# Create a Levi-Civita number from a real number
num = LeviCivitaNumber.from_number(5.0) # 5.0
print(num)  # Output: 5.0
# Create a Levi-Civita number with infinitesimal parts
num = LeviCivitaNumber({0: 1.0, 1: 2.0, 2: 3.0, -3: 4.0}) # -4.0ε⁻³ + 1.0 + 2.0ε + 3.0ε² 
print(num)  # Output: -4.0ε⁻³ + 1.0 + 2.0ε + 3.0ε² 

Operations

Levi-Civita numbers support arithmetic operations like addition, subtraction, multiplication, and division. Division is truncated to 8 terms by default since it may result in an infinite series, but the higher terms are infinitesimal with respect to the lower terms.

You may compare Levi-Civita numbers using the <, <=, >, >=, ==, != operators, which considers the lexicographical order of the coefficients.

Testing

Levi-Civita numbers come with unit tests to ensure correctness. You can run the tests using:

python -m unittest discover tests

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache 2 License.

TODO

  • add complex number support
  • support non-integer powers for non-pure terms

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

infnum-0.2.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infnum-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file infnum-0.2.0.tar.gz.

File metadata

  • Download URL: infnum-0.2.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for infnum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7c3beb47712349f5558434df0d588be2406aac60461b3307e52fcc5fdec9b4cb
MD5 6fd4ac1dea986cb17570ce9f241b423b
BLAKE2b-256 83ef4de2d178520660747c82d590a3808501bb9a766abc122b303a690ed267fe

See more details on using hashes here.

File details

Details for the file infnum-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: infnum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for infnum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8493656814be2bb2cc1176b55c59fd398c79fd80eae6256e4a135330e34a3ba
MD5 fc733c578b0e796fd7e79448f7e76683
BLAKE2b-256 61cc6235ee0af2bef815e01fe81515ff3a2e66d2b0597c17809bf4da5394bfe3

See more details on using hashes here.

Supported by

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