RE: Sequence and Or
- To: mathgroup at smc.vnet.net
- Subject: [mg34230] RE: Sequence and Or
- From: "DrBob" <majort at cox-internet.com>
- Date: Fri, 10 May 2002 03:05:16 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Curiouser and curiouser. First of all, why isn't OwnValues documented? Second and third, look at the following: Quit SetAttributes[myApply,HoldAll] myApply[f_,{x__}]:=f[x] p1 := 1 == 1 p2 := FullSimplify[Gamma[z]*z == z!] expr := {p1, p2}; Timing[ReleaseHold[Hold[expr] /. OwnValues[expr] /. {x___} :> Or[x]]] Timing[Or@@expr] Timing[Or@@expr] Timing[myApply[Or,expr]] Timing[myApply[Or,{p1,p2}]] {0. Second,True} {0.219 Second,True} {0. Second,True} {0. Second,myApply[Or,expr]} {0. Second,True} The third and fourth output lines mystify me. The fourth suggests that Andrezej's "myApply" method doesn't salvage efficiency for situations where you wouldn't want to type in all the logical expressions in a list. The difference in timing for identical expressions in the second and third output lines must be due (I suppose?) to startup costs. Allan's method is clever and instructive. Thanks to both of you! Bobby -----Original Message----- From: Allan Hayes [mailto:hay at haystack.demon.co.uk] To: mathgroup at smc.vnet.net Subject: [mg34230] Re: Sequence and Or "DrBob" <majort at cox-internet.com> wrote in message news:abdgc4$cil$1 at smc.vnet.net... > 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 Bobby, A suggestion, modifying Andrzej Kozlowski's example: p1 := 1 == 1 p2 := FullSimplify[Gamma[z]*z == z!] expr := {p1, p2}; Timing[ ReleaseHold[Hold[expr] /. OwnValues[expr] /. {x___} :> Or[x]] ] {0. Second, True} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565