Implement Exponentiation Operation for Polynomials
Now that all polynomials (with the exception, perhaps, of the Lagrange polynomial) supports polynomial-polynomial multiplication operation, we can implement __pow__()
in the MultivariatePolynomialSingleABC
for non-negative whole scalar numbers. Specifically:
>>> poly**2 == poly * poly
True
Basically, exponentiation by a non-negative whole scalar number is a syntactic sugar for (repeated) self-multiplications. Whole numbers here mostly means integers but in Python we may also accepts 1.0, 2.0, etc. as valid exponents because they are whole.
Note that exponentiation by non-positive non-whole numbers are not supported in the foreseeable future because it requires the definition of rational polynomial function.
This issue is part of extending the support for arithmetic operations involving polynomial (see Issue #142 (closed)).
Exponentiation by 0
One edge case that we may need to think about is exponentiation by 0 (included in the non-negative whole numbers). I think we can establish the following convention: polynomials exponentiated by 0 yields a polynomial whose coefficient associated with the index element (0, \ldots, 0) is 1.0 while the rest is 0.
What if there's no index element (0, \ldots, 0) in the set? In that case we add it there. The idea is any multivariate polynomials be they have a complete or incomplete set, downward-closed or non-downward closed set may be exponentiated with 0 and the results will be a constant polynomial of 1.0.
So to handle this particular case I would implement it as a multiplication of the current polynomial with 0 and then add it with a constant polynomial of 1.0.