in -- membership
Introductionx in set is the ``element of'' relation. Further, the
keyword in may also be used in combination with the
keywords for and $, where it means ``iterate over all
operands.''
Call(s)
x in set _in(x, set)
for y in object do ... end_for
f(y) $ y in object
Parametersx |
- | an arbitrary MuPAD object |
set |
- | a set or an object of set-like type |
y |
- | an identifier or a local variable (DOM_VAR) of a procedure |
object, f(y) |
- | arbitrary MuPAD objects |
x, set
Returnsx in set returns an expression of type "_or", or "_and", or "_equal", or "_in".
Related
Functions_seqin, bool, contains, for, has, is
Detailsx in set is the MuPAD notation for the
statement ``x is a member of set.''for or $, the meaning changes to ``iterate over
all operands of the object''. See for and $ for details. Cf. example 5.for and $, the statement x in object
is equivalent to the function call _in(x, object).DOM_SET, set unions, differences and intersections, x in set is
evaluated to an equivalent Boolean expression of equations and
expressions involving in. Cf. example 1.set is a solution set of a single equation in one
unknown, given by a symbolic call to solve, in returns a
Boolean condition that is equivalent to x being a
solution. Cf. example 2.set is a RootOf expression, in
returns a Boolean condition that is equivalent to x being
a root of the corresponding equation. Cf. example 3.is handles
various logical statements involving in, including a
variety of types for the parameter set which are not
handled by in itself. Cf. example 4 for a few typical cases.in call,
in can be overloaded by its second argument, too. This
argument must define the slot
"set2expr" for this purpose. The slot will be called with
the arguments set, x.
Example
1x in {1, 2, 3} is transformed into an
equivalent statement involving = and or:
>> x in {1, 2, 3}
x = 1 or x = 2 or x = 3
The same happens if you replace x by a
number, because Boolean expressions are only evaluated inside certain
functions such as bool or
is:
>> 1 in {1, 2, 3}, bool(1 in {1, 2, 3}), is(1 in {1, 2, 3})
1 = 1 or 1 = 2 or 1 = 3, TRUE, TRUE
If only some part of the expression can be simplified
this way, the returned expression can contain unevaluated calls to
in:
>> x in {1, 2, 3} union A
x in A or x = 1 or x = 2 or x = 3
Example
2For symbolic calls to solve representing the solution set of
a single equation in one unknown, in can be used to check
whether a particular value lies in the solution set:
>> solve(x^2 = 2^x, x); 2 in %, bool(2 in %)
2 x
solve(x - 2 = 0, x)
0 = 0, TRUE
Example
3in can be used to check whether a value is
a member of the solution set represented by a RootOf expression:
>> r := RootOf(x^2 - 1, x);
1 in r, bool(1 in r), 2 in r, bool(2 in r)
2
RootOf(x - 1, x)
0 = 0, TRUE, 3 = 0, FALSE
>> (y - 1) in RootOf(x^2 - 1 - y^2 + 2*y, x)
2 2
2 y - y + (y - 1) - 1 = 0
>> expand(%)
0 = 0
>> delete r:
Example
4The MuPAD function is can investigate membership of objects
in infinite sets. It respects properties of
identifiers:
>> is(123 in Q_), is(2/3 in Q_)
TRUE, TRUE
>> assume(p, Type::Prime): is(p in Z_), is(p in Type::NonNegative)
TRUE, TRUE
>> unassume(p):
Example
5In conjunction with for and $, y in object iterates
y over all operands of the object:
>> for y in [1, 2] do
print(y)
end_for:
1
2
>> y^2 + 1 $ y in a + b*c + d^2
2 2 2 4
a + 1, b c + 1, d + 1
>> delete y: