Hello,
I am new to Julia, which I learn in the hope to port some mathematical
software (group theory and arithmetic) to. I did a simple test with Hilbert
matrices, and to my disappointment I found that on this test Julia is
slower than all the other CAS systems I have access to.
Here is the Julia code I used:
hilb=n->[1//(BigInt(i)+j-1) for i in 1:n, j in 1:n]
function test(n) hilb(n)^-1 end
julia> @time test(80);
5.158600 seconds (42.41 M allocations: 1.072 GiB, 31.96% gc time)
Here is the code in GAP
hilb:=n->List([1..n],i->List([1..n],j->1/(i+j-1)));
hilb(80)^-1;;time;
706 (0.706 second)
Now the Magma version:
hilb:=function(n) return Matrix(n,n,[1/(i+j-1) : i in [1..n], j in[1..n]]);
end function;
time hilb(80)^-1;
140 (0.140 second)
Now the Maple version
with(linalg);
m:=Matrix(80,(i,j)->1/(i+j-1));
inverse(m); # takes 1.5 sec
It is also slower than in the languages Ruby and Python:
In Ruby
require "benchmark"
require "matrix"
m=Matrix.build(80,80){|i,j| Rational(1,i+j+1)}
Benchmark.measure{m.inv}
=> 2.4 sec
In Python via SageMath:
sage: a=Matrix([[1/(i+j-1) for j in (1..80)]for i in (1..80)])
sage: timeit('a^-1')
5 loops, best of 3: 1.03 s per loop
So what I am doing wrong in Julia? Is there another type than BigInt which
guarantees that hilb(80)*hilb(80)^-1 is the identity matrix? Is there a way
in Julia which is not 35 times slower than Magma?
Best regards,