MathGroup Archive 2002

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

Search the Archive

Re: RE: Sequence and Or

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34244] Re: [mg34213] RE: [mg34179] Sequence and Or
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Sat, 11 May 2002 04:05:06 -0400 (EDT)
  • References: <200205090917.FAA12685@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

DrBob wrote:
> 
> On second thought, I doubt this feature has much benefit, unless it
> works in a case like
> 
> Or@@expr
> 
> where expr resolves to a long list of logical expressions.  I'm
> wondering how that could be accomplished, and I fear it can't be.
> 
> If this performance feature is limited to small numbers of arguments to
> Or... as many as you'd be willing to type... the benefit seems small.
> With large numbers of arguments, it seems we'd have to use While, or a
> similar construct.
> 
> Bobby Treat
> 
> -----Original Message-----
> From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp]
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> Subject: [mg34244] [mg34213] Re: [mg34179] Sequence and Or
> 
> It seems to me this is just a matter of efficiency. Suppose you want to
> evaluate Or[p1,p2,p3,...,pn] for some statements p1, p2 ...pn. It is
> enough that just one pi is True for the answer to be true. So
> Mathematica evaluates each statement in turn and stops whenever it finds
> 
> one that turns out to be true. This can produce a big gain in
> efficiency, particularly if you sensibly arranged the statements so that
> 
> those more likely to be true come earlier. Of course for this sort of
> thing to be of any use you need to have the HoldAll attribute otherwise
> Mathematica would first evaluate all the statements even if only p1 was
> true and easy to check and the rest hard.
> 
> Andrzej Kozlowski
> Toyama International University
> JAPAN
> http://platon.c.u-tokyo.ac.jp/andrzej/
> 
> On Wednesday, May 8, 2002, at 11:54  PM, DrBob wrote:
> 
> > Thanks for the workaround!  It makes me wonder, though, why Or should
> > have the HoldAll attribute at all.
> >
> > Bobby

Efficiency is not the main reason for the HoldAll attribute. Logical
operators are frequently used in control structures e.g. If[...]. Hence
you can have a computation that returns some expression that might or
might not be a list of length greater than 1, and use something like
 
	If [ListQ[expr] && Length[expr]>1 && expr[[2]]===5, do something]

Without the held aspect this would give a Part::partd message. One can
imagine examples that might misbehave in more remarkable fashion.


Daniel Lichtblau
Wolfram Research


  • Prev by Date: RE: Re: How to integrate over a constrained domain
  • Next by Date: Re: How to put parameter list in or near a graph?
  • Previous by thread: RE: Sequence and Or
  • Next by thread: Re: Sequence and Or