Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: build-in commutativity

  • To: mathgroup at
  • Subject: [mg36731] RE: [mg36721] Re: build-in commutativity
  • From: "DrBob" <drbob at>
  • Date: Sat, 21 Sep 2002 02:21:56 -0400 (EDT)
  • Reply-to: <drbob at>
  • Sender: owner-wri-mathgroup at

Although And and Or don't have to evaluate all their arguments, I find
that this is useless in many situations I run into.  For instance, I
might have a long list 'boolList' of Boolean expressions and I want to
know if ANY of them are False, so I calculate


In this situation, ALL the expressions in 'boolList' are calculated,
even though the first may be False.  Here's an example in which I
overcome that:

boolList = Hold[Print@#; PrimeQ@#] & /@ Range[3, 1000, 2];
ReleaseHold[And @@ boolList]


Bobby Treat

-----Original Message-----
From: Carl K. Woll [mailto:carlw at] 
To: mathgroup at
Subject: [mg36731] [mg36721] Re: build-in commutativity


Note that both "And" and "Or" can return a value without evaluating all
their arguments. For example, if the first argument to And is False,
is no reason to look at the other arguments. Suppose a user knows that
of the arguments is usually false, and so would like to look at that
argument before any of the others, to avoid unneeded computations of the
other arguments. He would put that argument first. If Mathematica turned
around and sorted the arguments (which is what happens when a function
orderless), then that argument might end up being evaluated last. If the
arguments take a significant amount of time to compute, then sorting
may cause the function to take much longer to evaluate.

At any rate, if the above is not a concern for you, you may always
the attributes of And and Or to anything you want.

Carl Woll
Physics Dept
U of Washington

----- Original Message -----
From: "Evgeni Trifonov" <algolog at>
To: mathgroup at
Subject: [mg36731] [mg36721] build-in commutativity

> I'm curious, why the built-in boolean functions "And" and "Or"
> aren't commutative?
> Attributes/@{Or,And}//ColumnForm
> {Flat, HoldAll, OneIdentity, Protected}
> {Flat, HoldAll, OneIdentity, Protected}
> However, the arithmetical functions are "Orderless":
> Attributes/@{Plus,Times}//ColumnForm
> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}
> {Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}
> -------------------
> Evgeni Trifonov
> Vladivostok, Russia

  • Prev by Date: Re: Ball Rolling down on Cosh[t] Path
  • Next by Date: Re: Ball Rolling down on Cosh[t] Path
  • Previous by thread: Re: build-in commutativity
  • Next by thread: How to Properly Use Partition?