Re: [sage-devel] Re: Implementation of conjugacy classes

2010-01-31 Thread Nicolas M. Thiery
Dear Javier,

On Sat, Jan 09, 2010 at 02:01:07PM -0800, javier wrote:
 The implementation of the conjugacy classes is now ticket #7886:
 http://sagetrac.org/sage_trac/ticket/7886

I went through your patch, and am definitely +1 on the overall design
and user interface! Here are some suggestions for categorifying the
internals:

Split the ConjugacyClass into two classes (in the same module as before):

class ConjucacyClass(Parent):
# A parent, in the FiniteEnumeratedSets() category
# (see FiniteEnumeratedSets().example())
# Generic implementation with naive algorithm(s)

class ConjugacyClassGap(ConjugacyClass):
# Specializes the relevant methods of the above by calling GAP

In sage.categories.finite_groups.FiniteGroups, put in ParentMethods
the conjugacy class method for groups:

def conjugacy_class(self, g)
return ConjugacyClass(self, g)

and in ElementMethods the conjugacy class method for group elements:

def conjugacy_class(self):
return self.parent().conjugacy_class(self)

And finally, in those Sage groups which are implemented as GAP groups
(that is matrix and permutation groups), and only for those, override
the default method by:

def conjugacy_class(self, g)
return ConjugacyClassGAP(self, g)

Being in FiniteEnumeratedSets will give you for free some default
methods (like ``cardinality`` implemented by default in terms of
``list``), as well as sanity checks between
list/iter/cardinality/... when calling ``TestSuite(c).run()``.

It will be easy to later extend this to infinite groups when there
will be a concrete need/implementation.

By the way, a related feature which could afford a similar design, and
that would be useful in the short run for my PhD student would be:

sage: G = PermutationGroup(...)
sage: for C in G.conjugacy_classes():
...   ... C.cardinality() ... C.representative() ...

I'd be happy to review it (and the above), should you feel like
working on it :-)

Cheers,
Nicolas
--
Nicolas M. Thiéry Isil nthi...@users.sf.net
http://Nicolas.Thiery.name/

-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-11 Thread Jason Grout

Simon King wrote:

Hi Dima!

On 10 Jan., 13:47, Dima Pasechnik dimp...@gmail.com wrote:

On Jan 10, 7:04 pm, javier vengor...@gmail.com wrote:
well, there no static type matrices in GAP (well, unless you work
with, say, matrix Lie algebras, and have multiplication overloaded).
They are just lists of lists of right sizes, with entries in a common
ring.

I am surprised to hear that Sage is less flexible here


And I am surpised to hear that GAP has no proper matrices. Certainly a
matrix is MUCH more than a list of lists. For example, in order to
have a mathematical meaning, the marks of a matrix have to belong to
the same ring.


(ok ,there
could be, say, special matrices, say, dense numeric
and bit matrices, that deserve a special treatment, but otherwise this
seems strange...)


You seriously think that matrix multiplication, determinant, echelon
form etc. should be done with lists of lists? I doubt that this can be
any good. I acknowledge that GAP's main purpose is groups and not
linear algebra. But providing fast linear algebra is certainly an
objective of Sage.

What does all that mean for the sage() method of the GAP interface?

Do I understand correctly that IsMatrix just states that the object is
a list of lists of the same size?

Then, perhaps sage() could have an optional argument. For example, if
the user reckons that some GAP object L is formed by matrices (e.g.,
it is a list of lists of lists of the same size), then L.sage
(AsMatrix=True) would return a list of sage matrices, whereas L.sage()
would return a list of lists of lists.

But then, it would be challenging to make sage(AsMatrix=True) work for
a matrix of matrices...




Two comments.  First of all, we can deal with matrices of matrices, 
though it isn't as natural as I had hoped.  Here's the first thing that 
I tried:


sage: mm=matrix(MatrixSpace(ZZ,2),2)
sage: mm[0]
---
AttributeErrorTraceback (most recent call last)

