gap-system / gap

Main development repository for GAP - Groups, Algorithms, Programming, a System for Computational Discrete Algebra
https://www.gap-system.org
GNU General Public License v2.0
810 stars 160 forks source link

rational functions arithmetics #3086

Open ThomasBreuer opened 5 years ago

ThomasBreuer commented 5 years ago

The following happens in the master branch as well as in released versions of GAP.

gap> a:= Indeterminate( Cyclotomics, "a" );;
gap> b:= Indeterminate( Cyclotomics, "b" );;
gap> m:= a^-1 * b^-1;
1/(a*b)
gap> m + m;
1/(1/2*a*b)
gap> 2 * m;
2/(a*b)
gap> a^-1 * b^-2 + 10 * a^-1 * b^-1;
(100*b+10)/(10*a*b^2)

These results are of course correct, but is this behavior intended? I have examples where a rational function is constructed as a sum of many inverses of monomials, and where huge integer coefficients arise in numerator and denominator, which essentially cancel out.

fingolfin commented 5 years ago

Pinging @hulpke

One naive solution to this is to force the denominator to have lead coefficient 1 (in the monomial case: with respect to whatever monomial order is convenient, e.g. the one used for storage / printing).

For rational coefficients, one could get "nicer" results (subjectively, at least) by changing numerator and denominator into products of a primitive integral polynomials times a coefficient; then one can cancel those coefficients. Alas, I don't quite see how to generalize that to arbitrary coefficients, so it might be better to go with the simpler approach above.

hulpke commented 5 years ago

@fingolfin It is intended insofar as rational functions were assumed to not require a PID that would allow for cancellation of common factors, thus no coefficient cancellation is attempted. This even has effects such as -x/(-x-1);. Presumably the way to clear this up would be to allow for optional cancellation, depending on the coefficient ring.