noncommutative algebras

57 views
Skip to first unread message

John Palmieri

unread,
Feb 19, 2008, 2:56:54 PM2/19/08
to sage-support
I'm new to Sage, but I've looked through the reference manual, and
tried searching through the various discussion groups, etc., without
finding the answers to my questions:

1. Is there an easy way to define a noncommutative algebra like

F_2 <x,y> / (x^2 * y + y * x^2, x * y^2 + y^2 * x)?

(Here, F_2 is the field with two elements, but the field isn't that
important, and I understand how to specify it.) I don't see how to
use the stuff in the manual about quotients of free algebras (section
30.3) to do this; unless I'm misunderstanding, I would need the set of
monomials to be infinite here.

2. Is there an easy way to define an algebra map

f: F_2 <x,y> --> F_2 <a,b,c> / (relations)?

I want to be able to specify f(x) and f(y), and then have Sage tell me
what f(x^2 + x*y + x*y^5*x) is, for example. (As I said, I'm new to
Sage. Should I use a substitution for this?)

John Palmieri

unread,
Feb 19, 2008, 3:58:19 PM2/19/08
to sage-support


On Feb 19, 11:56 am, John Palmieri <jhpalmier...@gmail.com> wrote:
> I'm new to Sage, but I've looked through the reference manual, and
> tried searching through the various discussion groups, etc., without
> finding the answers to my questions:
>
> 1. Is there an easy way to define a noncommutative algebra like
>
> F_2 <x,y> / (x^2 * y + y * x^2, x * y^2 + y^2 * x)?
>
> (Here, F_2 is the field with two elements, but the field isn't that
> important, and I understand how to specify it.) I don't see how to
> use the stuff in the manual about quotients of free algebras (section
> 30.3) to do this; unless I'm misunderstanding, I would need the set of
> monomials to be infinite here.

Maybe I should be more specific here, because the form of the
relations in the examples I care about might be important. I'm
interested in algebras of the form

k <x_1, x_2, ..., x_n> / (relations),

where the relations guarantee that a basis for the algebra consists of
all monomials of the form x_1^{k_1} x_2^{k_2} ... x_n^{k_n}. In
particular, the relations are of the form x_j x_i = x_i x_j + (other
terms), for all i < j, where the other terms are sums of monomials of
the form above; thus you can use the relations to write any other
monomial as a sum of ones in this form.

Here's an example:

F_2 <x_1, x_12, x_2> / (relations),

where the relations are

x_12 x_1 + x_1 x_12,
x_2 x_1 + x_1 x_2 + x_12,
x_2 x_12 + x_12 x_2.

(This happens to be isomorphic to the algebra I mentioned in the first
post, but in this form, it might be more amenable to study by using a
computer.)

Simon King

unread,
Feb 19, 2008, 5:12:44 PM2/19/08
to sage-support
Dear John,

> Maybe I should be more specific here, because the form of the
> relations in the examples I care about might be important. I'm
> interested in algebras of the form
>
> k <x_1, x_2, ..., x_n> / (relations),
>
> where the relations guarantee that a basis for the algebra consists of
> all monomials of the form x_1^{k_1} x_2^{k_2} ... x_n^{k_n}.

Yes, this is possible via the Singular-interface. In fact, having a
Poincare-Birkhoff-Witt basis (i.e., the monomials of the form
x_1^{k_1} x_2^{k_2} ... x_n^{k_n} are a basis for the algebra) is
essential, because Singular doesn't know how to deal with free
algebras (sad enough).

> Here's an example:
>
> F_2 <x_1, x_12, x_2> / (relations),
>
> where the relations are
>
> x_12 x_1 + x_1 x_12,
> x_2 x_1 + x_1 x_2 + x_12,
> x_2 x_12 + x_12 x_2.

