Hi Dmitri, On Jan 10, 5:48 pm, Dima Pasechnik <dimp...@gmail.com> wrote: > This is not good enough. It could be that the [1,1]-element lies in a > proper subring. > One should either test each matrix entry and take the biggest ring, or > ask GAP to do it for you. > Say, if A is a GAP matrix you can do > gap> Field(Flat(A)); > to get the smallest field containing all the entries of A.
Ouch. That is easily doable, but will slow down quite a bit my conjugacy classes code. Oh well, better get it slow now and look for a way of passing a global ring around later on... Anyway I think it's better to use Ring() rather than Field() since the former can always be coerced into the latter. As of now, this is what I have (including methods for finite and cyclotomic fields). I don´t like all these nested if's so any alternative proposal will be welcome... def _sage_(self): r""" Override of ExpectElement._sage_ method. Aiming for a better conversion. Initially just for matrices! EXAMPLES: - Conversion of gap matrices into sage matrices, back and forth :: sage: h = matrix(GF(5),2,[1,2, -1, 1]) sage: hh = gap(h) sage: hh.sage() [1 2] [4 1] sage: hh.sage() == h True - Conversion of finite fields into the corresponding sage fields :: sage: R = gap("GF(16)") sage: R.sage() Finite Field in x16 of size 2^4 - Conversion of cyclotomic fields :: sage: K = gap("CF(9)") sage: K.sage() Cyclotomic Field of order 9 and degree 6 """ try: if self.IsMatrix(): # Conversion of matrices return self._matrix_() if self.IsRing(): # Conversion of rings if self.IsField(): # Fields if self.IsFinite(): # Finite fields from sage.rings.finite_field import GF size = self.Size() var = 'x'+str(size) return GF(size, var) # What is the right thing to use as generator name?? if self.IsCyclotomicField(): # Cyclotomic fields # Don't know if there is a gap way of getting the number n for CF(n), so use the defining string "CF(n)" instead. # The following strips the first three characters, that should be "C", "F", "(" and the last ")". from sage.rings.number_field.number_field import CyclotomicField n = int(str(self)[3:-1]) return CyclotomicField(n) except NotImplementedError: pass return ExpectElement._sage_(self) Is there a canonical or preferred way of calling the generator of GF (q)? I went for "xq" (where q is a prime power) but that can easily been changed. The code for determining the ring has been replaced by R = self.Flat().Ring().sage() and moved to the _matrix_ method in the same class. Cheers J
-- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org