| Name | polysolve JSON |
| Version |
0.6.0
JSON |
| download |
| home_page | None |
| Summary | A Python library for representing, manipulating, and solving exponential functions using analytical methods and genetic algorithms, with optional CUDA acceleration. |
| upload_time | 2025-10-30 15:36:21 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | MIT License
Copyright (c) 2025 Jonathan Rampersad
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| keywords |
math
polynomial
genetic algorithm
cuda
equation solver
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
<p align="center">
<img src="https://i.ibb.co/N22Gx6xq/Poly-Solve-Logo.png" alt="polysolve Logo" width="256">
</p>
[](https://pypi.org/project/polysolve/)
[](https://pypi.org/project/polysolve/)
A Python library for representing, manipulating, and solving polynomial equations. Features a high-performance, Numba-accelerated genetic algorithm for CPU, with an optional CUDA/GPU backend for massive-scale parallel solving.
---
## Key Features
* **Numerically Stable Solver**: Makes complex calculations **practical**. Leverage your GPU to power the robust genetic algorithm, solving high-degree polynomials accurately in a reasonable timeframe.
* **Numba Accelerated CPU Solver**: The default genetic algorithm is JIT-compiled with Numba for high-speed CPU performance, right out of the box.
* **CUDA Accelerated**: Leverage NVIDIA GPUs for a massive performance boost when finding roots in large solution spaces.
* **Create and Manipulate Polynomials**: Easily define polynomials of any degree using integer or float coefficients, and perform arithmetic operations like addition, subtraction, multiplication, and scaling.
* **Analytical Solvers**: Includes standard, exact solvers for simple cases (e.g., `quadratic_solve`).
* **Simple API**: Designed to be intuitive and easy to integrate into any project.
---
## Installation
Install the base package from PyPI:
```bash
pip install polysolve
```
### CUDA Acceleration
To enable GPU acceleration, install the extra that matches your installed NVIDIA CUDA Toolkit version. This provides a significant speedup for the genetic algorithm.
**For CUDA 12.x users:**
```bash
pip install polysolve[cuda12]
```
---
## Quick Start
Here is a simple example of how to define a quadratic function, find its properties, and solve for its roots.
```python
from polysolve import Function, GA_Options
# 1. Define the function f(x) = 2x^2 - 3x - 5
# Coefficients can be integers or floats.
f1 = Function(largest_exponent=2)
f1.set_coeffs([2, -3, -5])
print(f"Function f1: {f1}")
# > Function f1: 2x^2 - 3x - 5
# 2. Solve for y at a given x
y_val = f1.solve_y(5)
print(f"Value of f1 at x=5 is: {y_val}")
# > Value of f1 at x=5 is: 30.0
# 3. Get the derivative: 4x - 3
df1 = f1.derivative()
print(f"Derivative of f1: {df1}")
# > Derivative of f1: 4x - 3
# 4. Get the 2nd derivative: 4
ddf1 = f1.nth_derivative(2)
print(f"2nd Derivative of f1: {ddf1}")
# > Derivative of f1: 4
# 5. Find roots analytically using the quadratic formula
# This is exact and fast for degree-2 polynomials.
roots_analytic = f1.quadratic_solve()
print(f"Analytic roots: {sorted(roots_analytic)}")
# > Analytic roots: [-1.0, 2.5]
# 6. Find roots with the genetic algorithm (Numba CPU)
# ย ย This is the default, JIT-compiled CPU solver.
ga_opts = GA_Options(num_of_generations=20)
roots_ga = f1.get_real_roots(ga_opts, use_cuda=False)
print(f"Approximate roots from GA: {roots_ga[:2]}")
# > Approximate roots from GA: [-1.000..., 2.500...]
# If you installed a CUDA extra, you can run it on the GPU:
# roots_ga_gpu = f1.get_real_roots(ga_opts, use_cuda=True)
# print(f"Approximate roots from GA (GPU): {roots_ga_gpu[:2]}")
```
---
## Tuning the Genetic Algorithm
The `GA_Options` class gives you fine-grained control over the genetic algorithm's performance, letting you trade speed for accuracy.
The default options are balanced, but for very complex polynomials, you may want a more exhaustive search.
```python
from polysolve import GA_Options
# Create a config for a deep search, optimized for finding
# *all* real roots (even if they are far apart).
ga_robust_search = GA_Options(
num_of_generations=50, # Run for more generations
data_size=500000, # Use a larger population
# --- Key Tuning Parameters for Multi-Root Finding ---
# Widen the parent pool to 75% to keep more "niches"
# (solution-clouds around different roots) alive.
selection_percentile=0.75,
# Increase the crossover blend factor to 0.75.
# This allows new solutions to be created further
# away from their parents, increasing exploration.
blend_alpha=0.75
)
# Pass the custom options to the solver
roots = f1.get_real_roots(ga_accurate)
```
For a full breakdown of all parameters, including crossover_ratio, mutation_strength, and more, please see [the full GA_Options API Documentation](https://polysolve.jono-rams.work/docs/ga-options-api).
---
## Development & Testing Environment
This project is automatically tested against a specific set of dependencies to ensure stability. Our Continuous Integration (CI) pipeline runs on an environment using **CUDA 12.5** on **Ubuntu 24.04**.
While the code may work on other configurations, all contributions must pass the automated tests in our reference environment. For detailed information on how to replicate the testing environment, please see our [**Contributing Guide**](CONTRIBUTING.md).
## Contributing
[](http://makeapullrequest.com)
[](https://github.com/jono-rams/PolySolve/issues)
[](https://github.com/jono-rams/PolySolve/pulls)
Contributions are welcome! Whether it's a bug report, a feature request, or a pull request, please feel free to get involved.
Please read our `CONTRIBUTING.md` file for details on our code of conduct and the process for submitting pull requests.
## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://jono-rams.work"><img src="https://avatars.githubusercontent.com/u/29872001?v=4?s=100" width="100px;" alt="Jonathan Rampersad"/><br /><sub><b>Jonathan Rampersad</b></sub></a><br /><a href="https://github.com/jono-rams/PolySolve/commits?author=jono-rams" title="Maintenance">๐ง</a> <a href="https://github.com/jono-rams/PolySolve/commits?author=jono-rams" title="Code">๐ป</a> <a href="https://github.com/jono-rams/PolySolve/commits?author=jono-rams" title="Documentation">๐</a> <a href="#infra-jono-rams" title="Infrastructure (Hosting, Build-Tools, etc)">๐</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="center" size="13px" colspan="7">
<img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg">
<a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
</img>
</td>
</tr>
</tfoot>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
## License
This project is licensed under the MIT License - see the `LICENSE` file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "polysolve",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "math, polynomial, genetic algorithm, cuda, equation solver",
"author": null,
"author_email": "Jonathan Rampersad <jonathan@jono-rams.work>",
"download_url": "https://files.pythonhosted.org/packages/61/37/7d376371ded59cbe9de8e98b8f9f02aea3b5fca805b89bfa2688a9c8eb6e/polysolve-0.6.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <img src=\"https://i.ibb.co/N22Gx6xq/Poly-Solve-Logo.png\" alt=\"polysolve Logo\" width=\"256\">\n</p>\n\n[](https://pypi.org/project/polysolve/)\n[](https://pypi.org/project/polysolve/)\n\nA Python library for representing, manipulating, and solving polynomial equations. Features a high-performance, Numba-accelerated genetic algorithm for CPU, with an optional CUDA/GPU backend for massive-scale parallel solving.\n\n---\n\n## Key Features\n\n* **Numerically Stable Solver**: Makes complex calculations **practical**. Leverage your GPU to power the robust genetic algorithm, solving high-degree polynomials accurately in a reasonable timeframe.\n* **Numba Accelerated CPU Solver**: The default genetic algorithm is JIT-compiled with Numba for high-speed CPU performance, right out of the box.\n* **CUDA Accelerated**: Leverage NVIDIA GPUs for a massive performance boost when finding roots in large solution spaces.\n* **Create and Manipulate Polynomials**: Easily define polynomials of any degree using integer or float coefficients, and perform arithmetic operations like addition, subtraction, multiplication, and scaling.\n* **Analytical Solvers**: Includes standard, exact solvers for simple cases (e.g., `quadratic_solve`).\n* **Simple API**: Designed to be intuitive and easy to integrate into any project.\n\n---\n\n## Installation\n\nInstall the base package from PyPI:\n\n```bash\npip install polysolve\n```\n\n### CUDA Acceleration\n\nTo enable GPU acceleration, install the extra that matches your installed NVIDIA CUDA Toolkit version. This provides a significant speedup for the genetic algorithm.\n\n**For CUDA 12.x users:**\n```bash\npip install polysolve[cuda12]\n```\n\n---\n\n## Quick Start\n\nHere is a simple example of how to define a quadratic function, find its properties, and solve for its roots.\n\n```python\nfrom polysolve import Function, GA_Options\n\n# 1. Define the function f(x) = 2x^2 - 3x - 5\n# Coefficients can be integers or floats.\nf1 = Function(largest_exponent=2)\nf1.set_coeffs([2, -3, -5])\n\nprint(f\"Function f1: {f1}\")\n# > Function f1: 2x^2 - 3x - 5\n\n# 2. Solve for y at a given x\ny_val = f1.solve_y(5)\nprint(f\"Value of f1 at x=5 is: {y_val}\")\n# > Value of f1 at x=5 is: 30.0\n\n# 3. Get the derivative: 4x - 3\ndf1 = f1.derivative()\nprint(f\"Derivative of f1: {df1}\")\n# > Derivative of f1: 4x - 3\n\n# 4. Get the 2nd derivative: 4\nddf1 = f1.nth_derivative(2)\nprint(f\"2nd Derivative of f1: {ddf1}\")\n# > Derivative of f1: 4\n\n# 5. Find roots analytically using the quadratic formula\n# This is exact and fast for degree-2 polynomials.\nroots_analytic = f1.quadratic_solve()\nprint(f\"Analytic roots: {sorted(roots_analytic)}\")\n# > Analytic roots: [-1.0, 2.5]\n\n# 6. Find roots with the genetic algorithm (Numba CPU)\n# \u00a0 \u00a0This is the default, JIT-compiled CPU solver.\nga_opts = GA_Options(num_of_generations=20)\nroots_ga = f1.get_real_roots(ga_opts, use_cuda=False)\nprint(f\"Approximate roots from GA: {roots_ga[:2]}\")\n# > Approximate roots from GA: [-1.000..., 2.500...]\n\n# If you installed a CUDA extra, you can run it on the GPU:\n# roots_ga_gpu = f1.get_real_roots(ga_opts, use_cuda=True)\n# print(f\"Approximate roots from GA (GPU): {roots_ga_gpu[:2]}\")\n\n```\n\n---\n\n## Tuning the Genetic Algorithm\n\nThe `GA_Options` class gives you fine-grained control over the genetic algorithm's performance, letting you trade speed for accuracy.\n\nThe default options are balanced, but for very complex polynomials, you may want a more exhaustive search.\n\n```python\nfrom polysolve import GA_Options\n\n# Create a config for a deep search, optimized for finding\n# *all* real roots (even if they are far apart).\nga_robust_search = GA_Options(\n num_of_generations=50, # Run for more generations\n data_size=500000, # Use a larger population\n\n # --- Key Tuning Parameters for Multi-Root Finding ---\n\n # Widen the parent pool to 75% to keep more \"niches\"\n # (solution-clouds around different roots) alive.\n selection_percentile=0.75, \n\n # Increase the crossover blend factor to 0.75.\n # This allows new solutions to be created further\n # away from their parents, increasing exploration.\n blend_alpha=0.75\n)\n\n# Pass the custom options to the solver\nroots = f1.get_real_roots(ga_accurate)\n```\n\nFor a full breakdown of all parameters, including crossover_ratio, mutation_strength, and more, please see [the full GA_Options API Documentation](https://polysolve.jono-rams.work/docs/ga-options-api).\n\n---\n\n## Development & Testing Environment\n\nThis project is automatically tested against a specific set of dependencies to ensure stability. Our Continuous Integration (CI) pipeline runs on an environment using **CUDA 12.5** on **Ubuntu 24.04**.\n\nWhile the code may work on other configurations, all contributions must pass the automated tests in our reference environment. For detailed information on how to replicate the testing environment, please see our [**Contributing Guide**](CONTRIBUTING.md).\n\n## Contributing\n\n[](http://makeapullrequest.com)\n[](https://github.com/jono-rams/PolySolve/issues)\n[](https://github.com/jono-rams/PolySolve/pulls)\n\nContributions are welcome! Whether it's a bug report, a feature request, or a pull request, please feel free to get involved.\n\nPlease read our `CONTRIBUTING.md` file for details on our code of conduct and the process for submitting pull requests.\n\n## Contributors\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tbody>\n <tr>\n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://jono-rams.work\"><img src=\"https://avatars.githubusercontent.com/u/29872001?v=4?s=100\" width=\"100px;\" alt=\"Jonathan Rampersad\"/><br /><sub><b>Jonathan Rampersad</b></sub></a><br /><a href=\"https://github.com/jono-rams/PolySolve/commits?author=jono-rams\" title=\"Maintenance\">\ud83d\udea7</a> <a href=\"https://github.com/jono-rams/PolySolve/commits?author=jono-rams\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/jono-rams/PolySolve/commits?author=jono-rams\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"#infra-jono-rams\" title=\"Infrastructure (Hosting, Build-Tools, etc)\">\ud83d\ude87</a></td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <td align=\"center\" size=\"13px\" colspan=\"7\">\n <img src=\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\">\n <a href=\"https://all-contributors.js.org/docs/en/bot/usage\">Add your contributions</a>\n </img>\n </td>\n </tr>\n </tfoot>\n</table>\n\n<!-- markdownlint-restore -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\n## License\n\nThis project is licensed under the MIT License - see the `LICENSE` file for details.\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 Jonathan Rampersad\n \n Permission is hereby granted, free of charge, to any person obtaining a copy of this software and \n associated documentation files (the \"Software\"), to deal in the Software without restriction, including \n without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell \n copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the \n following conditions:\n \n The above copyright notice and this permission notice shall be included in all copies or substantial \n portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT \n LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO \n EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER \n IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE \n USE OR OTHER DEALINGS IN THE SOFTWARE.\n ",
"summary": "A Python library for representing, manipulating, and solving exponential functions using analytical methods and genetic algorithms, with optional CUDA acceleration.",
"version": "0.6.0",
"project_urls": {
"Bug Tracker": "https://github.com/jono-rams/PolySolve/issues",
"Documentation": "https://polysolve.jono-rams.work/docs",
"Homepage": "https://polysolve.jono-rams.work",
"Repository": "https://github.com/jono-rams/PolySolve"
},
"split_keywords": [
"math",
" polynomial",
" genetic algorithm",
" cuda",
" equation solver"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d17b8d1177b27cc3c5e03f80e6b7907a6671dcc93b86d9ba9c493bc8d191c3da",
"md5": "3e00c3b682b7a40f3eeff75383579134",
"sha256": "c0bc8cc640518e2c1bbcc9a1542190709300f17220408102a9edf667f3344d15"
},
"downloads": -1,
"filename": "polysolve-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3e00c3b682b7a40f3eeff75383579134",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 13800,
"upload_time": "2025-10-30T15:36:20",
"upload_time_iso_8601": "2025-10-30T15:36:20.189308Z",
"url": "https://files.pythonhosted.org/packages/d1/7b/8d1177b27cc3c5e03f80e6b7907a6671dcc93b86d9ba9c493bc8d191c3da/polysolve-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "61377d376371ded59cbe9de8e98b8f9f02aea3b5fca805b89bfa2688a9c8eb6e",
"md5": "f6bdbf11f0f8ada89168d7da6b071a37",
"sha256": "ac90ad1a97bf1c5c54a45397d5d6fac065caa4890abe09019a43eb0eec5715f1"
},
"downloads": -1,
"filename": "polysolve-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "f6bdbf11f0f8ada89168d7da6b071a37",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 18120,
"upload_time": "2025-10-30T15:36:21",
"upload_time_iso_8601": "2025-10-30T15:36:21.566950Z",
"url": "https://files.pythonhosted.org/packages/61/37/7d376371ded59cbe9de8e98b8f9f02aea3b5fca805b89bfa2688a9c8eb6e/polysolve-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-30 15:36:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jono-rams",
"github_project": "PolySolve",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "polysolve"
}