MathGroup Archive 2002

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

Search the Archive

RE: Re: RE: Sequence and Or

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34254] RE: [mg34244] Re: [mg34213] RE: [mg34179] Sequence and Or
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Sun, 12 May 2002 03:25:55 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks for the official explanation.  Avoiding the evaluation of
undefined expressions seems more crucial than the efficiency gain.

Both goals are defeated, though, by simple examples we've looked at in
this thread, in which the argument of Or is a Sequence or other
expression that resolves to a list of logicals.  Either the expression
isn't evaluated or ALL its parts are evaluated.

I think I've relearned the advantage of While over Or, and the
conceptual relationship between the two.

Thanks!

Bobby

-----Original Message-----
From: Daniel Lichtblau [mailto:danl at wolfram.com] 
To: mathgroup at smc.vnet.net
Subject: [mg34254] [mg34244] Re: [mg34213] RE: [mg34179] Sequence and Or

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
> Subject: [mg34254] [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: combining surface graphics objects
  • Next by Date: Factor Polynomials
  • Previous by thread: Re: Sequence and Or
  • Next by thread: Physical memory leak in Mathematica ?!