Dear All,
It turned out that our realization of the polynomial GCD
had a little glitch. The better code for the LCM that is
used in the computation of the GCD is as follows:
sys_poly_lcm(A, B, C) :-
S is A*Z,
T is B*(1-Z),
sys_poly_groeb([S,T],L),
sys_poly_min(L, C).
The fix is necessary since sys_poly_groeb/2 doesn't return
the Gröbner basis as a sorted list, sorted by the lexical
ordering that puts Z at last. With this little fix some
border cases such as this one now work correctly:
?- S is 1, T is 2/3*A+4/5*B, R is S/T.
S = 1,
T is 4/5*B+2/3*A,
R is 15/(12*B+10*A)
The algorithm itself works with rational monomial coefficients,
but there is also finishing step to make the numerator and
denumerator of the polynomial fraction with integer monomial
coefficients. This is all seen in the open source gist.
Now that we have polynomial GCD, what can we do with it?
Well we just made a little experiment in providing symbolic
matrices in Prolog. We made such an experiment already in
december 2016, but we added matrice inversion now.
We implemented an inline matrice inversion algorithm. Its
name is "Austauschschritt Verfahren" or AT-Algorithm. It
is in fact realized as Prolog-ish tail recursive, but our
implementation is derived from an originally inline approach.
Hilbert matrices are numerically difficult,
but we can do them now exact:
?- hilbert_matrice(4, X), Y is X^(-1).
X is [[1,1/2,1/3,1/4],[1/2,1/3,1/4,1/5],[1/3,1/4,1/5,1/6],[1/4,1/5,1/6,1/7]],
Y is [[16,-120,240,-140],[-120,1200,-2700,1680],[240,-2700,6480,-4200],[-140,1680,-4200,2800]]
The problem matrice can also have
fully symbolic entries:
?- X is [[1,B],[B^2,B]], Y is X^(-1).
X is [[1,B],[B^2,B]],
Y is [[-1/(B^2-1),1/(B^2-1)],[B/(B^2-1),-1/(B^3-B)]]
The AT-Algorithm uses less steps than for example the
Cramer method where we would compute a couple of
determinants. At the moment we only implemented a version
without pivoting.
Upon code inspection one will see that we used the same
programming approach for matrice inversion as in our
december 2016 matrice multiplication prototype, i.e
findall/3 and arg/3 that can be used inside is/2.
For more information:
Preview: Symbolic Matrice Inversion in OO Prolog. (Jekejeke)
https://plus.google.com/+JekejekeCh/posts/8jRmzruDMgs
Code Golf: Symbolic Matrix Multiplication in Prolog
http://codegolf.stackexchange.com/questions/106570/symbolic-matrix-multiplication/113875#113875