Ask Your Question

Using Singular's solve.lib

asked 2018-01-05 21:35:56 -0600

jaebond gravatar image

I am trying to use Singular's solve.lib from Sage, but I am running into issues with getting the result out of Singular. I tried using the Singular interface and was able to make it this far:

sage: singular.lib('solve.lib')
sage: r = singular.ring('complex', '(x,y)', 'lp')
sage: I = singular.ideal('(x-5)*y/32', 'y^2-x^3-5*x-10')
sage: R = singular.fglm_solve(I)
sage: singular.setring(R)

at which point the result is stored in a list rlist inside of R. I can do singular.eval('rlist') and see the answer, but in order to get it back into Sage I would have to parse the resulting string. Is there a better way to get rlist?

Alternatively, I tried to use libSingular as follows:

sage: from sage.libs.singular.function import singular_function, lib
sage: lib('solve.lib')
sage: fglm_solve = singular_function('fglm_solve')
sage: P = PolynomialRing(QQ,'x,y',order='lex'); x,y = P.gens()
sage: I = Ideal((x-5)*y/32, y^2-x^3-5*x-10)
sage: R = fglm_solve(I)

// 'fglm_solve' created a ring, in which a list rlist of numbers (the
// complex solutions) is stored.
// To access the list of complex solutions, type (if the name R was assigned
// to the return value):
        setring R; rlist; 

But then R is a <RingWrap> instance and this time I don't even know how to go about seeing the answer. Also, I would prefer to work over the complex field, but I couldn't get fglm_solve to accept an ideal in CC['x,y']

Any help in either direction would be greatly appreciated.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2018-01-06 11:16:35 -0600

jaebond gravatar image

updated 2018-01-06 11:48:52 -0600

Looking in src/sage/interfaces/ as suggested by @tmonteil, I noticed in some of the docstrings that the way to get at a Singular object is singular('obj_name'). Continuing the first example from the question, rlist can be accessed with singular('rlist'). Although it is still a Singular list, it can be indexed into, iterated over, etc. So something like the following will work:

sage: [[coord for coord in sol] for sol in singular('rlist')]

Again, the elements are still Singular objects, but one (perhaps rudimentary) way to convert them is

sage: [[sage_eval(coord._sage_repr()) for coord in sol] for sol in singular('rlist')]

Perhaps more robust than sage_eval and ._sage_repr() would be using .repart() and .impart() (which are the Singular functions for real and imaginary part):

sage: [[ComplexNumber(coord.repart(), coord.impart()) for coord in sol] for sol in singular('rlist')]

Note that ComplexNumber has an optional min_prec argument to control the precision of the ComplexField used to create the number, so that if the computations are performed at a high precision in Singular, the same precision can be ensured in Sage.

edit flag offensive delete link more

answered 2018-01-06 08:57:15 -0600

tmonteil gravatar image

I will not solve your interface problem, but you could search for inspiration in the file src/sage/interfaces/

I would however suggest the Sage way:

You can get the set of somutions by looking to the variety of the ideal:

sage: I
Ideal (1/32*x*y - 5/32*y, -x^3 - 5*x + y^2 - 10) of Multivariate Polynomial Ring in x, y over Rational Field
sage: I.variety()

As you can see, there is no rational solution. So, let me suggest to solve the system over the algebraic field:

sage: P = PolynomialRing(QQbar,'x,y',order='lex'); x,y = P.gens()
sage: I = Ideal((x-5)*y/32, y^2-x^3-5*x-10)
sage: I
Ideal (1/32*x*y + (-5/32)*y, -x^3 + (-5)*x + y^2 - 10) of Multivariate Polynomial Ring in x, y over Algebraic Field
sage: I.variety()
[{y: -12.64911064067352?, x: 5},
 {y: 0, x: -1.423318344753072?},
 {y: 0, x: 0.7116591723765360? - 2.553306940593506?*I},
 {y: 0, x: 0.7116591723765360? + 2.553306940593506?*I},
 {y: 12.64911064067352?, x: 5}]
edit flag offensive delete link more


When I tried I.variety(), Sage printed verbose 0 (3324:, groebner_basis) Warning: falling back to very slow toy implementation., so it looks like Sage is still using Groebner bases, just with a slower implementation. Is this accurate?

jaebond gravatar imagejaebond ( 2018-01-06 11:03:29 -0600 )edit

Indeed, for the algebraic field, the computation is done by Sage itself, not singular.

tmonteil gravatar imagetmonteil ( 2018-01-06 11:13:05 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-01-05 21:35:56 -0600

Seen: 34 times

Last updated: Jan 06