Support for (exact) Equality Operator for Polynomial Instances
Two instances of MultivariatePolynomialSingleABC
(including all the concrete classes) may be compared for exact equality in value via ==
operator.
The two instances are considered equal if and only if:
- they are of the same concrete class, and
- the underlying
MultiIndexSet
instances are equal, and - the underlying
Grid
instances are equal, and - the coefficient values are equal.
Both MultiIndexSet
and Grid
are conditions for equality because a polynomial of a given multi-index set may live on a grid of a multi-index superset. Two polynomials having the same multi-index set may live on two different grids and thus they cannot be consider equal.
Note that because the coefficients are of floating type, the equality check via ==
is exact in nature (not using almost equal).
Although this kind of comparison maybe restrictive, it is useful for many sanity checks and tests involving instances of the class.
In the future, a more loose equality check (e.g., isclose()
) may be implemented, say, as a context manager.