Skip to content

Commit 721fc79

Browse files
author
Release Manager
committed
gh-37492: make sagelib work with singular>=4.3.2.p15 (future 4.4) Two major breaking changes: - The `rp` ordering is renamed to `ip` - `hilb` now returns a `bigintvec` object (which isn't even exposed in the C++ API, seems to be an instance of `bigintmat`) This branch builds and works fine with 4.3.2.p15, but I have no idea how to make it work with both old and new singular, suggestions welcome. URL: #37492 Reported by: Antonio Rojas Reviewer(s): Antonio Rojas, Gonzalo Tornaría, Matthias Köppe
2 parents 2d77ac5 + d999b20 commit 721fc79

File tree

8 files changed

+89
-18
lines changed

8 files changed

+89
-18
lines changed

src/sage/interfaces/singular.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,14 @@ def current_ring(self):
12111211
polynomial ring, over a field, global ordering
12121212
// coefficients: ZZ/127
12131213
// number of vars : 3
1214-
// block 1 : ordering rp
1214+
// block 1 : ordering ip
12151215
// : names x y z
12161216
// block 2 : ordering C
12171217
sage: singular.current_ring()
12181218
polynomial ring, over a field, global ordering
12191219
// coefficients: ZZ/127
12201220
// number of vars : 3
1221-
// block 1 : ordering rp
1221+
// block 1 : ordering ip
12221222
// : names x y z
12231223
// block 2 : ordering C
12241224
"""
@@ -1402,6 +1402,14 @@ def _repr_(self):
14021402
if self._name in s:
14031403
if self.get_custom_name() is None and self.type() == 'matrix':
14041404
s = self.parent().eval('pmat(%s,20)' % (self.name()))
1405+
# compatibility for singular 4.3.2p10 and before
1406+
if s.startswith("polynomial ring,"):
1407+
from sage.rings.polynomial.term_order import singular_name_mapping
1408+
from sage.repl.rich_output import get_display_manager
1409+
# this is our cue that singular uses `rp` instead of `ip`
1410+
if singular_name_mapping['invlex'] == 'rp' and 'doctest' in str(get_display_manager()):
1411+
s = re.sub('^(// .*block.* : ordering )rp$', '\\1ip',
1412+
s, 0, re.MULTILINE);
14051413
return s
14061414

14071415
def __copy__(self):
@@ -2025,6 +2033,10 @@ def _sage_(self, R=None):
20252033
sage: type(singular(int(5)).sage())
20262034
<class 'sage.rings.integer.Integer'>
20272035
2036+
Test that bigintvec can be coerced::
2037+
2038+
sage: singular('hilb((ideal(x)), 1)').sage()
2039+
(1, -1, 0, 0, -1, 1, 0)
20282040
"""
20292041
typ = self.type()
20302042
if typ == 'poly':
@@ -2040,6 +2052,9 @@ def _sage_(self, R=None):
20402052
elif typ == 'intvec':
20412053
from sage.modules.free_module_element import vector
20422054
return vector([sage.rings.integer.Integer(str(e)) for e in self])
2055+
elif typ == 'bigintvec':
2056+
from sage.modules.free_module_element import vector
2057+
return vector([sage.rings.rational.Rational(str(e)) for e in self])
20432058
elif typ == 'intmat':
20442059
from sage.matrix.constructor import matrix
20452060
from sage.rings.integer_ring import ZZ

src/sage/libs/singular/decl.pxd

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ cdef extern from "factory/factory.h":
4848
cdef int SW_USE_NTL_SORT
4949

5050
cdef extern from "singular/Singular/libsingular.h":
51+
"""
52+
// compatibility for singular 4.3.2p10 and before
53+
#if SINGULAR_VERSION <= 4330
54+
#define ringorder_ip ringorder_rp
55+
#define BIGINTVEC_CMD INTVEC_CMD
56+
#endif
57+
"""
5158

5259
#
5360
# OPTIONS
@@ -243,7 +250,7 @@ cdef extern from "singular/Singular/libsingular.h":
243250
ringorder_s
244251
ringorder_lp
245252
ringorder_dp
246-
ringorder_rp
253+
ringorder_ip
247254
ringorder_Dp
248255
ringorder_wp
249256
ringorder_Wp
@@ -291,6 +298,10 @@ cdef extern from "singular/Singular/libsingular.h":
291298
int row
292299
int col
293300

301+
cdef cppclass bigintmat:
302+
int (*length)()
303+
number* (*get)(int i)
304+
294305
# omalloc bins
295306

296307
ctypedef struct omBin "omBin_s"
@@ -921,6 +932,7 @@ cdef extern from "singular/Singular/libsingular.h":
921932
cdef int MATRIX_CMD
922933
cdef int LIST_CMD
923934
cdef int INTVEC_CMD
935+
cdef int BIGINTVEC_CMD
924936
cdef int NONE
925937
cdef int RESOLUTION_CMD
926938
cdef int PACKAGE_CMD

src/sage/libs/singular/function.pyx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence_g
9898
from sage.libs.singular.decl cimport *
9999
from sage.libs.singular.option import opt_ctx
100100
from sage.libs.singular.polynomial cimport singular_vector_maximal_component
101-
from sage.libs.singular.singular cimport sa2si, si2sa, si2sa_intvec
101+
from sage.libs.singular.singular cimport sa2si, si2sa, si2sa_intvec, si2sa_bigintvec
102102
from sage.libs.singular.singular import error_messages
103103

104104
from sage.interfaces.singular import get_docstring
@@ -954,6 +954,8 @@ cdef class Converter(SageObject):
954954
return si2sa(<number *>to_convert.data, self._singular_ring, self._sage_ring.base_ring())
955955
elif rtyp == INTVEC_CMD:
956956
return si2sa_intvec(<intvec *> to_convert.data)
957+
elif rtyp == BIGINTVEC_CMD:
958+
return si2sa_bigintvec(<bigintmat *> to_convert.data)
957959
elif rtyp == STRING_CMD:
958960
# TODO: Need to determine what kind of data can be returned by a
959961
# STRING_CMD--is it just ASCII strings or can it be an arbitrary
@@ -1048,6 +1050,17 @@ cdef class LibraryCallHandler(BaseCallHandler):
10481050
"""
10491051
return False
10501052

1053+
# mapping int --> string for function arity
1054+
arity_dict = {
1055+
CMD_1: "CMD_1",
1056+
CMD_2: "CMD_2",
1057+
CMD_3: "CMD_3",
1058+
CMD_12: "CMD_12",
1059+
CMD_13: "CMD_13",
1060+
CMD_23: "CMD_23",
1061+
CMD_123: "CMD_123",
1062+
CMD_M: "CMD_M"
1063+
}
10511064

10521065
cdef class KernelCallHandler(BaseCallHandler):
10531066
"""
@@ -1125,8 +1138,9 @@ cdef class KernelCallHandler(BaseCallHandler):
11251138

11261139
errorreported += 1
11271140
error_messages.append(
1128-
"Wrong number of arguments (got {} arguments, arity code is {})"
1129-
.format(number_of_arguments, self.arity))
1141+
"Wrong number of arguments (got {} arguments, arity is {})"
1142+
.format(number_of_arguments,
1143+
arity_dict.get(self.arity) or self.arity))
11301144
return NULL
11311145

