Karatsuba's algorithm
> a1 := op(1,evalf(Pi,10000)):
> type(a1,integer);
How many digits are in the integer a1 ?
> length(a1);
How long (in seconds) does it take to square a1 ?
> st := time(): a2 := a1^2: t2 := time()-st;
> length(a2);
How long does it take to square a2, where a2 has almost double the number of digits (19999 digits) that a1 has.
> st := time(): a4 := a2^2: t4 := time()-st;
> length(a4);
The ratio of the computation times should be close to 3 if Karatsuba's algorithm is used for integer multiplication.
> almost_3 := t4/t2;