Efficiency Improvements in Maple 9A number of efficiency improvements have been applied to make Maple 9 faster and use less memory.Long Integer Arithmeticrtable_evalFreelist ChangesDynamic HashtablesLinearSolveLinearAlgebra Operationssparse numeric rtablescombinat[randperm]expand

<Text-field bookmark="bkmrk0" style="Heading 2" layout="Heading 2">Long Integer Arithmetic</Text-field>Maple 9 uses GNU Multiple Precision (GMP) library for integer arithmetic when the operands are longer than kernelopts(gmpthreshold) digits. GMP is very fast for arbitrary precision arithmetic on integers. The speed of GMP is achieved by using fullwords as the basic arithmetic type and sophisticated algorithms, and by including carefully optimized assembly code for the most common inner loops for many different CPUs. For more details about GMP library, see GMP.The following example runs in 160 seconds on Maple 8 but only in 6 seconds on Maple 9.<Text-field bookmark="bkmrk1" style="Heading 3" layout="Heading 3">Examples</Text-field>LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYnLUkjbWlHRiQ2I1EhRictRiM2J0YrLUYjNictRiw2JVEkYWRkRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LVEwJkFwcGx5RnVuY3Rpb247RicvRjpRJ25vcm1hbEYnLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0ZELyUpc3RyZXRjaHlHRkQvJSpzeW1tZXRyaWNHRkQvJShsYXJnZW9wR0ZELyUubW92YWJsZWxpbWl0c0dGRC8lJ2FjY2VudEdGRC8lJ2xzcGFjZUdRJjAuMGVtRicvJSdyc3BhY2VHRlMtSShtZmVuY2VkR0YkNiQtRiM2KC1JJm1mcmFjR0YkNigtRiM2JS1JI21uR0YkNiRRIjFGJ0ZALyUrZXhlY3V0YWJsZUdGREZALUYjNidGKy1GIzYkLUklbXN1cEdGJDYlLUYsNiVRImtGJ0Y2RjktRltvNiRRIjJGJ0ZALyUxc3VwZXJzY3JpcHRzaGlmdEdRIjBGJ0ZARitGXm9GQC8lLmxpbmV0aGlja25lc3NHRl1vLyUrZGVub21hbGlnbkdRJ2NlbnRlckYnLyUpbnVtYWxpZ25HRmRwLyUpYmV2ZWxsZWRHRkQtRj02LVEiLEYnRkBGQi9GRkY4RkdGSUZLRk1GT0ZRL0ZVUSwwLjMzMzMzMzNlbUYnLUYjNihGZ28tRj02LVEiPUYnRkBGQkZFRkdGSUZLRk1GTy9GUlEsMC4yNzc3Nzc4ZW1GJy9GVUZlcS1GIzYnRmpuLUY9Ni1RIy4uRidGQEZCRkVGR0ZJRktGTUZPL0ZSUSwwLjIyMjIyMjJlbUYnRlQtRltvNiRRJzEwMDAwMEYnRkBGXm9GQEYrRl5vRkBGK0Zeb0ZARkBGXm9GQEYrRl5vRkAtRj02LVEiOkYnRkBGQkZFRkdGSUZLRk1GT0ZkcUZmcUZeb0ZA<Text-field bookmark="bkmrk2" style="Heading 2" layout="Heading 2">rtable_eval</Text-field>Accessing elements from a Matrix, Vector, or Array inside a procedure is now more efficient in Maple 9. Evaluation rules for these structures, also known as rtables, have been changed so that it is possible to avoid repeated deep evaluation when elements are referenced.Applying eval() to an rtable returns immediately without changing the given rtable. This is unlike a list, which maps eval() onto each element and returns a copy. Evaluation of rtable elements is normally deferred until elements are referenced. If the same elements are repeatedly referenced, evaluation of those elements is also repeated. Again, this is in contrast to a list, which when individual elements are referenced, needs only to apply one level of evaluation. Using the rtable_eval(A) command provides a way to evaluate every element once so that, like lists, future references can bypass evaluation.When Maple has enough information to determine that a given rtable does not need full evaluation, it automatically uses the one level evaluation scheme. This can be done, for example, if the datatype is set to a hardware type, or if the rtable only ever contained literal data. In addition, many internal algorithms now use rtable_eval to avoid repeated full evaluations.The following example compares the cost of an LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYlLUkjbWlHRiQ2JlEiT0YnLyUnaXRhbGljR1EmZmFsc2VGJy8lK2V4ZWN1dGFibGVHRjEvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLUkjbW9HRiQ2LVEwJkFwcGx5RnVuY3Rpb247RidGNC8lJmZlbmNlR0YxLyUqc2VwYXJhdG9yR0YxLyUpc3RyZXRjaHlHRjEvJSpzeW1tZXRyaWNHRjEvJShsYXJnZW9wR0YxLyUubW92YWJsZWxpbWl0c0dGMS8lJ2FjY2VudEdGMS8lJ2xzcGFjZUdRJjAuMGVtRicvJSdyc3BhY2VHRkstSShtZmVuY2VkR0YkNiUtRiM2Iy1JJW1zdXBHRiQ2JS1GLDYmUSJORicvRjBRJXRydWVGJ0YyL0Y1USdpdGFsaWNGJy1JI21uR0YkNiVRIjNGJ0YyRjQvJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnRjJGNA== operation with and without rtable_eval() using a Matrix containing polynomials that are expensive to evaluate.F := proc(n) option remember; if n <= 2 then n else x*F(n-1)+F(n-2); end if; end proc:M := Matrix(5,5,(i,j)->F(5*i+j)):dostuff1 := proc(M) local i, j, k, y;
for i from 1 to op([1,1],M) do
for j from 1 to op([1,2],M) do
for k from 1 to op([1,2],M) do
y := M[i,j];
end do;
end do;
end do;
end proc:dostuff2 := proc(M) local i, j, k, y;
rtable_eval(M,'inplace');
for i from 1 to op([1,1],M) do
for j from 1 to op([1,2],M) do
for k from 1 to op([1,2],M) do
y := M[i,j];
end do;
end do;
end do;
end proc:time(dostuff1(M));time(dostuff2(M));<Text-field bookmark="bkmrk3" style="Heading 2" layout="Heading 2">Freelist Changes</Text-field>Before Maple 9, Maple used a linked list to store large free memory blocks. To allocate a large block, a linear scan of the list was performed to find the first block large enough to satisfy the request. In most cases this was sufficient. However, as problem sizes increased and larger settings for gcfreq became common, the average length of these free lists increased. Internal testing found examples whose running time increased as gcfreq increased (usually increasing gcfreq decreases running time). The problem was long free lists which took a long time to search. For Maple 9, the free lists have been replaced by a tree. The tree allows for faster searches, especially when lists would have become long.In general there is no slowdown related to using the tree. For those cases where long free lists were a problem, the tree accelerates allocations considerably. A test file that takes 56 seconds in Maple 8, takes 9 seconds for Maple 9. Another test that took 50 seconds in Maple 8 now takes only 8. As well, this change fixes reports involving Maple performance decreasing as memory allocation increases.<Text-field bookmark="bkmrk4" style="Heading 2" layout="Heading 2">Dynamic Hashtables</Text-field>The hashtables in Maple 8 were designed to give good performance for most cases. However in extreme cases, when a very large amount of data is inserted into the table, their performance decreased. To fix this, Maple 9 has dynamic hashtables. Dynamic hashtables reorganize themselves so that table operations remain fast even when large amounts of data are inserted. Due to the overhead of reorganization, a dynamic hashtable is only used when a normal hashtable becomes overloaded. Therefore using dynamic hashtables does not cause a slowdown.A simple way to test the performance of the dynamic hashtables is to perform a large number of insertions and searches on a table. The following example runs in 430 seconds in Maple 8, but only 200 seconds in Maple 9.num := 2^22:a := table():r := rand( 1..num ):for i from 1 to num do
a[r()] := r();
end do:
for i from 1 to num do
a[r()]:
end do:Dynamic hashtables also interact better with the Maple memory manager. This can mean a significant reduction in memory allocation when dealing with very large tables. The example above allocates 62 Mb in Maple 8 and 40 Mb in Maple 9.<Text-field bookmark="bkmrk5" style="Heading 2" layout="Heading 2">LinearSolve</Text-field>The LinearSolve function in the LinearAlgebra package has a new solver, which is activated by supplying the optional parameter method=hybrid. This solver does the LU factorization in hardware floating-point mode followed by iterative refinement of the solution done in software floating-point mode. This can be measurably more efficient, especially at higher settings of Digits.<Text-field bookmark="bkmrk6" style="Heading 3" layout="Heading 3">Examples</Text-field>with(LinearAlgebra):UseHardwareFloats:=false:m := RandomMatrix(100,outputoptions=[datatype=sfloat]):v := RandomVector(100,outputoptions=[datatype=sfloat]):Digits := 40:st:=time():hsol:=LinearSolve(m,v,method=hybrid):time()-st;st:=time():lsol:=LinearSolve(m,v):time()-st;Norm(m.hsol-v);Norm(m.lsol-v);<Text-field bookmark="bkmrk7" style="Heading 2" layout="Heading 2">LinearAlgebra Operations</Text-field>The Basic Linear Algebra Subprograms (BLAS) libraries for Sun and Linux platforms now have built-in architecture-specific optimizations, as well as expected updates resulting from an upgrade to newer versions of ATLAS BLAS.The following is a quick comparison between Maple 8 and Maple 9 of the run time for multiplication of two 1000x1000 random float[8] matrices:

