Skip to content

Commit 50fb70e

Browse files
authored
Change MolienSeries to not hang on certain invalid inputs (#5919)
When a virtual character that is not an actual character was fed to MolienSeries, that could lead to an infinite loop. The reason in that case was that a quotient of two polynomials was computed that did not produce a polynomial, but rather a rational function. Calling `GcdRepresentation(F, f)` on that as a first step then tried to compute a ring containing both arguments, which ultimately caused the infinite loop. We fix this by passing a parent ring to `GcdRepresentation` which then raises an error in the above situation. The error message of course is not perfect, but note that other invalid inputs already can lead to different errors in other places in the code. Essentially the user is at fault here for passing in garbage. But we make this patch anyway because getting any error is certainly more helpful than an infinite loop.
1 parent 3bf5b4d commit 50fb70e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/ctblmoli.gi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ InstallGlobalFunction( MolienSeries, function( arg )
208208
chi, # character of `tbl', optional third argument
209209
numers, # list of numerators of sum of polynomial quotients
210210
denoms, # list of denominators of sum of polynomial quotients
211+
R,
211212
x, # indeterminate
212213
tblclasses, # class lengths of `tbl'
213214
orders, # representative orders of `tbl'
@@ -279,7 +280,8 @@ InstallGlobalFunction( MolienSeries, function( arg )
279280
# `pol' is an additive polynomial.
280281
numers:= [];
281282
denoms:= [];
282-
x:= Indeterminate( Rationals );
283+
R:= UnivariatePolynomialRing(Rationals);
284+
x:= R.1;
283285
pol:= Zero( x );
284286

285287
tblclasses:= SizesConjugacyClasses( tbl );
@@ -361,7 +363,7 @@ InstallGlobalFunction( MolienSeries, function( arg )
361363
# Split the summand into two summands, with denominators
362364
# the special factor `f' resp. the remaining factors `F'.
363365
f:= ( x ^ special[1] - 1 ) ^ special[2];
364-
repr:= GcdRepresentation( F, f );
366+
repr:= GcdRepresentation( R, F, f );
365367

366368
# Reduce the numerators if possible.
367369
num:= numer * repr[1];
@@ -413,7 +415,7 @@ InstallGlobalFunction( MolienSeries, function( arg )
413415
# $\prod_{j>i} f_j$ is stored in `F', and $f_i$ is in `f'.
414416

415417
# at first position $r_i$, at second position $q_i$
416-
repr:= GcdRepresentation( F, f );
418+
repr:= GcdRepresentation( R, F, f );
417419

418420
# The numerator $p_i$.
419421
p:= q * repr[1];

tst/testinstall/ctblmoli.tst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,16 @@ true
5353
gap> ser = ser2;
5454
true
5555

56+
#
57+
# MolienSeries used to hang when given an non-character as input
58+
# now an error is raised
59+
#
60+
gap> G:=Group((1,2,3,4,5,6,7),(5,6,7));;
61+
gap> MolienSeries(NaturalCharacter(G));
62+
( 1-z^3+z^6-z^9+z^12-z^15+z^18 ) / ( (1-z^7)*(1-z^5)*(1-z^4)*(1-z^3)^2*(1-z^2)\
63+
*(1-z) )
64+
gap> MolienSeries(-NaturalCharacter(G));
65+
Error, <ns> must be a subset of <R>
66+
5667
#
5768
gap> STOP_TEST("ctblmoli.tst");

0 commit comments

Comments
 (0)