Package defining mathematical single-variable polynomials.
Project description
Python package defining single-variable polynomials and operations with them
Installation
pip3 install py-polynomial
Sample functionality
>>> from polynomial import Polynomial as P
>>> a = P(1, 2, 3, 4)
>>> a
Polynomial(1, 2, 3, 4)
>>> str(a)
x^3 + 2x^2 + 3x + 4
>>> b = P(map(lambda x: 4-x, range(4)))
>>> str(b)
4x^3 + 3x^2 + 2x + 1
>>> b.derivative
Polynomial(12, 6, 2)
>>> str(b.derivative)
12x^2 + 6x + 2
>>> str(a + b)
5x^3 + 5x^2 + 5x + 5
>>> (a + b).calculate(5)
780
>>> c = P(1, 2) * P(1, 2)
>>> c
Polynomial(1, 4, 4)
>>> c[0] = -4
>>> c
Polynomial(1, 4, -4)
>>> c.A = -1
>>> c
Polynomial(-1, 4, -4)
>>> str(c)
-x^2 + 4x - 4
>>> str(P("abc"))
ax^2 + bx + c
>>> 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))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py-polynomial-0.4.1.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for py_polynomial-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2df538b81308418f41623bb00b6eb6a61fd463918ad324b15ec71affc570724f |
|
MD5 | c93fa0acb137164cb46bee7e8625f50b |
|
BLAKE2b-256 | 4ccd2e45931c1cb6b0cd867849970d2f1224bd75a237b1968bfc22fb8d971a52 |