Skip to content

Commit

Permalink
Support singular older than 4.3.2.p15 too
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-rojas committed Mar 31, 2024
1 parent 79bbec1 commit ad3aa56
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
21 changes: 19 additions & 2 deletions src/sage/interfaces/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/sage/libs/singular/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/sage/libs/singular/function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::
Expand Down
14 changes: 7 additions & 7 deletions src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1280,26 +1280,32 @@ 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
// block 1 : ordering ip
// : 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
// block 1 : ordering ip
// : 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
Expand Down
8 changes: 7 additions & 1 deletion src/sage/rings/polynomial/term_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ad3aa56

Please sign in to comment.