Addition-chain exponentiation: Difference between revisions

deleted a pseudo solution that did not use addition chains at all
m (→‎{{header|Go}}: now hopefully agreed upon)
(deleted a pseudo solution that did not use addition chains at all)
Line 443:
1.00002550055251^27182: 1.99999999997876
count of multiplies: 18
</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
{{incorrect|matlab|Assuming that Matlab or Octave has an optimal algorithm is certainly not enough: the problem is difficult and it's highly likely that they both use a variant of binary exponentiation instead, which is usually enough, but not in the scope of the task}}
 
I assume that Matlab and Octave have about such optimization already included. On a single core of an "Pentium(R) Dual-Core CPU E5200 @ 2.50GHz", the computation of 100000 repetitions of the matrix exponentiation A<sup>27182</sup> and A<sup>31415</sup> take about 2 and 2.2 seconds, resp.
<lang Matlab>x = sqrt(.5);
A = [x,0,x,0,0,0;0,x,0,x,0,0; 0,x,0,-x,0,0;-x,0,x,0,0,0;0,0,0,0,0,1; 0,0,0,0,1,0];A
t = cputime(); for k=1:100000,x1=A^27182;end; cputime()-t,x1,
t = cputime(); for k=1:100000,x2=A^31415;end; cputime()-t,x2, </lang>
Output:
<pre>Octave3.4.3> t = cputime(); for k=1:100000,x1=A^27182;end; cputime()-t,x1,
ans = 1.9900
x1 =
 
-0.50000 -0.50000 -0.50000 0.50000 0.00000 0.00000
0.50000 -0.50000 -0.50000 -0.50000 0.00000 0.00000
-0.50000 -0.50000 0.50000 -0.50000 0.00000 0.00000
0.50000 -0.50000 0.50000 0.50000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 1.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 1.00000
 
Octave3.4.3> t = cputime(); for k=1:100000,x2=A^31415;end; cputime()-t,x2,
ans = 2.2000
x2 =
 
0.70711 0.00000 0.00000 -0.70711 0.00000 0.00000
0.00000 0.70711 0.70711 0.00000 0.00000 0.00000
0.70711 0.00000 0.00000 0.70711 0.00000 0.00000
0.00000 0.70711 -0.70711 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 1.00000
0.00000 0.00000 0.00000 0.00000 1.00000 0.00000
</pre>
 
Anonymous user