Mathematica 7 compares to other languages

Jon Harrop jon at ffconsultancy.com
Mon Dec 8 08:10:32 EST 2008


Xah Lee wrote:
> For those interested in this Mathematica problem, i've now cleaned up
> the essay with additional comments here:
> 
> • A Mathematica Optimization Problem
>   http://xahlee.org/UnixResource_dir/writ/Mathematica_optimization.html

In that article you say:

> Further, if Intersect is made to take a flat sequence of argument as
> in “Intersect[o_, d_, lambda_, n_, c_, r_, s_]”, then pattern matching can
> be avoided by making it into a pure function “Function”. And when it is
> a “Function”, then Intersect or part of it may be compiled with Compile.
> When the code is compiled, the speed should be a order of magnitude
> faster.     

That is incorrect. Mathematica's Compile function cannot handle recursive
functions like Intersect. For example:

In[1]:= Compile[{n_, _Integer}, If[# == 0, 1, #0[[# n - 1]] #1] &[n]]

During evaluation of In[1]:= Compile::fun: Compilation of
(If[#1==0,1,#0[[#1 n-1]] #1]&)[Compile`FunctionVariable$435] cannot
proceed. It is not possible to compile pure functions with arguments
that represent the function itself. >>

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u



More information about the Python-list mailing list