Problem with factor in SymbolicRing

64 views
Skip to first unread message

Enrique Artal

unread,
Jul 24, 2019, 7:31:08 AM7/24/19
to sage-support
I have encountered a problem with factor in SR which can be avoided but it shows a problem. If I run this code:

var('t',domain='complex')
var('r,x,y',domain='real')
h= r^6+r^4*t^2 + 4*r^4*t*conjugate(t) + r^4*conjugate(t)^2 + r^2*t^2*conjugate(t)^2  - r^2*t^2 - r^2*conjugate(t)^2 + t^2*conjugate(t)^2
H=h(t=x+I*y).factor()
num=1/2*(H.derivative(x)/H).derivative(x)+1/2*(H.derivative(y)/H).derivative(y)
num.factor()

I get the following error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-bfb20671ab22> in <module>()
      6 H=h(t=x+I*y).factor()
      7 num=Integer(1)/Integer(2)*(H.derivative(x)/H).derivative(x)+Integer(1)/Integer(2)*(H.derivative(y)/H).derivative(y)
----> 8 num.factor()

/home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.factor (build/cythonized/sage/symbolic/expression.cpp:57759)()
  11107         cdef GEx x
  11108         cdef bint b
> 11109         if dontfactor or not self.is_rational_expression():
  11110             m = self._maxima_()
  11111             name = m.name()

/home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.is_rational_expression (build/cythonized/sage/symbolic/expression.cpp:15368)()
   2030             False
   2031         """
-> 2032         return all(part.is_polynomial(v)
   2033                    for part in (self.numerator(), self.denominator())
   2034                    for v in part.variables())

/home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in genexpr (build/cythonized/sage/symbolic/expression.cpp:15110)()
   2031         """
   2032         return all(part.is_polynomial(v)
-> 2033                    for part in (self.numerator(), self.denominator())
   2034                    for v in part.variables())
   2035 

/home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.numerator (build/cythonized/sage/symbolic/expression.cpp:48252)()
   9377             sig_on()
   9378             try:
-> 9379                 ex = self._gobj.numer()
   9380             finally:
   9381                 sig_off()

ValueError: divide: arguments must be polynomials over the rationals

This error does not happen if I erase some terms of h; and some times it gives the error only if I did not restart the jupyter notebook. Any ideas? Enrique.

Enrique Artal

unread,
Jul 24, 2019, 7:35:19 AM7/24/19
to sage-support
I forgot to add, it worked in 8.1 version and it does not work since 8.4 (at least). Adding the option dontfactor=[some variable not involved in h] it works but much slower.

Vincent Delecroix

unread,
Aug 4, 2019, 9:19:59 AM8/4/19
to sage-s...@googlegroups.com
I confirm the bug on 8.9.beta5. It is most probably a bug in Pynac. Note
that if you multiply by 2 it "works"

sage: (2*num).factor()
(16*r^6 - 32*r^4*x^2 + 16*r^2*x^4 + 32*r^4*y^2 + 32*r^2*x^2*y^2 +
16*r^2*y^4 + 80*r^2*x^2 + 16*x^4 + 16*r^2*y^2 + 32*x^2*y^2 + 16*y^4 -
16*x^2 - 16*y^2)*r^4/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 +
2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4)^2


Le 24/07/2019 à 13:31, Enrique Artal a écrit :
> I have encountered a problem with factor in SR which can be avoided but it
> shows a problem. If I run this code:
>
> var('t',domain='complex')
> var('r,x,y',domain='real')
> h= r^6+r^4*t^2 + 4*r^4*t*conjugate(t) + r^4*conjugate(t)^2 +
> r^2*t^2*conjugate(t)^2 - r^2*t^2 - r^2*conjugate(t)^2 + t^2*conjugate(t)^2
> H=h(t=x+I*y).factor()
> num=1/2*(H.derivative(x)/H).derivative(x)+1/2*(H.derivative(y)/H).derivative(y)
> num.factor()
>
> I get the following error
>
> ---------------------------------------------------------------------------ValueError Traceback (most recent call last)<ipython-input-1-bfb20671ab22> in <module>() 6 H=h(t=x+I*y).factor() 7 num=Integer(1)/Integer(2)*(H.derivative(x)/H).derivative(x)+Integer(1)/Integer(2)*(H.derivative(y)/H).derivative(y)----> 8 num.factor()
> /home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.factor (build/cythonized/sage/symbolic/expression.cpp:57759)() 11107 cdef GEx x 11108 cdef bint b> 11109 if dontfactor or not self.is_rational_expression(): 11110 m = self._maxima_() 11111 name = m.name()
> /home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.is_rational_expression (build/cythonized/sage/symbolic/expression.cpp:15368)() 2030 False 2031 """-> 2032 return all(part.is_polynomial(v) 2033 for part in (self.numerator(), self.denominator()) 2034 for v in part.variables())
> /home/artal/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in genexpr (build/cythonized/sage/symbolic/expression.cpp:15110)() 2031 """ 2032 return all(part.is_polynomial(v)-> 2033 for part in (self.numerator(), self.denominator()) 2034 for v in part.variables()) 2035

Enrique Artal

unread,
Aug 7, 2019, 10:17:22 AM8/7/19
to sage-support
The behavior is quite erratic; my first example was more complicated; I eliminate terms and sometimes it worked, some times not.

Emmanuel Charpentier

unread,
Aug 8, 2019, 12:45:26 AM8/8/19
to sage-support
Possible workaround:

sage: num
-1/2*(12*r^4*x + 4*r^2*x^3 + 4*r^2*x*y^2 - 4*r^2*x + 4*x^3 + 4*x*y^2)^2/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4)^2 - 1/2*(4*r^4*y + 4*r^2*x^2*y + 4*r^2*y^3 + 4*r^2*y + 4*x^2*y + 4*y^3)^2/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4)^2 + 1/2*(12*r^4 + 12*r^2*x^2 + 4*r^2*y^2 - 4*r^2 + 12*x^2 + 4*y^2)/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4) + 1/2*(4*r^4 + 4*r^2*x^2 + 12*r^2*y^2 + 4*r^2 + 4*x^2 + 12*y^2)/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4)
sage: num.maxima_methods().factor()
8*(r^6 - 2*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 + 5*r^2*x^2 + x^4 + r^2*y^2 + 2*x^2*y^2 + y^4 - x^2 - y^2)*r^4/(r^6 + 6*r^4*x^2 + r^2*x^4 + 2*r^4*y^2 + 2*r^2*x^2*y^2 + r^2*y^4 - 2*r^2*x^2 + x^4 + 2*r^2*y^2 + 2*x^2*y^2 + y^4)^2

HTH,
Reply all
Reply to author
Forward
0 new messages