Refactor Scalar Addition/Subtraction for All Instances of Polynomials
Currently, the implementation of scalar addition/subtraction for instances of all polynomial classes is done concretely at MultivariatePolynomialSingleABC
(first raised in Issue #140 (closed); resolved via MR !147 (merged)).
However, scalar addition/subtraction for polynomials in the Lagrange basis is different because it does not operate on the monomials; while the monomial (0, \ldots, 0) corresponds to the constant term for all the other polynomial bases, the same monomial has a different meaning in the Lagrange basis. Adding or subtracting a scalar to polynomials in the Lagrange basis alters all the coefficients uniformly. On the other hand, adding or subtracting a scalar to polynomials in all the other bases only alters the coefficient that corresponds to the monomial (0, \ldots, 0) if presence (if not, the multi-index set is expanded to include the constant term).
Refactor MultivariatePolynomialSingleABC
such that the scalar addition routine becomes an abstract method whose concrete implementation is deferred to each of the concrete classes. CanonicalPolynomial
, ChebyshevPolynomial
, and NewtonPolynomial
may share a single implementation while LagrangePolynomial
may be implemented differently that reflects the particularity of adding/subtracting a scalar to a polynomials in the Lagrange basis.
Furthermore, while scalar addition/subtraction operation currently supports in-place operation (explicitly via __iadd__
and __isub__
and only for scalars), keeping the promise that the instance will be mutated in-place consistently is difficult and may be currently unnecessary anyway. I would propose via the resolution of this issue to remove the in-place operation support for scalar addition/subtraction. By default, the statement +=
or -=
will fall back to __add__()
and __sub__()
if __iadd__()
and __isub__()
are not implemented so a new instance will always be created and assign to the previous variable.
This issue is part of refactoring and extending the support for arithmetic operations involving polynomial (see Issue #142 (closed)).