From ec5ac91c55fe5c1c86b25111e850eb81a5c9a7b2 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 25 Feb 2024 20:27:47 +0100 Subject: [PATCH 01/11] Adapt to singular 4.4 API changes --- src/sage/interfaces/singular.py | 7 +++++-- src/sage/libs/singular/decl.pxd | 7 ++++++- src/sage/libs/singular/function.pyx | 12 +++++++----- src/sage/libs/singular/ring.pyx | 4 ++-- src/sage/libs/singular/singular.pxd | 3 ++- src/sage/libs/singular/singular.pyx | 19 +++++++++++++++++++ .../multi_polynomial_libsingular.pyx | 6 +++--- src/sage/rings/polynomial/term_order.py | 2 +- 8 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index dedbebab99c..a8217314506 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1211,14 +1211,14 @@ def current_ring(self): polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 - // block 1 : ordering rp + // block 1 : ordering ip // : names x y z // block 2 : ordering C sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 - // block 1 : ordering rp + // block 1 : ordering ip // : names x y z // block 2 : ordering C """ @@ -2040,6 +2040,9 @@ def _sage_(self, R=None): elif typ == 'intvec': from sage.modules.free_module_element import vector return vector([sage.rings.integer.Integer(str(e)) for e in self]) + elif typ == 'bigintvec': + from sage.modules.free_module_element import vector + return vector([sage.rings.rational.Rational(str(e)) for e in self]) elif typ == 'intmat': from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ diff --git a/src/sage/libs/singular/decl.pxd b/src/sage/libs/singular/decl.pxd index e36216d6395..855c95b00bd 100644 --- a/src/sage/libs/singular/decl.pxd +++ b/src/sage/libs/singular/decl.pxd @@ -243,7 +243,7 @@ cdef extern from "singular/Singular/libsingular.h": ringorder_s ringorder_lp ringorder_dp - ringorder_rp + ringorder_ip ringorder_Dp ringorder_wp ringorder_Wp @@ -291,6 +291,10 @@ cdef extern from "singular/Singular/libsingular.h": int row int col + cdef cppclass bigintmat: + int (*length)() + number* (*get)(int i) + # omalloc bins ctypedef struct omBin "omBin_s" @@ -921,6 +925,7 @@ cdef extern from "singular/Singular/libsingular.h": cdef int MATRIX_CMD cdef int LIST_CMD cdef int INTVEC_CMD + cdef int BIGINTVEC_CMD cdef int NONE cdef int RESOLUTION_CMD cdef int PACKAGE_CMD diff --git a/src/sage/libs/singular/function.pyx b/src/sage/libs/singular/function.pyx index 4a5ab6d78f6..844e070fe74 100644 --- a/src/sage/libs/singular/function.pyx +++ b/src/sage/libs/singular/function.pyx @@ -98,7 +98,7 @@ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence_g from sage.libs.singular.decl cimport * from sage.libs.singular.option import opt_ctx from sage.libs.singular.polynomial cimport singular_vector_maximal_component -from sage.libs.singular.singular cimport sa2si, si2sa, si2sa_intvec +from sage.libs.singular.singular cimport sa2si, si2sa, si2sa_intvec, si2sa_bigintvec from sage.libs.singular.singular import error_messages from sage.interfaces.singular import get_docstring @@ -954,6 +954,8 @@ cdef class Converter(SageObject): return si2sa(to_convert.data, self._singular_ring, self._sage_ring.base_ring()) elif rtyp == INTVEC_CMD: return si2sa_intvec( to_convert.data) + elif rtyp == BIGINTVEC_CMD: + return si2sa_bigintvec( to_convert.data) elif rtyp == STRING_CMD: # TODO: Need to determine what kind of data can be returned by a # STRING_CMD--is it just ASCII strings or can it be an arbitrary @@ -1231,7 +1233,7 @@ cdef class SingularFunction(SageObject): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'size': - Wrong number of arguments (got 2 arguments, arity code is 302) + Wrong number of arguments (got 2 arguments, arity code is 303) sage: size('foobar', ring=P) 6 @@ -1634,17 +1636,17 @@ def singular_function(name): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 0 arguments, arity code is 305) + Wrong number of arguments (got 0 arguments, arity code is 306) sage: factorize(f, 1, 2) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 3 arguments, arity code is 305) + Wrong number of arguments (got 3 arguments, arity code is 306) sage: factorize(f, 1, 2, 3) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 4 arguments, arity code is 305) + Wrong number of arguments (got 4 arguments, arity code is 306) The Singular function ``list`` can be called with any number of arguments:: diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index 0efff45904d..80d77249594 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -24,7 +24,7 @@ from sage.libs.gmp.mpz cimport mpz_init_set_ui from sage.libs.singular.decl cimport ring, currRing from sage.libs.singular.decl cimport rChangeCurrRing, rComplete, rDelete, idInit from sage.libs.singular.decl cimport omAlloc0, omStrDup, omAlloc -from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_rp, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t +from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_ip, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t from sage.libs.singular.decl cimport prCopyR from sage.libs.singular.decl cimport n_unknown, n_algExt, n_transExt, n_Z, n_Zn, n_Znm, n_Z2m from sage.libs.singular.decl cimport n_coeffType @@ -60,7 +60,7 @@ order_dict = { "dp": ringorder_dp, "Dp": ringorder_Dp, "lp": ringorder_lp, - "rp": ringorder_rp, + "ip": ringorder_ip, "ds": ringorder_ds, "Ds": ringorder_Ds, "ls": ringorder_ls, diff --git a/src/sage/libs/singular/singular.pxd b/src/sage/libs/singular/singular.pxd index 05f32b68079..ca31d02456c 100644 --- a/src/sage/libs/singular/singular.pxd +++ b/src/sage/libs/singular/singular.pxd @@ -1,4 +1,4 @@ -from sage.libs.singular.decl cimport ring, poly, number, intvec +from sage.libs.singular.decl cimport ring, poly, number, intvec, bigintmat from sage.libs.singular.function cimport Resolution from sage.rings.rational cimport Rational @@ -29,6 +29,7 @@ cdef object si2sa_ZZmod(number *n, ring *_ring, object base) cdef object si2sa_NF(number *n, ring *_ring, object base) cdef object si2sa_intvec(intvec *v) +cdef object si2sa_bigintvec(bigintmat *v) # dispatches to all the above. cdef object si2sa(number *n, ring *_ring, object base) diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index e256949298e..04634957fca 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -1699,6 +1699,25 @@ cdef object si2sa_intvec(intvec *v): l.append(v.get(r)) return tuple(l) +cdef object si2sa_bigintvec(bigintmat *v) noexcept: + r""" + create a sage tuple from a singular vector of big integers + + INPUT: + + - ``v`` -- a (pointer to) singular bigintmat + + OUTPUT: + + a sage tuple + """ + cdef int r + cdef list l = list() + for r in range(v.length()): + n = v.get(r) + l.append(si2sa_QQ(n, &n, currRing)) + return tuple(l) + # ============== # Initialisation # ============== diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 40fbc8c69aa..d1f17f7f899 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -1285,7 +1285,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): polynomial ring, over a field, global ordering // coefficients: ZZ/2[a]/(a^8+a^4+a^3+a^2+1) // number of vars : 10 - // block 1 : ordering rp + // block 1 : ordering ip // : names x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 // block 2 : ordering C @@ -1294,7 +1294,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 2 - // block 1 : ordering rp + // block 1 : ordering ip // : names x0 x1 // block 2 : ordering C @@ -1303,7 +1303,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 - // block 1 : ordering rp + // block 1 : ordering ip // : names x0 x1 // block 2 : ordering C diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index 4a3e78fe879..ce2faa2e41b 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -388,7 +388,7 @@ singular_name_mapping = { 'lex' : 'lp', - 'invlex' : 'rp', + 'invlex' : 'ip', 'degrevlex' : 'dp', 'deglex' : 'Dp', 'neglex' : 'ls', From 1265e52a7e0aef6fe7d6edccc5511ea535f236c7 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 31 Mar 2024 22:54:20 +0200 Subject: [PATCH 02/11] Support singular older than 4.3.2.p15 too --- src/sage/interfaces/singular.py | 21 +++++++++++++++++-- src/sage/libs/singular/decl.pxd | 1 + src/sage/libs/singular/function.pyx | 8 +++---- src/sage/libs/singular/ring.pyx | 14 ++++++------- .../multi_polynomial_libsingular.pyx | 12 ++++++++--- src/sage/rings/polynomial/term_order.py | 8 ++++++- 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index a8217314506..ca20b90f648 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1206,15 +1206,18 @@ def current_ring(self): EXAMPLES:: + sage: import re sage: r = PolynomialRing(GF(127),3,'xyz', order='invlex') - sage: r._singular_() + sage: rsing = r._singular_() + sage: print(re.sub('ordering rp', 'ordering ip', rsing._repr_())) polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C - sage: singular.current_ring() + sage: curring = singular.current_ring() + sage: print(re.sub('ordering rp', 'ordering ip', curring._repr_())) polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 @@ -2469,6 +2472,20 @@ def singular_version(): return singular.eval('system("--version");') +def singular_version_number(): + """ + Return the version number of Singular being used as a string. + + EXAMPLES:: + + sage: singular.version_number() + '4...' + """ + import re + r = re.compile(r"\((\d+),") + return r.findall(singular_version())[0] + + class SingularGBLogPrettyPrinter: """ A device which prints Singular Groebner basis computation logs diff --git a/src/sage/libs/singular/decl.pxd b/src/sage/libs/singular/decl.pxd index 855c95b00bd..0c260e6e513 100644 --- a/src/sage/libs/singular/decl.pxd +++ b/src/sage/libs/singular/decl.pxd @@ -243,6 +243,7 @@ cdef extern from "singular/Singular/libsingular.h": ringorder_s ringorder_lp ringorder_dp + ringorder_rp ringorder_ip ringorder_Dp ringorder_wp diff --git a/src/sage/libs/singular/function.pyx b/src/sage/libs/singular/function.pyx index 844e070fe74..fc167657639 100644 --- a/src/sage/libs/singular/function.pyx +++ b/src/sage/libs/singular/function.pyx @@ -1233,7 +1233,7 @@ cdef class SingularFunction(SageObject): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'size': - Wrong number of arguments (got 2 arguments, arity code is 303) + Wrong number of arguments (got 2 arguments, arity code is 30...) sage: size('foobar', ring=P) 6 @@ -1636,17 +1636,17 @@ def singular_function(name): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 0 arguments, arity code is 306) + Wrong number of arguments (got 0 arguments, arity code is 30...) sage: factorize(f, 1, 2) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 3 arguments, arity code is 306) + Wrong number of arguments (got 3 arguments, arity code is 30...) sage: factorize(f, 1, 2, 3) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 4 arguments, arity code is 306) + Wrong number of arguments (got 4 arguments, arity code is 30...) The Singular function ``list`` can be called with any number of arguments:: diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index 80d77249594..e7463a90a20 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -24,7 +24,7 @@ from sage.libs.gmp.mpz cimport mpz_init_set_ui from sage.libs.singular.decl cimport ring, currRing from sage.libs.singular.decl cimport rChangeCurrRing, rComplete, rDelete, idInit from sage.libs.singular.decl cimport omAlloc0, omStrDup, omAlloc -from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_ip, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t +from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_ip, ringorder_rp, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t from sage.libs.singular.decl cimport prCopyR from sage.libs.singular.decl cimport n_unknown, n_algExt, n_transExt, n_Z, n_Zn, n_Znm, n_Z2m from sage.libs.singular.decl cimport n_coeffType @@ -50,17 +50,12 @@ from cpython.object cimport Py_EQ, Py_NE from collections import defaultdict - - - - - # mapping str --> SINGULAR representation + order_dict = { "dp": ringorder_dp, "Dp": ringorder_Dp, "lp": ringorder_lp, - "ip": ringorder_ip, "ds": ringorder_ds, "Ds": ringorder_Ds, "ls": ringorder_ls, @@ -71,6 +66,11 @@ order_dict = { "a": ringorder_a, } +from sage.interfaces.singular import singular_version_number +if int(singular_version_number()[0:3]) < 432 or (int(singular_version_number()[0:3]) == 432 and int(singular_version_number()[3:]) < 15): + order_dict["rp"] = ringorder_rp +else: + order_dict["ip"] = ringorder_ip ############################################################################# cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL: diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index d1f17f7f899..a765cd99050 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -1280,8 +1280,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x y // block 2 : ordering C + sage: import re sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex') # needs sage.rings.finite_rings - sage: singular(R) # needs sage.rings.finite_rings + sage: out = singular(R) # needs sage.rings.finite_rings + sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/2[a]/(a^8+a^4+a^3+a^2+1) // number of vars : 10 @@ -1289,8 +1291,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 // block 2 : ordering C + sage: import re sage: R = PolynomialRing(GF(127),2,'x', order='invlex') - sage: singular(R) # needs sage.rings.finite_rings + sage: out = singular(R) # needs sage.rings.finite_rings + sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 2 @@ -1298,8 +1302,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x0 x1 // block 2 : ordering C + sage: import re sage: R = PolynomialRing(QQ,2,'x', order='invlex') - sage: singular(R) # needs sage.rings.function_field + sage: out = singular(R) # needs sage.rings.function_field + sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.function_field polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index ce2faa2e41b..4d78f207622 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -386,9 +386,15 @@ 'negwdeglex' : 'Negative weighted degree lexicographic', } +from sage.interfaces.singular import singular_version_number +if int(singular_version_number()[0:3]) < 432 or (int(singular_version_number()[0:3]) == 432 and int(singular_version_number()[3:]) < 15): + invlex_singular_name = 'rp' +else: + invlex_singular_name = 'ip' + singular_name_mapping = { 'lex' : 'lp', - 'invlex' : 'ip', + 'invlex' : invlex_singular_name, 'degrevlex' : 'dp', 'deglex' : 'Dp', 'neglex' : 'ls', From f2319306fbae3a095506d8aca833c7e939c8b732 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 31 Mar 2024 22:58:36 +0200 Subject: [PATCH 03/11] Remove noexcept keyword MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gonzalo TornarĂ­a --- src/sage/libs/singular/singular.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index 04634957fca..014effa9e3f 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -1699,7 +1699,7 @@ cdef object si2sa_intvec(intvec *v): l.append(v.get(r)) return tuple(l) -cdef object si2sa_bigintvec(bigintmat *v) noexcept: +cdef object si2sa_bigintvec(bigintmat *v): r""" create a sage tuple from a singular vector of big integers From 08db5bd0d9720cbe04b4d14143d8965e11eab4d0 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Tue, 9 Apr 2024 09:11:05 +0200 Subject: [PATCH 04/11] Revert "Support singular older than 4.3.2.p15 too" This reverts commit ad3aa564986cb33468c341a18f70ff3a328e38d7. --- src/sage/interfaces/singular.py | 21 ++----------------- src/sage/libs/singular/decl.pxd | 1 - src/sage/libs/singular/function.pyx | 8 +++---- src/sage/libs/singular/ring.pyx | 14 ++++++------- .../multi_polynomial_libsingular.pyx | 12 +++-------- src/sage/rings/polynomial/term_order.py | 8 +------ 6 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index ca20b90f648..a8217314506 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1206,18 +1206,15 @@ def current_ring(self): EXAMPLES:: - sage: import re sage: r = PolynomialRing(GF(127),3,'xyz', order='invlex') - sage: rsing = r._singular_() - sage: print(re.sub('ordering rp', 'ordering ip', rsing._repr_())) + sage: r._singular_() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C - sage: curring = singular.current_ring() - sage: print(re.sub('ordering rp', 'ordering ip', curring._repr_())) + sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 @@ -2472,20 +2469,6 @@ def singular_version(): return singular.eval('system("--version");') -def singular_version_number(): - """ - Return the version number of Singular being used as a string. - - EXAMPLES:: - - sage: singular.version_number() - '4...' - """ - import re - r = re.compile(r"\((\d+),") - return r.findall(singular_version())[0] - - class SingularGBLogPrettyPrinter: """ A device which prints Singular Groebner basis computation logs diff --git a/src/sage/libs/singular/decl.pxd b/src/sage/libs/singular/decl.pxd index 0c260e6e513..855c95b00bd 100644 --- a/src/sage/libs/singular/decl.pxd +++ b/src/sage/libs/singular/decl.pxd @@ -243,7 +243,6 @@ cdef extern from "singular/Singular/libsingular.h": ringorder_s ringorder_lp ringorder_dp - ringorder_rp ringorder_ip ringorder_Dp ringorder_wp diff --git a/src/sage/libs/singular/function.pyx b/src/sage/libs/singular/function.pyx index fc167657639..844e070fe74 100644 --- a/src/sage/libs/singular/function.pyx +++ b/src/sage/libs/singular/function.pyx @@ -1233,7 +1233,7 @@ cdef class SingularFunction(SageObject): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'size': - Wrong number of arguments (got 2 arguments, arity code is 30...) + Wrong number of arguments (got 2 arguments, arity code is 303) sage: size('foobar', ring=P) 6 @@ -1636,17 +1636,17 @@ def singular_function(name): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 0 arguments, arity code is 30...) + Wrong number of arguments (got 0 arguments, arity code is 306) sage: factorize(f, 1, 2) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 3 arguments, arity code is 30...) + Wrong number of arguments (got 3 arguments, arity code is 306) sage: factorize(f, 1, 2, 3) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 4 arguments, arity code is 30...) + Wrong number of arguments (got 4 arguments, arity code is 306) The Singular function ``list`` can be called with any number of arguments:: diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index e7463a90a20..80d77249594 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -24,7 +24,7 @@ from sage.libs.gmp.mpz cimport mpz_init_set_ui from sage.libs.singular.decl cimport ring, currRing from sage.libs.singular.decl cimport rChangeCurrRing, rComplete, rDelete, idInit from sage.libs.singular.decl cimport omAlloc0, omStrDup, omAlloc -from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_ip, ringorder_rp, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t +from sage.libs.singular.decl cimport ringorder_dp, ringorder_Dp, ringorder_lp, ringorder_ip, ringorder_ds, ringorder_Ds, ringorder_ls, ringorder_M, ringorder_c, ringorder_C, ringorder_wp, ringorder_Wp, ringorder_ws, ringorder_Ws, ringorder_a, rRingOrder_t from sage.libs.singular.decl cimport prCopyR from sage.libs.singular.decl cimport n_unknown, n_algExt, n_transExt, n_Z, n_Zn, n_Znm, n_Z2m from sage.libs.singular.decl cimport n_coeffType @@ -50,12 +50,17 @@ from cpython.object cimport Py_EQ, Py_NE from collections import defaultdict -# mapping str --> SINGULAR representation + + + + +# mapping str --> SINGULAR representation order_dict = { "dp": ringorder_dp, "Dp": ringorder_Dp, "lp": ringorder_lp, + "ip": ringorder_ip, "ds": ringorder_ds, "Ds": ringorder_Ds, "ls": ringorder_ls, @@ -66,11 +71,6 @@ order_dict = { "a": ringorder_a, } -from sage.interfaces.singular import singular_version_number -if int(singular_version_number()[0:3]) < 432 or (int(singular_version_number()[0:3]) == 432 and int(singular_version_number()[3:]) < 15): - order_dict["rp"] = ringorder_rp -else: - order_dict["ip"] = ringorder_ip ############################################################################# cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL: diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index a765cd99050..d1f17f7f899 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -1280,10 +1280,8 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x y // block 2 : ordering C - sage: import re sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex') # needs sage.rings.finite_rings - sage: out = singular(R) # needs sage.rings.finite_rings - sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.finite_rings + sage: singular(R) # needs sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/2[a]/(a^8+a^4+a^3+a^2+1) // number of vars : 10 @@ -1291,10 +1289,8 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 // block 2 : ordering C - sage: import re sage: R = PolynomialRing(GF(127),2,'x', order='invlex') - sage: out = singular(R) # needs sage.rings.finite_rings - sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.finite_rings + sage: singular(R) # needs sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 2 @@ -1302,10 +1298,8 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // : names x0 x1 // block 2 : ordering C - sage: import re sage: R = PolynomialRing(QQ,2,'x', order='invlex') - sage: out = singular(R) # needs sage.rings.function_field - sage: print(re.sub('ordering rp', 'ordering ip', out._repr_())) # needs sage.rings.function_field + sage: singular(R) # needs sage.rings.function_field polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index 4d78f207622..ce2faa2e41b 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -386,15 +386,9 @@ 'negwdeglex' : 'Negative weighted degree lexicographic', } -from sage.interfaces.singular import singular_version_number -if int(singular_version_number()[0:3]) < 432 or (int(singular_version_number()[0:3]) == 432 and int(singular_version_number()[3:]) < 15): - invlex_singular_name = 'rp' -else: - invlex_singular_name = 'ip' - singular_name_mapping = { 'lex' : 'lp', - 'invlex' : invlex_singular_name, + 'invlex' : 'ip', 'degrevlex' : 'dp', 'deglex' : 'Dp', 'neglex' : 'ls', From 14586f1fd4b26d5f91c390747466d5ea034b13d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sat, 6 Apr 2024 19:28:44 -0300 Subject: [PATCH 05/11] singular: add a doctest for bigintvec coercion Function `hilb` now returns a `bigintvec` object and the coercion to a sage vector was implemented in the previous commit. Here we add a doctest for this coercion. --- src/sage/interfaces/singular.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index a8217314506..6fa786c7d7e 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -2025,6 +2025,10 @@ def _sage_(self, R=None): sage: type(singular(int(5)).sage()) + Test that bigintvec can be coerced:: + + sage: singular('hilb((ideal(x)), 1)').sage() + (1, -1, 0, 0, -1, 1, 0) """ typ = self.type() if typ == 'poly': From 729e77d16690f5a053a4ae03894c84e79fed3c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sat, 6 Apr 2024 19:29:15 -0300 Subject: [PATCH 06/11] singular: print arity as a symbol name This makes the output independent of changes in the version of singular --- src/sage/libs/singular/function.pyx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/sage/libs/singular/function.pyx b/src/sage/libs/singular/function.pyx index 844e070fe74..5c333e8d7e6 100644 --- a/src/sage/libs/singular/function.pyx +++ b/src/sage/libs/singular/function.pyx @@ -1050,6 +1050,17 @@ cdef class LibraryCallHandler(BaseCallHandler): """ return False +# mapping int --> string for function arity +arity_dict = { + CMD_1: "CMD_1", + CMD_2: "CMD_2", + CMD_3: "CMD_3", + CMD_12: "CMD_12", + CMD_13: "CMD_13", + CMD_23: "CMD_23", + CMD_123: "CMD_123", + CMD_M: "CMD_M" +} cdef class KernelCallHandler(BaseCallHandler): """ @@ -1127,8 +1138,9 @@ cdef class KernelCallHandler(BaseCallHandler): errorreported += 1 error_messages.append( - "Wrong number of arguments (got {} arguments, arity code is {})" - .format(number_of_arguments, self.arity)) + "Wrong number of arguments (got {} arguments, arity is {})" + .format(number_of_arguments, + arity_dict.get(self.arity) or self.arity)) return NULL cdef bint free_res(self) noexcept: @@ -1233,7 +1245,7 @@ cdef class SingularFunction(SageObject): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'size': - Wrong number of arguments (got 2 arguments, arity code is 303) + Wrong number of arguments (got 2 arguments, arity is CMD_1) sage: size('foobar', ring=P) 6 @@ -1636,17 +1648,17 @@ def singular_function(name): Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 0 arguments, arity code is 306) + Wrong number of arguments (got 0 arguments, arity is CMD_12) sage: factorize(f, 1, 2) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 3 arguments, arity code is 306) + Wrong number of arguments (got 3 arguments, arity is CMD_12) sage: factorize(f, 1, 2, 3) Traceback (most recent call last): ... RuntimeError: error in Singular function call 'factorize': - Wrong number of arguments (got 4 arguments, arity code is 306) + Wrong number of arguments (got 4 arguments, arity is CMD_12) The Singular function ``list`` can be called with any number of arguments:: From e04869ff6e690cc5d0158981158905e95f8b3287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sat, 6 Apr 2024 19:29:21 -0300 Subject: [PATCH 07/11] singular: compatibility for 4.3.2p10 and before Add two fallback compatibility `#define`s: - `ringorder_ip` - `BIGINTVEC_CMD` Also for old singular: - patch the term_order mappings to send `rp` to singular instead of `ip` - patch the display of a ring so it prints `ip` instead of `rp` --- src/sage/interfaces/singular.py | 7 +++++++ src/sage/libs/singular/decl.pxd | 7 +++++++ src/sage/libs/singular/ring.pyx | 12 +++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index 6fa786c7d7e..5e5463dbb83 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1402,6 +1402,13 @@ def _repr_(self): if self._name in s: if self.get_custom_name() is None and self.type() == 'matrix': s = self.parent().eval('pmat(%s,20)' % (self.name())) + # compatibility for singular 4.3.2p10 and before + if s.startswith("polynomial ring,"): + from sage.rings.polynomial.term_order import singular_name_mapping + # this is our cue that singular uses `rp` instead of `ip` + if singular_name_mapping['invlex'] == 'rp': + s = re.sub('^(// .*block.* : ordering )rp$', '\\1ip', + s, 0, re.MULTILINE); return s def __copy__(self): diff --git a/src/sage/libs/singular/decl.pxd b/src/sage/libs/singular/decl.pxd index 855c95b00bd..3affdb34e11 100644 --- a/src/sage/libs/singular/decl.pxd +++ b/src/sage/libs/singular/decl.pxd @@ -48,6 +48,13 @@ cdef extern from "factory/factory.h": cdef int SW_USE_NTL_SORT cdef extern from "singular/Singular/libsingular.h": + """ + // compatibility for singular 4.3.2p10 and before + #if SINGULAR_VERSION <= 4330 + #define ringorder_ip ringorder_rp + #define BIGINTVEC_CMD INTVEC_CMD + #endif + """ # # OPTIONS diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index 80d77249594..b3295206e5b 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -16,7 +16,7 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.cpython.string cimport str_to_bytes +from sage.cpython.string cimport str_to_bytes, bytes_to_str from sage.libs.gmp.types cimport __mpz_struct from sage.libs.gmp.mpz cimport mpz_init_set_ui @@ -71,6 +71,16 @@ order_dict = { "a": ringorder_a, } +cdef extern from "singular/Singular/libsingular.h": + cdef char * rSimpleOrdStr(rRingOrder_t) + +if bytes_to_str(rSimpleOrdStr(ringorder_ip)) == "rp": + # compatibility for singular 4.3.2p10 and before + order_dict["rp"] = ringorder_ip + # also patch term_order mappings + from sage.rings.polynomial import term_order + term_order.singular_name_mapping['invlex'] = 'rp' + term_order.inv_singular_name_mapping['rp'] = 'invlex' ############################################################################# cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL: From d999b201a21f747f2c049ee2eafbda58f0e9c889 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 14 Apr 2024 14:20:26 +0200 Subject: [PATCH 08/11] Only replace the Singular ordering string in doctests --- src/sage/interfaces/singular.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index 5e5463dbb83..59cd9a8afcd 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1405,8 +1405,9 @@ def _repr_(self): # compatibility for singular 4.3.2p10 and before if s.startswith("polynomial ring,"): from sage.rings.polynomial.term_order import singular_name_mapping + from sage.repl.rich_output import get_display_manager # this is our cue that singular uses `rp` instead of `ip` - if singular_name_mapping['invlex'] == 'rp': + if singular_name_mapping['invlex'] == 'rp' and 'doctest' in str(get_display_manager()): s = re.sub('^(// .*block.* : ordering )rp$', '\\1ip', s, 0, re.MULTILINE); return s From fe83636308bf1fba6c5e1feee4e52281d1a93c83 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 9 Mar 2024 00:07:41 -0800 Subject: [PATCH 09/11] build/pkgs/singular: Update to 4.3.2p16 --- build/pkgs/singular/checksums.ini | 6 +++--- build/pkgs/singular/package-version.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/pkgs/singular/checksums.ini b/build/pkgs/singular/checksums.ini index 40ba7b3153f..34e88e385b4 100644 --- a/build/pkgs/singular/checksums.ini +++ b/build/pkgs/singular/checksums.ini @@ -1,5 +1,5 @@ tarball=singular-VERSION.tar.gz -sha1=0dd736f26935ed72999bb9a4bbb98c6df18ab9ea -md5=0f9368193bad9a0c3dc84545b2404761 -cksum=1698641648 +sha1=8353ecad136806922061e4e13ce34ec7c8689719 +md5=c14594039817cd77ae74c75901262dbb +cksum=3489246459 upstream_url=ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/SOURCES/4-3-2/singular-VERSION.tar.gz diff --git a/build/pkgs/singular/package-version.txt b/build/pkgs/singular/package-version.txt index 7801ff9a882..935ba26c9ba 100644 --- a/build/pkgs/singular/package-version.txt +++ b/build/pkgs/singular/package-version.txt @@ -1 +1 @@ -4.3.2p8 +4.3.2p16 From 2f5bcf667f91002085d76f0becf47a54ac3f12d3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 24 Apr 2024 00:19:53 -0700 Subject: [PATCH 10/11] build/pkgs/flint/spkg-configure.m4: Accept FLINT 3.1.x --- build/pkgs/flint/spkg-configure.m4 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/pkgs/flint/spkg-configure.m4 b/build/pkgs/flint/spkg-configure.m4 index ddf60b596fd..4c1a347152d 100644 --- a/build/pkgs/flint/spkg-configure.m4 +++ b/build/pkgs/flint/spkg-configure.m4 @@ -3,12 +3,12 @@ SAGE_SPKG_CONFIGURE([flint], [ AC_CHECK_HEADER(flint/flint.h, [dnl dnl gr_get_fexpr appears in Flint 3.0 AC_SEARCH_LIBS([gr_get_fexpr], [flint], [dnl - dnl Flint 3.1 is too new - AC_MSG_CHECKING([whether FLINT version is >= 3.1.0]) + dnl Assume Flint 3.2 is too new + AC_MSG_CHECKING([whether FLINT version is >= 3.2.0]) AC_COMPILE_IFELSE([dnl AC_LANG_PROGRAM([[#include - #if __FLINT_RELEASE >= 30100 - # error "FLINT 3.1 is too new" + #if __FLINT_RELEASE >= 30200 + # error "FLINT 3.2 is too new" #endif ]]) ], [dnl From 6cd10a27cc07cbd1c990887c1ef9ba0f69552588 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 May 2024 16:56:06 -0700 Subject: [PATCH 11/11] build/pkgs/singular: Update to 4.4.0 --- build/pkgs/singular/checksums.ini | 8 ++++---- build/pkgs/singular/package-version.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/pkgs/singular/checksums.ini b/build/pkgs/singular/checksums.ini index 34e88e385b4..3273f5f7055 100644 --- a/build/pkgs/singular/checksums.ini +++ b/build/pkgs/singular/checksums.ini @@ -1,5 +1,5 @@ tarball=singular-VERSION.tar.gz -sha1=8353ecad136806922061e4e13ce34ec7c8689719 -md5=c14594039817cd77ae74c75901262dbb -cksum=3489246459 -upstream_url=ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/SOURCES/4-3-2/singular-VERSION.tar.gz +sha1=1f678e1cc756fd8dc29dcdef5ae67441b6bcc779 +md5=09382cdacbfe67b4099056b65c2ec016 +cksum=244065751 +upstream_url=ftp://jim.mathematik.uni-kl.de/pub/Math/Singular/SOURCES/${VERSION_MAJOR}-${VERSION_MINOR}-${VERSION_MICRO}/singular-VERSION.tar.gz diff --git a/build/pkgs/singular/package-version.txt b/build/pkgs/singular/package-version.txt index 935ba26c9ba..fdc6698807a 100644 --- a/build/pkgs/singular/package-version.txt +++ b/build/pkgs/singular/package-version.txt @@ -1 +1 @@ -4.3.2p16 +4.4.0