Previous Page Next Page Contents

in -- membership

Introduction

x 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

Parameters

x - 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

Overloadable:

x, set

Returns

x in set returns an expression of type "_or", or "_and", or "_equal", or "_in".

Related Functions

_seqin, bool, contains, for, has, is

Details

Example 1

x 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 2

For 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 3

in 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 4

The 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 5

In 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:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000