Opened 12 years ago

Last modified 7 years ago

#7890 needs_work defect

[with patch, needs work] Improve conversion of GAP objects into sage objects.

Reported by: jlopez Owned by: was
Priority: major Milestone:
Component: interfaces Keywords:
Cc: Merged in:
Authors: Javier López Peña Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

As of now, certain kinds of sage objects can be converted into GAP objects, but the resulting GAP objects cannot be converted back to sage objects.

Examples of this are matrices over finite fields:

sage: g = matrix(GF(5),2,[1,2, -1, 1])
sage: gg = g._gap_()
sage: gg.sage()
---------------------------------------------------------------------------
NotImplementedError
sage: a = gap('E(9)')
sage: a
-E(9)^4-E(9)^7
sage: a.sage()
---------------------------------------------------------------------------
NotImplementedError  

Being able to translate gap field elements into sage ones would help accesing GAP character tables, and a good conversion of matrices would allow many methods to be available for matrix groups.

See this thread at sage devel for more details: http://groups.google.com/group/sage-devel/browse_thread/thread/a04006e5da578bd

Attachments (4)

13590.patch (3.0 KB) - added by jlopez 12 years ago.
Added a _sage_ method in GapElement? class (gap.py) that tries to convert matrices into sage matrices. This only work if the coefficient ring can be converted into a sage ring. Also, modified _matrix_ in the same class so that it tries to find a ring if none is given.
13591.patch (6.6 KB) - added by jlopez 12 years ago.
Conversion for finite and cyclotomic fields and their elements.
13592.patch (2.4 KB) - added by jlopez 12 years ago.
Simplification of one of the previous functions
gap_to_sage.patch (13.4 KB) - added by jlopez 12 years ago.
Further simplifications and merging. Apply only this patch.

Download all attachments as: .zip

Change History (11)

Changed 12 years ago by jlopez

Added a _sage_ method in GapElement? class (gap.py) that tries to convert matrices into sage matrices. This only work if the coefficient ring can be converted into a sage ring. Also, modified _matrix_ in the same class so that it tries to find a ring if none is given.

comment:1 Changed 12 years ago by jlopez

  • Authors set to Javier López Peña
  • Status changed from new to needs_work
  • Summary changed from [new] Improve conversion of GAP objects into sage objects. to [with patch, needs work] Improve conversion of GAP objects into sage objects.

Changed 12 years ago by jlopez

Conversion for finite and cyclotomic fields and their elements.

comment:2 Changed 12 years ago by jlopez

  • Status changed from needs_work to needs_review

The patches should be applied in order. This provides conversion of finite fields, cyclotomic fields and their elements, as well as gap matrices.

Changed 12 years ago by jlopez

Simplification of one of the previous functions

Changed 12 years ago by jlopez

Further simplifications and merging. Apply only this patch.

comment:3 Changed 12 years ago by wdj

  • Status changed from needs_review to needs_work

Last patch applied fine to sage-4.3.a0 on a 64bit ubuntu machine, but the following tests failed:

The following tests failed:


        sage -t  "devel/sage/sage/groups/perm_gps/permgroup.py"
        sage -t  "devel/sage/sage/structure/parent.pyx"
        sage -t  "devel/sage/sage/structure/parent_old.pyx"
        sage -t  "devel/sage/sage/misc/sagedoc.py"
        sage -t  "devel/sage/sage/misc/sage_eval.py"

comment:4 Changed 10 years ago by was

Hi Javier,

What are your intentions regarding http://trac.sagemath.org/sage_trac/ticket/7890 It seems to have got dropped over two years ago. Now none of the patches apply to recent versions of Sage. I wonder if you're planning to clean this up and finish it?

-- William

comment:5 Changed 9 years ago by jlopez

Hi William,

yeah, sorry about that. I changed jobs in 2010 and my whole work plan went south. I would like to get this thing working eventually, but I don't believe the approach I was trying is a good one. The lack of types in GAP creates some ambiguity in gap elements that can have different parents and where a choice needs to be made.

Probably a better approach would be to provide an optional argument sage_parent to the _sage_ function in GapElement?, and then put the heavy lift into the sage parent where an ad-hoc gap-to-sage function can be defined, something like this:

def _sage_(self, sage_parent = None):
    if sage_parent is not None:
        return sage_parent._call_from_gap(self)
    else:
        .... # The function as it used to work

In this way, anyone creating a sage structure could implement their own "take an element from gap here" function rather than mess up with the interface. How does that sound?

In any case it might make sense to wait a little bit and get GAP 4.5 working first, as it seems the representation of some objects has changed.

Last edited 9 years ago by jlopez (previous) (diff)

comment:6 Changed 7 years ago by vdelecroix

Hello,

With #18152, it works fine for cyclotomic elements (because I introduced a function E in the global namespace)

sage: a = gap('E(9)')
sage: a.sage()
-E(9)^4 - E(9)^7

Vincent

Last edited 7 years ago by vdelecroix (previous) (diff)

comment:7 Changed 7 years ago by vdelecroix

Note that with the new libgap the conversion works almost fine for matrices (it is converted into a list of lists instead of a matrix)

sage: m = matrix(GF(5), 2, [1,2,-1,1])
sage: a = m._libgap_().sage()
sage: a
[[1, 2], [4, 1]]
sage: matrix(a) == m
True
Note: See TracTickets for help on using tickets.