<Text-field bookmark="bkmrk8" style="Heading 2" layout="Heading 2">sparse numeric rtables</Text-field>When using storage=sparse, and a hardware datatype with an Array, Matrix, or Vector, the NAG sparse format is used. The internal data structure is the same as in previous versions of Maple, except that the index vectors are now maintained in sorted and unsorted blocks. A resort is automatically triggered after the insertion of kernelopts (sparse_sort_cutoff) new elements.The following example, which took 10.200 seconds to initialize a 200 x 200 corner of a sparse Matrix in Maple 8, now takes under 0.2 seconds on the same computer in Maple 9.<Text-field bookmark="bkmrk9" style="Heading 3" layout="Heading 3">Examples</Text-field>M := Matrix(10000,10000,storage=sparse,datatype=float[8]):t:=time():for i from 1 to 200 do
for j from 1 to 200 do
M[i,j]:=i+j:
end do:
end do:
time()-t;<Text-field bookmark="bkmrk10" style="Heading 2" layout="Heading 2">combinat[randperm]</Text-field>The procedure combinat[randperm] has been optimized. It is now 10 to 20 percent faster, and uses nearly an order of magnitude less memory.<Text-field bookmark="bkmrk11" style="Heading 2" layout="Heading 2">expand</Text-field>Expansion of large powers of some kinds of expressions is now faster. For example, the following computation is much faster in Maple 9 than in Maple 8.time( expand( ((sqrt(5)-1)/2)^10000 ) );See AlsoArraycombinat[randperm]DigitsgcfreqGMPIndex of New Maple 9 FeatureskerneloptsLinearAlgebraMatrixprocrememberrtablertable_evalrtable_options/datatypesparsetimetype/literalVector