Compare MultiIndexSet Instances#
import minterpy as mp
import numpy as np
This guide shows how to check whether a MultiIndexSet
instance is a superset or subset of another MultiIndexSet
instance.
The guide covers the following methods of a MultiIndexSet
instance:
is_subset()
(resp.is_propsubset()
) checks whether aMultiIndexSet
instance is a subset (resp. proper subset) of anotherMultiIndexSet
instance.is_superset()
(resp.is_propsuperset()
) checks whether aMultiIndexSet
instance is a superset (resp. proper superset) of anotherMultiIndexSet
instance.
Operators may also be used instead of (some) methods above.
Motivating example#
As a motivating example, consider the following three multi-index sets of the same dimension and \(l_p\)-degree of \(2.0\):
mi_a = mp.MultiIndexSet(
np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0]]),
lp_degree=2.0,
)
mi_b = mp.MultiIndexSet(
np.array([[0, 0, 0], [1, 0, 0]]),
lp_degree=2.0,
)
mi_c = mp.MultiIndexSet(
np.array(
[[0, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 2]],
),
lp_degree=2.0,
)
Check for superset#
The operator >=
is used to check whether a given MultiIndexSet
instance is a superset of another MultiIndexSet
instance (i.e., checking if \(A \supseteq B\)).
The method returns True
if the given MultiIndexSet
is a superset of another instance and False
otherwise.
Note that both of the operands must be instances of the MultiIndexSet
class.
For instance, to check if the multi-index set \(A\) is a superset of \(B\) (it is):
mi_a >= mi_b
True
Alternatively, the method is_superset()
may also be used:
mi_a.is_superset(mi_b)
True
On the other hand, the multi-index set \(C\) is not a superset of \(B\):
mi_c >= mi_b
False
Proper superset#
To determine whether a MultiIndexSet
instance is a proper superset of another, the operator >
is used.
For instance, a set is a subset of itself but not its proper superset:
mi_a > mi_a
False
Alternatively, the method is_propsuperset()
may also be used:
mi_a.is_propsuperset(mi_a)
False
mi_a.is_propsuperset(mi_b)
True
Check for subset#
The operator <=
is used to check whether a given MultiIndexSet
instance is a subset of another MultiIndexSet
instance (i.e., checking if \(A \subseteq B\)).
The method returns True
if the given MultiIndexSet
is a subset of another instance and False
otherwise.
Note that both of the operands must be of MultiIndexSet
.
For instance, to check if the multi-index set \(B\) is a subset of \(A\) (it is):
mi_b <= mi_a
True
Alternatively, the method is_subset()
may also be used:
mi_b.is_subset(mi_a)
True
On the other hand, the multi-index set \(B\) is not a subset of \(C\):
mi_b <= mi_c
False
or:
mi_b.is_subset(mi_c)
False
Proper subset#
To determine whether a MultiIndexSet
instance is a proper subset of another, the operator <
is used.
For instance, a set is a subset of itself but not its proper subset:
mi_a < mi_a
False
Alternatively, the method is_propsubset()
may also be used:
mi_a.is_propsubset(mi_a)
False
mi_b.is_propsubset(mi_a)
True
Check for disjoint#
Two determine whether a MultiIndexSet
instance is disjoint with another, the method is_disjoint()
is used.
For instance, the multi-index sets \(A\), \(B\), and \(C\) are not disjoint because their intersection is not empty:
mi_a.is_disjoint(mi_b)
False
mi_b.is_disjoint(mi_c)
False
mi_c.is_disjoint(mi_a)
False
They are, however, disjoint with the set \(\left\{ (2, 2, 2) \right\}\):
mi_d = mp.MultiIndexSet(np.array([[2, 2, 2]]), lp_degree=1.0)
mi_a.is_disjoint(mi_d)
True
mi_b.is_disjoint(mi_d)
True
mi_c.is_disjoint(mi_d)
True
Different in Spatial Dimension#
Using operators to check whether a set is either a subset or superset of another does not require the spatial dimension of the operands to be equal. For instance the set:
is a subset of:
as the dimension of set \(D\) is first expanded such that:
mi_e = mp.MultiIndexSet(np.array([[0, 0], [1, 0], [2, 0]]), lp_degree=1.0)
mi_f = mp.MultiIndexSet(
np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0]]),
lp_degree=1.0,
)
mi_e <= mi_f
True
To restrict the checking only for instances of the same dimension, use the method call instead (e.g., mi_d.is_subset(mi_e)
).
If there’s a dimension mismatch, an exception is raised.
The parameter expand_dim
of the methods can be used to alter this behavior; note that this parameter is default to False
.
For instance:
mi_e.is_subset(mi_f, expand_dim=True)
True