diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index dd1c5a35239..d4ed0e3b064 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -1393,6 +1393,13 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept: (a + 1) sage: R(F.gen()^5) + 1 (-a^2 + a + 2) + + Ensures :issue:`36101` is fixed:: + + sage: RR. = AA[] + sage: f = -4*r^2+(((1+2*AA(cos(pi/6)))*c0*r+2*c1*r+(1+2*AA(cos(pi/6)))*s0*r+2*s1*r)/2-1/2)^2+((1-(1+2*AA(cos(pi/6)))*c0*r-2*c1*r+(1+2*AA(cos(pi/6)))*s0*r+2*s1*r)/2-1/2)^2 + sage: f.change_ring( QuadraticField(3) ) + ... """ cdef int i cdef number *n1 @@ -1403,13 +1410,6 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept: cdef number *apow1 cdef number *apow2 - cdef nMapFunc nMapFuncPtr = NULL - - nMapFuncPtr = naSetMap(_ring.cf, currRing.cf) # choose correct mapping function - - if nMapFuncPtr is NULL: - raise RuntimeError("Failed to determine nMapFuncPtr") - elem = list(elem) if _ring != currRing: @@ -1432,7 +1432,10 @@ cdef number *sa2si_NF(object elem, ring *_ring) noexcept: rComplete(qqr,1) qqr.ShortOut = 0 - nMapFuncPtr = naSetMap(qqr.cf, _ring.cf) # choose correct mapping function + assert _ring.cf.type == n_algExt # if false naSetMap will segmentation fault (should never happen) + cdef nMapFunc nMapFuncPtr = naSetMap(qqr.cf, _ring.cf) # choose correct mapping function + if nMapFuncPtr is NULL: + raise RuntimeError("Failed to determine nMapFuncPtr") cdef poly *_p for i from 0 <= i < len(elem): nlCoeff = nlInit2gmp( mpq_numref((elem[i]).value), mpq_denref((elem[i]).value), qqr.cf )