Mathematica 7 compares to other languages
Xah Lee
xahlee at gmail.com
Thu Dec 11 01:51:00 CET 2008
On Dec 10, 2:47 pm, John W Kennedy <jwke... at attglobal.net> wrote:
> Xah Lee wrote:
> > In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
> > you'll have 50 or hundreds lines.
>
> C:
>
> #include <stdlib.h>
> #include <math.h>
>
> void normal(int dim, float* x, float* a) {
> float sum = 0.0f;
> int i;
> float divisor;
> for (i = 0; i < dim; ++i) sum += x[i] * x[i];
> divisor = sqrt(sum);
> for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
>
> }
>
> Java:
>
> static float[] normal(final float[] x) {
> float sum = 0.0f;
> for (int i = 0; i < x.length; ++i) sum += x[i] * x[i];
> final float divisor = (float) Math.sqrt(sum);
> float[] a = new float[x.length];
> for (int i = 0; i < x.length; ++i) a[i] = x[i]/divisor;
> return a;
>
> }
Thanks to various replies.
I've now gather code solutions in ruby, python, C, Java, here:
• A Example of Mathematica's Expressiveness
http://xahlee.org/UnixResource_dir/writ/Mathematica_expressiveness.html
now lacking is perl, elisp, which i can do well in a condensed way.
It'd be interesting also to have javascript... and perhaps erlang,
OCaml/F#, Haskell too.
Xah
∑ http://xahlee.org/
☄
More information about the Python-list
mailing list