in - Maple Help

in

membership operator for sets or lists

Calling Sequence

 element in objs $\mathrm{element}\in \mathrm{objs}$ element in SetOf( type ) $\mathrm{element}\in \mathrm{SetOf}\left(\mathrm{type}\right)$

Parameters

 element - expression objs - set or list type - valid type expression

Description

 • The in operator tests for set or list membership.  The given container, objs, is searched for element. Evaluating an in expression in a boolean context, or via evalb, returns true if element is in objs, it returns false if element is not in objs.  If the input contains symbolic components and the answer cannot be determined, a symbolic answer is returned. The default evaluator always returns in expressions unevaluated.
 • You can enter the command in using either the 1-D or 2-D calling sequence. For example, 1 in {1,2,3,4} is equivalent to $1\in \left\{1,2,3,4\right\}$.
 • When using the SetOf abstract set constructor, sets can be constructed from types.  For example, the set of all integers can be created using SetOf( integer ).  The SetOf constructor takes only one argument.  More complex sets can be constructed using union, intersect and minus.
 • If obj is a complex expression involving union, intersect or minus, it may be more efficient to pass obj as an unevaluated expression.  Using an unevaluated expression allows in to use its own rules for set membership across these functions.
 • The assume facility accepts the in operator.

Examples

 > $1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{1,2,3,4\right\}$
 ${1}{\in }\left\{{1}{,}{2}{,}{3}{,}{4}\right\}$ (1)
 > $\mathrm{evalb}\left(\right)$
 ${\mathrm{true}}$ (2)
 > $1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{integer}\right)$
 ${1}{\in }{\mathrm{SetOf}}{}\left({\mathrm{integer}}\right)$ (3)
 > $\mathrm{evalb}\left(\right)$
 ${\mathrm{true}}$ (4)
 > $1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{polynom}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{minus}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{integer}\right)$
 ${1}{\in }{\mathrm{SetOf}}{}\left({\mathrm{polynom}}\right){\setminus }{\mathrm{SetOf}}{}\left({\mathrm{integer}}\right)$ (5)
 > $\mathrm{evalb}\left(\right)$
 ${\mathrm{false}}$ (6)
 > $1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}A\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{union}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}B\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{union}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}C\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{minus}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D}$
 ${1}{\in }{A}{\cup }{B}{\cup }{C}{\setminus }{\mathrm{D}}$ (7)
 > $\mathrm{evalb}\left(\right)$
 $\left({1}{\in }{A}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{1}{\in }{B}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{or}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{1}{\in }{C}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{and}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{\mathbf{not}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{1}{\in }{\mathrm{D}}$ (8)
 > $1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{1,2,3\right\}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{intersect}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left(\left\{1,2,6\right\}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{minus}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{1,4,7\right\}\right)$
 ${1}{\in }\left\{{2}\right\}$ (9)
 > $\mathrm{evalb}\left(\right)$
 ${\mathrm{false}}$ (10)
 > $\mathrm{evalb}\left(1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}'\left\{1,2,3\right\}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{intersect}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left(\left\{1,2,6\right\}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{minus}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{1,4,7\right\}\right)'\right)$
 ${\mathrm{false}}$ (11)
 > $\mathrm{is}\left(x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{real}\right)\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}x::\mathrm{fraction}$
 ${\mathrm{true}}$ (12)
 > $\mathrm{is}\left(x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{integer}\right)\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}x::\mathrm{rational}$
 ${\mathrm{false}}$ (13)
 > $\mathrm{coulditbe}\left(x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{integer}\right)\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{assuming}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}x::\mathrm{rational}$
 ${\mathrm{true}}$ (14)
 > $\mathrm{assume}\left(x\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{SetOf}\left(\mathrm{real}\right)\right);$$\mathrm{about}\left(x\right)$
 Originally x, renamed x~:   is assumed to be: real

The command in also works with lists.

 > $\mathrm{evalb}\left(1\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left[6,7,1,8\right]\right)$
 ${\mathrm{true}}$ (15)
 > $s≔\mathrm{op}\left(\mathrm{solve}\left(\left\{a+b=5,{b}^{2}-{a}^{2}=25\right\},\left[a,b\right]\right)\right)$
 ${s}{≔}\left[{a}{=}{0}{,}{b}{=}{5}\right]$ (16)
 > $\mathrm{evalb}\left('a=0'\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}s\right)$
 ${\mathrm{true}}$ (17)