Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Mathematica and F#

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91588] Re: Mathematica and F#
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Thu, 28 Aug 2008 03:18:27 -0400 (EDT)
  • References: <g93b2d$km1$1@smc.vnet.net>

Salvatore Mangano wrote:
> I refer members of this group to my blog for a review of the section of "F# for Scientists" that is relevant to Mathematica.
> 
> http://semanticvector.blogspot.com/2008/08/f-for-scientists-misses-boat-on.html
> 
There is a simple reason why functional code in Mathematica outperforms 
procedural code - it is that each step in Mathematica comes with a 
substantial overhead because of the generality of the language.

For example, in Mathematica, an operation like a=b+c clearly requires 
many things to be done - such as checking the types of the variables b 
and c, adjusting the reference count for any existing value attached to 
a, etc. Functional programming offers a way to reduce this overhead by 
bundling a lot of steps into one step. Lower level, fully typed 
languages - such as Fortran (where the variables are always typed, even 
if implicitly) do not suffer such overheads, and therefore there are no 
real speed advantages to using whole array operations (somewhat 
analogous to functional programming).

If you really need the ultimate in speed, you might as well code the 
core of a calculation in Java - but whether you use F# or C or Java, or 
whatever, you have to make sure that the extra speed is not lost in 
process swapping - remember that MathLink communicates to another process.

Note that, as I understand it, compilation in Mathematica only generates 
pseudo code which is executed by interpretation, so it should be 
outperformed by languages which are fully compiled. Java and .NET 
languages come into this category because their pseudo code is compiled 
immediately prior to the first use by a so called just-in-time (JIT) 
compiler.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Superimposing Normal on a Histogram of data
  • Next by Date: Re: efficiently adding many 2D Gaussians
  • Previous by thread: Mathematica and F#
  • Next by thread: Re: Re: Mathematica and F#