Mathematica 7 compares to other languages

Xah Lee xahlee at gmail.com
Thu Dec 11 13:28:31 EST 2008


On Dec 11, 12:32 am, Gerard flanagan <grflana... at gmail.com> wrote:
> Xah Lee wrote:
> > 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.
> [...]
>
> > 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...
>
> mmm, stone soup...
>
> javascript:
>
> var map = function(fn, a) {
>      var b = new Array(a.length);
>      for (i = 0; i < a.length; i++) {
>          b[i] = fn(a[i]);
>      }
>      return b
>
> };
>
> var reduce = function(fn, a, init) {
>      var s = init;
>      for (i = 0; i < a.length; i++) {
>          s = fn(s, a[i]);
>      }
>      return s
>
> };
>
> var sum = function(a) {
>      return reduce(function(x, y) { return x + y }, a, 0.0)
>
> };
>
> var norm = function(a) {
>      var pow = Math.pow;
>      return Math.sqrt(sum(map(function(x) { return pow(x, 2) }, a)))
>
> };
>
> var Unit = function(a) {
>      var N = norm(a);
>      return map(function(x) { return x/N }, a)
>
> };

thats about 15 lines. I'm pretty sure JavaScript doesn't need that
many?

  Xah
∑ http://xahlee.org/


More information about the Python-list mailing list