/home/grout/.sage/temp/tiny/2005/_home_grout__sage_init_sage_0.py in 
module()


/home/grout/sage/local/lib/python2.6/site-packages/sage/matrix/matrix0.so 
in sage.matrix.matrix0.Matrix.__getitem__ (sage/matrix/matrix0.c:5314)()


/home/grout/sage/local/lib/python2.6/site-packages/sage/matrix/matrix1.so 
in sage.matrix.matrix1.Matrix.row (sage/matrix/matrix1.c:7428)()


/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/factory.so 
in sage.structure.factory.UniqueFactory.__call__ 
(sage/structure/factory.c:919)()


/home/grout/sage/local/lib/python2.6/site-packages/sage/structure/factory.so 
in sage.structure.factory.UniqueFactory.get_object 
(sage/structure/factory.c:1125)()


/home/grout/sage/local/lib/python2.6/site-packages/sage/modules/free_module.pyc 
in create_object(self, version, key)
343 raise TypeError, Argument sparse (= %s) must be 
True or False % sparse

344
-- 345 if not base_ring.is_commutative():
346 raise TypeError, The base_ring must be a 
commutative ring.

347

AttributeError: 'MatrixSpace_generic' object has no attribute 
'is_commutative'



Since we can create a matrix of matrices appropriately, maybe we can fix 
up a few things to make it make sense?


But there's also another way to get the dynamically typed matrices 
through the generality of the symbolic ring.  Here, I create a symbolic 
matrix.  Since symbolic objects wrap any other objects, I set the first 
element of the matrix to a 2x2 identity matrix, and another element to a 
real number.  Printing is a little messed up, but you can see it's doing 
the right thing here.


sage: mmsr=matrix(SR,2)
sage: mmsr[0,0]=SR(matrix(ZZ,2,2,1))
sage: mmsr
[[1 0]
[0 1]   0]
[  0   0]
sage: mmsr[0,0]
[1 0]
[0 1]
sage: mmsr[0,1]=RR(e)
sage: mmsr
[ [1 0]
[0 1] 2.71828182845905]
[   00]
sage: mmsr[0,0]
[1 0]
[0 1]
sage: mmsr[0,1]
2.71828182845905

Thanks,

Jason

-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread javier
This is now Ticket #7890:
http://trac.sagemath.org/sage_trac/ticket/7890

Thanks for volunteering to work on this, Dmitri! It would be awesome
to be able to access all that gap functions from sage.
Skimming a bit at the conversion code, it looks like the function
sage is called on the gap string representing the gap object. A big
part of the problem seems to be deciding what to do with that string
(i.e. to what type of sage object is it converted). For instance if
you create a gap matrix (with integral coefficients) it gets converted
back into a list of lists and not into a sage matrix:

sage: A = gap([[1,2],[2,3]])
sage: A.IsMatrix()
true
sage: B = A.sage()
sage: B
[[1, 2], [2, 3]]
sage: type(B)
type 'list'

Maybe the best place to start is to look at any objects that can be
successfully converted back and forth and see what is going on there.

Cheers
J

On Jan 10, 7:43 am, Alex Ghitza aghi...@gmail.com wrote:
 On Sat, 9 Jan 2010 21:35:31 -0800 (PST), Dima Pasechnik dimp...@gmail.com 
 wrote:

  from what I gather, it asks first of all for a consistent way to
  handle GAP's field elements. A field can be finite, as here in this
  thread, or, say, cyclotomic, as it would happen, e.g., when dealing
  with character tables (or representations of finite groups over C).
  And there seems to be no functionality whatsoever for this in Sage. Am
  I correct?

 What is this in your sentence?  Finite fields?  Cyclotomic fields?
 Both of these are definitely in Sage, have a look at

 sage: FiniteField?

 sage: CyclotomicField?

  Actually, I particularly badly need a way to convert GAP's cyclotomics
  into Sage's data, so I might like to pick this up, although this would
  be my very 1st Sage coding project, and I would need a lot of pointers
  of how to start...

 You can start by having a look at interfaces/gap.py in the Sage library,
 for instance at the GapElement class.  You would want something like
 this to work:

 sage: a = gap('E(9)')
 sage: a.sage()

 At the moment, that raises a NotImplementedError.

 You also want to look at the CyclotomicField class in
 rings/number_field/number_field.py, more particularly at its __call__()
 method which converts various things into elements of a cyclotomic
 field.

 I don't have time to give more details now, but it should help you to
 start.  Let us know how it's going!

 Best,
 Alex

 --
 Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne
 -- Australia --http://www.ms.unimelb.edu.au/~aghitza/
