14 views

Skip to first unread message

Jun 4, 2011, 1:00:25 PM6/4/11

to sage-s...@googlegroups.com

Hi,

How can I convert a Singular list to a Sage list?

For instance:

T is a Singular list with value

[1]:

_[1]=1

[2]:

_[1]=1

[3]:

[1]:

[1]:

_[1]=0

[2]:

[1]:

_[1]=(x^2+y^2-4*y+3)

[2]:

_[1]=(x^4+2*x^2*y^2-9*x^2+y^4-9*y^2+4*y+12)

I can get a Sage string (using singular.eval(T)) but it would be more

convenient getting a (structured) Sage list. Is there a command for

doing so?

Thanks.

Jun 5, 2011, 2:26:40 AM6/5/11

to sage-support

Hi Francisco,

On 4 Jun., 19:00, Francisco Botana <fbot...@uvigo.es> wrote:

> How can I convert a Singular list to a Sage list?

It *should* be working (if L is a list in the Singular pexpect

interface) with L.sage().

However, it doesn't at all. I am really surprised that it doesn't,

because such a feature should have been implemented a long time ago.

Perhaps other people can point us to a solution? For now I can only

offer part of a solution, as sketched below, hoping that you consider

a special case for which the partial solution is enough.

First, L.sage() does not work, e.g., in the following example:

sage: singular.eval('ring R')

sage: L = singular('ringlist(R)')

sage: L

[1]:

32003

[2]:

[1]:

x

[2]:

y

[3]:

z

[3]:

[1]:

[1]:

dp

[2]:

1,1,1

[2]:

[1]:

C

[2]:

0

[4]:

_[1]=0

sage: L.sage()

<KABOOM>

sage: L[1].sage() # that's just an integer!

<KABOOM>

sage: L[2][1].sage() # that's just a string!!

<KABOOM>

> I can get a Sage string (using singular.eval(T)) but it would be more

> convenient getting a (structured) Sage list. Is there a command for

> doing so?

I think string parsing is not a good idea. It seems better to ask for

the type of each item on the list, and then uses a specialised method.

Note that there are specialised methods such as sage_poly() for

polynomials. However, this requires that you have already a ring in

Sage that matches the basering in Singular.

Anyway, back to the example:

sage: L[1].typeof()

int

sage: Integer(L[1])

32003

sage: L[2][1].typeof()

string

sage: repr(L[2][1])

'x'

sage: L[3].typeof()

list

sage: L[3][1].typeof()

list

sage: L[3][1][1].typeof()

string

sage: repr(L[3][1][1])

'dp'

Etc.

For ideals, one may try to do

sage: singular.eval('ring r = (9,a),(x,y,z),dp')

sage: I = singular.ideal(['x^2','y*z','z+x'])

# First, convert the base ring into Sage

# One needs to do special cases for different types of base rings:

# - integers

# - rational field

# - field extension

# Here, we have a finite field, and may do

sage: RS = singular('basering')

sage: br = GF(*repr(RS.charstr()).split(','))

sage: br

Finite Field in a of size 3^2

sage: vars = [repr(singular.var(i)) for i in range(1,RS.nvars()+1)]

sage: vars

['x', 'y', 'z']

sage: P = br[tuple(vars)]

sage: P

Multivariate Polynomial Ring in x, y, z over Finite Field in a of size

3^2

And then, there is again a case of a feature that should work since a

long time. As I have mentioned above, there is a method sage_poly,

taking a ring as a additional argument. So, why does it not work?

sage: I[1]

x2

sage: I[1].sage_poly(P)

...

TypeError:

There's even no error message.

I suppose what happens here is that I[1].sage_poly(P) tries to use the

string representation, which is a bad thing to do with "x2".

Anyway, IMHO it *should* work to do

sage: P*[p.sage_poly(P) for p in I] # not implemented

Ideal (x^2, x*z, x + z) of Multivariate Polynomial Ring in x, y, z

over Finite Field in a of size 3^2

In the example that you gave, the string representation of polynomials

seems fine (i.e., x^2, not x2). So, there is some hope that it works

for you.

Best regards,

Simon

On 4 Jun., 19:00, Francisco Botana <fbot...@uvigo.es> wrote:

> How can I convert a Singular list to a Sage list?

interface) with L.sage().

However, it doesn't at all. I am really surprised that it doesn't,

because such a feature should have been implemented a long time ago.

Perhaps other people can point us to a solution? For now I can only

offer part of a solution, as sketched below, hoping that you consider

a special case for which the partial solution is enough.

First, L.sage() does not work, e.g., in the following example:

sage: singular.eval('ring R')

sage: L = singular('ringlist(R)')

sage: L

[1]:

32003

[2]:

[1]:

x

[2]:

y

[3]:

z

[3]:

[1]:

[1]:

dp

[2]:

1,1,1

[2]:

[1]:

C

[2]:

0

[4]:

_[1]=0

sage: L.sage()

<KABOOM>

sage: L[1].sage() # that's just an integer!

<KABOOM>

sage: L[2][1].sage() # that's just a string!!

<KABOOM>

> I can get a Sage string (using singular.eval(T)) but it would be more

> convenient getting a (structured) Sage list. Is there a command for

> doing so?

the type of each item on the list, and then uses a specialised method.

Note that there are specialised methods such as sage_poly() for

polynomials. However, this requires that you have already a ring in

Sage that matches the basering in Singular.

Anyway, back to the example:

sage: L[1].typeof()

int

sage: Integer(L[1])

32003

sage: L[2][1].typeof()

string

sage: repr(L[2][1])

'x'

