Is there an equivalent to Sum
for And
?
That is, just like instead of Plus@@Table[f[i], {i,3,6}]
(or Total@Table[f[i], {i,3,6}]
) you can write Sum[f[i], {i,3,6}]
, is there a single pre-defined function that can replace And@@Table[f[i], {i,3,6}]
?
If not, is there a better alternative for And@@Table[...]
?
Note that, at least in Mathematica 8, Conjunction
is not the right tool (despite the claim in the documentation that "Conjunction
is to And
what Product
is to Times
") because it only substitutes logical values, that is, it can only replace the special case And@@Table[f[var], {var, {False, True}}]
(and of course multi-variable versions of the same structure).
SetAttributes[and, HoldAll]; and[expr_, iter_] := And @@ Catch[Table[With[{e = expr}, If[e === False, Throw[False]]; e], iter]]
$\endgroup$ – Szabolcs Jun 11 '14 at 15:57Product
together withBoole
. $\endgroup$ – Szabolcs Jun 11 '14 at 16:00Module[{},Do[If[!f[i],Return[False,Module]],{i,3,7}];True]
. $\endgroup$ – celtschk Jun 11 '14 at 16:05AllTrue
will do this documentation. It even short-cuts. $\endgroup$ – Daniel W Jun 11 '14 at 16:10