-- 
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


Re: [sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread David Joyner
On Sun, Jan 10, 2010 at 6:04 AM, javier vengor...@gmail.com wrote:
 This is now Ticket #7890:
 http://trac.sagemath.org/sage_trac/ticket/7890

 Thanks for volunteering to work on this, Dmitri! It would be awesome
 to be able to access all that gap functions from sage.
 Skimming a bit at the conversion code, it looks like the function
 sage is called on the gap string representing the gap object. A big
 part of the problem seems to be deciding what to do with that string
 (i.e. to what type of sage object is it converted). For instance if
 you create a gap matrix (with integral coefficients) it gets converted
 back into a list of lists and not into a sage matrix:

 sage: A = gap([[1,2],[2,3]])
 sage: A.IsMatrix()
 true
 sage: B = A.sage()
 sage: B
 [[1, 2], [2, 3]]
 sage: type(B)
 type 'list'

 Maybe the best place to start is to look at any objects that can be
 successfully converted back and forth and see what is going on there.


Some conversions of gap matrices into sage matrices over a finite field
is done in coding/guava.py. Another place to look is in
interfaces/gap.py.




 Cheers
 J

 On Jan 10, 7:43 am, Alex Ghitza aghi...@gmail.com wrote:
 On Sat, 9 Jan 2010 21:35:31 -0800 (PST), Dima Pasechnik dimp...@gmail.com 
 wrote:

  from what I gather, it asks first of all for a consistent way to
  handle GAP's field elements. A field can be finite, as here in this
  thread, or, say, cyclotomic, as it would happen, e.g., when dealing
  with character tables (or representations of finite groups over C).
  And there seems to be no functionality whatsoever for this in Sage. Am
  I correct?

 What is this in your sentence?  Finite fields?  Cyclotomic fields?
 Both of these are definitely in Sage, have a look at

 sage: FiniteField?

 sage: CyclotomicField?

  Actually, I particularly badly need a way to convert GAP's cyclotomics
  into Sage's data, so I might like to pick this up, although this would
  be my very 1st Sage coding project, and I would need a lot of pointers
  of how to start...

 You can start by having a look at interfaces/gap.py in the Sage library,
 for instance at the GapElement class.  You would want something like
 this to work:

 sage: a = gap('E(9)')
 sage: a.sage()

 At the moment, that raises a NotImplementedError.

 You also want to look at the CyclotomicField class in
 rings/number_field/number_field.py, more particularly at its __call__()
 method which converts various things into elements of a cyclotomic
 field.

 I don't have time to give more details now, but it should help you to
 start.  Let us know how it's going!

 Best,
 Alex

 --
 Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne
 -- Australia --http://www.ms.unimelb.edu.au/~aghitza/

 --
 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


-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Dima Pasechnik

On Jan 10, 7:04 pm, javier vengor...@gmail.com wrote:
[...]
 For instance if
 you create a gap matrix (with integral coefficients)
well, there no static type matrices in GAP (well, unless you work
with, say, matrix Lie algebras, and have multiplication overloaded).
They are just lists of lists of right sizes, with entries in a common
ring.

I am surprised to hear that Sage is less flexible here (ok ,there
could be, say, special matrices, say, dense numeric
and bit matrices, that deserve a special treatment, but otherwise this
seems strange...)

 it gets converted
 back into a list of lists and not into a sage matrix:

 sage: A = gap([[1,2],[2,3]])
 sage: A.IsMatrix()
 true
 sage: B = A.sage()
 sage: B
 [[1, 2], [2, 3]]
 sage: type(B)
 type 'list'

so I'd rather see Sage becoming more GAP-like in this sense,
although I realise this may not happen soon or ever...

Dmitrii
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Simon King
Hi Dima!

On 10 Jan., 13:47, Dima Pasechnik dimp...@gmail.com wrote:
 On Jan 10, 7:04 pm, javier vengor...@gmail.com wrote:
 well, there no static type matrices in GAP (well, unless you work
 with, say, matrix Lie algebras, and have multiplication overloaded).
 They are just lists of lists of right sizes, with entries in a common
 ring.

 I am surprised to hear that Sage is less flexible here

And I am surpised to hear that GAP has no proper matrices. Certainly a
matrix is MUCH more than a list of lists. For example, in order to
have a mathematical meaning, the marks of a matrix have to belong to
the same ring.

 (ok ,there
 could be, say, special matrices, say, dense numeric
 and bit matrices, that deserve a special treatment, but otherwise this
 seems strange...)

You seriously think that matrix multiplication, determinant, echelon
form etc. should be done with lists of lists? I doubt that this can be
any good. I acknowledge that GAP's main purpose is groups and not
linear algebra. But providing fast linear algebra is certainly an
objective of Sage.

What does all that mean for the sage() method of the GAP interface?

Do I understand correctly that IsMatrix just states that the object is
a list of lists of the same size?

Then, perhaps sage() could have an optional argument. For example, if
the user reckons that some GAP object L is formed by matrices (e.g.,
it is a list of lists of lists of the same size), then L.sage
(AsMatrix=True) would return a list of sage matrices, whereas L.sage()
would return a list of lists of lists.

But then, it would be challenging to make sage(AsMatrix=True) work for
a matrix of matrices...

Cheers,
Simon
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread javier
Hi Simon,

On Jan 10, 11:33 am, Simon King simon.k...@nuigalway.ie wrote:
 Well, that's a default method, i.e., if nothing else is implemented
 than a conversion by strings is attempted, because there is some hope
 that the result makes sense.

 So, a proper way would be to override the default sage() method (from
 pexpect, or where is it defined?) for the gap interface.

I think the method called is in interfaces/expect.pyc but I am not
sure about that.

 This new method would test the type of gap data (matrix; permutation
 group element; conjugacy class, ...) and do whatever needs to be done
 (return a sage matrix; return a permutation; return an instance of the
 new conjugacy class class, ...). Only if an unknown data type
 occurs, a string conversion would be attempted, as a last  resort. If
 it fails, then nothing can be done.

The problem, as I see it, is that AFAIK gap has no type checking to
tell what kind of object we are dealing with (if there really is such
a method, I'd love to be corrected!).

 I don't know how to properly test the data type in gap. Would one use
 functions like IsPermGroup, IsMatrix?

 So, if IsMatrix is true for a gap object M, then the next step is to
 determine the underlying ring (dunno how). If R is that ring, then
 M.sage() would return a matrix over R.sage().

For the particular case of matrices that might actually work. Since
gap's IsMatrix ensures that all the entries belong to a common ring
(beyond checking the lists have the right size) we only need to check
the base ring of one of the elements, for instance the [1,1], which is
always going to be there:

sage: h = matrix(GF(5),2,[1,2, -1, 1])
sage: hh = h._gap_()
sage: hh.IsMatrix()
true
sage: hh[1,1].Ring()
GF(5)

So, lacking a better choice we could just make a list of distinguished
objects in which to apply ad-hoc conversion methods.

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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Dima Pasechnik
Hi Simon,
On Jan 10, 9:32 pm, Simon King simon.k...@nuigalway.ie wrote:
 Hi Dima!

 On 10 Jan., 13:47, Dima Pasechnik dimp...@gmail.com wrote:

  On Jan 10, 7:04 pm, javier vengor...@gmail.com wrote:
  well, there no static type matrices in GAP (well, unless you work
  with, say, matrix Lie algebras, and have multiplication overloaded).
  They are just lists of lists of right sizes, with entries in a common
  ring.

  I am surprised to hear that Sage is less flexible here

 And I am surpised to hear that GAP has no proper matrices. Certainly a
 matrix is MUCH more than a list of lists. For example, in order to
 have a mathematical meaning, the marks of a matrix have to belong to
 the same ring.
Actually, I mentioned that entries must be in a common ring for
IsMatrix to return true.


  (ok ,there
  could be, say, special matrices, say, dense numeric
  and bit matrices, that deserve a special treatment, but otherwise this
  seems strange...)

 You seriously think that matrix multiplication, determinant, echelon
 form etc. should be done with lists of lists?
No, I don't mean these *should* be, but
there is only a very small and tolerable loss in efficiency when the
matrix entries lie in
a ring with expensive arithmetic, e.g. cyclotomics, or a large finite
field of non-prime order,
or huge integers.
GAP has a special type of matrices with entries in a small finite
field, on which it operates
quite fast. (One can convert to these fast matrices explicitly (or
even implicitly?) when possible)

The advantage for a semi-interactive system is obvious - one does not
need to worry about the
particular matrix ring (if we talk about square matrices) when playing
with the data!
(I still recall how much grief an overtly typed system can give you,
from experience with CAYLEY in 1993 :-))

Actually, a similar point of view is taken when one works with
permutations - they need not be
confined to a  fixed permutation group.

I somehow expected Sage to follow the GAP's suit here --- have slower
dynamically typed
matrices for all rings, and faster ones for specific fast rings  and
approximate rings, i.e. floating
point numbers.

And don't get me started on sparse matrices here. :-)

 I doubt that this can be
 any good. I acknowledge that GAP's main purpose is groups and not
 linear algebra. But providing fast linear algebra is certainly an
 objective of Sage.

 What does all that mean for the sage() method of the GAP interface?

 Do I understand correctly that IsMatrix just states that the object is
 a list of lists of the same size?
no, a bit more --- see above.


 Then, perhaps sage() could have an optional argument. For example, if
 the user reckons that some GAP object L is formed by matrices (e.g.,
 it is a list of lists of lists of the same size), then L.sage
 (AsMatrix=True) would return a list of sage matrices, whereas L.sage()
 would return a list of lists of lists.

 But then, it would be challenging to make sage(AsMatrix=True) work for
 a matrix of matrices...
From GAP's point of view, these are not matrices.
Actually, GAP is kinda weak on block matrices...

Dima

 Cheers,
 Simon
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread javier
Hi all,

have been hacking around a bit and finally got to this:

the class GapElement doesn't have a _sage_ method, when sage() is
called, it defers to the ExpectElement method, which is not  aware of
the fact that we have a GAP object to start with. OTOH, I observed
there is a _matrix_ method that creates sage matrices when the ring is
provided and decided to build up from there.

So, I included a _sage_ method in the GapElement class in gap.py,
going like this:

def _sage_(self):

Override of ExpectElement._sage_ method. Aiming for a better
conversion. Initially just for matrices!

if self.IsMatrix():
ring = self[1,1].Ring().sage()
return self._matrix_(ring)
else:# If we don't know how to deal with this, return to
the default.
return ExpectElement._sage_(self)

after applying the patch one can do as follows:

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


So, it wasn't that hard (for matrices) after all. I don't know whether/
how this can be applied to the E(9) thing unless there is an
IsSomething gap method that can be used for them.

I'll prepare some doctests and upload a first patch.

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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Simon King
Hi Javier!

On 10 Jan., 15:26, javier vengor...@gmail.com wrote:
 def _sage_(self):
         
         Override of ExpectElement._sage_ method. Aiming for a better
 conversion. Initially just for matrices!
         
         if self.IsMatrix():
             ring = self[1,1].Ring().sage()
             return self._matrix_(ring)
         else:    # If we don't know how to deal with this, return to
 the default.
             return ExpectElement._sage_(self)

Yep, this is what I meant.

Perhaps, for providing an additional layer of safety, one, might put
the if part in a try-except clause, such as

try:
if self.IsMatrix():
ring = self[1,1].Ring().sage()
return self._matrix_(ring)
except ...: # insert the expected kind of error to be catched
here
pass
# If we don't know how to deal with this, return to the
default.
return ExpectElement._sage_(self)

Cheers,
Simon
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Dima Pasechnik
Javier,

[...]

 So, it wasn't that hard (for matrices) after all.
Good!
 I don't know whether/
 how this can be applied to the E(9) thing unless there is an
 IsSomething gap method that can be used for them.
Sure, there is
IsCyclotomic
and IsIntegralCyclotomic
for cyclotomics, resp., cyclotomic integers:

gap IsIntegralCyclotomic(E(9));
true
gap Field(E(9));
CF(9)


and

IsFFE for finite field elements:

gap IsFFE(Z(5));
true
gap Field(Z(5));
GF(5)

for more general fields and for rings it's also doable...

Cheers,
Dima

 I'll prepare some doctests and upload a first patch.

 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


Re: [sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread John Cremona
This is the way objects from the pari library are converted to Sage.
pari has an (imperfect) system of attributing types to objects, and
the conversion code branches on the value of its pari type, calling
suitable conversion code in each case.

So this seems like a sensible way to go for GAP conversion.

John

2010/1/10 Dima Pasechnik dimp...@gmail.com:
 Javier,

 [...]

 So, it wasn't that hard (for matrices) after all.
 Good!
 I don't know whether/
 how this can be applied to the E(9) thing unless there is an
 IsSomething gap method that can be used for them.
 Sure, there is
 IsCyclotomic
 and IsIntegralCyclotomic
 for cyclotomics, resp., cyclotomic integers:

 gap IsIntegralCyclotomic(E(9));
 true
 gap Field(E(9));
 CF(9)


 and

 IsFFE for finite field elements:

 gap IsFFE(Z(5));
 true
 gap Field(Z(5));
 GF(5)

 for more general fields and for rings it's also doable...

 Cheers,
 Dima

 I'll prepare some doctests and upload a first patch.

 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


-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread javier
Patch submitted at
http://sagetrac.org/sage_trac/ticket/7890

the conversion of matrices only works when the conversion of the gap
ring works. In particular, it fails for cyclotomic fields, cyclotomic
rings, and finite fields of non-prime order. I have also modified the
_matrix_ method so that if no ring is given it tries to pick it up
from the first matrix entry.

To make this patch *really* useful conversion for all the missing
kinds of rings and fields should be implemented. For GF(p^x) the only
thing that needs to be done is to expand the p^x part (gap actually
returns something like GF(2^4) rather than GF(16) into a number
and then call the sage conversion specifying a generator name.

For cyclotomic and other kinds of fields some more work is needed.

Since GAP has two methods (Ring() and Field()) that are relevant here,
it would be great to have a way of deciding which one should be
called.

Any further work along these lines will be most welcome!

Cheers
J

On Jan 10, 2:37 pm, Dima Pasechnik dimp...@gmail.com wrote:
 Javier,

 [...]

  So, it wasn't that hard (for matrices) after all.
 Good!
  I don't know whether/
  how this can be applied to the E(9) thing unless there is an
  IsSomething gap method that can be used for them.

 Sure, there is
 IsCyclotomic
 and IsIntegralCyclotomic
 for cyclotomics, resp., cyclotomic integers:

 gap IsIntegralCyclotomic(E(9));
 true
 gap Field(E(9));
 CF(9)

 and

 IsFFE for finite field elements:

 gap IsFFE(Z(5));
 true
 gap Field(Z(5));
 GF(5)

 for more general fields and for rings it's also doable...

 Cheers,
 Dima



  I'll prepare some doctests and upload a first patch.

  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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Dima Pasechnik
Javier,


 def _sage_(self):
         
         Override of ExpectElement._sage_ method. Aiming for a better
 conversion. Initially just for matrices!
         
         if self.IsMatrix():
             ring = self[1,1].Ring().sage()

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.


             return self._matrix_(ring)
         else:    # If we don't know how to deal with this, return to
 the default.
             return ExpectElement._sage_(self)

[...]

Dima
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-10 Thread Dima Pasechnik


On Jan 11, 12:07 am, javier vengor...@gmail.com wrote:
 Patch submitted athttp://sagetrac.org/sage_trac/ticket/7890

 the conversion of matrices only works when the conversion of the gap
 ring works. In particular, it fails for cyclotomic fields, cyclotomic
 rings, and finite fields of non-prime order. I have also modified the
 _matrix_ method so that if no ring is given it tries to pick it up
 from the first matrix entry.

 To make this patch *really* useful conversion for all the missing
 kinds of rings and fields should be implemented. For GF(p^x) the only
 thing that needs to be done is to expand the p^x part (gap actually
 returns something like GF(2^4) rather than GF(16) into a number
 and then call the sage conversion specifying a generator name.
you can ask GAP to compute the size of the finite field:
gap Size(Field(Z(2^4)));
16
 and use it to set up the Sage field.


 For cyclotomic and other kinds of fields some more work is needed.

 Since GAP has two methods (Ring() and Field()) that are relevant here,
 it would be great to have a way of deciding which one should be
 called.

 Any further work along these lines will be most welcome!

 Cheers
 J

 On Jan 10, 2:37 pm, Dima Pasechnik dimp...@gmail.com wrote:



  Javier,

  [...]

   So, it wasn't that hard (for matrices) after all.
  Good!
   I don't know whether/
   how this can be applied to the E(9) thing unless there is an
   IsSomething gap method that can be used for them.

  Sure, there is
  IsCyclotomic
  and IsIntegralCyclotomic
  for cyclotomics, resp., cyclotomic integers:

  gap IsIntegralCyclotomic(E(9));
  true
  gap Field(E(9));
  CF(9)

  and

  IsFFE for finite field elements:

  gap IsFFE(Z(5));
  true
  gap Field(Z(5));
  GF(5)

  for more general fields and for rings it's also doable...

  Cheers,
  Dima

   I'll prepare some doctests and upload a first patch.

   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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-09 Thread javier
The implementation of the conjugacy classes is now ticket #7886:
http://sagetrac.org/sage_trac/ticket/7886

At the moment all the test pass except the one for _getitem_; since
the elements of the conjugacy class appear in a random order, I don't
know how to make a working test for that function. I went for Set
instead of set because the output looks better. I intend to wrap a few
more functions on that patch, if you have a favorite one you'd like to
see now is the time to tell!

Concerning Dmitri remark above, if there was a way to convert gap
matrices into sage matrices it could be possible to extend
conjugacy_classes_representatives (as well as conjugacy_classes) to
matrix groups. That would also make computation of conjugacy classes
for matrix groups several times faster by avoiding the naive fallback.
Should I open a different ticket for that?

Cheers
J

On Jan 9, 8:03 pm, Minh Nguyen nguyenmi...@gmail.com wrote:
 Hi,

 On Sun, Jan 10, 2010 at 2:06 AM, javier vengor...@gmail.com wrote:
  Sorted it out, I had forgotten to import one file. Sorry for the
  noise. Class patches nicely now; I am just having some test failures
  due to different orderings of some output sets. Is there a standard
  way of implementing tests that involve sets as outputs?

 You should be aware there is no fixed ordering when you output the
 elements of a set. This is especially important when you have the
 string representation of all elements of a set as expected output in a
 doctest. For example, on some platform a set consisting of the
 elements 1, 2, 3 might be output in a different order such as 3, 2, 1.
 If the elements of your set can be sorted in some standard order, it
 might be a good idea to first sort the elements, then have the sorted
 elements be expected output of a doctest. A similar issue applies when
 you have the values of a dictionary as expected output in a doctest.

  In a related matter, in the _set_ method, is it better to return a
  python set or a sage Set?

 I don't know how to answer this question without knowing the (updated)
 code or the context of the code.

 --
 Regards
 Minh Van Nguyen
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-09 Thread Simon King
Hi Javier!

On 9 Jan., 23:01, javier vengor...@gmail.com wrote:
 The implementation of the conjugacy classes is now ticket 
 #7886:http://sagetrac.org/sage_trac/ticket/7886

 At the moment all the test pass except the one for _getitem_; since
 the elements of the conjugacy class appear in a random order, I don't
 know how to make a working test for that function.

Yes, sets and dictionaries are not good for doc tests. AFAIK, the
method of choice is to transforme the output into a sorted list,
  sage: sorted(Set([1,3,2]))
  [1, 2, 3]
  sage: sorted({3:2,1:5}.items())
  [(1, 5), (3, 2)]

Thank you very much for working on it!
Simon
-- 
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


[sage-devel] Re: Implementation of conjugacy classes

2010-01-09 Thread Dima Pasechnik


On Jan 10, 6:01 am, javier vengor...@gmail.com wrote:
[...]
 Concerning Dmitri remark above, if there was a way to convert gap
 matrices into sage matrices it could be possible to extend
 conjugacy_classes_representatives (as well as conjugacy_classes) to
 matrix groups. That would also make computation of conjugacy classes
 for matrix groups several times faster by avoiding the naive fallback.
 Should I open a different ticket for that?

from what I gather, it asks first of all for a consistent way to
handle GAP's field elements. A field can be finite, as here in this
thread, or, say, cyclotomic, as it would happen, e.g., when dealing
with character tables (or representations of finite groups over C).
And there seems to be no functionality whatsoever for this in Sage. Am
I correct?
Actually, I particularly badly need a way to convert GAP's cyclotomics
into Sage's data, so I might like to pick this up, although this would
be my very 1st Sage coding project, and I would need a lot of pointers
of how to start...

[...]

Dmitrii

-- 
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


Re: [sage-devel] Re: Implementation of conjugacy classes

2010-01-09 Thread Alex Ghitza
On Sat, 9 Jan 2010 21:35:31 -0800 (PST), Dima Pasechnik dimp...@gmail.com 
wrote:
 
 from what I gather, it asks first of all for a consistent way to
 handle GAP's field elements. A field can be finite, as here in this
 thread, or, say, cyclotomic, as it would happen, e.g., when dealing
 with character tables (or representations of finite groups over C).
 And there seems to be no functionality whatsoever for this in Sage. Am
 I correct?

What is this in your sentence?  Finite fields?  Cyclotomic fields?
Both of these are definitely in Sage, have a look at

sage: FiniteField?

sage: CyclotomicField?

 Actually, I particularly badly need a way to convert GAP's cyclotomics
 into Sage's data, so I might like to pick this up, although this would
 be my very 1st Sage coding project, and I would need a lot of pointers
 of how to start...
 

You can start by having a look at interfaces/gap.py in the Sage library,
for instance at the GapElement class.  You would want something like
this to work:

sage: a = gap('E(9)')
sage: a.sage()

At the moment, that raises a NotImplementedError.

You also want to look at the CyclotomicField class in
rings/number_field/number_field.py, more particularly at its __call__()
method which converts various things into elements of a cyclotomic
field.

I don't have time to give more details now, but it should help you to
start.  Let us know how it's going!


Best,
Alex



-- 
Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne
-- Australia -- http://www.ms.unimelb.edu.au/~aghitza/
-- 
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