Here is how to do it with k=Q, via the interface:
sage: singular.LIB('ncall.lib') # this loads the non-commutative
Singular libraries
sage: R=singular.ring(0,'(x1,x12,x2)','dp') # this is a commutative
ring
# if you want to do it over F_2, use
singular.ring(2,'(x1,x12,x2)','dp')
sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
sage: D=singular.matrix(3,3,'0,0,-x12, 0,0,0, 0,0,0')
# these two matrices define your algebra
sage: S=C.nc_algebra(D) # now S is the non-commutative ring of your
example
sage: S.set_ring() # don't forget to tell Singular it should
now work with S instead of R
sage: x1=singular('x1') # define Sage objects that correspond to
your variables
sage: x2=singular('x2')
sage: x12=singular('x12')
sage: x2*x1 # now you can do computations in the usual way...
-x1*x2-x12 # ... and get the correct result
# Of course, over F_2 it would be x1*x2+x12

Your find more information about nc_algebra in the Singular manual at
http://www.singular.uni-kl.de/Manual/latest/sing_401.htm#SEC441

The disadvantage is that everything has to pass an interface.

Concerning your second question:
There is a 'map' type in Singular. I don't know how to use it in an
elegant way (perhaps someone else on that list knows?)

A non-elegant solution:
sage: singular.eval('map f=%s, x2,-x12,x1'%S.name())
# S.name() is the name under which S is known to
Singular.
# Now, Singular knows a map from S to the current
basering
# (which happens to be S as well).
# Hence, f is a map from S to S, mapping x1 to x2, x12 to
-x12, and x2 to x1
sage: f=singular('f') # now it is known to sage ...
sage: f(x1^3*x12) # ... and can be used in the usual way
x12*x2^3 # which is equal to f(x1)^3*f(x12) = - x2^3*x12

Concerning map, see
http://www.singular.uni-kl.de/Manual/latest/sing_113.htm#SEC153

I hope this was of some help.
Cheers
Simon


John Palmieri

unread,
Feb 20, 2008, 1:22:49 AM2/20/08
to sage-support
Hi Simon,

Thanks, this is very helpful (the first part, at least -- I haven't
tried maps yet). If I can figure out tensor products, I'll be really
happy. Singular seems to have tensor products for algebras, using
'+', documented here:

http://www.singular.uni-kl.de/Manual/3-0-3/sing_383.htm

I can't figure out how to access this with sage, though. Suppose I
have everything set up as you have described, so I have the
noncommutative ring S. How do I define S tensor_k S? I tried
singular(S+S), but that didn't work...
> Your find more information about nc_algebra in the Singular manual athttp://www.singular.uni-kl.de/Manual/latest/sing_401.htm#SEC441
>
> The disadvantage is that everything has to pass an interface.
>
> Concerning your second question:
> There is a 'map' type in Singular. I don't know how to use it in an
> elegant way (perhaps someone else on that list knows?)
>
> A non-elegant solution:
> sage: singular.eval('map f=%s, x2,-x12,x1'%S.name())
>              # S.name() is the name under which S is known to
> Singular.
>              # Now, Singular knows a map from S to the current
> basering
>              # (which happens to be S as well).
>              # Hence, f is a map from S to S, mapping x1 to x2, x12 to
> -x12, and x2 to x1
> sage: f=singular('f')     # now it is known to sage ...
> sage: f(x1^3*x12)       # ... and can be used in the usual way
> x12*x2^3  # which is equal to f(x1)^3*f(x12) = - x2^3*x12
>
> Concerning map, seehttp://www.singular.uni-kl.de/Manual/latest/sing_113.htm#SEC153

William Stein

unread,
Feb 20, 2008, 1:31:00 AM2/20/08
to sage-s...@googlegroups.com
On Feb 19, 2008 10:22 PM, John Palmieri <jhpalm...@gmail.com> wrote:
>
> Hi Simon,
>
> Thanks, this is very helpful (the first part, at least -- I haven't
> tried maps yet). If I can figure out tensor products, I'll be really
> happy. Singular seems to have tensor products for algebras, using
> '+', documented here:
>
> http://www.singular.uni-kl.de/Manual/3-0-3/sing_383.htm
>
> I can't figure out how to access this with sage, though. Suppose I
> have everything set up as you have described, so I have the
> noncommutative ring S. How do I define S tensor_k S? I tried
> singular(S+S), but that didn't work...
>

Try

singular('%s + %s'%(S.name(), S.name()))

Other comments:
1. Are you the John Palmieri that is a professor at Univ of Washington too?
If so, perhaps we should chat in person...
2. Using Singular as suggested above probably seems pretty awkward.
Don't worry -- if you find that it is doing the right thing for you,
we can design
some nice Sage classes that give a nice clean interface, then "secretly"
have Singular do all the real work behind the sences. This is how many
interesting things in Sage are (first) implemented.

