In Python, there is a function all
which returns true if all of its arguments are true, and any
which returns true if at least one of its arguments is true. I find these quite useful in functional programming. Given how much Mathematica encourages functional programming constructs, I was surprised not to find anything equivalent to these all
and any
functions in the documentation. Does Mathematica have equivalents to these functions, or some standard way to achieve the same effect?
I can implement them myself as
AllOf[b_List] := Fold[And, True, b][[1]]
AllOf[b__] := Fold[And, True, {b}][[1]]
AnyOf[b_List] := Fold[Or, True, b][[1]]
AnyOf[b__] := Fold[Or, True, {b}][[1]]
(these may not be always correct, but they've worked for my purposes). But I would rather use something built-in if it exists.
AllOf[b_List] := And @@ b
andAnyOf[b_List] := Or @@ b
... $\endgroup$ – J. M.'s ennui♦ Jan 29 '12 at 4:03MemberQ
andFreeQ
. $\endgroup$ – amr Jan 1 '13 at 8:37