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: build-in commutativity

  • To: mathgroup at
  • Subject: [mg36721] Re: build-in commutativity
  • From: "Carl K. Woll" <carlw at>
  • Date: Fri, 20 Sep 2002 04:16:42 -0400 (EDT)
  • References: <ambu72$qst$>
  • Sender: owner-wri-mathgroup at


Note that both "And" and "Or" can return a value without evaluating all of
their arguments. For example, if the first argument to And is False, there
is no reason to look at the other arguments. Suppose a user knows that one
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 is
orderless), then that argument might end up being evaluated last. If the
arguments take a significant amount of time to compute, then sorting first
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 change
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: [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: Drawing an ellipse
  • Next by Date: RE: FW: Re: empirical CDF
  • Previous by thread: Re: build-in commutativity
  • Next by thread: RE: Re: build-in commutativity