Opened 15 months ago

Last modified 15 months ago

#26300 new defect

Fix side-effect of errors in singular_function

Reported by: SimonKing Owned by:
Priority: major Milestone: sage-8.4
Component: commutative algebra Keywords: singular function error side-effect
Cc: tscrim Merged in:
Authors: Reviewers:
Report Upstream: Not yet reported upstream; Will do shortly. Work issues:
Branch: Commit:
Dependencies: #20145 Stopgaps:

Description

Working on #20145, I found that an error raised in a singular function can have a side-effect:

sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens(); M = Matrix(n, x)
sage: Minors = P.ideal(M.minors(2))
sage: hp = Minors.hilbert_polynomial(); hp
1/21772800*t^13 + 61/21772800*t^12 + 1661/21772800*t^11 + 26681/21772800*t^10 + 93841/7257600*t^9 + 685421/7257600*t^8 + 1524809/3110400*t^7 + 39780323/21772800*t^6 + 6638071/1360800*t^5 + 12509761/1360800*t^4 + 2689031/226800*t^3 + 1494509/151200*t^2 + 12001/2520*t + 1
sage: Minors.hilbert_polynomial(algorithm = 'singular')
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: Error raised calling singular function
Exception RuntimeError: RuntimeError('Error raised calling singular function',) in 'sage.libs.singular.function.LibraryCallHandler.handle_call' ignored
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-bfe31fe9a36b> in <module>()
----> 1 Minors.hilbert_polynomial(algorithm = 'singular')

/home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc in __call__(self, *args, **kwds)
    295         if not R.base_ring().is_field():
    296             raise ValueError("Coefficient ring must be a field for function '%s'."%(self.f.__name__))
--> 297         return self.f(self._instance, *args, **kwds)
    298 
    299 require_field = RequireField

/home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc in hilbert_polynomial(self, algorithm)
   2466             hilbPoly = sage.libs.singular.function_factory.ff.poly__lib.hilbPoly
   2467 
-> 2468             hp = hilbPoly(self)
   2469             t = ZZ['t'].gen()
   2470             fp = ZZ(len(hp)-1).factorial()

/home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/libs/singular/function.pyx in sage.libs.singular.function.SingularFunction.__call__ (build/cythonized/sage/libs/singular/function.cpp:15394)()
   1328         if not (isinstance(ring, MPolynomialRing_libsingular) or isinstance(ring, NCPolynomialRing_plural)):
   1329             raise TypeError("Cannot call Singular function '%s' with ring parameter of type '%s'"%(self._name,type(ring)))
-> 1330         return call_function(self, args, ring, interruptible, attributes)
   1331 
   1332     def _instancedoc_(self):

/home/king/Sage/git/sage/local/lib/python2.7/site-packages/sage/libs/singular/function.pyx in sage.libs.singular.function.call_function (build/cythonized/sage/libs/singular/function.cpp:17499)()
   1526     if errorreported:
   1527         errorreported = 0
-> 1528         raise RuntimeError("error in Singular function call %r:\n%s" %
   1529             (self._name, "\n".join(error_messages)))
   1530 

RuntimeError: error in Singular function call 'hilbPoly':
int overflow in hilb 1
error occurred in or before poly.lib::hilbPoly line 58: `   intvec v=hilb(I,2);`
expected intvec-expression. type 'help intvec;'
sage: P.<x,y,z> = PolynomialRing(QQ)
sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5])
sage: I.hilbert_series()
   skipping text from `parameter`
(t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1)
sage: P.<x,y,z> = PolynomialRing(QQ)
sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5])
sage: I.hilbert_series()
(t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1)

The side-effect is that skipping text from 'parameter' is printed.

Change History (7)

comment:1 Changed 15 months ago by SimonKing

Note the error within the error:

RuntimeError: Error raised calling singular function
Exception RuntimeError: RuntimeError('Error raised calling singular function',) in 'sage.libs.singular.function.LibraryCallHandler.handle_call' ignored

Could it be that because of an error in the call handler the error log is left in an invalid state?

comment:2 Changed 15 months ago by SimonKing

It is a bug to raise an error in a cdef method that has no except value. However, not raising the error in handle_call does not make the side-effect disappear.

comment:3 Changed 15 months ago by SimonKing

Adding an except value to call_handle does have the effect that the error message changes to "Error calling singular function", which is not very informative. The side-effect however remains.

comment:4 Changed 15 months ago by SimonKing

I found that the line "skipping text from parameter" is printed during the line

         cdef bint error = iiMake_proc(self.proc_idhdl, NULL, argument_list.args)

in LibraryCallHandler.handle_call.

Is iiMake_proc from libsingular? Then perhaps the side-effect is a bug in libsingular, not Sage.

comment:5 Changed 15 months ago by SimonKing

  • Report Upstream changed from N/A to Not yet reported upstream; Will do shortly.

comment:6 Changed 15 months ago by SimonKing

I have not been able to reproduce the problem using Singular directly.

The line "skipping text from" is printed during Singular's macro YY_USER_ACTION (defined in scanner.cc, scanner.l and scanner.ll), provided ((inerror==1)&&(*yytext>=' ')). So, apparently either inerror or yytext has not the correct value. But why?

comment:7 Changed 15 months ago by SimonKing

I also tried to create a sequence of singular_function calls, but couldn't reproduce the side-effect. Really tricky.

Note: See TracTickets for help on using tickets.