11321146
cdef bint free_res(self) noexcept:
@@ -1231,7 +1245,7 @@ cdef class SingularFunction(SageObject):
12311245
Traceback (most recent call last):
12321246
...
12331247
RuntimeError: error in Singular function call 'size':
1234-
Wrong number of arguments (got 2 arguments, arity code is 302)
1248+
Wrong number of arguments (got 2 arguments, arity is CMD_1)
12351249
sage: size('foobar', ring=P)
12361250
6
12371251
@@ -1634,17 +1648,17 @@ def singular_function(name):
16341648
Traceback (most recent call last):
16351649
...
16361650
RuntimeError: error in Singular function call 'factorize':
1637-
Wrong number of arguments (got 0 arguments, arity code is 305)
1651+
Wrong number of arguments (got 0 arguments, arity is CMD_12)
16381652
sage: factorize(f, 1, 2)
16391653
Traceback (most recent call last):
16401654
...
16411655
RuntimeError: error in Singular function call 'factorize':
1642-
Wrong number of arguments (got 3 arguments, arity code is 305)
1656+
Wrong number of arguments (got 3 arguments, arity is CMD_12)
16431657
sage: factorize(f, 1, 2, 3)
16441658
Traceback (most recent call last):
16451659
...
16461660
RuntimeError: error in Singular function call 'factorize':
1647-
Wrong number of arguments (got 4 arguments, arity code is 305)
1661+
Wrong number of arguments (got 4 arguments, arity is CMD_12)
16481662
16491663
The Singular function ``list`` can be called with any number of
16501664
arguments::

src/sage/libs/singular/ring.pyx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ AUTHORS:
1616
# https://www.gnu.org/licenses/
1717
# ****************************************************************************
1818

19-
from sage.cpython.string cimport str_to_bytes
19+
from sage.cpython.string cimport str_to_bytes, bytes_to_str
2020

2121
from sage.libs.gmp.types cimport __mpz_struct
2222
from sage.libs.gmp.mpz cimport mpz_init_set_ui
2323

