Mathematica 7 compares to other languages
Bakul Shah
bakul+usenet at bitblocks.com
Wed Dec 10 19:25:02 EST 2008
Bakul Shah wrote:
> John W Kennedy 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;
>> }
>>
>>
>
> q){x%sqrt sum x}3 4
> 0.6 0.8
Oops. I meant to write {x%sqrt sum x*x}3 4
More information about the Python-list
mailing list