The gap interface overwrites my variables

7 views
Skip to first unread message

Simon King

unread,
Mar 1, 2008, 5:13:10 PM3/1/08
to sage-support
Dear team,

at the moment i try to implement methods such that, if F is a number
field, gap(F) is the corresponding thing in the interface, and
similarly for matrices over F. While some parts work, i have a problem
with variable names in the interface.

My approach is as follows:
- One needs a _gap_init_ method for F. It should return a string that
provides a definition of a gap-version of F.
- As much as i know, creating an algebraic extension of the rationals
in gap requires several lines; hence it is hardly possible that
_gap_init_ returns a string that defines the gap-version of F from
scratch.
- I think a solution is: If F._gap_init_ is called for the first time,
it creates some object in the gap interface; and at each call,
F._gap_init_ returns the name of that object.

First, do you think the approach makes sense?

Now, some things work well:

sage: F=CyclotomicField(8)
sage: f=gap(F)
sage: f.name()
'$sage5'
sage: gap('$sage4')
<algebraic extension over the Rationals of degree 4>

Remark: $sage4 is the name under which the gap version of F was
constructed by F._gap_init_().

sage: z=F.gen()
sage: a=z+1/z
sage: MS=MatrixSpace(F,2,2)
sage: g1=MS([[1/a,1/a],[1/a,-1/a]])
sage: g1^2
[1 0]
[0 1]
sage: gap(g1)
[ [ (1/2*a-1/2*a^3), (1/2*a-1/2*a^3) ], [ (1/2*a-1/2*a^3), (-1/2*a
+1/2*a^3) ] ]
sage: gap('$sage4')
<algebraic extension over the Rationals of degree 4>
sage: t=gap(g1)^2
sage: t.name()
'$sage8'
sage: t
[ [ !1, !0 ], [ !0, !1 ] ]

Up to here, everything is fine. But now:
sage: gap('$sage4')
[ [ (1/2*a-1/2*a^3), (1/2*a-1/2*a^3) ], [ (1/2*a-1/2*a^3), (-1/2*a
+1/2*a^3) ] ]
sage: gap('$sage4')^2
[ [ !1, !0 ], [ !0, !1 ] ]

So apparently when computing gap(g1)^2, the variable $sage4 was
overwritten by one copy of gap(g1). How can this be? I thought that
when there is some assignment in the gap interface (e.g. when the
multiplication is performed) then the variable number is automatically
incremented?! Do you have an idea what may have happened?

Best regards
Simon

n...@uiuc.edu

unread,
Mar 2, 2008, 8:49:26 AM3/2/08
to sage-support
Simon,

I have no idea what's going on with the renaming issue, but let me
address one point that might help, and will certainly simplify your
code if perhaps not solve your problem.

> - One needs a _gap_init_ method for F. It should return a string that
> provides a definition of a gap-version of F.
> - As much as i know, creating an algebraic extension of the rationals
> in gap requires several lines; hence it is hardly possible that
> _gap_init_ returns a string that defines the gap-version of F from
> scratch.

Actually, you can still have _gap_init_ return a string, just use one
of GAP's temporary functions:

sage: a._gap_init_()
'CallFuncList(function() local F, a, b, c, d; F := FreeGroup("a", "b",
"c", "d"); a := F.1; b := F.2; c := F.3; d := F.4; return F/
[a^(2)*b*d^(-1)*c*a^(-1)*b*c*b*d*c^(-1)*b*d^(2)]; end, [])'
sage: A = gap(a)
sage: A; A.RelatorsOfFpGroup()
Group( [ a, b, c, d ] )
[ a^2*b*d^-1*c*a^-1*b*c*b*d*c^-1*b*d^2 ]

This also has the advantage of not adding a bunch of extra variables
(F, a, etc., in the above example) to the GAP namespace.

Best,

Nathan

Simon King

unread,
Mar 2, 2008, 9:48:43 AM3/2/08
to sage-support
Dear Nathan,

On Mar 2, 2:49 pm, "dunfi...@caltech.edu" <n...@uiuc.edu> wrote:
> I have no idea what's going on with the renaming issue, but let me
> address one point that might help, and will certainly simplify your
> code if perhaps not solve your problem.

I guess it does! If i don't have variables, they can't be
overwritten :)

> Actually, you can still have _gap_init_ return a string, just use one
> of GAP's temporary functions:

Great! I didn't know about them. I think that is exactly what i was
looking for.

Thank you very much!
Simon

Simon King

unread,
Mar 2, 2008, 9:54:31 AM3/2/08
to sage-support
Oh, and perhaps some of you know:

> Actually, you can still have _gap_init_ return a string, just use one
> of GAP's temporary functions:

Is there a similar thing in Singular?

Cheers
Simon
Reply all
Reply to author
Forward
0 new messages