A Hybrid Symbolic-Numeric Mathematics Engine
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_math_ext-1.0.5-py3-none-any.whl.
File metadata
- Download URL: py_math_ext-1.0.5-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37c3acad3471b09a7793af57a7137c753fe1f77a4f188845f42361bd2247c12a
|
|
| MD5 |
1bb76d94eaa12e270a7e68eb55a1c51d
|
|
| BLAKE2b-256 |
8349499f831851bd274d668b96f9356b497910b62ac4818639d299aaf78b8717
|