Re: Algorithm Analysis Course: Should I use Mathematica for projects?

*To*: mathgroup at smc.vnet.net*Subject*: [mg127287] Re: Algorithm Analysis Course: Should I use Mathematica for projects?*From*: David Bailey <dave at removedbailey.co.uk>*Date*: Sat, 14 Jul 2012 01:29:08 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <jtkuhh$2a$1@smc.vnet.net>

On 11/07/2012 23:25, Brentt wrote: > Hi, > > I'm an undergrad math major, and taking a cross disciplinary Algorithm > Analysis course in the fall. I talked to the professor and he said we can > use whichever language we like and Mathematica would be fine if it had a > way to evaluate run-time. > > Two questions: > > I think the required capabilities are those found in the documentation > under "Time Measurement& Optimization". Would this be correct? And would > those functions be adequate for an algorithm analysis course? > > > I know this list would be a little biased but: should I use Mathematica? > > Cons: I absolutely adore Mathematica and never find myself wanting to > program in anything else (I've toyed with Python and other languages, but > Mathematica inspires me to play with programming like other languages have > not), and thought committing to Python for the class might expand my > programming skills. Also I'm guessing the course will focus on procedural > algorithms which might not be a good fit for Mathematica's functional > paradigm. I know Mathematica can be shoehorned in to any paradigm, but > maybe it'd be better to use a more procedural language. > > Pros: I will learn Mathematica with more depth, and there are good reasons > to get really good at one thing as opposed to OK at many things. Plus what > I learn in Mathematica may just as well translate to other languages anyway > so it may not be a big deal which I choose. > > Input anyone? > If you time much Mathematica code, you will become aware of a mass of subtleties, that might trip you up if you were primarily interested in algorithm performances. Here are a few examples: 1) If you use Fourier to do a DFT of a list of values, the internal algorithm will use a faster algorithm for particular lengths, such as powers of 2. 2) Some results can be cached inside Mathematica so that they don't get re-computed if needed again. 3) Many operations on lists or matrices go at very different speeds depending on whether these structures are packed or not. 4) Code may seem to execute slowly because it isn't doing what you think. For example, if you iterate: Nest[(#^2 + 2)/(#^2 + 3) &, 2, 4] Discarding the answer because you are only interested in the CPU time, you may not notice that it has performed the calculation in exact fractional arithmetic - which is much slower than floating point arithmetic. An interesting approach might be to run the code in C, but use Mathematica to provide the overall timing, C compilation, report generation, etc. David Bailey http://www.dbaileyconsultancy.co.uk