pymodab 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.
- pymodab-1.0.0/LICENSE +21 -0
- pymodab-1.0.0/MANIFEST.in +3 -0
- pymodab-1.0.0/PKG-INFO +94 -0
- pymodab-1.0.0/README.md +65 -0
- pymodab-1.0.0/pyproject.toml +42 -0
- pymodab-1.0.0/setup.cfg +4 -0
- pymodab-1.0.0/src/pymodab/ModAB.dll +0 -0
- pymodab-1.0.0/src/pymodab/ModAB.lib +0 -0
- pymodab-1.0.0/src/pymodab/__init__.py +15 -0
- pymodab-1.0.0/src/pymodab/libModAB.so +0 -0
- pymodab-1.0.0/src/pymodab/libModAB_arm64.dylib +0 -0
- pymodab-1.0.0/src/pymodab/libModAB_x64.dylib +0 -0
- pymodab-1.0.0/src/pymodab/modab.py +168 -0
- pymodab-1.0.0/src/pymodab/py.typed +0 -0
- pymodab-1.0.0/src/pymodab.egg-info/PKG-INFO +94 -0
- pymodab-1.0.0/src/pymodab.egg-info/SOURCES.txt +16 -0
- pymodab-1.0.0/src/pymodab.egg-info/dependency_links.txt +1 -0
- pymodab-1.0.0/src/pymodab.egg-info/top_level.txt +1 -0
pymodab-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ned Ganchovski
|
|
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.
|
pymodab-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymodab
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Fast and robust root-finding using the Modified Anderson-Bjork method
|
|
5
|
+
Author: Ganchovski, Traykov
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ModAB-Root-Finding/ModAB-Python
|
|
8
|
+
Project-URL: Repository, https://github.com/ModAB-Root-Finding/ModAB-Python
|
|
9
|
+
Keywords: root-finding,numerical,mathematics,optimization,bisection,secant
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: C
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
A fast and robust root-finding library using the Modified Anderson-Bjork method (Ganchovski, Traykov), written in C for Python.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install pymodab
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import math
|
|
43
|
+
from pymodab import find_root, find_default, get_evaluation_count
|
|
44
|
+
|
|
45
|
+
# Find the root of cos(x) - x = 0 in [0, 1]
|
|
46
|
+
root = find_root(lambda x: math.cos(x) - x, 0, 1, 100)
|
|
47
|
+
print(f"Root: {root}") # 0.7390851332151607
|
|
48
|
+
|
|
49
|
+
# Using default tolerances
|
|
50
|
+
root = find_default(lambda x: x**2 - 2, 1, 2)
|
|
51
|
+
print(f"sqrt(2) = {root}") # 1.4142135623730951
|
|
52
|
+
|
|
53
|
+
# Get the number of function evaluations
|
|
54
|
+
print(f"Evaluations: {get_evaluation_count()}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### `find_root(f, x1, x2, atol=1e-14, rtol=1e-14, max_iter=200)`
|
|
60
|
+
|
|
61
|
+
Find the root of `f(x) = 0` within the interval `[x1, x2]`.
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
- `f`: A continuous function of one variable
|
|
65
|
+
- `x1`, `x2`: Bracket interval endpoints (must satisfy `f(x1) * f(x2) < 0`)
|
|
66
|
+
- `atol`: Absolute tolerance (default: 1e-14)
|
|
67
|
+
- `rtol`: Relative tolerance (default: 1e-14)
|
|
68
|
+
- `max_iter`: Maximum iterations (default: 200)
|
|
69
|
+
|
|
70
|
+
**Returns:** The root, or `NaN` if not found.
|
|
71
|
+
|
|
72
|
+
### `find_default(f, x1, x2)`
|
|
73
|
+
|
|
74
|
+
Convenience wrapper for `find_root` with default tolerances.
|
|
75
|
+
|
|
76
|
+
### `get_evaluation_count()`
|
|
77
|
+
|
|
78
|
+
Returns the number of function evaluations from the last root-finding call.
|
|
79
|
+
|
|
80
|
+
## Algorithm
|
|
81
|
+
|
|
82
|
+
Modified Anderson-Björck's method is a new robust and efficient bracketing root-finding algorithm. It combines bisection with Anderson-Björk's method to achieve both fast performance and worst-case optimality.
|
|
83
|
+
|
|
84
|
+
References:
|
|
85
|
+
|
|
86
|
+
Ganchovski N.; Traykov A. Modified Anderson-Björck's method for solving non-linear equations in structural mechanics. IOP Conference Series: Materials Science and Engineering 2023, 1276 (1) 012010, IOP Publishing.
|
|
87
|
+
https://iopscience.iop.org/article/10.1088/1757-899X/1276/1/012010/pdf
|
|
88
|
+
|
|
89
|
+
Ganchovski, N.; Smith, O.; Rackauckas, C.; Tomov, L.; Traykov, A. Improvements of the Modified Anderson-Björck (modAB) Root-Finding Algorithm. Preprints 2026, 2026032190.
|
|
90
|
+
https://www.preprints.org/manuscript/202603.2190
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT License
|
pymodab-1.0.0/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
A fast and robust root-finding library using the Modified Anderson-Bjork method (Ganchovski, Traykov), written in C for Python.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install pymodab
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import math
|
|
14
|
+
from pymodab import find_root, find_default, get_evaluation_count
|
|
15
|
+
|
|
16
|
+
# Find the root of cos(x) - x = 0 in [0, 1]
|
|
17
|
+
root = find_root(lambda x: math.cos(x) - x, 0, 1, 100)
|
|
18
|
+
print(f"Root: {root}") # 0.7390851332151607
|
|
19
|
+
|
|
20
|
+
# Using default tolerances
|
|
21
|
+
root = find_default(lambda x: x**2 - 2, 1, 2)
|
|
22
|
+
print(f"sqrt(2) = {root}") # 1.4142135623730951
|
|
23
|
+
|
|
24
|
+
# Get the number of function evaluations
|
|
25
|
+
print(f"Evaluations: {get_evaluation_count()}")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API
|
|
29
|
+
|
|
30
|
+
### `find_root(f, x1, x2, atol=1e-14, rtol=1e-14, max_iter=200)`
|
|
31
|
+
|
|
32
|
+
Find the root of `f(x) = 0` within the interval `[x1, x2]`.
|
|
33
|
+
|
|
34
|
+
**Parameters:**
|
|
35
|
+
- `f`: A continuous function of one variable
|
|
36
|
+
- `x1`, `x2`: Bracket interval endpoints (must satisfy `f(x1) * f(x2) < 0`)
|
|
37
|
+
- `atol`: Absolute tolerance (default: 1e-14)
|
|
38
|
+
- `rtol`: Relative tolerance (default: 1e-14)
|
|
39
|
+
- `max_iter`: Maximum iterations (default: 200)
|
|
40
|
+
|
|
41
|
+
**Returns:** The root, or `NaN` if not found.
|
|
42
|
+
|
|
43
|
+
### `find_default(f, x1, x2)`
|
|
44
|
+
|
|
45
|
+
Convenience wrapper for `find_root` with default tolerances.
|
|
46
|
+
|
|
47
|
+
### `get_evaluation_count()`
|
|
48
|
+
|
|
49
|
+
Returns the number of function evaluations from the last root-finding call.
|
|
50
|
+
|
|
51
|
+
## Algorithm
|
|
52
|
+
|
|
53
|
+
Modified Anderson-Björck's method is a new robust and efficient bracketing root-finding algorithm. It combines bisection with Anderson-Björk's method to achieve both fast performance and worst-case optimality.
|
|
54
|
+
|
|
55
|
+
References:
|
|
56
|
+
|
|
57
|
+
Ganchovski N.; Traykov A. Modified Anderson-Björck's method for solving non-linear equations in structural mechanics. IOP Conference Series: Materials Science and Engineering 2023, 1276 (1) 012010, IOP Publishing.
|
|
58
|
+
https://iopscience.iop.org/article/10.1088/1757-899X/1276/1/012010/pdf
|
|
59
|
+
|
|
60
|
+
Ganchovski, N.; Smith, O.; Rackauckas, C.; Tomov, L.; Traykov, A. Improvements of the Modified Anderson-Björck (modAB) Root-Finding Algorithm. Preprints 2026, 2026032190.
|
|
61
|
+
https://www.preprints.org/manuscript/202603.2190
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT License
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pymodab"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Fast and robust root-finding using the Modified Anderson-Bjork method"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Ganchovski, Traykov"}
|
|
13
|
+
]
|
|
14
|
+
keywords = ["root-finding", "numerical", "mathematics", "optimization", "bisection", "secant"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: Microsoft :: Windows",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Operating System :: MacOS",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Programming Language :: C",
|
|
30
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
31
|
+
]
|
|
32
|
+
requires-python = ">=3.8"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/ModAB-Root-Finding/ModAB-Python"
|
|
36
|
+
Repository = "https://github.com/ModAB-Root-Finding/ModAB-Python"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
pymodab = ["*.dll", "*.so", "*.dylib", "*.lib", "py.typed"]
|
pymodab-1.0.0/setup.cfg
ADDED
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyModAB - Python wrapper for the Modified Anderson-Bjork (modAB) algorithm .
|
|
3
|
+
ModAB is a fast and robust root-finding method that combines bisection with the
|
|
4
|
+
Anderson-Bjork method for that provide fast convergence for well-behaved functions
|
|
5
|
+
while preserving wost-case optimality.
|
|
6
|
+
|
|
7
|
+
Ganchovski, N.; Smith, O.; Rackauckas, C.; Tomov, L.; Traykov, A.
|
|
8
|
+
Improvements of the Modified Anderson-Björck (modAB) Root-Finding Algorithm.
|
|
9
|
+
Preprints 2026, 2026032190. https://doi.org/10.20944/preprints202603.2190.v1
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .modab import find_root, find_default, get_evaluation_count
|
|
13
|
+
|
|
14
|
+
__version__ = "1.0.0"
|
|
15
|
+
__all__ = ["find_root", "find_default", "get_evaluation_count"]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python wrapper for the ModAB C library.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import ctypes
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
import sys
|
|
9
|
+
from ctypes import c_double, c_int, CFUNCTYPE
|
|
10
|
+
from typing import Callable
|
|
11
|
+
|
|
12
|
+
# Define the callback function type for the C library
|
|
13
|
+
FUNC_TYPE = CFUNCTYPE(c_double, c_double)
|
|
14
|
+
|
|
15
|
+
def _get_library_path() -> str:
|
|
16
|
+
"""Get the path to the shared library based on the platform."""
|
|
17
|
+
package_dir = os.path.dirname(os.path.abspath(__file__))
|
|
18
|
+
|
|
19
|
+
system = platform.system()
|
|
20
|
+
if system == "Windows":
|
|
21
|
+
lib_name = "ModAB.dll"
|
|
22
|
+
elif system == "Darwin":
|
|
23
|
+
machine = platform.machine()
|
|
24
|
+
if machine == "arm64":
|
|
25
|
+
lib_name = "libModAB_arm64.dylib"
|
|
26
|
+
else:
|
|
27
|
+
lib_name = "libModAB_x64.dylib"
|
|
28
|
+
else: # Linux and others
|
|
29
|
+
lib_name = "libModAB.so"
|
|
30
|
+
|
|
31
|
+
lib_path = os.path.join(package_dir, lib_name)
|
|
32
|
+
|
|
33
|
+
if not os.path.exists(lib_path):
|
|
34
|
+
raise FileNotFoundError(
|
|
35
|
+
f"Could not find {lib_name} in {package_dir}. "
|
|
36
|
+
f"Please ensure the library is built for your platform."
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return lib_path
|
|
40
|
+
|
|
41
|
+
def _load_library():
|
|
42
|
+
"""Load the ModAB shared library."""
|
|
43
|
+
lib_path = _get_library_path()
|
|
44
|
+
lib = ctypes.CDLL(lib_path)
|
|
45
|
+
|
|
46
|
+
# Configure modAB_find_root
|
|
47
|
+
lib.modAB_find_root.argtypes = [FUNC_TYPE, c_double, c_double, c_double, c_double, c_int]
|
|
48
|
+
lib.modAB_find_root.restype = c_double
|
|
49
|
+
|
|
50
|
+
# Configure modAB_default
|
|
51
|
+
lib.modAB_default.argtypes = [FUNC_TYPE, c_double, c_double]
|
|
52
|
+
lib.modAB_default.restype = c_double
|
|
53
|
+
|
|
54
|
+
# Configure get_evaluation_count
|
|
55
|
+
lib.get_evaluation_count.argtypes = []
|
|
56
|
+
lib.get_evaluation_count.restype = c_int
|
|
57
|
+
|
|
58
|
+
return lib
|
|
59
|
+
|
|
60
|
+
# Load the library once at module import
|
|
61
|
+
_lib = _load_library()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def find_root(
|
|
65
|
+
f: Callable[[float], float],
|
|
66
|
+
x1: float,
|
|
67
|
+
x2: float,
|
|
68
|
+
atol: float = 1e-14,
|
|
69
|
+
rtol: float = 1e-14,
|
|
70
|
+
max_iter: int = 200
|
|
71
|
+
) -> float:
|
|
72
|
+
"""
|
|
73
|
+
Find the root of f(x) = 0 within the interval [x1, x2].
|
|
74
|
+
|
|
75
|
+
Uses an improved version of the Modified Anderson-Bjork method
|
|
76
|
+
(Ganchovski, Traykov) which combines bisection with the secant method
|
|
77
|
+
for robust and fast convergence.
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
f : callable
|
|
82
|
+
A continuous function of one variable.
|
|
83
|
+
x1 : float
|
|
84
|
+
Left endpoint of the bracket interval.
|
|
85
|
+
x2 : float
|
|
86
|
+
Right endpoint of the bracket interval.
|
|
87
|
+
atol : float, optional
|
|
88
|
+
Absolute tolerance for convergence (default: 1e-14).
|
|
89
|
+
rtol : float, optional
|
|
90
|
+
Relative tolerance for convergence (default: 1e-14).
|
|
91
|
+
max_iter : int, optional
|
|
92
|
+
Maximum number of iterations (default: 200).
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
float
|
|
97
|
+
The root of f(x) = 0 within [x1, x2].
|
|
98
|
+
Returns NaN if no root is found or if f(x1) and f(x2) have the same sign.
|
|
99
|
+
|
|
100
|
+
Notes
|
|
101
|
+
-----
|
|
102
|
+
The function f must be continuous on [x1, x2] and f(x1) * f(x2) < 0
|
|
103
|
+
(i.e., the function must have opposite signs at the endpoints).
|
|
104
|
+
|
|
105
|
+
Examples
|
|
106
|
+
--------
|
|
107
|
+
>>> import math
|
|
108
|
+
>>> from pymodab import find_root
|
|
109
|
+
>>> # Find the root of cos(x) - x in [0, 1]
|
|
110
|
+
>>> root = find_root(lambda x: math.cos(x) - x, 0, 1)
|
|
111
|
+
>>> print(f"{root:.10f}")
|
|
112
|
+
0.7390851332
|
|
113
|
+
"""
|
|
114
|
+
c_func = FUNC_TYPE(f)
|
|
115
|
+
return _lib.modAB_find_root(c_func, x1, x2, atol, rtol, max_iter)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def find_default(f: Callable[[float], float], x1: float, x2: float) -> float:
|
|
119
|
+
"""
|
|
120
|
+
Find the root of f(x) = 0 within the interval [x1, x2] using default tolerances.
|
|
121
|
+
|
|
122
|
+
This is a convenience function that calls find_root with default parameters:
|
|
123
|
+
atol=1e-14, rtol=1e-14, max_iter=200.
|
|
124
|
+
|
|
125
|
+
Parameters
|
|
126
|
+
----------
|
|
127
|
+
f : callable
|
|
128
|
+
A continuous function of one variable.
|
|
129
|
+
x1 : float
|
|
130
|
+
Left endpoint of the bracket interval.
|
|
131
|
+
x2 : float
|
|
132
|
+
Right endpoint of the bracket interval.
|
|
133
|
+
|
|
134
|
+
Returns
|
|
135
|
+
-------
|
|
136
|
+
float
|
|
137
|
+
The root of f(x) = 0 within [x1, x2].
|
|
138
|
+
Returns NaN if no root is found or if f(x1) and f(x2) have the same sign.
|
|
139
|
+
|
|
140
|
+
Examples
|
|
141
|
+
--------
|
|
142
|
+
>>> import math
|
|
143
|
+
>>> from pymodab import find_default
|
|
144
|
+
>>> root = find_default(lambda x: x**2 - 2, 1, 2)
|
|
145
|
+
>>> print(f"{root:.10f}")
|
|
146
|
+
1.4142135624
|
|
147
|
+
"""
|
|
148
|
+
c_func = FUNC_TYPE(f)
|
|
149
|
+
return _lib.modAB_default(c_func, x1, x2)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def get_evaluation_count() -> int:
|
|
153
|
+
"""
|
|
154
|
+
Get the number of function evaluations from the last root-finding call.
|
|
155
|
+
|
|
156
|
+
Returns
|
|
157
|
+
-------
|
|
158
|
+
int
|
|
159
|
+
The number of times the function was evaluated during the last
|
|
160
|
+
call to find_root or find_default.
|
|
161
|
+
|
|
162
|
+
Examples
|
|
163
|
+
--------
|
|
164
|
+
>>> from pymodab import find_default, get_evaluation_count
|
|
165
|
+
>>> root = find_default(lambda x: x**2 - 2, 1, 2)
|
|
166
|
+
>>> print(f"Evaluations: {get_evaluation_count()}")
|
|
167
|
+
"""
|
|
168
|
+
return _lib.get_evaluation_count()
|
|
File without changes
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymodab
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Fast and robust root-finding using the Modified Anderson-Bjork method
|
|
5
|
+
Author: Ganchovski, Traykov
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ModAB-Root-Finding/ModAB-Python
|
|
8
|
+
Project-URL: Repository, https://github.com/ModAB-Root-Finding/ModAB-Python
|
|
9
|
+
Keywords: root-finding,numerical,mathematics,optimization,bisection,secant
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: C
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
A fast and robust root-finding library using the Modified Anderson-Bjork method (Ganchovski, Traykov), written in C for Python.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install pymodab
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import math
|
|
43
|
+
from pymodab import find_root, find_default, get_evaluation_count
|
|
44
|
+
|
|
45
|
+
# Find the root of cos(x) - x = 0 in [0, 1]
|
|
46
|
+
root = find_root(lambda x: math.cos(x) - x, 0, 1, 100)
|
|
47
|
+
print(f"Root: {root}") # 0.7390851332151607
|
|
48
|
+
|
|
49
|
+
# Using default tolerances
|
|
50
|
+
root = find_default(lambda x: x**2 - 2, 1, 2)
|
|
51
|
+
print(f"sqrt(2) = {root}") # 1.4142135623730951
|
|
52
|
+
|
|
53
|
+
# Get the number of function evaluations
|
|
54
|
+
print(f"Evaluations: {get_evaluation_count()}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### `find_root(f, x1, x2, atol=1e-14, rtol=1e-14, max_iter=200)`
|
|
60
|
+
|
|
61
|
+
Find the root of `f(x) = 0` within the interval `[x1, x2]`.
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
- `f`: A continuous function of one variable
|
|
65
|
+
- `x1`, `x2`: Bracket interval endpoints (must satisfy `f(x1) * f(x2) < 0`)
|
|
66
|
+
- `atol`: Absolute tolerance (default: 1e-14)
|
|
67
|
+
- `rtol`: Relative tolerance (default: 1e-14)
|
|
68
|
+
- `max_iter`: Maximum iterations (default: 200)
|
|
69
|
+
|
|
70
|
+
**Returns:** The root, or `NaN` if not found.
|
|
71
|
+
|
|
72
|
+
### `find_default(f, x1, x2)`
|
|
73
|
+
|
|
74
|
+
Convenience wrapper for `find_root` with default tolerances.
|
|
75
|
+
|
|
76
|
+
### `get_evaluation_count()`
|
|
77
|
+
|
|
78
|
+
Returns the number of function evaluations from the last root-finding call.
|
|
79
|
+
|
|
80
|
+
## Algorithm
|
|
81
|
+
|
|
82
|
+
Modified Anderson-Björck's method is a new robust and efficient bracketing root-finding algorithm. It combines bisection with Anderson-Björk's method to achieve both fast performance and worst-case optimality.
|
|
83
|
+
|
|
84
|
+
References:
|
|
85
|
+
|
|
86
|
+
Ganchovski N.; Traykov A. Modified Anderson-Björck's method for solving non-linear equations in structural mechanics. IOP Conference Series: Materials Science and Engineering 2023, 1276 (1) 012010, IOP Publishing.
|
|
87
|
+
https://iopscience.iop.org/article/10.1088/1757-899X/1276/1/012010/pdf
|
|
88
|
+
|
|
89
|
+
Ganchovski, N.; Smith, O.; Rackauckas, C.; Tomov, L.; Traykov, A. Improvements of the Modified Anderson-Björck (modAB) Root-Finding Algorithm. Preprints 2026, 2026032190.
|
|
90
|
+
https://www.preprints.org/manuscript/202603.2190
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT License
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/pymodab/ModAB.dll
|
|
6
|
+
src/pymodab/ModAB.lib
|
|
7
|
+
src/pymodab/__init__.py
|
|
8
|
+
src/pymodab/libModAB.so
|
|
9
|
+
src/pymodab/libModAB_arm64.dylib
|
|
10
|
+
src/pymodab/libModAB_x64.dylib
|
|
11
|
+
src/pymodab/modab.py
|
|
12
|
+
src/pymodab/py.typed
|
|
13
|
+
src/pymodab.egg-info/PKG-INFO
|
|
14
|
+
src/pymodab.egg-info/SOURCES.txt
|
|
15
|
+
src/pymodab.egg-info/dependency_links.txt
|
|
16
|
+
src/pymodab.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pymodab
|