Hi Francisco,

On 4 Jun., 19:00, Francisco Botana <[email protected]> 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

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to