andseq - Maple Help

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

Parameters

 f - expression that evaluates to a Boolean value i - name m, n - numerical values x - expression step - (optional) numerical value

Description

 • 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.

Examples

 > $\mathrm{andseq}\left(\mathrm{type}\left(i,\mathrm{integer}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{orseq}\left(\mathrm{type}\left(i,\mathrm{integer}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{xorseq}\left(\mathrm{type}\left(i,\mathrm{integer}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{andseq}\left(\mathrm{type}\left(i,\mathrm{even}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{orseq}\left(\mathrm{type}\left(i,\mathrm{even}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{xorseq}\left(\mathrm{type}\left(i,\mathrm{even}\right),i=\left[1,2,3,4,5\right]\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{andseq}\left(\mathrm{isprime}\left(i\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left[2,3,5,7\right]\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{andseq}\left(\mathrm{isprime}\left(i\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left[2,3,5,8\right]\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{orseq}\left(\mathrm{isprime}\left(i\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{2,3,5,8\right\}\right)$
 ${\mathrm{true}}$ (9)
 > $t≔\mathrm{table}\left(\left[a=1,b=2,c=3\right]\right):$
 > $\mathrm{andseq}\left(\mathrm{type}\left(i,\mathrm{integer}\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{eval}\left(t,1\right)\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{andseq}\left(\mathrm{type}\left(i,\mathrm{even}\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{eval}\left(t,1\right)\right)$
 ${\mathrm{false}}$ (11)

Do all the terms in a sum contain an integration?

 > $e≔\mathrm{expand}\left(\mathrm{Int}\left(\mathrm{randpoly}\left(x\right),x\right)\right)$
 ${e}{≔}{-}{7}{}\left({\int }{{x}}^{{5}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right){+}{22}{}\left({\int }{{x}}^{{4}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right){-}{55}{}\left({\int }{{x}}^{{3}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right){-}{94}{}\left({\int }{{x}}^{{2}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right){+}{87}{}\left({\int }{x}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right){-}{56}{}\left({\int }{1}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{x}\right)$ (12)
 > $\mathrm{andseq}\left(\mathrm{hastype}\left(i,\mathrm{specfunc}\left(\mathrm{Int}\right)\right),i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}e\right)$
 ${\mathrm{true}}$ (13)

Check if a column of a Matrix contains a particular value.

 > $M≔⟨⟨1|2|3⟩,⟨4|5|6⟩,⟨7|8|9⟩⟩:$
 > $\mathrm{orseq}\left(M\left[i,2\right]=5,i=1..\mathrm{upperbound}\left(M,1\right)\right)$
 ${\mathrm{true}}$ (14)
 > $\mathrm{orseq}\left(M\left[i,2\right]=9,i=1..\mathrm{upperbound}\left(M,1\right)\right)$
 ${\mathrm{false}}$ (15)

Compatibility

 • The andseq, orseq and xorseq commands were introduced in Maple 2021.