Mathematica 7 compares to other languages

S

sln

Xah said:
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 * x;
divisor = sqrt(sum);
for (i = 0; i < dim; ++i) a = x/divisor;

}


Due to the low level of C, this C example should perhaps then accept a
sequence of numbers separated by space...


In other words, you want a REPL.

Why don't we have another challenge that involves handling a non-trivial
input format, i.e. parsing?


Maybe you could speed it up.

sln

----------------------------------
void normal (int Dimension, double *X, double *A)
{
double *xp, *ap, divisor, sum;
int i;

for ( i=0, sum=0., xp=X; i<Dimension; i++, xp++)
sum += (*xp) ** 2;
divisor = sqrt ( sum );
for ( i=0, ap=A, xp=X; i<Dimension; i++, ap++, xp++)
*ap = *xp / divisor;

// if Dimension is greater than
// sizeof double X[] or double A[] it will GPF.
// this is a really, really bad design.
}
 
M

MRAB

Xah said:
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 * x;
divisor = sqrt(sum);
for (i = 0; i < dim; ++i) a = x/divisor;
}
Due to the low level of C, this C example should perhaps then accept a
sequence of numbers separated by space...

In other words, you want a REPL.

Why don't we have another challenge that involves handling a non-trivial
input format, i.e. parsing?


Maybe you could speed it up.

sln

----------------------------------
void normal (int Dimension, double *X, double *A)
{
double *xp, *ap, divisor, sum;
int i;

for ( i=0, sum=0., xp=X; i<Dimension; i++, xp++)
sum += (*xp) ** 2;


C doesn't have a "**" operator.
divisor = sqrt ( sum );
for ( i=0, ap=A, xp=X; i<Dimension; i++, ap++, xp++)
*ap = *xp / divisor;

// if Dimension is greater than
// sizeof double X[] or double A[] it will GPF.
// this is a really, really bad design.
}
 
S

soul.mirror1

I vaguely remember you plonking the guy before. Did you unplonk him in
the meantime? Or was that just a figure of speech?

teasingly yours,
/W

Andreas Waldenburger, I hold up a mirror to your soul!

A couple of years ago you started posting to the newsgroup
comp.lang.java.programmer. Unlike most newbies, instead of lurking for
a while and then contributing on-topic posts about Java, you jumped
into the nearest available flamewar and immediately got in up to your
neck. Then, on November 13, 2007, you stooped to intentionally
misquoting one of your opponents. When he wrote

http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e90afa4a20?dmode=source

you quoted him thusly:
http://groups.google.com/group/comp.lang.java.programmer/msg/0386cc91ce75a3c6?dmode=source

A few days later, you did it again, misquoting this post

http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d413549f499?dmode=source

in this one:

http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b23537c1b?dmode=source

In both cases, you publicly portrayed this poor man as a pervert, even
though, whatever his other faults, that is clearly not one of them.

Since that date, you have continued to participate on and off in a
flamewar with many of the same participants, including the one you so
mistreated that November. In fact, it seems that the very SAME
flamewar is still in progress, in another newsgroup, fourteen whole
months later, and you are still in it up to your neck.

Repeatedly you have claimed to be primarily motivated by finding the
disrupting of newsgroups to be entertaining. This is tantamount to
admitting to being a troll.

If you have an excuse for your behavior, please speak now, and give
your apology before the witnesses gathered here.

If you do not, then know that your soul is forever tainted!
 
J

Jerry Gerrone

I vaguely remember you plonking [Xah Lee] before. Did you unplonk him in
the meantime? Or was that just a figure of speech?
teasingly yours,
/W

Andreas Waldenburger, I hold up a mirror to your soul!

A couple of years ago you started posting to the newsgroup
comp.lang.java.programmer. Unlike most newbies, instead of lurking for
a while and then contributing on-topic posts about Java, you jumped
into the nearest available flamewar and immediately got in up to your
neck. Then, on November 13, 2007, you stooped to intentionally
misquoting one of your opponents. When he wrote

http://groups.google.com/group/comp.lang.java.programmer/msg/7797d4e9...

A few days later, you did it again, misquoting this post

http://groups.google.com/group/comp.lang.java.programmer/msg/fca19d41...

in this one:

http://groups.google.com/group/comp.lang.java.programmer/msg/397e1d4b...

In both cases, you publicly portrayed this poor man as a pervert, even
though, whatever his other [insult deleted], that is clearly not one of
them.

None of the nasty things that you have said or implied about me are at
all true.
Repeatedly you have claimed to be primarily motivated by finding the
disrupting of newsgroups to be entertaining. This is tantamount to
admitting to being a troll.

Yes, and here you are, feeding him. Way to go, genius.

(And cljp had just gotten peaceful again, too!)
 
W

William James

The JavaScript example:

// Javascript. By William James
function normalize( vec ) {
var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b)
a+b))   return vec.map(function(x) x/div)

}

is also not qualified. (it is syntax error in SpiderMonkey engine
“JavaScript-C 1.7.0 2007-10-03”)

Since you are using the latest version of Mathematica, you should
also use the latest version of SpiderMonkey.

The function works outside of a web browser with jslibs, and it
works in Firefox 3.0.1.

<html>
<body>

<script type="application/javascript;version=1.8"/>

// Tested with Firefox 3.0.1.
// SpiderMonkey JavaScript 1.6 added map().
// 1.8 added reduce() and function shorthand:
// function(x) { return x * x }
// can now be:
// function(x) x * x

// Javascript. By William James
function normalize( vec ) {
var div=Math.sqrt(vec.map(function(x) x*x).reduce(function(a,b) a+b))
return vec.map(function(x) x/div)
}

window.alert( normalize( [2,3,4] ).toSource() )

</script>

</body>
</html>

Reduce:

procedure normalize vec;
begin scalar div;
div := for each u in vec sum u^2;
return map(~x/div, vec)
end;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top