ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 06 Apr 2020 13:47:31 -0500Random errors when using Singular via Sagehttps://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/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 PaulMon, 06 Apr 2020 11:07:09 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/Comment by rburing for <p>Hello everyone,</p>
<p>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.</p>
<p>Here is my code:</p>
<pre><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'))
</code></pre>
<p>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:</p>
<pre><code>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;
</code></pre>
<p>Thanks for your help! Greetings Paul</p>
https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50602#post-id-50602I'll have a look, but in the meantime note that everything you are doing can be done in ordinary `PolynomialRing`s 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`.Mon, 06 Apr 2020 11:58:34 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50602#post-id-50602Comment by PaulEbert for <p>Hello everyone,</p>
<p>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.</p>
<p>Here is my code:</p>
<pre><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'))
</code></pre>
<p>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:</p>
<pre><code>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;
</code></pre>
<p>Thanks for your help! Greetings Paul</p>
https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50603#post-id-50603Thanks! I'll try doing in that way and report the result.Mon, 06 Apr 2020 12:04:50 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50603#post-id-50603Answer by rburing for <p>Hello everyone,</p>
<p>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.</p>
<p>Here is my code:</p>
<pre><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'))
</code></pre>
<p>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:</p>
<pre><code>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;
</code></pre>
<p>Thanks for your help! Greetings Paul</p>
https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?answer=50604#post-id-50604The 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.Mon, 06 Apr 2020 12:33:54 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?answer=50604#post-id-50604Comment by rburing for <p>The answer is that the output of Singular's <code>primdecGTZ</code> 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 <code>J</code> becomes the unit ideal, and hence <code>solve</code> fails.</p>
https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50606#post-id-50606You'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.Mon, 06 Apr 2020 13:47:31 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50606#post-id-50606Comment by PaulEbert for <p>The answer is that the output of Singular's <code>primdecGTZ</code> 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 <code>J</code> becomes the unit ideal, and hence <code>solve</code> fails.</p>
https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50605#post-id-50605Thank 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?Mon, 06 Apr 2020 13:11:44 -0500https://ask.sagemath.org/question/50599/random-errors-when-using-singular-via-sage/?comment=50605#post-id-50605