Mathematica 7 compares to other languages

Xah Lee xahlee at gmail.com
Mon Dec 8 12:34:43 EST 2008


On Dec 8, 5:10 am, Jon Harrop <j... at ffconsultancy.com> wrote:
> 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.

i didn't claim it can. You can't expect to have a fast or good program
if you code Java style in a functional lang.

Similarly, if you want code to run fast in Mathematica, you don't just
slap in your OCaml code into Mathematica syntax and expect it to work
fast.

If you are a Mathematica expert, you could make it recurse yet have
the speed as other langs. First, by changing your function's form, to
avoid pattern matching, and rewrite your bad recursion. That is what i
claimed in the above paragraph. Read it again to see.

> 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. >>

Mathematica's Compile function is intended to speed up numerical
computation. To want Compile to handle recursion in the context of
Mathematica's programing features, is not something possible even in
theoretical sense.

Scheme lisp implementations can compile recursive code, but lisp is a
lower level lang than Mathematica, where perhaps the majority of
Mathematica's builtin functions can equate to 10 or more lines of
lisp, and any of its hundreds math functions equates to entire
libraries of other langs. It is reasonable, but silly, to expect
Mathematica's Compile function to compile any code in Mathematica.

Perhaps in the future version of Mathematica, its Compile function can
handle basic recursive forms.

Also, in this discussion, thanks to Thomas M Hermann's $20 offered to
me for my challenge to you, that i have taken the time to show working
code that demonstrate many problems in your code. Unless you think my
code and replies to you are totally without merit or fairness, but
otherwise you should acknowledge it, in whole or in parts you agree,
in a honest and wholehearted way, instead of pushing on with petty
verbal fights.

  Xah
∑ http://xahlee.org/


More information about the Python-list mailing list