Math-Extension
A Hybrid Symbolic-Numeric Mathematics Engine for Python.
Math-Extension is a powerful library designed to bridge the gap between simple numerical calculators and complex symbolic engines. By using a Traceable architecture, it remembers how a formula was built, allowing for automatic differentiation, multi-variable systems solving, and advanced regression—all while maintaining high-speed numerical performance through a custom Matrix core. A computation-graph-based math engine where expressions are traceable objects that support symbolic manipulation and numerical evaluation through a shared variable environment.
🚀 Key Features
- Symbolic Traceability: Every operation is stored in a tree, allowing for
f.diff(x)(Recursive Automatic Differentiation). - Advanced Regressions: Linear, Polynomial, Exponential, Logarithmic, Power, and Multiple Linear Regression with $R^2$ validation.
- Omniscient Root Finding: Automatically detects polynomial degrees and calculates search ranges using Cauchy's Bound—no more manual guessing.
- Non-Linear System Solver: Solves systems of equations using a Jacobian-based multi-variable Newton-Raphson method.
- Matrix Core: Pure-Python implementation featuring Gaussian Elimination with Partial Pivoting, Inversion, and Determinants.
🛠 Installation & Setup
To use this in your project, clone the repository:
git clone https://github.com/NeoZett-School/Math-Extension.git
We also have a pypi page here. You can download this package using:
pip install py-math-ext
📖 Quick Start Examples
1. Symbolic Differentiation & "Smart" Solving
Solve for the roots of a cubic function. The solver automatically detects the degree (3) and sets the search range using Cauchy's Bound.
from math_extension import Canvas, Symbol, Function, Solver
canvas = Canvas()
x = Symbol('x')
f = Function('x', x**3 - 6*x**2 + 9*x + 15)
# The solver investigates the complexity of 'f' and finds all real roots
roots = Solver.solve_all(f, target=0, symbol=x)
print(f"Roots of {f.written}: {roots}")
2. Solving Non-Linear Systems (Jacobian Method)
Find the intersection points of a unit circle and a diagonal line.
from math_extension import Canvas, Symbol, RegressionPoly
canvas = Canvas()
x, y = Symbol('x'), Symbol('y')
eq1 = x**2 + y**2 - 1 # Unit Circle equation
eq2 = y - x # Line y = x
# Uses the multi-variable Newton-Raphson method
result = SystemSolver.solve_nonlinear([eq1, eq2], [x, y], guesses=[0.5, 0.5])
print(f"Intersection Point: {result}")
3. Data Regression & Goodness of Fit ($R^2$)
Fit a polynomial to data and verify the accuracy of the model.
from math_extension import Canvas, Symbol, RegressionPoly
canvas = Canvas()
x = Symbol("x")
data = [(0, 1), (1, 2.1), (2, 3.9), (3, 9.2)]
reg = RegressionPoly(data, degree=2)
coeffs = reg.calculate() # Returns [a0, a1, a2]
accuracy = reg.r_squared() # Returns the Coefficient of Determination
print(f"Model: {reg.create_function('x').written}")
print(f"R^2 Accuracy: {accuracy:.4f}")
🧪 Technical Architecture
The Traceable Object
Unlike standard Python floats, a Traceable object stores its "history." When you perform x * 2, it returns a new object that knows its operator was * and its parents were x and 2. This allows the engine to perform the Chain Rule recursively for differentiation:
- Power Rule: Handles $x^n$.
- Exponential Rule: Handles $a^x$.
- General Power Rule: Handles $f(x)^{g(x)}$.
The Matrix Engine
The Matrix class handles the heavy lifting for regressions and system solving.
- Partial Pivoting: Ensures numerical stability by selecting the largest available pivot.
- Normal Equations: Used in all regression classes to solve $(X^T X)\beta = X^T Y$.
📈 Roadmap
- Trigonometric support (
sin,cos,tan). - Automatic Complexity (Degree) Detection.
- Multiple Linear Regression.
- Imaginary Numbers (further development is in progress...)
- String Parser (LaTeX String, presumably)
- Unit Tests
- LaTeX String Exporting for documentation.
- Residual Analysis Plotting.
Metadata
Release files for py-math-ext 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_math_ext-1.0.7-py3-none-any.whl | Python 3 | none | any | Details for py_math_ext-1.0.7-py3-none-any.whl |
Release files / py_math_ext-1.0.7-py3-none-any.whl
| Download URL | py_math_ext-1.0.7-py3-none-any.whl |
|---|---|
| Size | 23.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3c01f9eaadada2f87e69a85989676dd046d87784242df46dd5abaf14016049b
|
|
BLAKE2b-256 checksum How to use checksums |
40da91ab0b60f9bb9bd59ecb9b04a20b4ef951fedaa067d2fb0e5414d6e90b67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for py-math-ext 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.