Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve conversion of GAP objects into sage objects. #7890

Open
sagetrac-jlopez mannequin opened this issue Jan 10, 2010 · 12 comments
Open

Improve conversion of GAP objects into sage objects. #7890

sagetrac-jlopez mannequin opened this issue Jan 10, 2010 · 12 comments

Comments

@sagetrac-jlopez
Copy link
Mannequin

sagetrac-jlopez mannequin commented Jan 10, 2010

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

Component: interfaces

Author: Javier López Peña

Issue created by migration from https://trac.sagemath.org/ticket/7890

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 10, 2010

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.

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 10, 2010

comment:1

Attachment: 13590.patch.gz

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 10, 2010

Author: Javier López Peña

@sagetrac-jlopez sagetrac-jlopez mannequin changed the title [new] Improve conversion of GAP objects into sage objects. Improve conversion of GAP objects into sage objects. Jan 10, 2010
@sagetrac-jlopez sagetrac-jlopez mannequin added the s: needs work label Jan 10, 2010
@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 12, 2010

Conversion for finite and cyclotomic fields and their elements.

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 12, 2010

comment:2

Attachment: 13591.patch.gz

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

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 12, 2010

Simplification of one of the previous functions

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jan 12, 2010

Attachment: 13592.patch.gz

Further simplifications and merging. Apply only this patch.

@wdjoyner
Copy link

comment:3

Attachment: gap_to_sage.patch.gz

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"

@williamstein
Copy link
Contributor

comment:4

Hi Javier,

What are your intentions regarding #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

@sagetrac-jlopez
Copy link
Mannequin Author

sagetrac-jlopez mannequin commented Jun 15, 2012

comment:5

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.

@videlec
Copy link
Contributor

videlec commented Apr 9, 2015

comment:6

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

@videlec
Copy link
Contributor

videlec commented Apr 11, 2015

comment:7

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants