andmap - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

andmap

determine whether a predicate is true of all operands of an expression

ormap

determine whether a predicate is true of some operands of an expression

xormap

determine whether a predicate is true of an odd number of operands of an expression

 Calling Sequence andmap(p, expr, ...) ormap(p, expr, ...) xormap(p, expr, ...)

Parameters

 p - predicate returning either true or false expr - expression ... - (optional) other arguments to pass to p

Description

 • The procedures andmap, ormap, and xormap determine whether a predicate p returns true for all, some, or an odd number of operands respectively of an expression expr.
 • For a table, Vector, Matrix, or Array, p is applied to each entry.
 • If expr is atomic, andmap(p, expr, ...), ormap(p, expr, ...), and xormap(p, expr, ...) are equivalent to p(expr, ... ).
 • In general, andmap(p, expr, ...) returns true if p(opnd, ...) is true for all operands opnd of expr, returns false if any call to p returns false, and returns FAIL when calls to p lead to at least one FAIL result and no false results.
 • Similarly, ormap(p, expr, ...) returns false if p(opnd, ...) is false for all operands opnd of expr, true when any call to p returns true, and FAIL when calls to p lead to at least one FAIL result and no true results.
 • Invoking xormap(p, expr, ...) returns true if p(opnd, ...) is true for an odd number of operands opnd of expr and all other calls to p yield false. If any call to p returns FAIL, then xormap returns FAIL.
 • Each of andmap, ormap, and xormap have short-circuit ("McCarthy") semantics, which means that an answer is returned as soon as it cannot change. The predicate only evaluates the operands of the expression expr until the result can be determined (false for andmap, true for ormap, and FAIL for xormap). The order in which the operands are examined, and thus which are examined, is not specified. You should not rely on side effects of the predicate p.
 • Since strings are atomic expressions in Maple, you cannot map a procedure over a string using andmap, ormap, or xormap. However, the StringTools package contains the exports AndMap and OrMap that provide this functionality.

 • The andmap and ormap commands are thread safe as of Maple 15, provided that evaluating the expression p is thread safe.
 • The xormap command is thread safe as of Maple 2021, provided that evaluating the expression p is thread safe.

Examples

 > $\mathrm{andmap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{integer}'\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{ormap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{integer}'\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{xormap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{integer}'\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{andmap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{even}'\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{ormap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{even}'\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{xormap}\left(\mathrm{type},\left[1,2,3,4,5\right],'\mathrm{even}'\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{andmap}\left(\mathrm{isprime},\left[2,3,5,7\right]\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{andmap}\left(\mathrm{isprime},\left[2,3,5,8\right]\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{ormap}\left(\mathrm{isprime},\left\{2,3,5,8\right\}\right)$
 ${\mathrm{true}}$ (9)
 > $t≔\mathrm{table}\left(\left[a=1,b=2,c=3\right]\right):$
 > $\mathrm{andmap}\left(\mathrm{type},\mathrm{eval}\left(t,1\right),'\mathrm{integer}'\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{andmap}\left(\mathrm{type},\mathrm{eval}\left(t,1\right),'\mathrm{even}'\right)$
 ${\mathrm{false}}$ (11)
 > $\mathrm{ormap}\left(\mathrm{type},\mathrm{eval}\left(t,1\right),'\mathrm{even}'\right)$
 ${\mathrm{true}}$ (12)
 > $e≔\mathrm{expand}\left({∫}\mathrm{randpoly}\left(x\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}x\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)$ (13)
 > $\mathrm{andmap}\left(\mathrm{hastype},e,'\mathrm{specfunc}\left(\mathrm{anything},\mathrm{Int}\right)'\right)$
 ${\mathrm{true}}$ (14)

This examples illustrates a technique for quickly destructuring a record.

 > RecordSlots := proc( r::record )       if not type( [ args[ 2 .. nargs ] ], 'list( symbol )' ) then               error "arguments after the first must be of type symbol'"       end if;       andmap( e -> member( cat( e ), r, e ), [ args[ 2 .. nargs ] ] ) end proc:
 > $r≔\mathrm{Record}\left('a'=2,'b'=3,'c'=\mathrm{Array}\left(1..5\right)\right)$
 ${r}{≔}{\mathrm{Record}}{}\left({a}{=}{2}{,}{b}{=}{3}{,}{c}{=}\left[\begin{array}{ccccc}{0}& {0}& {0}& {0}& {0}\end{array}\right]\right)$ (15)
 > $\mathrm{RecordSlots}\left(r,'a','b','c'\right)$
 ${\mathrm{true}}$ (16)
 > $a,b,c$
 ${2}{,}{3}{,}\left[\begin{array}{ccccc}{0}& {0}& {0}& {0}& {0}\end{array}\right]$ (17)
 > $\mathrm{andmap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[7,14\right]\right)$
 ${\mathrm{true}}$ (18)
 > $\mathrm{andmap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[7,14,-7\right]\right)$
 ${\mathrm{FAIL}}$ (19)
 > $\mathrm{andmap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[7,14,-7,3\right]\right)$
 ${\mathrm{false}}$ (20)
 > $\mathrm{ormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[7,14,-7\right]\right)$
 ${\mathrm{true}}$ (21)
 > $\mathrm{ormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[1,3\right]\right)$
 ${\mathrm{false}}$ (22)
 > $\mathrm{ormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[1,3,-5\right]\right)$
 ${\mathrm{FAIL}}$ (23)
 > $\mathrm{xormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[7,14,-7\right]\right)$
 ${\mathrm{FAIL}}$ (24)
 > $\mathrm{xormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[1,3\right]\right)$
 ${\mathrm{false}}$ (25)
 > $\mathrm{xormap}\left(a→\mathrm{if}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[1,3,7\right]\right)$
 ${\mathrm{true}}$ (26)
 > $\mathrm{xormap}\left(a→\mathrm{if`}\left(a<0,\mathrm{FAIL},a\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}7=0\right),\left[1,3,7,-5\right]\right)$
 ${\mathrm{FAIL}}$ (27)

Compatibility

 • The andmap and ormap commands were updated in Maple 2017.
 • The xormap command was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.