Re: Conditionals -- what is "fastest" way to evaluate

*To*: mathgroup at smc.vnet.net*Subject*: [mg84303] Re: Conditionals -- what is "fastest" way to evaluate*From*: Szabolcs <szhorvat at gmail.com>*Date*: Tue, 18 Dec 2007 05:32:39 -0500 (EST)*References*: <fk73mo$67o$1@smc.vnet.net>

On Dec 18, 2:19 am, "Coleman, Mark" <Mark.Cole... at LibertyMutual.com> wrote: > Greetings, > > I've built a simple function that calculates the distance between a pair > of points on the Great Circle, e.g.., the distance between two addresses > given their latitude-longitude coordinates. I need to apply this against > very large lists of points, resulting in potentially tens or hundreds of > millions of calculations. The input data that I am processing will list > a point's location as (0,0) if for some reason the lat-long coordinate > is not known (nb: this is a poor way to return a lat-long coordinate, > but I am taking these as given from another processing system). For > pairs of points where at least one of the arguments is (0,0), I'd like > to skip the calculation and return an error code or a perhaps a value of > infinity. > > I'm curious as to what is the fastest way to apply a conditional test in > Mathematica under these circumstances? Is it a simple If[ ] statement, a "/;" > construct, Boole, etc? I am happy to test out all of the alternatives, > but many times some very ingenious solutions are presented on MathGroup, > so I thought I'd pose the question. (note: I am presuming that is it > faster to process a conditional test than to evaluate the underlying > function) I haven't actually tested this, but I believe that the fastest solution would be a pure function (i.e. something like f = #^2& instead of f[x_] = x^2) with an If[] test. This ensure that the function is compilable, and automatic compilation is possible. You may want to read this presentation by Carl Woll: http://library.wolfram.com/infocenter/Conferences/7005/ I know that there is a webpage somewhere on the Wolfram site that lists all the functions that work with Compile[], but I just can't find it now! Could someone please point to the right page?