2424
from sage.libs.singular.decl cimport ring, currRing
2525
from sage.libs.singular.decl cimport rChangeCurrRing, rComplete, rDelete, idInit
2626
from sage.libs.singular.decl cimport omAlloc0, omStrDup, omAlloc
27-
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
27+
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
2828
from sage.libs.singular.decl cimport prCopyR
2929
from sage.libs.singular.decl cimport n_unknown, n_algExt, n_transExt, n_Z, n_Zn, n_Znm, n_Z2m
3030
from sage.libs.singular.decl cimport n_coeffType
@@ -60,7 +60,7 @@ order_dict = {
6060
"dp": ringorder_dp,
6161
"Dp": ringorder_Dp,
6262
"lp": ringorder_lp,
63-
"rp": ringorder_rp,
63+
"ip": ringorder_ip,
6464
"ds": ringorder_ds,
6565
"Ds": ringorder_Ds,
6666
"ls": ringorder_ls,
@@ -71,6 +71,16 @@ order_dict = {
7171
"a": ringorder_a,
7272
}
7373

74+
cdef extern from "singular/Singular/libsingular.h":
75+
cdef char * rSimpleOrdStr(rRingOrder_t)
76+
77+
if bytes_to_str(rSimpleOrdStr(ringorder_ip)) == "rp":
78+
# compatibility for singular 4.3.2p10 and before
79+
order_dict["rp"] = ringorder_ip
80+
# also patch term_order mappings
81+
from sage.rings.polynomial import term_order
82+
term_order.singular_name_mapping['invlex'] = 'rp'
83+
term_order.inv_singular_name_mapping['rp'] = 'invlex'
7484

7585
#############################################################################
7686
cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL:

src/sage/libs/singular/singular.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sage.libs.singular.decl cimport ring, poly, number, intvec
1+
from sage.libs.singular.decl cimport ring, poly, number, intvec, bigintmat
22
from sage.libs.singular.function cimport Resolution
33

44
from sage.rings.rational cimport Rational
@@ -29,6 +29,7 @@ cdef object si2sa_ZZmod(number *n, ring *_ring, object base)
2929
cdef object si2sa_NF(number *n, ring *_ring, object base)
3030

3131
cdef object si2sa_intvec(intvec *v)
32+
cdef object si2sa_bigintvec(bigintmat *v)
3233

3334
# dispatches to all the above.
3435
cdef object si2sa(number *n, ring *_ring, object base)

src/sage/libs/singular/singular.pyx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,25 @@ cdef object si2sa_intvec(intvec *v):
16991699
l.append(v.get(r))
17001700
return tuple(l)
17011701

1702+
cdef object si2sa_bigintvec(bigintmat *v):
1703+
r"""
1704+
create a sage tuple from a singular vector of big integers
1705+
1706+
INPUT:
1707+
1708+
- ``v`` -- a (pointer to) singular bigintmat
1709+
1710+
OUTPUT:
1711+
1712+
a sage tuple
1713+
"""
1714+
cdef int r
1715+
cdef list l = list()
1716+
for r in range(v.length()):
1717+
n = v.get(r)
1718+
l.append(si2sa_QQ(n, &n, currRing))
1719+
return tuple(l)
1720+
17021721
# ==============
17031722
# Initialisation
17041723
# ==============

src/sage/rings/polynomial/multi_polynomial_libsingular.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
12851285
polynomial ring, over a field, global ordering
12861286
// coefficients: ZZ/2[a]/(a^8+a^4+a^3+a^2+1)
12871287
// number of vars : 10
1288-
// block 1 : ordering rp
1288+
// block 1 : ordering ip
12891289
// : names x0 x1 x2 x3 x4 x5 x6 x7 x8 x9
12901290
// block 2 : ordering C
12911291
@@ -1294,7 +1294,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
12941294
polynomial ring, over a field, global ordering
12951295
// coefficients: ZZ/127
12961296
// number of vars : 2
1297-
// block 1 : ordering rp
1297+
// block 1 : ordering ip
12981298
// : names x0 x1
12991299
// block 2 : ordering C
13001300
@@ -1303,7 +1303,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
13031303
polynomial ring, over a field, global ordering
13041304
// coefficients: QQ
13051305
// number of vars : 2
1306-
// block 1 : ordering rp
1306+
// block 1 : ordering ip
13071307
// : names x0 x1
13081308
// block 2 : ordering C
13091309

src/sage/rings/polynomial/term_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@
388388

389389
singular_name_mapping = {
390390
'lex' : 'lp',
391-
'invlex' : 'rp',
391+
'invlex' : 'ip',
392392
'degrevlex' : 'dp',
393393
'deglex' : 'Dp',
394394
'neglex' : 'ls',

0 commit comments

Comments
 (0)