-- William

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Simon King

unread,
Feb 20, 2008, 3:53:41 AM2/20/08
to sage-support
Dear John,

> If I can figure out tensor products, I'll be really
> happy. Singular seems to have tensor products for algebras, using
> '+', documented here:
<snip>
> Suppose I
> have everything set up as you have described, so I have the
> noncommutative ring S. How do I define S tensor_k S? I tried
> singular(S+S), but that didn't work...

I'm afraid in Singular it wouldn't work either, as shown by this
Singular session:
> ring R = 0, (x1,x12,x2),dp;
> matrix C[3][3]=1,-1,-1, -1,1,-1, -1,-1,1;
> matrix D[3][3]=0,0,-x12, 0,0,0, 0,0,0;
> LIB "ncall.lib";
> def S=nc_algebra (C,D);
> def X=S+S;
> X;
// characteristic : 0
// number of vars : 3
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering C
// noncommutative relations: ...

Hence, adding S with itself seems to return S again. So, i guess one
has to produce a copy 'S of S with *different* variable names, and add
these:
> ring 'R = 0, ('x1,'x12,'x2),dp;
> matrix C[3][3]=1,-1,-1, -1,1,-1, -1,-1,1;
> matrix D[3][3]=0,0,-'x12, 0,0,0, 0,0,0;
> def 'S=nc_algebra (C,D);
> def X=S+'S;
// ** redefining X **
> X;
// characteristic : 0
// number of vars : 6
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering dp
// : names 'x1 'x12 'x2
// block 3 : ordering C
// noncommutative relations: ...

According to what William suggests, it may be needed (working in Sage)
to directly communicate this to Singular via the interface.

Cheers
Simon

John Palmieri

unread,
Feb 20, 2008, 2:56:54 PM2/20/08
to sage-support
Thanks, I didn't realize it was an issue with Singular, not with
Sage. Anyway, if I do as you suggest and make two copies of S (which
is a bit tedious, and is only going to get worse for the larger rings
I have in mind), called S and S1, then I can type

singular(S+S1)

and it seems to work: I get

// characteristic : 2
// number of vars : 6
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering dp
// : names y1 y12 y2
// block 3 : ordering C
// noncommutative relations: ...

So I don't quite need to follow William's advice.

I'm a little surprised that it's not easy to take a tensor product of
an algebra with itself; I can't imagine I'm the only person who wants
to use this sort of thing to study Hopf algebras (not to mention
things like A-infinity algebras...).

John

Simon King

unread,
Feb 20, 2008, 3:30:48 PM2/20/08
to sage-support
Dear all,

On Feb 20, 8:56 pm, John Palmieri <jhpalmier...@gmail.com> wrote:
<snip>
> I'm a little surprised that it's not easy to take a tensor product of
> an algebra with itself; I can't imagine I'm the only person who wants
> to use this sort of thing to study Hopf algebras (not to mention
> things like A-infinity algebras...).

Certainly (as a former student of V. Turaev) i agree!

I just tested whether
sage: R=singular.ring(0,'(x,y,z)','dp')
has a __copy__ method. It hasn't!

Would it be a reasonable idea to implement such method, so that
copy(R)
yields a ring that is isomorphic with R but has different variable
names (e.g., by adding a prime to the variable names)?

Then, John (and many others) could do
S=R+copy(R)
S.setring()
which should be reasonably short.

I think, without creating new variable names R+R doesn't make much
sense.

More generally, i believe it'd be a good idea to have a __copy__
method for *any* Sage objects defined via the Singular interface.

E.g., when one defines a matrix
sage: D=singular.matrix(3,3,'a,b,c, a**2,b**2,c**2, a**3,b**3,c**3')
then
C=copy(D)
should be a copy of D (in the same ring). Up to now, one obtains
sage: C=copy(D)
sage: C
(invalid object -- defined in terms of closed session)

Yours
Simon

William Stein

