andseq
determine whether all elements of a generated sequence are true
orseq
determine whether any elements of a generated sequence are true
xorseq
determine whether an odd number of elements of a generated sequence are true
Calling Sequence
Parameters
Description
Thread Safety
Examples
Compatibility
andseq(f, i = m..n, step)
andseq(f, i = x)
andseq(f, i in x)
andseq(x)
orseq(f, i = m..n, step)
orseq(f, i = x)
orseq(f, i in x)
orseq(x)
xorseq(f, i = m..n, step)
xorseq(f, i = x)
xorseq(f, i in x)
xorseq(x)
f
-
expression that evaluates to a Boolean value
i
name
m, n
numerical values
x
expression
step
(optional) numerical value
The andseq, orseq, and xorseq functions conceptually construct a sequence of values, and then use the elements of that sequence as operands of the corresponding Boolean operator (and, or, or xor). The return value will be true, false, or FAIL.
Semantically, andseq( ... ) is equivalent to `and`(seq( ... )), except that the sequence is not actually constructed in memory. A similar equivalence holds true for orseq and xorseq.
In the case of andseq and orseq only, McCarthy short-circuit evaluation rules are used. As soon as the result is known (false if any element in andseq is found to be false, or true if any element in orseq is found to be true), computation of the sequence terminates and the result is returned.
In the interest of brevity, in the paragraphs below, descriptions of the operation of andseq should be understood to apply to orseq and xorseq as well.
For some expression f(i), the sequence for andseq(f(i), i=m..n) computes f(i) for each value of i in [m, m+1, ..., n].
If the optional step argument is given, f(i) is computed for each value of i in [m, m+step, ..., n].
The sequence for andseq(f(i), i = x) or andseq(f(i), i in x) is computed by applying f to each operand or entry of x. Here, x is most commonly a set or list, but can be any other data structure to which op or entries can be applied, such as a sum, product, Array, or Matrix.
The form, andseq('x'), is equivalent to andseq(i, i = x). For this to be meaningful, x must contain only Boolean values.
When x is a sparse Matrix, Vector, or Array, only the nonzero entries are scanned. Otherwise, regardless of the indexing function, or storage, the entire index space of the object is scanned.
The index variable i refers to the instance of the variable that is in scope in the context where the call to andseq occurs. At the top-level (outside of any procedure or module), the global variable is used. Within a procedure or module, the local variable of that name is used. If the procedure or module does not explicitly declare a local variable with that name, an implicit local declaration is quietly generated.
Regardless of whether the index variable is local or global, the value that the variable had before the invocation of andseq is restored afterwards. Thus the value of that variable is not affected.
The andseq, orseq, and xorseq commands are thread safe as of Maple 2021 provided that evaluating f is itself thread safe. Further, the index variable i must not be shared between threads. Using a procedure local is advised.
For more information on thread safety, see index/threadsafe.
andseq⁡type⁡i,integer,i=1,2,3,4,5
true
orseq⁡type⁡i,integer,i=1,2,3,4,5
xorseq⁡type⁡i,integer,i=1,2,3,4,5
andseq⁡type⁡i,even,i=1,2,3,4,5
false
orseq⁡type⁡i,even,i=1,2,3,4,5
xorseq⁡type⁡i,even,i=1,2,3,4,5
andseq⁡isprime⁡i,iin2,3,5,7
andseq⁡isprime⁡i,iin2,3,5,8
orseq⁡isprime⁡i,iin2,3,5,8
t≔table⁡a=1,b=2,c=3:
andseq⁡type⁡i,integer,iineval⁡t,1
andseq⁡type⁡i,even,iineval⁡t,1
Do all the terms in a sum contain an integration?
e≔expand⁡Int⁡randpoly⁡x,x
e≔−7⁢∫x5ⅆx+22⁢∫x4ⅆx−55⁢∫x3ⅆx−94⁢∫x2ⅆx+87⁢∫xⅆx−56⁢∫1ⅆx
andseq⁡hastype⁡i,specfunc⁡Int,iine
Check if a column of a Matrix contains a particular value.
M≔1|2|3,4|5|6,7|8|9:
orseq⁡Mi,2=5,i=1..upperbound⁡M,1
orseq⁡Mi,2=9,i=1..upperbound⁡M,1
The andseq, orseq and xorseq commands were introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
andmap
ormap
seq
xormap
Download Help Document