Staticification of p_Invers

7 views
Skip to first unread message

Jean-Pierre Flori

unread,
Apr 26, 2017, 4:58:01 AM4/26/17
to libsingular-devel
Hi Hans,

I see you made p_Invers static in e6c82d85aac825e8a
We used to use that function in Sage (though for a dubious purpose, it seems it only computes inverses of units in polynomial rings, so of constants...)
I've tentatively replaced it with this change:
* https://git.sagemath.org/sage.git/commit/?h=85d00244d0db1cce5933bd6ee46114c58bb32fbb&id=0d6f025a6bf3ac858f331de21b4d9dc298c5c7ec
sig_on()
- cdef MPolynomial_libsingular r = new_MP(self._parent, pInvers(0, self._poly, NULL))
+ cdef MPolynomial_libsingular r = new_MP(self._parent, p_Series(0, p_Copy(_one_element_poly, _ring), self._poly, NULL, _ring))

Where _one_element_poly is _ring(1).
It seems to me that the second argument to p_Series gets modified, whence the p_Copy.
By the way, I guess the above snippet leaks the copy of r(1)... do you confirm it?

Any advice on this piece of code?
Or would you consider reexposing p_Invers?
Or have a better solution in mind?

Thanks for your help,
JP

han...@mathematik.uni-kl.de

unread,
Apr 26, 2017, 8:04:20 AM4/26/17
to libsingu...@googlegroups.com
Hi Jean-Pierre,

pInvers was made static because - in contrast to its name - it does in
general not compute the (complete) inverse of poly.

Assuming that "self" is a constant!=0, a better solution would be:

cdef MPolynomial_libsingular r = new_MP(self._parent, p_NSet(n_Invers(pGetCoeff(self._poly),_ring->cf),_ring))

(derived from the lines 3..4 of p_Invers).

Remark: p_IsUnit (in the lines directly above this change)
is not sufficient, as in a ring with a local
ordering for example 1+x is also a unit.
Better:
(p!=NULL) && (pNext(p)==NULL) && n_IsUnit(pGetCoeff(p),_ring->cf)
or
p_IsUnit(p,_ring) && rHasGlobalOrdering(_ring)

Hans

Jean-Pierre Flori

unread,
Apr 26, 2017, 8:12:08 AM4/26/17
to libsingular-devel
Thanks a lot!
I'll go with these solutions.
Reply all
Reply to author
Forward
0 new messages