sage: L[3].typeof()

list

sage: L[3][1].typeof()

list

sage: L[3][1][1].typeof()

string

sage: repr(L[3][1][1])

'dp'

Etc.

For ideals, one may try to do

sage: singular.eval('ring r = (9,a),(x,y,z),dp')

sage: I = singular.ideal(['x^2','y*z','z+x'])

# First, convert the base ring into Sage

# One needs to do special cases for different types of base rings:

# - integers

# - rational field

# - field extension

# Here, we have a finite field, and may do

sage: RS = singular('basering')

sage: br = GF(*repr(RS.charstr()).split(','))

sage: br

Finite Field in a of size 3^2

sage: vars = [repr(singular.var(i)) for i in range(1,RS.nvars()+1)]

sage: vars

['x', 'y', 'z']

sage: P = br[tuple(vars)]

sage: P

Multivariate Polynomial Ring in x, y, z over Finite Field in a of size

3^2

And then, there is again a case of a feature that should work since a

long time. As I have mentioned above, there is a method sage_poly,

taking a ring as a additional argument. So, why does it not work?

sage: I[1]

x2

sage: I[1].sage_poly(P)

...

TypeError:

There's even no error message.

I suppose what happens here is that I[1].sage_poly(P) tries to use the

string representation, which is a bad thing to do with "x2".

Anyway, IMHO it *should* work to do

sage: P*[p.sage_poly(P) for p in I] # not implemented

Ideal (x^2, x*z, x + z) of Multivariate Polynomial Ring in x, y, z

over Finite Field in a of size 3^2

In the example that you gave, the string representation of polynomials

seems fine (i.e., x^2, not x2). So, there is some hope that it works

for you.

Best regards,

Simon

Jun 6, 2011, 2:10:31 AM6/6/11

to sage-support

Hi Francisco,

On 5 Jun., 08:26, Simon King <simon.k...@uni-jena.de> wrote:

> Anyway, IMHO it *should* work to do

> sage: P*[p.sage_poly(P) for p in I] # not implemented

My fault: Singular has an optional parameter, determining whether a

short or a long polynomial representation is used. So, I should have

done:

sage: singular.eval('ring R')

'ring R;'

sage: singular.eval('short=0') # That's what I forgot to do

'short=0;'

x^2,

y*z,

x+z

over Finite Field of size 32003

I think the procedure above should be automated (but the term order

should be taken care of as well, I suppose). I'll open a ticket.

Cheers,

Simon

On 5 Jun., 08:26, Simon King <simon.k...@uni-jena.de> wrote:

> Anyway, IMHO it *should* work to do

> sage: P*[p.sage_poly(P) for p in I] # not implemented

short or a long polynomial representation is used. So, I should have

done:

sage: singular.eval('ring R')

sage: singular.eval('short=0') # That's what I forgot to do

'short=0;'

sage: RS = singular('basering')

sage: br = GF(*repr(RS.charstr()).split(','))

sage: br

Finite Field of size 32003
sage: br = GF(*repr(RS.charstr()).split(','))

sage: br

sage: vars = [repr(singular.var(i)) for i in range(1,RS.nvars()+1)]

sage: vars

['x', 'y', 'z']

sage: P = br[tuple(vars)]

sage: vars

['x', 'y', 'z']

sage: P = br[tuple(vars)]

sage: I = singular.ideal(['x^2','y*z','z+x'])

sage: I # now it is a long representation: x^2, not x2
x^2,

y*z,

x+z

sage: P*[p.sage_poly(P) for p in I]

Ideal (x^2, y*z, x + z) of Multivariate Polynomial Ring in x, y, z
over Finite Field of size 32003

I think the procedure above should be automated (but the term order

should be taken care of as well, I suppose). I'll open a ticket.

Cheers,

Simon

Jun 6, 2011, 5:46:09 AM6/6/11

to sage-support

Hi Francisco and all other potential reviewers,

On 6 Jun., 08:10, Simon King <simon.k...@uni-jena.de> wrote:

> I think the procedure above should be automated (but the term order

> should be taken care of as well, I suppose). I'll open a ticket.

It is #11431, and it seems ready for review. One can convert quite

complicated things with the patch. For example:

sage: singular.eval('ring r10 = (9,a), (x,y,z),lp')

'ring r10 = (9,a), (x,y,z),lp;'

sage: Q = singular('std(ideal(x^2,x+y^2+z^3))',

type='qring')

sage: Q.sage()

Quotient of Multivariate Polynomial Ring in x, y, z over

Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x +

y^2 + z^3)

sage: singular('x^2+y').sage()

x^2 + y

sage: singular('x^2+y').sage().parent()

Quotient of Multivariate Polynomial Ring in x, y, z over

Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x +

y^2 + z^3)

Cheers,

Simon

On 6 Jun., 08:10, Simon King <simon.k...@uni-jena.de> wrote:

> I think the procedure above should be automated (but the term order

> should be taken care of as well, I suppose). I'll open a ticket.

complicated things with the patch. For example:

sage: singular.eval('ring r10 = (9,a), (x,y,z),lp')

'ring r10 = (9,a), (x,y,z),lp;'

sage: Q = singular('std(ideal(x^2,x+y^2+z^3))',

type='qring')

sage: Q.sage()

Quotient of Multivariate Polynomial Ring in x, y, z over

Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x +

y^2 + z^3)

sage: singular('x^2+y').sage()

x^2 + y

sage: singular('x^2+y').sage().parent()

Quotient of Multivariate Polynomial Ring in x, y, z over

Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x +

y^2 + z^3)

Cheers,

Simon

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu