Mathematica 7 compares to other languages

Xah Lee xahlee at gmail.com
Wed Dec 10 17:08:12 EST 2008


Xah Lee wrote:
> > Let's say for example, we want to write a function that takes a vector
> > (of linear algebra), and return a vector in the same direction but
> > with length 1. In linear algebar terminology, the new vector is called
> > the “normalized” vector of the original.
>
> > For those of you who don't know linear algebra but knows coding, this
>
> If I were to guess who that would be ...
>
> > means, we want a function whose input is a list of 3 elements say
> > {x,y,z}, and output is also a list of 3 elements, say {a,b,c}, with
> > the condition that
>
> > a = x/Sqrt[x^2+y^2+z^2]
> > b = y/Sqrt[x^2+y^2+z^2]
> > c = z/Sqrt[x^2+y^2+z^2]
>
> > In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
> > you'll have 50 or hundreds lines.


Kaz Kylheku wrote:
> Really? ``50 or hundreds'' of lines in C?
>
>   #include <math.h> /* for sqrt */
>
>   void normalize(double *out, double *in)
>   {
>         double denom = sqrt(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]);
>
>         out[0] = in[0]/denom;
>         out[1] = in[1]/denom;
>         out[2] = in[2]/denom;
>   }
>
> Doh?

Kaz, pay attention:

Xah wrote: «Note, that the “norm” as defined above works for vectors
of any dimention, i.e. list of any length.»

The essay on the example of Mathematica expressiveness of defining
Normalize is now cleaned up and archived at:

• A Example of Mathematica's Expressiveness
  http://xahlee.org/UnixResource_dir/writ/Mathematica_expressiveness.html

  Xah
∑ http://xahlee.org/


More information about the Python-list mailing list