Question: How do I simplify the elements of a matrix return from a procedure?

I have been looking at a method for computing the inverse of a periodic, tridiagonal, matrix (tridiagonal with non-zero elements in (1,n) and (n,1), where n is the order of the matrix).

Using test matrices with rational elements I get a good improvement in execution time compared to Maple's MatrixInverse procedure from LinearAlgebra. However when I use algebraic elements I get faster times with small orders but from around
n=25 (for a particular example matrix) my method is running slower than MatrixInverse.

If I look at the element (1,1) of the inverse returned by both procedures I see that the Maple inverse is quite compact while the value returned by my procedure is very complex (on printing Maple extracts 17 subexpressions of varying complexity). I
have a check in the test rig to determine if the two inverses are the same; this uses

evalb(simplify(AinvMaple[i,j]-Ainv[i,j])==0)

and all the elements do agree.

The Maple MatrixInverse appears to be able to simplify the elements of the inverse; is this a feature of the algorithm that's being used or is there some mechanism I should be using to achieve this?

The source code of the procedure I've written (first 100 odd lines) and the test rig are attached. The file is set up to run the algebraic test (Test4) for n=20 and to print the (1,1) inverse elements generated by both the Maple and my procedures.

Any help in improving my code to produce simplified forms of the elements would be greatfully received.

Maple source as text file: KilicInv.txt

Please Wait...