Skip to main content

Pythematics

Pythematics is a zero-dependency math library for Python that aims to extend some Mathematical fields that are seemingly abandoned by other libraries while offering a fully Pythonic experience.

The main field that this library aims to enhance to Python is Polynomials in a way that allows for super-complicated and high degree polynomial equations to be solved giving all Real and Complex Solutions as well as combining it with fields such as Linear Algebra and allowing for Matrix-Polynomial Manipulation methods like finding Eigenvalues and Eigenvectors.

Pythematics can also be used as an ordinary math module since it contains various sub-packages for computations in Trigonometry, Number Theory and other fields such as Random Number Generation or Calculus

The thing that makes this library unique is the ability to Interact will Polynomials at the following format:

import pythematics.polynomials as pl

x = pl.x
pol: pl.Polynomial = x**4 + 3*x**2 + 2*x
print("Solve x^4 + 3x^2+ 2x = 0 : ", pol == 0)
print("Inequality: ", pol > 0)

which outputs

Solve x^4 + 3x^2+ 2x = 0 :  [(-0.5960716379833215+1.2508571630922372e-33j), (0.29803581899166076+1.8073394944520218j), (0.2980358189916609-1.8073394944520218j), 0j]
Inequality:  {(-inf, -0.5960716379833215): True, (-0.5960716379833215, 0.0): False, (0.0, inf): True}

And the results can be verified by subsituting

roots = pol.roots(5000) # Same as pol == 0
for root in roots:
    print(pol(root)) # Substituting

# The output: Very small numbers close to 0
    # (1.1102230246251565e-16+1.0171730768082222e-32j)
    # 0j
    # (-1.7763568394002505e-15-8.881784197001252e-16j)
    # (3.552713678800501e-15+8.881784197001252e-16j)

This can be generalised not to just polynomials

a, b = symbol('a', 'b')
for i in range(5):
    print(f"{i}: ", (a + b)**i)
  • Output
0:  1 # Unicode can be disabled by setting `Polynomial.use_unicode=False` and/or `Multinomial.use_unicode=False`
1:  Multivariable Polynomial : b + a
2:  Multivariable Polynomial : b² + a² + 2ab 
3:  Multivariable Polynomial : b³ + a³ + 3a²b + 3ab²
4:  Multivariable Polynomial : b⁴ + a⁴ + 4a³b + 6a²b² + 4ab³

Linear Algebra is another huge part of this module. Here is an example of solving a 3x3 system of Linear of equations.

import pythematics.linear as lin
A = lin.Matrix([
    [1,2,3],  # R1:  x +  2y +  3z
    [4,7,8],  # R2: 4x +  7y +  8z
    [5,10,11] # R3: 5x + 10y + 11z
])

unknowns = ('x','y','z') # Our Varaibles
Output = Vector([10, 15, 25]) # Our Target Output (R1=10, R2=15, R3=25)

print(A.solve(Output, unknowns)) # Using Cramer's rule of the determinants
print(A.solve(Output, unknowns, useRef=True)) # Using Row Reduction

And as expected the results are identical dispite a small floating point error

{'x': -8.75, 'y': 0.0, 'z': 6.25}
{'x': -8.749999999999993, 'y': -6.217248937900877e-15, 'z': 6.250000000000002}

Metadata

Release files for pythematics 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythematics 4.0.0
File Size Uploaded
pythematics-4.0.0.tar.gz 35.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pythematics 4.0.0
File Interpreter ABI Platform
pythematics-4.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 72.3 kB

Release files / pythematics-4.0.0.tar.gz

Download URL pythematics-4.0.0.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
708f04e5dcfa16e5b249ed0112d0af205fa9d11a9ca85b9a9f296986c684a447
BLAKE2b-256 checksum
How to use checksums
9830668557d9b022d611959eb0093954b517bda82d6e913a77518ab04cefd519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

Release files / pythematics-4.0.0-py3-none-any.whl

Download URL pythematics-4.0.0-py3-none-any.whl
Size 37.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0840d1d0244ef73a2ebf2747da02b758d684e99a4e32622797d843de729d2edb
BLAKE2b-256 checksum
How to use checksums
a941c51accc340b39a944fbb2d8c0f02020fb7e93e6da705d0195781137594e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page