unread,
Feb 20, 2008, 3:47:42 PM2/20/08
to sage-s...@googlegroups.com
On Feb 20, 2008 12:30 PM, Simon King <ki...@mathematik.uni-jena.de> wrote:
>
> Dear all,
>
> On Feb 20, 8:56 pm, John Palmieri <jhpalmier...@gmail.com> wrote:
> <snip>
> > I'm a little surprised that it's not easy to take a tensor product of
> > an algebra with itself; I can't imagine I'm the only person who wants
> > to use this sort of thing to study Hopf algebras (not to mention
> > things like A-infinity algebras...).
>
> Certainly (as a former student of V. Turaev) i agree!
>
> I just tested whether
> sage: R=singular.ring(0,'(x,y,z)','dp')
> has a __copy__ method. It hasn't!
>
> Would it be a reasonable idea to implement such method, so that
> copy(R)
> yields a ring that is isomorphic with R but has different variable
> names (e.g., by adding a prime to the variable names)?

No, that would not be reasonable. [[woah, John Palmieri just appeared
in my office... chat for a while...] Anyway, copy should return an exact
copy since that's the semantics of __copy__ in Python. However,
I strongly encourage you to write a method like you describe and
just call it something slightly different, e.g.,
def change_names(self, ...):

or

def copy_with_names_changed(...):

or whatever. Just anything but "copy".

> Then, John (and many others) could do
> S=R+copy(R)
> S.setring()
> which should be reasonably short.
>
> I think, without creating new variable names R+R doesn't make much
> sense.
>
> More generally, i believe it'd be a good idea to have a __copy__
> method for *any* Sage objects defined via the Singular interface.
>
> E.g., when one defines a matrix
> sage: D=singular.matrix(3,3,'a,b,c, a**2,b**2,c**2, a**3,b**3,c**3')
> then
> C=copy(D)
> should be a copy of D (in the same ring). Up to now, one obtains
> sage: C=copy(D)
> sage: C
> (invalid object -- defined in terms of closed session)

I would certainly be all for that too!

Any chance you could write it, or do I have to?

-- William

John Palmieri

unread,
Feb 20, 2008, 4:22:08 PM2/20/08
to sage-support
By the way, is the following a bug?

sage: singular.LIB('ncall.lib')
sage: R=singular.ring(0,'(x1,x12,x2)','dp')
sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
sage: C

1, -1,-1,
-1,1, -1,
-1,-1,1
sage: R=singular.ring(0,'(x1,x12,x2)','dp')
sage: C
`sage1`

Calling singular.ring(...) seems to redefine C.

(I discovered this because when I was making a copy of the algebra S,
I wanted to use the same matrix C for the copy, but by that point it
had been redefined to be `sage1`, to my surprise.)


On Feb 20, 12:47 pm, "William Stein" <wst...@gmail.com> wrote:
I might consider writing it, but I'm probably not the best person for
the job, since I'm completely new to Sage and programming with it.

> -- William

William Stein

unread,
Feb 20, 2008, 5:45:54 PM2/20/08
to sage-s...@googlegroups.com
On Wed, Feb 20, 2008 at 1:22 PM, John Palmieri <jhpalm...@gmail.com> wrote:
>
> By the way, is the following a bug?
>
>
> sage: singular.LIB('ncall.lib')
> sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
> sage: C
>
>
> 1, -1,-1,
> -1,1, -1,
> -1,-1,1
> sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> sage: C
> `sage1`
>
> Calling singular.ring(...) seems to redefine C.
>
> (I discovered this because when I was making a copy of the algebra S,
> I wanted to use the same matrix C for the copy, but by that point it
> had been redefined to be `sage1`, to my surprise.)

No, it is not a bug. It's a perfect example of how
Singular itself has a rather -- let's say old fashioned -- user
interface and language. That's what I was trying to convey
to you earlier today in my office: Singular best at doing
exactly one thing at a time, and no more.
That's why code that we've written that combines
Sage and Singular is vastly nicer to use than just
plain Singular. The main problem for you of course
is that nobody has written any such code that "wraps"
noncommutative functionality in Singular yet.

I would sit down and try to fix this right now, but I have too
many other things on my plate, and I've been jumping
into every basic thing that needs to get done in
Sage for 3 years; that has to stop or I won't have
enough time to do my own research.

-- William

--

Simon King

unread,
Feb 21, 2008, 2:57:29 AM2/21/08
to sage-support
Dear John, dear William,

On Feb 20, 11:45 pm, "William Stein" <wst...@gmail.com> wrote:
> On Wed, Feb 20, 2008 at 1:22 PM, John Palmieri <jhpalmier...@gmail.com> wrote:
>
> > By the way, is the following a bug?
>
> > sage: singular.LIB('ncall.lib')
> > sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> > sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
> > sage: C
>
> > 1, -1,-1,
> > -1,1, -1,
> > -1,-1,1
> > sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> > sage: C
> > `sage1`
>
> > Calling singular.ring(...) seems to redefine C.
>
> > (I discovered this because when I was making a copy of the algebra S,
> > I wanted to use the same matrix C for the copy, but by that point it
> > had been redefined to be `sage1`, to my surprise.)
>
> No, it is not a bug. It's a perfect example of how
> Singular itself has a rather -- let's say old fashioned ...

... or neatly ordered...

The point is that a matrix in Singular has coefficients in a ring.
There may be different rings at the same time, but only one of them is
active (its nick name is "basering"). If you want to access a matrix
then you first have to make its ring active (using "setring").

Above, you define a ring, define a matrix in that ring, and then
change the ring (it doesn't matter that it is re-defined by an exact
copy of itself). So the matrix is lost.

Yours
Simon

Simon King

unread,
Feb 21, 2008, 3:24:16 AM2/21/08
to sage-support
Dear William, dear John,

On Feb 20, 9:47 pm, "William Stein" <wst...@gmail.com> wrote:
<snip>
> > More generally, i believe it'd be a good idea to have a __copy__
> > method for *any* Sage objects defined via the Singular interface.
>
> > E.g., when one defines a matrix
> > sage: D=singular.matrix(3,3,'a,b,c, a**2,b**2,c**2, a**3,b**3,c**3')
> > then
> > C=copy(D)
> > should be a copy of D (in the same ring). Up to now, one obtains
> > sage: C=copy(D)
> > sage: C
> > (invalid object -- defined in terms of closed session)
>
> I would certainly be all for that too!
>
> Any chance you could write it, or do I have to?

My to-do-list says: First make the tax declaration :-((, then finally
provide a tensor product of matrices (as i promised earlier), and then
i may try to do it.

Moreover, i just found that Singular provides a method called
'ringtensor'. Unfortunately it seems that it doesn't help John:

sage: R=singular.ring(0,'(x1,x12,x2)','dp')
sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
sage: D=singular.matrix(3,3,'0,0,-x12, 0,0,0, 0,0,0')
sage: singular.LIB('ncall.lib')
sage: S=C.nc_algebra(D)
sage: X=S.ringtensor(S)
sage: S.set_ring()
sage: singular('x12*x1')
-x1*x12
sage: X.set_ring()
sage: singular('x12*x1')
x1*x12
sage: X

// characteristic : 0
// number of vars : 6
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering dp
// : names @(4) @(5) @(6)
// block 3 : ordering C

So, in principle it does a tensor product and changes names if
necessary. However, when implementing ringtensor it was forgotten to
include the non-commutative case. I will notify the Singular team.

Yours
Simon

Simon King

unread,
Feb 21, 2008, 5:18:23 AM2/21/08
to sage-support
Dear John,

i think i figured out how to form a tensor product of several copies
of a (non-commutative) ring with itself...

On Feb 20, 9:47 pm, "William Stein" <wst...@gmail.com> wrote:
<snip>
> No, that would not be reasonable. [[woah, John Palmieri just appeared
> in my office... chat for a while...] Anyway, copy should return an exact
> copy since that's the semantics of __copy__ in Python. However,
> I strongly encourage you to write a method like you describe and
> just call it something slightly different, e.g.,
> def change_names(self, ...):
<snip>

... and i can also demonstrate how "change_names" could work.

The idea is as follows.
Singular describes a ring by means of a "ringlist". It provides the
variable names, the characteristic, the ordering, and also (if it
applies) the non-commutative relations or quotients by an ideal.

Now, we simply change the variable names in the ringlist and form a
new ring by the altered ringlist. Eventually, we sum up the copies of
the ring.
I've put the following into a file tensorpower.spyx:

import sage
import sage.all
from sage.interfaces.singular import singular

def tensorpower(R,n):
R.set_ring()
L=R.ringlist()
OutR=R
for nr from 0<=nr<n-1:
R.set_ring()
for i from 1<=i<=len(L[2]):
singular.eval('%s[2][%d] = "%s"'%(L.name(),i,"'"+str(L[2]
[i])))
OutR=OutR+L.ring()
return OutR

Now, i get the following sage session:

sage: attach tensorpower.spyx
Compiling /home/king/Projekte/Plural/tensorpower.spyx...
sage: R=singular.ring(0,'(x1,x12,x2)','dp')
sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
sage: D=singular.matrix(3,3,'0,0,-x12, 0,0,0, 0,0,0')
sage: singular.LIB('ncall.lib')
sage: S=C.nc_algebra(D)
sage: X=tensorpower(S,3)
sage: X.set_ring()
sage: X

// characteristic : 0
// number of vars : 6
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering dp
// : names 'x1 'x12 'x2
// block 3 : ordering dp
// : names ''x1 ''x12 ''x2
// block 4 : ordering C
// noncommutative relations:
// x12x1=-x1*x12
// x2x1=-x1*x2-x12
// x2x12=-x12*x2
// 'x12'x1=-'x1*'x12
// 'x2'x1=-'x1*'x2-'x12
// 'x2'x12=-'x12*'x2
// ''x12''x1=-''x1*''x12
// ''x2''x1=-''x1*''x2-''x12
// ''x2''x12=-''x12*''x2

So, after tax declaration and adding a doc-string and doc-tests, i
think this might be a patch.

Yours
Simon

John Palmieri

unread,
Feb 21, 2008, 7:50:03 PM2/21/08
to sage-support
I'm having problems with this: if I call this tensorpower.spyx (or use
the one you emailed to me), I get this:

sage: attach tensorpower.spyx
Loading of file "/Users/palmieri/.sage/tensorpower.spy" has type not
implemented.

If I rename it to tensor.sage (not sure if this is a good idea), I
get:

sage: attach tensor.sage
line 10
for nr from Integer(0)<=nr<n-Integer(1):

The same thing happens if I type the function definition directly into
Sage.

This is with Sage 2.10.1 on Mac OS X (although I can test it on a
linux machine tomorrow). I'm probably doing something stupid,
though...

I have one question about the results of your computation; see below.


> Now, i get the following sage session:
>
> sage: attach tensorpower.spyx
> Compiling /home/king/Projekte/Plural/tensorpower.spyx...
> sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
> sage: D=singular.matrix(3,3,'0,0,-x12, 0,0,0, 0,0,0')
> sage: singular.LIB('ncall.lib')
> sage: S=C.nc_algebra(D)
> sage: X=tensorpower(S,3)
> sage: X.set_ring()
> sage: X
>
> //   characteristic : 0
> //   number of vars : 6

Shouldn't this be 9?

William Stein

unread,
Feb 21, 2008, 7:58:03 PM2/21/08
to sage-s...@googlegroups.com

Yes, that's a VERY GOOD idea. It's really crazy to use a compiled
spyx for the purposes of interfacing with the Singular interpreter
via pexpect.

> I get:
>
> sage: attach tensor.sage
> line 10
> for nr from Integer(0)<=nr<n-Integer(1):
>
> The same thing happens if I type the function definition directly into
> Sage.

That's as it should be. That's all that happens when you attached
a file. It's supposed to be the same as typing in the code.

>
> This is with Sage 2.10.1 on Mac OS X (although I can test it on a
> linux machine tomorrow). I'm probably doing something stupid,
> though...
>
> I have one question about the results of your computation; see below.
>

One trivial thing occurred to me. Sage includes Maxima and has a very
interface to it. Maybe Maxima can do the sort of noncommutative
calculations you want -- it's worth at least checking. The main reason
I suggest this is: (1) you're not going to do something that pushes the
limits of computation, so speed isn't of the utmost importance,
and (2) you (John's) main programming background is in lisp,
so you might feel very comfortable with Maxima, given that it
is written in lisp.

http://maxima.sourceforge.net/

sage: maxima('2+2')
4


-- William

--

Simon King

unread,
Feb 22, 2008, 3:42:45 AM2/22/08
to sage-support
Dear John,

On Feb 22, 1:50 am, John Palmieri <jhpalmier...@gmail.com> wrote:
> I'm having problems with this: if I call this tensorpower.spyx (or use
> the one you emailed to me), I get this:
>
> sage: attach tensorpower.spyx
> Loading of file "/Users/palmieri/.sage/tensorpower.spy" has type not
> implemented.

I don't know where this comes from, sorry,

> I have one question about the results of your computation; see below.
> > //   characteristic : 0
> > //   number of vars : 6
>
> Shouldn't this be 9?

Yes. Sorry, first i did the example with tensorpower(S,2), but then i
thought tensorpower(S,3) is nicer, and then i made a mistake with cut-
and-past. So, it *is* 9.

Yours
Simon

Simon King

unread,
Feb 22, 2008, 3:50:08 AM2/22/08
to sage-support
Dear William,

On Feb 22, 1:58 am, "William Stein" <wst...@gmail.com> wrote:
> >  If I rename it to tensor.sage (not sure if this is a good idea),
>
> Yes, that's a VERY GOOD idea.  It's really crazy to use a compiled
> spyx for the purposes of interfacing with the Singular interpreter
> via pexpect.

Sorry, using a compiled spyx was just, well, let's call it my personal
tradition.

Am i right that the loop must be re-written if it is .sage rather
than .spyx?
I think
for i from 1<=i<=len(L[2]):
is only possible in .spyx, while in .sage it should be
for i in range(1,len(L[2])+1)

@John, this would explain the new error message after renaming the
file.

However, i don't know why attaching the .spyx didn't work.

Yours
Simon

William Stein

unread,
Feb 22, 2008, 11:47:24 AM2/22/08
to sage-s...@googlegroups.com
On Fri, Feb 22, 2008 at 12:50 AM, Simon King
<ki...@mathematik.uni-jena.de> wrote:
>
> Dear William,
>
>
> On Feb 22, 1:58 am, "William Stein" <wst...@gmail.com> wrote:
> > > If I rename it to tensor.sage (not sure if this is a good idea),
> >
> > Yes, that's a VERY GOOD idea. It's really crazy to use a compiled
> > spyx for the purposes of interfacing with the Singular interpreter
> > via pexpect.
>
> Sorry, using a compiled spyx was just, well, let's call it my personal
> tradition.
>
> Am i right that the loop must be re-written if it is .sage rather
> than .spyx?
> I think
>
> for i from 1<=i<=len(L[2]):
> is only possible in .spyx, while in .sage it should be
> for i in range(1,len(L[2])+1)

Yes, that is correct. But when you're not working with pure C data structures
you're going to get no speed improvements by using


> for i from 1<=i<=len(L[2]):

instead of


> for i in range(1,len(L[2])+1)

You're just making things a little more difficult.

> @John, this would explain the new error message after renaming the
> file.

Yes, that would.

>
> However, i don't know why attaching the .spyx didn't work.
>
>

That's very suspicious:

"sage: attach tensorpower.spyx
Loading of file "/Users/palmieri/.sage/tensorpower.spy" has type not
implemented."

That suggests there is either a very very weird serious bug that got
magically fixed
or maybe the above log isn't what really happened -- notice that in
the error message
it says .spy not .spyx.

-- William

John Palmieri

unread,
Feb 22, 2008, 1:03:57 PM2/22/08
to sage-support
Right, I'm confused by that, too, but that's what it says. I just
took the new file tensorpower.sage that Simon sent me, copied it to
tp.spyx, and did the following (in a new worksheet).

sage: attach tp.spyx
Loading of file "/home/palmieri/.sage/tp.spy" has type not
implemented.
sage: attach tensorpower.sage
sage: R=singular.ring(2,'(x1,x12,x2)','dp')
sage: D=singular.matrix(3,3,'0,0,-x12, 0,0,0, 0,0,0')
sage: S=singular.nc_algebra(1,D)
sage: S
// characteristic : 2
// number of vars : 3
// block 1 : ordering dp
// : names x1 x12 x2
// block 2 : ordering C
// noncommutative relations: ...

This is with Sage 2.9.3 on the linux box in my office, and I had a
similar problem with Sage 2.10.1 on my mac at home.

...

Now, after trying one or two more things, here's more information: if
I start sage from a terminal, then type "attach tp.spyx", I get an
error about not being able to find the file (which makes sense, since
I put the file in ~/.sage/, not in my home directory). Then I type
"notebook()", go to my web browser, and do the stuff I pasted in
above. Then I quit that, go back to the terminal, hit ctrl-C twice,
and do "attach tp.spyx". This time it works: typing "notebook()" and
then quitting it seems to change my default directory from ~/ to
~/.sage/.

So, anyway, it seems that I can attach .spyx files from the terminal
session, but not from a notebook in a web browser.

John

> -- William

William Stein

unread,
Feb 22, 2008, 1:09:39 PM2/22/08
to sage-s...@googlegroups.com

To attach files in a *local* notebook give the exact path to the file.

-- William

Simon King

unread,
Feb 22, 2008, 3:10:05 PM2/22/08
to sage-support
Dear John,

a brief addendum to a previous post of yours:

On Feb 20, 10:22 pm, John Palmieri <jhpalmier...@gmail.com> wrote:
> By the way, is the following a bug?
>
> sage: singular.LIB('ncall.lib')
> sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> sage: C=singular.matrix(3,3,'1,-1,-1, -1,1,-1, -1,-1,1')
> sage: C
>
> 1, -1,-1,
> -1,1, -1,
> -1,-1,1
> sage: R=singular.ring(0,'(x1,x12,x2)','dp')
> sage: C
> `sage1`

As William pointed out, this is not a bug.

When re-defining R, then i think the matrix C is in fact lost.
However, it may be worth mentioning that after defining the 'same'
ring under a new name, it is easy to produce a copy of C in the new
ring; let R and C be defined as above. Then:
sage: newR=singular.ring(0,'(x1,x12,x2)','dp')
sage: C
`sage1`
sage: newC=R.fetch(C)
sage: newC

1, -1,-1,
-1,1, -1,
-1,-1,1
sage: R.set_ring()
sage: C

1, -1,-1,
-1,1, -1,
-1,-1,1
sage: newC
`sage3`

You see, a matrix (or an ideal) is only accessible if its ring is
active. But as long as the ring is not overwritten, the matrix isn't
lost.

Singular offers two commands to ship data from one ring to another:
fetch and imap. See
http://www.singular.uni-kl.de/Manual/latest/sing_197.htm#SEC237
and
http://www.singular.uni-kl.de/Manual/latest/sing_215.htm#SEC255

Cheers
Simon

Simon King

unread,
Feb 25, 2008, 5:03:23 AM2/25/08
to sage-support
Dear William,

On Feb 20, 9:47 pm, "William Stein" <wst...@gmail.com> wrote:
> On Feb 20, 2008 12:30 PM, Simon King <k...@mathematik.uni-jena.de> wrote:
<snip>
> > Would it be a reasonable idea to implement such method, so that
> > copy(R)
> > yields a ring that is isomorphic with R but has different variable
> > names (e.g., by adding a prime to the variable names)?
>
> No, that would not be reasonable. [[woah, John Palmieri just appeared
> in my office... chat for a while...] Anyway,copyshould return an exactcopysince that's the semantics of __copy__ in Python.
<snip>
> > More generally, i believe it'd be a good idea to have a __copy__
> > method for *any* Sage objects defined via the Singular interface.
>
> > E.g., when one defines a matrix
> > sage: D=singular.matrix(3,3,'a,b,c, a**2,b**2,c**2, a**3,b**3,c**3')
> > then
> > C=copy(D)
> > should be a copy of D (in the same ring). Up to now, one obtains
> > sage: C=copy(D)
> > sage: C
> > (invalid object -- defined in terms of closed session)
>
> I would certainly be all for that too!
>
> Any chance you could write it, or do I have to?

Done - see http://trac.sagemath.org/sage_trac/ticket/2300
With that patch, copy(R) for a SingularElement R returns a
SingularElement that is the same as R but not identical with R.

I am not sure whether that ticket belongs to "commutative algebra" or
to "interfaces". I chose "commutative algebra", hoping it is ok.

Cheers
Simon
Reply all
Reply to author
Forward
0 new messages