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
811 stars 161 forks source link

Make CoefficientsRing(Ring(f)) work for polynomials f #3159

Open dimpase opened 5 years ago

dimpase commented 5 years ago

Observed behaviour

gap> r:=PolynomialRing(GF(17)); 
GF(17)[x_1]
gap> x:=IndeterminatesOfPolynomialRing(r)[1];
x_1
gap> x^2 in r;  # sanity check
true
gap> Ring(x^2); # sanity check
<ring with 1 generators>
gap> CoefficientsRing(Ring(x^2));
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `CoefficientsRing' on 1 arguments at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/methsel2.g:250 called from
<function "HANDLE_METHOD_NOT_FOUND">( <arguments> )
 called from read-eval loop at *stdin*:20
type 'quit;' to quit to outer loop
...
gap> Ring(x^2)=r;  # this hangs in a infinite loop...
^CError, user interrupt in
  ac := CoefficientsOfLaurentPolynomial( a )
 ; at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/ratfunul.gi:814 called from 
new 
in set at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/ring.gi:638 called from
Enumerator( C 
 ) at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/coll.gi:192 called from
Size( C 
 ) at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/coll.gi:153 called from
IsFinite( D1 
 ) at /home/dimpase/Sage/sagetrac-mirror/local/share/gap/lib/domain.gi:67 called from
<function "unknown">( <arguments> )
 called from read-eval loop at *stdin*:9
you can 'return;'

Expected behaviour

The last command should return GF(17), or its subring.

As well, Ring(x^2)=r; should complete, or at least print a warning...

Copy and paste GAP banner (to tell us about your setup)

 ┌───────┐   GAP 4.10.0 of 01-Nov-2018
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-pc-linux-gnu-default64
 Configuration:  gmp 6.0.0, readline
 Loading the library and packages ...
 Packages:   AClib 1.3.1, Alnuth 3.1.0, AtlasRep 1.5.1, AutoDoc 2018.09.20, 
             AutPGrp 1.10, CRISP 1.4.4, Cryst 4.1.18, CrystCat 1.1.8, 
             CTblLib 1.2.2, FactInt 1.6.2, FGA 1.4.0, GAPDoc 1.6.2, IO 4.5.4, 
             IRREDSOL 1.4, LAGUNA 3.9.0, Polenta 1.3.8, Polycyclic 2.14, 
             PrimGrp 3.3.2, RadiRoot 2.8, ResClasses 4.7.1, SmallGrp 1.3, 
             Sophus 1.24, TomLib 1.2.7, TransGrp 2.0.4, utils 0.59
fingolfin commented 5 years ago

The problem is that Ring does not know anything about polynomial rings, so the ring it returns here is just a bland generic ring, which knows nothing about concepts like "coefficients" and so on.

In the end, this is just one of many ways in which it shows that rings in GAP really are more an afterthought, so I don't find it surprising. Of course we could probably fix this particular instance by installing a suitable method for RingByGenerators. But I am pretty sure similar issues will appear in other places.

dimpase commented 5 years ago

Maybe CoefficientsRing should accept a polynomial (Laurent or not) as input? One way or another, there ought to be a sane way to handle this for libgap - that's where the question came from.

fingolfin commented 5 years ago

Note that CoefficientsRing(DefaultRing(x^2)) works just fine here.