Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/sage/libs/singular/polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,19 @@ cdef int singular_polynomial_cmp(poly *p, poly *q, ring *r) noexcept:
sage: P(0) > P(-1)
True
"""
# similar to p_Compare in p_polys.h
cdef int tmp

if r != currRing:
rChangeCurrRing(r)

while True:
# workaround for https://github.com/Singular/Singular/issues/1293
while p != NULL and r.cf.cfIsZero(p_GetCoeff(p, r), r.cf):
p = pNext(p)
while q != NULL and r.cf.cfIsZero(p_GetCoeff(q, r), r.cf):
q = pNext(q)

if p == NULL:
if q == NULL:
return 0
Expand Down
16 changes: 15 additions & 1 deletion src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL:
// block 1 : ordering dp
// : names a b
// block 2 : ordering C
sage: R(2)^32 == R(0)
True

The following may use ``n_Z2m`` or ``n_Znm`` depends on ``sizeof(unsigned long)``::

sage: R = PolynomialRing(Zmod(2^64), ("a", "b"), implementation="singular")
sage: ZZ(R(3^1000)) == 3^1000 % 2^64
True
sage: ZZ(R(5^1000)) == 5^1000 % 2^64
True

Integer modulo large power of 2::

Expand All @@ -262,6 +272,10 @@ cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL:
// block 1 : ordering dp
// : names a b
// block 2 : ordering C
sage: ZZ(R(5^1000)) == 5^1000 % 2^1000
True
sage: R(2)^1000 == R(0)
True

Integer modulo large power of odd prime::

Expand Down Expand Up @@ -516,7 +530,7 @@ cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL:
else:
modbase, cexponent = ch.perfect_power()

if modbase == 2 and cexponent > 1:
if modbase == 2 and 1 < cexponent <= 8*sizeof(unsigned long): # see :issue:`40855`
_cf = nInitChar(n_Z2m, <void *>cexponent)

elif modbase.is_prime() and cexponent > 1:
Expand Down
11 changes: 8 additions & 3 deletions src/sage/libs/singular/singular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,6 @@ cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring) noexcept:

cdef number *nn

cdef int64_t _d
cdef char *_name
cdef char **_ext_names

Expand All @@ -1552,8 +1551,14 @@ cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring) noexcept:
return n_Init(int(d), _ring.cf)

if _ring.cf.type == n_Z2m:
_d = d
return nr2mMapZp(<number *>_d, currRing.cf, _ring.cf)
if sizeof(number *) >= sizeof(unsigned long):
# one may also always choose the second branch,
# but the first branch may allow inlining (?)
# casting to unsigned long is safe because n_Z2m
# is only chosen if the exponent is small, see singular_ring_new
return nr2mMapZp(<number *> <unsigned long> d, currRing.cf, _ring.cf)
else:
return _ring.cf.cfInit(<long> <unsigned long> d, _ring.cf)
elif _ring.cf.type == n_Zn or _ring.cf.type == n_Znm:
lift = d.lift()

Expand Down
Loading