Simple polynomial class with basic operations
Polynomial in one variable with integer coefficients in the same order as in the classical notation.
For example, Polynomial([1, -2, 3]) means x^2 - 2x + 3
Supported operations:
-
addition, addition with a constant (both sides)
-
subtraction, subtraction with a constant (both sides)
-
multiplication, multiplication by a constant (both sides)
-
comparison (
==), constant comparison (both sides) -
converting to string
str(p)like"x^2-2x+3" -
print the internal representation of the object
repr(p)in the style of"Polynomial([1, 2, -4])" -
copying in
Polynomial(p)style, wherepis an object of classPolynomial -
the list of coefficients (list) can be obtained/modified as
p.coeffs
- import
polynomialmodule - create an instance of the class (eg.
Polynomial(5),Polynomial([1, 2]),Polynomial((1, 2, 3)),Polynomial(p)), list and tuple contain only integers,pis an instance of the Polynomial - use the arithmetic methods of the polynomial class
Run next Python scripts depending on OS.
Linux:
python3 <path>/polynomial/test_polynomial_init.py
python3 <path>/polynomial/test_polynomial_arithmetic.py
python3 <path>/polynomial/test_polynomial_operations.py
Windows:
python.exe <path>\polynomial\test_polynomial_init.py
python.exe <path>\polynomial\test_polynomial_arithmetic.py
python.exe <path>\polynomial\test_polynomial_operations.py