Skip to content

Refactor scalar addition/subtraction for instances of all polynomial classes.

Damar Wicaksono requested to merge dev-173 into dev

The addition and subtraction of polynomials by scalar is now an abstract static method (_scalar_add()) that must be implemented in the concrete classes implementing MultivariatePolynomialSingleABC.

NewtonPolynomial, CanonicalPolynomial, and ChebyshevPolynomial share a common scalar addition implementation. It is monomial-based, taking the multi-index set element (0, \ldots, 0) as the constant term to be modified by the scalar.

On the other hand, the scalar addition for LagrangePolynomial is implemented differently. Adding or subtracting a scalar number alters all the coefficients uniformly.

Additionally:

  • Instances of LagrangePolynomial now cannot be added with another instance even if the other instance is a constant scalar polynomial. Before, scalar addition passes via construction of a scalar polynomial that must be handled by the corresponding concrete methods including by LagrangePolynomial. Now with _scalar_add() as a static method specifically for scalar addition, no need to go via scalar polynomial.
  • abstract static method _iadd() has been removed from MultivariatePolynomialSingleABC; the method is no longer required to be implemented in the concrete polynomial class.
  • The test suite has been modified and updated to reflect the latest changes.
  • Include ID's for several important fixtures in the test for pretty printing.

This commit should resolve Issue #173 (closed) and part of refactoring and extending the support for arithmetic operations involving polynomial (see Issue #142 (closed)).

Edited by Damar Wicaksono

Merge request reports

Loading