Ask Your Question
1

Random errors when using Singular via Sage

asked 2020-04-06 18:07:09 +0100

PaulEbert gravatar image

updated 2020-04-06 18:12:00 +0100

Hello everyone,

I'd like to use Singulars capabilities in solving systems of polynomial equations, however I regularly obtain errors of Singular not recognizing the ring, that is created when executing the solve() command from the solve.lib Singular package. It seems somehow random to me, because the error only appears at about 30% of the time running to programm, so just giving it another try (without making any changes to the code) results in the desired result most of the time.

Here is my code:

C.<x, y> = PolynomialRing(QQ)
f = x^2 +y^2
epsilon = 1
# suggested by "rburing" to my question 'Passing functions to Singular'
# because I need to split f=f1+i*f2 in real and imaginary part
S.<x_1,x_2,y_1,y_2,i> = PolynomialRing(QQ)
F = f.subs({x: x_1 + i*x_2, y: y_1 + i*y_2}).reduce([i^2+1])
f1, f2 = F.polynomial(i).coefficients()
R = singular.ring(0,'(x_1,x_2,y_1,y_2)', 'lp')
g1 = singular.new(str(f1))
g2 = singular.new(str(f2))
g3 = singular.new('x_1^2 + x_2^2 +y_1^2+y_2^2 -' + str(epsilon) + '^2')
# creating the first ideal
I = singular.ideal(g1, g2, g3)
singular.lib("primdec.lib")
singular.lib("solve.lib")
# obtain the simplified components of the solution
components = I.primdecGTZ()
k1_1 = components[1][2][1]
k1_2 = components[1][2][2]
k1_3 = components[1][2][3]
singular.setring(R)
# creating a new ideal containing only the first component
H = singular.ideal(str(k1_1),str(k1_2),str(k1_3))
singular.setring(R)
# I now add another constraint to get two real solutions
# sphere around a point close to the solution
J = singular.ideal(H, '(x_1-0)^2 + (x_2+985/1393)^2 +(y_1-985/1393)^2+(y_2-0)^2 -1/10^2')
T = singular.solve(J)
singular.setring(T)
print(singular.eval('SOL'))

It might seem complicated to create that many Ideals but it is necessary because some of them are needed more often. Executing it 10 times results in 2 to 3 errors of the following kind:

SingularError                             Traceback (most recent call last)
<ipython-input-55-da8b511c4e72> in <module>()
    28 J = singular.ideal(H, '(x_1-0)^2 + (x_2+985/1393)^2 +(y_1-985/1393)^2+(y_2-0)^2 -1/10^2')
    29 T = singular.solve(J)
->  30 singular.setring(T)
    31 print(singular.eval('SOL'))

 /opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/interfaces/singular.py in set_ring(self, R)
    1097         if not isinstance(R, SingularElement):
    1098             raise TypeError("R must be a singular ring")
->  1099         self.eval("setring %s; short=0"%R.name(), allow_semicolon=True)
    1100 
    1101     setring = set_ring

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/interfaces/singular.py in eval(self, x, allow_semicolon,      strip, **kwds)
    657         # Singular actually does use that string
    658         if s.find("error occurred") != -1 or s.find("Segment fault") != -1:
 -> 659             raise SingularError('Singular error:\n%s'%s)
    660 
    661         if get_verbose() > 0:

SingularError: Singular error:
   ? sage2437 is no name of a ring/qring
   ? error occurred in or before STDIN line 746: `setring sage2437; short=0;

Thanks for your help! Greetings Paul

edit retag flag offensive close merge delete

Comments

1

I'll have a look, but in the meantime note that everything you are doing can be done in ordinary PolynomialRings in SageMath (which will use Singular in the background), e.g. using the methods of an ideal primary_decomposition (with argument algorithm='gtz') and variety.

rburing gravatar imagerburing ( 2020-04-06 18:58:34 +0100 )edit

Thanks! I'll try doing in that way and report the result.

PaulEbert gravatar imagePaulEbert ( 2020-04-06 19:04:50 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-04-06 19:33:54 +0100

rburing gravatar image

The answer is that the output of Singular's primdecGTZ is not deterministic; particularly the ordering can change. You implicitly assumed that it was deterministic, by using indices to access the components. Sometimes you get a component which does not intersect your sphere, so J becomes the unit ideal, and hence solve fails.

edit flag offensive delete link more

Comments

1

Thank you for helping me out again! I tried giving the functions to solve() directly and never got an error, one can also see the behavior by printing out I.primdecGTZ(). You mentioned doing in the "Sage-way" with Singular only acting in the background. Do you know about runtime advantages of one over the other?

PaulEbert gravatar imagePaulEbert ( 2020-04-06 20:11:44 +0100 )edit

You're welcome. When using Sage, I find it easiest to use the Sage interface. Mostly for the ease of writing code (which should not be forgotten), but also because the runtime cost compared to using the programs/interfaces directly is often negligible. For example here the most time is probably spent on things like the GTZ algorithm and computing a Gröbner basis (as part of solve). I only use interfaces to other programs directly if it cannot be avoided.

rburing gravatar imagerburing ( 2020-04-06 20:47:31 +0100 )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

Stats

Asked: 2020-04-06 18:07:09 +0100

Seen: 683 times

Last updated: Apr 06 '20