Skip to content

Commit

Permalink
singular: compatibility for 4.3.2p10 and before
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
tornaria authored and antonio-rojas committed Apr 13, 2024
1 parent c33a96b commit bb5b360
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/sage/interfaces/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions src/sage/libs/singular/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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
Expand Down
12 changes: 11 additions & 1 deletion src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
Expand Down Expand Up @@ -72,6 +72,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:
Expand Down

0 comments on commit bb5b360

Please sign in to comment.