Tuesday, 26 May 2009

F# vs Mathematica: Pythagoras tree

The F# News blog recently published an article about the Pythagoras tree that included the complete F# source code for a program that renders the tree. Interestingly, the Wolfram Demonstrations Project contains a similar implementation written in the Mathematica language, which is a domain-specific language designed for interactive technical computing.

Surprisingly, the implementation written in the general purpose F# programming language is not only much faster but is also substantially shorter and clearer. Here is the F# code:

And here is the substantially more complicated Mathematica code:

This example really highlights just how versatile the F# programming language has become without sacrificing the benefits of more conventional languages.

Friday, 8 May 2009

Mathematica bug afflicting our product

Our Mathematica library for wavelet-based time-frequency analysis does not work with the first release of Mathematica 7 due to a bug in Mathematica's FFT routines that silently corrupts data. Any customers using this product are advised to avoid Mathematica version 7.0.0.

Specifically, the Fourier function and all related functions drop the imaginary parts of complex numbers in the result. For example, Mathematica 7.0.0 gives the wrong result here:

In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]
Out[1]= {0.00353553, 0.00636396}

The correct answer in this case is:

In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]
Out[1]= {0.00353553 + 0.00537401 I, 0.00636396 + 0.00876812 I}

If anyone would be interested in us porting this software to other environments, such as Matlab or F#, please let us know.