# Python package defining single-variable polynomials and operations with them
[![PyPI version](https://badge.fury.io/py/py-polynomial.svg)](https://badge.fury.io/py/py-polynomial)
[![Downloads](https://static.pepy.tech/personalized-badge/py-polynomial?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/py-polynomial)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/py-polynomial.svg)](https://pypi.python.org/pypi/py-polynomial/)
[![PyPI license](https://img.shields.io/pypi/l/py-polynomial.svg)](https://pypi.python.org/pypi/py-polynomial/)
![Unit Tests](https://github.com/allexks/py-polynomial/workflows/Unit%20Tests/badge.svg)
![Code Documentation Style](https://github.com/allexks/py-polynomial/workflows/Code%20Documentation%20Style/badge.svg)
[![CodeFactor](https://www.codefactor.io/repository/github/allexks/py-polynomial/badge)](https://www.codefactor.io/repository/github/allexks/py-polynomial)
[![codecov](https://codecov.io/gh/allexks/py-polynomial/branch/master/graph/badge.svg)](https://codecov.io/gh/allexks/py-polynomial)
## Installation
`pip install py-polynomial`
## Documentation
[Click here for code-derived documentation and help](https://allexks.github.io/py-polynomial/)
## Quick examples
### Flexible initialization
``` pycon
>>> from polynomial import Polynomial
>>> a = Polynomial(1, 2, 3, 4)
>>> str(a)
x^3 + 2x^2 + 3x + 4
>>> b = Polynomial([4 - x for x in range(4)])
>>> str(b)
4x^3 + 3x^2 + 2x + 1
```
### First derivative
``` pycon
>>> b.derivative
Polynomial(12, 6, 2)
>>> str(b.derivative)
12x^2 + 6x + 2
```
### Second or higher derivative
``` pycon
>>> str(b.nth_derivative(2))
24x + 6
```
### Addition
``` pycon
>>> str(a + b)
5x^3 + 5x^2 + 5x + 5
```
### Calculating value for a given x
``` pycon
>>> (a + b).calculate(5)
780
>>> а(2) # equivalent to a.calculate(2)
26
```
### Multiplication
``` pycon
>>> p = Polynomial(1, 2) * Polynomial(1, 2)
>>> p
Polynomial(1, 4, 4)
```
### Accessing coefficient by degree
``` pycon
>>> p[0] = -4
>>> p
Polynomial(1, 4, -4)
```
### Slicing
``` pycon
>>> p[1:] = [4, -1]
>>> p
Polynomial(-1, 4, -4)
```
### Accessing coefficients by name convention
``` pycon
>>> (p.a, p.b, p.c)
(-1, 4, -4)
>>> p.a, p.c = 1, 4
>>> (p.A, p.B, p.C)
(1, 4, 4)
```
### Division and remainder
``` pycon
>>> q, remainder = divmod(p, Polynomial(1, 2))
>>> q
Polynomial(1.0, 2.0)
>>> remainder
Polynomial()
>>> p // Polynomial(1, 2)
Polynomial(1.0, 2.0)
>>> P(1, 2, 3) % Polynomial(1, 2)
Polynomial(3)
```
### Check whether it contains given terms
``` pycon
>>> Polynomial(2, 1) in Polynomial(4, 3, 2, 1)
True
```
### Definite integral
```pycon
>>> Polynomial(3, 2, 1).integral(0, 1)
3
```
### Misc
``` pycon
>>> str(Polynomial("abc"))
ax^2 + bx + c
```
### Roots and discriminants
``` pycon
>>> from polynomial import QuadraticTrinomial, Monomial
>>> y = QuadraticTrinomial(1, -2, 1)
>>> str(y)
x^2 - 2x + 1
>>> y.discriminant
0
>>> y.real_roots
(1, 1)
>>> y.real_factors
(1, Polynomial(1, -1), Polynomial(1, -1))
>>> str(Monomial(5, 3))
5x^3
>>> y += Monomial(9, 2)
>>> y
Polynomial(10, -2, 1)
>>> str(y)
10x^2 - 2x + 1
>>> (y.a, y.b, y.c)
(10, -2, 1)
>>> (y.A, y.B, y.C)
(10, -2, 1)
>>> y.complex_roots
((0.1 + 0.3j), (0.1 - 0.3j))
```
Raw data
{
"_id": null,
"home_page": "https://github.com/allexks/py-polynomial",
"name": "py-polynomial",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "algebra,polynomial,polynomials,mathematics,maths,derivative,derivatives,factor,factors,root,roots,terms,coefficients,quadratic,linear,sympy,numpy",
"author": "Alexander Ignatov",
"author_email": "yalishanda@abv.bg",
"download_url": "https://files.pythonhosted.org/packages/17/76/bee6bded85e454e47bde6d1a700d920ca1f45879ba5b0f438ca988730848/py-polynomial-0.6.2.tar.gz",
"platform": null,
"description": "# Python package defining single-variable polynomials and operations with them\n\n[![PyPI version](https://badge.fury.io/py/py-polynomial.svg)](https://badge.fury.io/py/py-polynomial)\n[![Downloads](https://static.pepy.tech/personalized-badge/py-polynomial?period=total&units=none&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/py-polynomial)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/py-polynomial.svg)](https://pypi.python.org/pypi/py-polynomial/)\n[![PyPI license](https://img.shields.io/pypi/l/py-polynomial.svg)](https://pypi.python.org/pypi/py-polynomial/)\n\n![Unit Tests](https://github.com/allexks/py-polynomial/workflows/Unit%20Tests/badge.svg)\n![Code Documentation Style](https://github.com/allexks/py-polynomial/workflows/Code%20Documentation%20Style/badge.svg)\n[![CodeFactor](https://www.codefactor.io/repository/github/allexks/py-polynomial/badge)](https://www.codefactor.io/repository/github/allexks/py-polynomial)\n[![codecov](https://codecov.io/gh/allexks/py-polynomial/branch/master/graph/badge.svg)](https://codecov.io/gh/allexks/py-polynomial)\n\n## Installation\n`pip install py-polynomial`\n\n## Documentation\n[Click here for code-derived documentation and help](https://allexks.github.io/py-polynomial/)\n\n## Quick examples\n### Flexible initialization\n``` pycon\n>>> from polynomial import Polynomial\n\n>>> a = Polynomial(1, 2, 3, 4)\n>>> str(a)\nx^3 + 2x^2 + 3x + 4\n\n>>> b = Polynomial([4 - x for x in range(4)])\n>>> str(b)\n4x^3 + 3x^2 + 2x + 1\n```\n\n### First derivative\n``` pycon\n>>> b.derivative\nPolynomial(12, 6, 2)\n\n>>> str(b.derivative)\n12x^2 + 6x + 2\n```\n\n### Second or higher derivative\n``` pycon\n>>> str(b.nth_derivative(2))\n24x + 6\n```\n\n### Addition\n``` pycon\n>>> str(a + b)\n5x^3 + 5x^2 + 5x + 5\n```\n\n### Calculating value for a given x\n``` pycon\n>>> (a + b).calculate(5)\n780\n\n>>> \u0430(2) # equivalent to a.calculate(2)\n26\n```\n\n### Multiplication\n``` pycon\n>>> p = Polynomial(1, 2) * Polynomial(1, 2)\n>>> p\nPolynomial(1, 4, 4)\n```\n\n### Accessing coefficient by degree\n``` pycon\n>>> p[0] = -4\n>>> p\nPolynomial(1, 4, -4)\n```\n\n### Slicing\n``` pycon\n>>> p[1:] = [4, -1]\n>>> p\nPolynomial(-1, 4, -4)\n```\n\n### Accessing coefficients by name convention\n``` pycon\n>>> (p.a, p.b, p.c)\n(-1, 4, -4)\n\n>>> p.a, p.c = 1, 4\n>>> (p.A, p.B, p.C)\n(1, 4, 4)\n```\n\n### Division and remainder\n``` pycon\n>>> q, remainder = divmod(p, Polynomial(1, 2))\n>>> q\nPolynomial(1.0, 2.0)\n>>> remainder\nPolynomial()\n\n>>> p // Polynomial(1, 2)\nPolynomial(1.0, 2.0)\n\n>>> P(1, 2, 3) % Polynomial(1, 2)\nPolynomial(3)\n```\n\n### Check whether it contains given terms\n``` pycon\n>>> Polynomial(2, 1) in Polynomial(4, 3, 2, 1)\nTrue\n```\n\n### Definite integral\n```pycon\n>>> Polynomial(3, 2, 1).integral(0, 1)\n3\n```\n\n### Misc\n``` pycon\n>>> str(Polynomial(\"abc\"))\nax^2 + bx + c\n```\n\n### Roots and discriminants\n``` pycon\n>>> from polynomial import QuadraticTrinomial, Monomial\n>>> y = QuadraticTrinomial(1, -2, 1)\n>>> str(y)\nx^2 - 2x + 1\n\n>>> y.discriminant\n0\n\n>>> y.real_roots\n(1, 1)\n\n>>> y.real_factors\n(1, Polynomial(1, -1), Polynomial(1, -1))\n\n>>> str(Monomial(5, 3))\n5x^3\n\n>>> y += Monomial(9, 2)\n>>> y\nPolynomial(10, -2, 1)\n\n>>> str(y)\n10x^2 - 2x + 1\n\n>>> (y.a, y.b, y.c)\n(10, -2, 1)\n\n>>> (y.A, y.B, y.C)\n(10, -2, 1)\n\n>>> y.complex_roots\n((0.1 + 0.3j), (0.1 - 0.3j))\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Package defining mathematical single-variable polynomials.",
"version": "0.6.2",
"split_keywords": [
"algebra",
"polynomial",
"polynomials",
"mathematics",
"maths",
"derivative",
"derivatives",
"factor",
"factors",
"root",
"roots",
"terms",
"coefficients",
"quadratic",
"linear",
"sympy",
"numpy"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "3c6c48e44586a8c697648e0ba36edd00",
"sha256": "fe9fe1f3901cd84b1b327d041f1321ac0ebf863ce367e63569305eca95bfac25"
},
"downloads": -1,
"filename": "py_polynomial-0.6.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3c6c48e44586a8c697648e0ba36edd00",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13775,
"upload_time": "2022-12-10T13:15:06",
"upload_time_iso_8601": "2022-12-10T13:15:06.937484Z",
"url": "https://files.pythonhosted.org/packages/e4/74/97f38fb78527d32e0d1cd7ec1285370a535c83382aca97fd942586d6a678/py_polynomial-0.6.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "2ce0a7d9a133782a6e594564a6ca1caf",
"sha256": "2a641dca63678d05d27ffd9bfd7242e37ec0197045c2126afc47459f949f3aad"
},
"downloads": -1,
"filename": "py-polynomial-0.6.2.tar.gz",
"has_sig": false,
"md5_digest": "2ce0a7d9a133782a6e594564a6ca1caf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13917,
"upload_time": "2022-12-10T13:15:08",
"upload_time_iso_8601": "2022-12-10T13:15:08.790095Z",
"url": "https://files.pythonhosted.org/packages/17/76/bee6bded85e454e47bde6d1a700d920ca1f45879ba5b0f438ca988730848/py-polynomial-0.6.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-10 13:15:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "allexks",
"github_project": "py-polynomial",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "py-polynomial"
}