Python Math library for Matrix and Polynomial manipulation extending to the complex plane
Project description
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}
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
Built Distribution
File details
Details for the file pythematics-4.0.0.tar.gz
.
File metadata
- Download URL: pythematics-4.0.0.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 708f04e5dcfa16e5b249ed0112d0af205fa9d11a9ca85b9a9f296986c684a447 |
|
MD5 | 30f359a12b29dfa4b1f3398fced37154 |
|
BLAKE2b-256 | 9830668557d9b022d611959eb0093954b517bda82d6e913a77518ab04cefd519 |
File details
Details for the file pythematics-4.0.0-py3-none-any.whl
.
File metadata
- Download URL: pythematics-4.0.0-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0840d1d0244ef73a2ebf2747da02b758d684e99a4e32622797d843de729d2edb |
|
MD5 | 54234dc0b90b5f1dbd5dd739ee9729fa |
|
BLAKE2b-256 | a941c51accc340b39a944fbb2d8c0f02020fb7e93e6da705d0195781137594e8 |