Skip to main content

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.
  • 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

py_math_ext-1.0.2-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file py_math_ext-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_math_ext-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_math_ext-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02b1328b83f4492f9acaac44472929b498679c0e2f388691eb3498ae690ef8f8
MD5 9911fe55e9a895e99fa980b0b0b76680
BLAKE2b-256 470b7e305ac75d3eb550b154bf0a68402f93b64a713990475c46890f586d3e71

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