Skip to content

Commit

Permalink
FIX: Scaling of gcd of polynomials to be standard
Browse files Browse the repository at this point in the history
This fixes #3212
  • Loading branch information
hulpke authored and fingolfin committed Jan 24, 2019
1 parent 0d25d1f commit 5963695
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 7 additions & 3 deletions hpcgap/lib/polyrat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,17 @@ local brci,gcd,fam,fc,gc;
if gcd=fail then
# fall back to the original version:
gcd:=RPIGcd(f,g);
if Length(gcd)>0 and not IsOne(gcd[1]) then gcd:=gcd/gcd[1];fi;
if Length(gcd)>0 and not IsOne(gcd[Length(gcd)]) then
gcd:=gcd/gcd[Length(gcd)];
fi;
return gcd;

fi;
fc:=Minimum(fc[2],gc[2]);
fc:=fc+RemoveOuterCoeffs(gcd,fam!.zeroCoefficient);
if Length(gcd)>0 and not IsOne(gcd[1]) then gcd:=gcd/gcd[1];fi;
if Length(gcd)>0 and not IsOne(gcd[Length(gcd)]) then
gcd:=gcd/gcd[Length(gcd)];
fi;
return LaurentPolynomialByExtRepNC(fam,gcd,fc,brci);
end);

Expand Down Expand Up @@ -1859,7 +1863,7 @@ local fc,ind, v, g, q, s, r, x,shift;
Append(s,List([1..v],f->x));
Sort(s);

if not IsBound(opt.stopdegs) and Sum(s,DegreeOfLaurentPolynomial)<>DegreeOfLaurentPolynomial(f)+v then
if not (IsBound(opt.stopdegs) or IsBound(opt.onlydegs)) and Sum(s,DegreeOfLaurentPolynomial)<>DegreeOfLaurentPolynomial(f)+v then
Error("degree discrepancy!");
fi;

Expand Down
8 changes: 6 additions & 2 deletions lib/polyrat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,17 @@ local brci,gcd,fam,fc,gc;
if gcd=fail then
# fall back to the original version:
gcd:=RPIGcd(f,g);
if Length(gcd)>0 and not IsOne(gcd[1]) then gcd:=gcd/gcd[1];fi;
if Length(gcd)>0 and not IsOne(gcd[Length(gcd)]) then
gcd:=gcd/gcd[Length(gcd)];
fi;
return gcd;

fi;
fc:=Minimum(fc[2],gc[2]);
fc:=fc+RemoveOuterCoeffs(gcd,fam!.zeroCoefficient);
if Length(gcd)>0 and not IsOne(gcd[1]) then gcd:=gcd/gcd[1];fi;
if Length(gcd)>0 and not IsOne(gcd[Length(gcd)]) then
gcd:=gcd/gcd[Length(gcd)];
fi;
return LaurentPolynomialByExtRepNC(fam,gcd,fc,brci);
end);

Expand Down
4 changes: 4 additions & 0 deletions tst/testinstall/ratfun.tst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ gap> (t^24-1)/(t^16-1);
gap> (t^24-1)/(t^-16-1);
(t^32+t^24+t^16)/(-t^8-1)

#
gap> Gcd(t-2,t^2-2*t);
t-2

#
# multivariate
#
Expand Down

0 comments on commit 5963695

Please sign in to comment.