py-math-ext 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_math_ext-1.0.0/LICENSE +21 -0
- py_math_ext-1.0.0/PKG-INFO +119 -0
- py_math_ext-1.0.0/README.md +105 -0
- py_math_ext-1.0.0/math_extension/__init__.py +11 -0
- py_math_ext-1.0.0/math_extension/__init__.pyi +2 -0
- py_math_ext-1.0.0/math_extension/_internal/core.py +1225 -0
- py_math_ext-1.0.0/math_extension/_internal/core.pyi +210 -0
- py_math_ext-1.0.0/math_extension/core.py +19 -0
- py_math_ext-1.0.0/py_math_ext.egg-info/PKG-INFO +119 -0
- py_math_ext-1.0.0/py_math_ext.egg-info/SOURCES.txt +12 -0
- py_math_ext-1.0.0/py_math_ext.egg-info/dependency_links.txt +1 -0
- py_math_ext-1.0.0/py_math_ext.egg-info/top_level.txt +1 -0
- py_math_ext-1.0.0/pyproject.toml +21 -0
- py_math_ext-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Neo Östlund Zetterberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-math-ext
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Hybrid Symbolic-Numeric Mathematics Engine
|
|
5
|
+
Author-email: Neo Östlund Zetterberg <20091103neo@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/NeoZett-School/Math-Extention
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Math-Extension
|
|
16
|
+
**A Hybrid Symbolic-Numeric Mathematics Engine for Python.**
|
|
17
|
+
|
|
18
|
+
`Math-Extention` 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.
|
|
19
|
+
|
|
20
|
+
## 🚀 Key Features
|
|
21
|
+
* **Symbolic Traceability**: Every operation is stored in a tree, allowing for `f.diff(x)` (Recursive Automatic Differentiation).
|
|
22
|
+
* **Advanced Regressions**: Linear, Polynomial, Exponential, Logarithmic, Power, and Multiple Linear Regression with $R^2$ validation.
|
|
23
|
+
* **Omniscient Root Finding**: Automatically detects polynomial degrees and calculates search ranges using Cauchy's Bound—no more manual guessing.
|
|
24
|
+
* **Non-Linear System Solver**: Solves systems of equations using a Jacobian-based multi-variable Newton-Raphson method.
|
|
25
|
+
* **Matrix Core**: Pure-Python implementation featuring Gaussian Elimination with Partial Pivoting, Inversion, and Determinants.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🛠 Installation & Setup
|
|
30
|
+
|
|
31
|
+
To use this in your project, clone the repository:
|
|
32
|
+
|
|
33
|
+
```batch
|
|
34
|
+
git clone https://github.com/NeoZett-School/Math-Extention.git
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📖 Quick Start Examples
|
|
40
|
+
|
|
41
|
+
### 1. Symbolic Differentiation & "Smart" Solving
|
|
42
|
+
Solve for the roots of a cubic function. The solver automatically detects the degree (3) and sets the search range using Cauchy's Bound.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from math_extention import Canvas, Symbol, Function, Solver
|
|
46
|
+
|
|
47
|
+
canvas = Canvas()
|
|
48
|
+
x = Symbol('x')
|
|
49
|
+
|
|
50
|
+
f = Function('x', x**3 - 6*x**2 + 9*x + 15)
|
|
51
|
+
|
|
52
|
+
# The solver investigates the complexity of 'f' and finds all real roots
|
|
53
|
+
roots = Solver.solve_all(f, target=0, symbol=x)
|
|
54
|
+
print(f"Roots of {f.written}: {roots}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Solving Non-Linear Systems (Jacobian Method)
|
|
58
|
+
Find the intersection points of a unit circle and a diagonal line.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from math_extention import Canvas, Symbol, RegressionPoly
|
|
62
|
+
|
|
63
|
+
canvas = Canvas()
|
|
64
|
+
x = Symbol("x")
|
|
65
|
+
|
|
66
|
+
data = [(0, 1), (1, 2.1), (2, 3.9), (3, 9.2)]
|
|
67
|
+
reg = RegressionPoly(data, degree=2)
|
|
68
|
+
|
|
69
|
+
coeffs = reg.calculate() # Returns [a0, a1, a2]
|
|
70
|
+
accuracy = reg.r_squared() # Returns the Coefficient of Determination
|
|
71
|
+
|
|
72
|
+
print(f"Model: {reg.create_function('x').written}")
|
|
73
|
+
print(f"R^2 Accuracy: {accuracy:.4f}")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Data Regression & Goodness of Fit ($R^2$)
|
|
77
|
+
Fit a polynomial to data and verify the accuracy of the model.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from math_extention import Canvas, Symbol, RegressionPoly
|
|
81
|
+
|
|
82
|
+
canvas = Canvas()
|
|
83
|
+
x = Symbol("x")
|
|
84
|
+
|
|
85
|
+
data = [(0, 1), (1, 2.1), (2, 3.9), (3, 9.2)]
|
|
86
|
+
reg = RegressionPoly(data, degree=2)
|
|
87
|
+
|
|
88
|
+
coeffs = reg.calculate() # Returns [a0, a1, a2]
|
|
89
|
+
accuracy = reg.r_squared() # Returns the Coefficient of Determination
|
|
90
|
+
|
|
91
|
+
print(f"Model: {reg.create_function('x').written}")
|
|
92
|
+
print(f"R^2 Accuracy: {accuracy:.4f}")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 🧪 Technical Architecture
|
|
98
|
+
|
|
99
|
+
### The `Traceable` Object
|
|
100
|
+
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:
|
|
101
|
+
* **Power Rule**: Handles $x^n$.
|
|
102
|
+
* **Exponential Rule**: Handles $a^x$.
|
|
103
|
+
* **General Power Rule**: Handles $f(x)^{g(x)}$.
|
|
104
|
+
|
|
105
|
+
### The `Matrix` Engine
|
|
106
|
+
The `Matrix` class handles the heavy lifting for regressions and system solving.
|
|
107
|
+
* **Partial Pivoting**: Ensures numerical stability by selecting the largest available pivot.
|
|
108
|
+
* **Normal Equations**: Used in all regression classes to solve $(X^T X)\beta = X^T Y$.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 📈 Roadmap
|
|
113
|
+
- [x] Trigonometric support (`sin`, `cos`, `tan`).
|
|
114
|
+
- [x] Automatic Complexity (Degree) Detection.
|
|
115
|
+
- [x] Multiple Linear Regression.
|
|
116
|
+
- [ ] LaTeX String Exporting for documentation.
|
|
117
|
+
- [ ] Residual Analysis Plotting.
|
|
118
|
+
|
|
119
|
+
---
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Math-Extension
|
|
2
|
+
**A Hybrid Symbolic-Numeric Mathematics Engine for Python.**
|
|
3
|
+
|
|
4
|
+
`Math-Extention` 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.
|
|
5
|
+
|
|
6
|
+
## 🚀 Key Features
|
|
7
|
+
* **Symbolic Traceability**: Every operation is stored in a tree, allowing for `f.diff(x)` (Recursive Automatic Differentiation).
|
|
8
|
+
* **Advanced Regressions**: Linear, Polynomial, Exponential, Logarithmic, Power, and Multiple Linear Regression with $R^2$ validation.
|
|
9
|
+
* **Omniscient Root Finding**: Automatically detects polynomial degrees and calculates search ranges using Cauchy's Bound—no more manual guessing.
|
|
10
|
+
* **Non-Linear System Solver**: Solves systems of equations using a Jacobian-based multi-variable Newton-Raphson method.
|
|
11
|
+
* **Matrix Core**: Pure-Python implementation featuring Gaussian Elimination with Partial Pivoting, Inversion, and Determinants.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🛠 Installation & Setup
|
|
16
|
+
|
|
17
|
+
To use this in your project, clone the repository:
|
|
18
|
+
|
|
19
|
+
```batch
|
|
20
|
+
git clone https://github.com/NeoZett-School/Math-Extention.git
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 📖 Quick Start Examples
|
|
26
|
+
|
|
27
|
+
### 1. Symbolic Differentiation & "Smart" Solving
|
|
28
|
+
Solve for the roots of a cubic function. The solver automatically detects the degree (3) and sets the search range using Cauchy's Bound.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from math_extention import Canvas, Symbol, Function, Solver
|
|
32
|
+
|
|
33
|
+
canvas = Canvas()
|
|
34
|
+
x = Symbol('x')
|
|
35
|
+
|
|
36
|
+
f = Function('x', x**3 - 6*x**2 + 9*x + 15)
|
|
37
|
+
|
|
38
|
+
# The solver investigates the complexity of 'f' and finds all real roots
|
|
39
|
+
roots = Solver.solve_all(f, target=0, symbol=x)
|
|
40
|
+
print(f"Roots of {f.written}: {roots}")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Solving Non-Linear Systems (Jacobian Method)
|
|
44
|
+
Find the intersection points of a unit circle and a diagonal line.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from math_extention import Canvas, Symbol, RegressionPoly
|
|
48
|
+
|
|
49
|
+
canvas = Canvas()
|
|
50
|
+
x = Symbol("x")
|
|
51
|
+
|
|
52
|
+
data = [(0, 1), (1, 2.1), (2, 3.9), (3, 9.2)]
|
|
53
|
+
reg = RegressionPoly(data, degree=2)
|
|
54
|
+
|
|
55
|
+
coeffs = reg.calculate() # Returns [a0, a1, a2]
|
|
56
|
+
accuracy = reg.r_squared() # Returns the Coefficient of Determination
|
|
57
|
+
|
|
58
|
+
print(f"Model: {reg.create_function('x').written}")
|
|
59
|
+
print(f"R^2 Accuracy: {accuracy:.4f}")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3. Data Regression & Goodness of Fit ($R^2$)
|
|
63
|
+
Fit a polynomial to data and verify the accuracy of the model.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from math_extention import Canvas, Symbol, RegressionPoly
|
|
67
|
+
|
|
68
|
+
canvas = Canvas()
|
|
69
|
+
x = Symbol("x")
|
|
70
|
+
|
|
71
|
+
data = [(0, 1), (1, 2.1), (2, 3.9), (3, 9.2)]
|
|
72
|
+
reg = RegressionPoly(data, degree=2)
|
|
73
|
+
|
|
74
|
+
coeffs = reg.calculate() # Returns [a0, a1, a2]
|
|
75
|
+
accuracy = reg.r_squared() # Returns the Coefficient of Determination
|
|
76
|
+
|
|
77
|
+
print(f"Model: {reg.create_function('x').written}")
|
|
78
|
+
print(f"R^2 Accuracy: {accuracy:.4f}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🧪 Technical Architecture
|
|
84
|
+
|
|
85
|
+
### The `Traceable` Object
|
|
86
|
+
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:
|
|
87
|
+
* **Power Rule**: Handles $x^n$.
|
|
88
|
+
* **Exponential Rule**: Handles $a^x$.
|
|
89
|
+
* **General Power Rule**: Handles $f(x)^{g(x)}$.
|
|
90
|
+
|
|
91
|
+
### The `Matrix` Engine
|
|
92
|
+
The `Matrix` class handles the heavy lifting for regressions and system solving.
|
|
93
|
+
* **Partial Pivoting**: Ensures numerical stability by selecting the largest available pivot.
|
|
94
|
+
* **Normal Equations**: Used in all regression classes to solve $(X^T X)\beta = X^T Y$.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 📈 Roadmap
|
|
99
|
+
- [x] Trigonometric support (`sin`, `cos`, `tan`).
|
|
100
|
+
- [x] Automatic Complexity (Degree) Detection.
|
|
101
|
+
- [x] Multiple Linear Regression.
|
|
102
|
+
- [ ] LaTeX String Exporting for documentation.
|
|
103
|
+
- [ ] Residual Analysis Plotting.
|
|
104
|
+
|
|
105
|
+
---
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Math Extention allow symbols as variables and expressions, functions to use in different type of regression."""
|
|
2
|
+
|
|
3
|
+
from sys import version_info
|
|
4
|
+
from warnings import warn
|
|
5
|
+
if version_info < (3, 10):
|
|
6
|
+
warn(
|
|
7
|
+
message = "Math Extention expects a python version >=3.10",
|
|
8
|
+
category = RuntimeWarning
|
|
9
|
+
)
|
|
10
|
+
from .core import *
|
|
11
|
+
__all__ = core.__all__
|