SR matrices

1 view
Skip to first unread message

mb

unread,
Dec 14, 2007, 4:31:17 PM12/14/07
to sage-forum
Hello,

The following code produces error

var('a b c d e f g')
V=[a,b,c,d,e,f,g]
M=matrix(SR,7,7,[[z^i for i in range(7)] for z in V])
print det(M)

Is that because output is too large? If 7 is replaced by 6 everything
is fine.

--mb

mabshoff

unread,
Dec 14, 2007, 6:52:01 PM12/14/07
to sage-forum
Hi mb,

which Sage version are you running? With 2.8.15 as well as 2.9.alpha7
I get on 64 bit Linux:

mabshoff@sage:/tmp/Work-mabshoff/release-cycles-2.9/sage-2.9.rc0$ ./
sage
----------------------------------------------------------------------
| SAGE Version 2.9.alpha7, Release Date: 2007-12-13 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: var('a b c d e f g')
(a, b, c, d, e, f, g)
sage: V=[a,b,c,d,e,f,g]
sage: M=matrix(SR,7,7,[[z^i for i in range(7)] for z in V])
sage: d=det(M)

----------------------------------------------------------------------
| SAGE Version 2.8.15, Release Date: 2007-12-03 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: var('a b c d e f g')
(a, b, c, d, e, f, g)
sage: V=[a,b,c,d,e,f,g]
sage: M=matrix(SR,7,7,[[z^i for i in range(7)] for z in V])
sage: d=det(M)

printing d works in both cases.

if it still fails with 2.8.15 we need to know a little bit more about
your system, i.e. amount of RAM, gcc -v output and so on.

Cheers,

Michael

mb

unread,
Dec 14, 2007, 8:36:09 PM12/14/07
to sage-forum
Michael,

> printing d works in both cases.
>
> if it still fails with 2.8.15 we need to know a little bit more about
> your system, i.e. amount of RAM, gcc -v output and so on.

It's a laptop with 500mb RAM running ubuntu dapper, gcc 4.1.2.

--mb

mabshoff

unread,
Dec 16, 2007, 10:48:37 AM12/16/07
to sage-forum


On Dec 15, 2:36 am, mb <bestv...@gmail.com> wrote:
> Michael,
>
> > printing d works in both cases.
>
> > if it still fails with 2.8.15 we need to know a little bit more about
> > your system, i.e. amount of RAM, gcc -v output and so on.
>

Hi mb,

> It's a laptop with 500mb RAM running ubuntu dapper, gcc 4.1.2.

sorry for the late followup, but the 2.9 release kept me busy. Nothing
about the above pops out, so could you post the exact error message
you get with "7"?

>
> --mb

Cheers,

Michael

mb

unread,
Dec 18, 2007, 9:23:16 AM12/18/07
to sage-forum
Hi Michael,

I compiled 2.9 from sources and the script works fine.

--mb

mabshoff

unread,
Dec 18, 2007, 2:47:25 PM12/18/07
to sage-forum


On Dec 18, 3:23 pm, mb <bestv...@gmail.com> wrote:
> Hi Michael,
>
> I compiled 2.9 from sources and the script works fine.
>

Good to know, let's hope it doesn't pop up somewhere else again. I
wasn't quite sure what caused it in the first place, so I will wait
for it to reappear.

> --mb

Cheers,

Michael

William Stein

unread,
Dec 28, 2007, 4:43:06 PM12/28/07
to sage-...@googlegroups.com

Hi. As you know, this now works fine in Sage-2.9.1, since Mike Hanson
and Robert Bradshaw wrote a special symbolic matrix class:

sage: var('a b c d e f g')
sage: V=[a,b,c,d,e,f,g]
sage: M=matrix(SR,7,7,[[z^i for i in range(7)] for z in V])
sage: time w=det(M)
Time: CPU 6.57 s, Wall: 9.87 s

However, it's very interesting to note that you can do exactly the
same calculation _vastly_ more quickly using the specialized
"multivariate polynomial ring over the rational numbers" functionality
in Sage (which partly comes from Singular, by the way):

sage: R.<a,b,c,d,e,f,g> = QQ[]
sage: V=[a,b,c,d,e,f,g]
sage: M=matrix(R,7,7,[[z^i for i in range(7)] for z in V])
sage: time w=det(M)
Time: CPU 0.02 s, Wall: 0.02 s
sage: str(w)[:50]
'-a^6*b^5*c^4*d^3*e^2*f + a^5*b^6*c^4*d^3*e^2*f + a'

William

Jaap Spies

unread,
Dec 28, 2007, 5:48:28 PM12/28/07
to sage-...@googlegroups.com
William Stein wrote:

> However, it's very interesting to note that you can do exactly the
> same calculation _vastly_ more quickly using the specialized
> "multivariate polynomial ring over the rational numbers" functionality
> in Sage (which partly comes from Singular, by the way):
>
> sage: R.<a,b,c,d,e,f,g> = QQ[]
> sage: V=[a,b,c,d,e,f,g]
> sage: M=matrix(R,7,7,[[z^i for i in range(7)] for z in V])
> sage: time w=det(M)
> Time: CPU 0.02 s, Wall: 0.02 s
> sage: str(w)[:50]
> '-a^6*b^5*c^4*d^3*e^2*f + a^5*b^6*c^4*d^3*e^2*f + a'
>


sage: time p = M.permanent()
CPU times: user 4.56 s, sys: 0.40 s, total: 4.96 s
Wall time: 5.01

sage: str(p)[:46]
'a^6*b^5*c^4*d^3*e^2*f + a^5*b^6*c^4*d^3*e^2*f '

Notice the difference :)

When I change QQ in ZZ it goes *boom*! Memory usage to 99% and more.

Why?

Jaap

William Stein

unread,
Jan 2, 2008, 2:56:59 PM1/2/08
to sage-...@googlegroups.com

Sage has very optimized multivariate polynomial arithmetic over QQ.
It has very very slow arithmetic over ZZ. This is temporary, and
has been temporary
for about 6 months now, which is why I think we should just do some hack to
make polys over ZZ actually use polys over QQ as their underlying
implementation,
at least until libsingular supports ZZ.

-- William

Reply all
Reply to author
Forward
0 new messages