Check for Equality between Two MultiIndexSet Instances#
import minterpy as mp
import numpy as np
Two instances of MultiIndexSet
may be checked for equality in value via the ==
operator as demonstrated in this guide.
Two instances of MultiIndexSet
are equal in value if and only if:
The multi-indices elements stored in the
exponents
property of the two instances are equal andThe underlying \(l_p\)-degrees of the two instances are equal.
Equality in value#
Consider the following three-dimensional multi-index sets defined for \(l_p\)-degree \(1.0\):
and create two instances of MultiIndexSet
with identical exponents and \(l_p\)-degree.
mi_1 = mp.MultiIndexSet(
np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [0, 0, 1]]),
lp_degree=1.0,
)
mi_2 = mp.MultiIndexSet(
np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [0, 0, 1]]),
lp_degree=1.0,
)
To check the equality between these two instances, use the ==
operator as follows:
mi_1 == mi_2
True
Note that the two instances are not identical as shown by the following check:
mi_1 is mi_2
False
as well as the id’s of the instances:
id(mi_1), id(mi_2)
(139836170119408, 139836170120656)
Inequality in value#
As explained in the beginning of the guide, for two instances of MultiIndexSet
to be equal both the exponents and \(l_p\)-degree must be equal.
If two instances of MultiIndexSet
has the same exponents but a different \(l_p\)-degree, the instances are not equal. Consider a multi-index set with the same exponents as the set above but with \(l_p\)-degree of \(2.0\) (instead of \(1.0\)):
mi_3 = mp.MultiIndexSet(mi_1.exponents, lp_degree=2.0)
mi_1 == mi_3
False
The inequality between two instances may also be checked via the !=
operator as follows:
mi_1 != mi_3
True
Accordingly, and perhaps the more obvious case, if two instances has the same \(l_p\)-degree but different exponents, the instances are not equal as well. Consider another multi-index set defined also for \(l_p\)-degree \(2.0\):
mi_2 = mp.MultiIndexSet(
np.array([[0, 0], [1, 0], [2, 0], [0, 1]]),
lp_degree=mi_1.lp_degree,
)
This multi-index set is of dimension \(2\) instead of \(1\). As expected, the instance is not equal with the previous one:
mi_1 != mi_2
True
Finally, and as expected, two instances having different set of exponents and \(l_p\)-degree are not equal in value:
mi_4 = mp.MultiIndexSet(
np.array([[0], [1], [2]]),
lp_degree=np.inf
)
mi_5 = mp.MultiIndexSet(
np.array([[0, 0], [1, 0], [2, 0]]),
lp_degree=1.0
)
mi_4 != mi_5
True