Strange behavior of the magma interface

2 views
Skip to first unread message

Kwankyu Lee

unread,
Nov 13, 2009, 2:43:54 AM11/13/09
to sage-devel
Hi,

Is this an expected behavior of the magma interface?

----------------------------------------------------------------------
| Sage Version 4.2, Release Date: 2009-10-24 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: m=matrix(ZZ,2,[1,2,3,4])
sage: magma.eval(magma(m).name()+';')
'0'
sage: mm=magma(m)
sage: magma.eval(mm.name()+';')
'[1 2]\n[3 4]'
sage:


I cann't understand the first output '0'.

Kwankyu

Kwankyu Lee

unread,
Nov 14, 2009, 3:33:03 AM11/14/09
to sage-devel
Hi,

What is the standard way to get a reference to a magma object in Sage?

Is it "m._ref()" or "m.name()"? What is their difference?


Kwankyu

William Stein

unread,
Nov 14, 2009, 1:56:42 PM11/14/09
to sage-...@googlegroups.com

Yes, the above is correct and expected behavior. It arises from
*garbage collection*. Consider the following session:

First, I create a matrix m in Sage:
sage: m=matrix(ZZ,2,[1,2,3,4])


Then I create a corresponding matrix A in Magma:
sage: A = magma(m)

It is called _sage_[2] in Magma.

sage: A.name()
'_sage_[2]'

It's there:

sage: magma.eval('_sage_[2]')


'[1 2]\n[3 4]'

Now I *delete* the reference to that matrix:
sage: del A

Now _sage_[2] is "zeroed out" in Magma:

sage: magma.eval('_sage_[2]')
'0'

If Sage did not do this, then every single time you ever create any
magma object from a sage object, e.g., by doing magma(m), you would
use up a lot of memory in that Magma session. This would be an
absolutely massive memory leak situation, which would make the magma
interface nearly useless for serious work.

A version of the above discussion is

http://trac.sagemath.org/sage_trac/ticket/7463

Please referee this, since I wrote it for you, and you are one of the
few people with access to Magma, which is needed to referee this.

William

William Stein

unread,
Nov 14, 2009, 1:58:51 PM11/14/09
to sage-...@googlegroups.com

m.name() gives the name of the variable corresponding to m in the
magma session.

m._ref() is documented at length in the output of m._ref?.
Basically, m._ref() gives you a brand new reference. It's like doing

a := 5;
b := a;

in magma. Now even if a is deleted, b is still around.

William

Kwankyu Lee

unread,
Nov 16, 2009, 1:08:38 AM11/16/09
to sage-devel


On Nov 15, 3:56 am, William Stein <wst...@gmail.com> wrote:
I couln't do this because Georg was quicker than me. But I uploaded a
patch for the related ticket #7462.

Thank you for the explanation.


Kwankyu
Reply all
Reply to author
Forward
0 new messages