Ask Your Question
2

Are these integrate interface issues with Fricas known?

asked 2021-05-23 01:23:09 +0100

Nasser gravatar image

updated 2021-05-23 03:39:55 +0100

I noticed one test file I have that all intergate problems fail when using Fricas. But these work when using Fricas directly.

I do not know now if these issues are known or not.

Here are some examples. Most give TypeError TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'function'>' and TypeError: unsupported operand type(s) for *: 'function' and 'sage.symbolic.expression.Expression'

Yet the same exact input works with no problem in Fricas. I am using Fricas 1.3.6 on Linux (via sagemath 9.3)

Example 1

sage: var('x d b c a D C A B')
(x, d, b, c, a, D, C, A, B)
sage: integrate((b*x+a)^2*(D*x^3+C*x^2+B*x+A)/(d*x+c),x, algorithm="fricas")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-48-ea922a26bbb0> in <module>
----> 1 integrate((b*x+a)**Integer(2)*(D*x**Integer(3)+C*x**Integer(2)+B*x+A)/(d*x+c),x, algorithm="fricas")

/usr/lib/python3.9/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    757     """
    758     if hasattr(x, 'integral'):
--> 759         return x.integral(*args, **kwds)
    760     else:
    761         from sage.symbolic.ring import SR

/usr/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:66867)()
  12645                     R = SR
  12646             return R(integral(f, v, a, b, **kwds))
> 12647         return integral(self, *args, **kwds)
  12648 
  12649     integrate = integral

/usr/lib/python3.9/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    988         if not integrator:
    989             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 990         return integrator(expression, v, a, b)
    991     if a is None:
    992         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python3.9/site-packages/sage/symbolic/integration/external.py in fricas_integrator(expression, v, a, b, noPole)
    409             result = ex.integrate(seg)
    410 
--> 411     result = result.sage()
    412 
    413     if result == "failed":

/usr/lib/python3.9/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1966             # we treat Expression Integer and Expression Complex
   1967             # Integer just the same
-> 1968             return FriCASElement._sage_expression(P.get_InputForm(self._name))
   1969 
   1970         if head == 'DistributedMultivariatePolynomial':

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _sage_expression(fricas_InputForm)
   1654         register_symbol(convert_rootOf, {'fricas': 'rootOf'})
   1655 
-> 1656         ex, _ = FriCASElement._parse_and_eval(fricas_InputForm)
   1657         # postprocessing of rootOf
   1658         from sage.rings.all import QQbar, PolynomialRing

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1278             args.append(e)
   1279             a += 1
-> 1280         return fun(*args), a
   1281 
   1282     @staticmethod

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in <lambda>(x, y)
   1600         register_symbol(lambda x, y: x + y, {'fricas': '+'})
   1601         register_symbol(lambda x, y: x - y, {'fricas': '-'})
-> 1602         register_symbol(lambda x, y: x * y, {'fricas': '*'})
   1603         register_symbol(lambda x, y: x / y, {'fricas': '/'})
   1604         register_symbol(lambda x, y: x ** y, {'fricas': '^'})

/usr/lib/python3.9/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__mul__ (build/cythonized/sage/rings/integer.c:14021)()
   1980             return y
   1981 
-> 1982         return coercion_model.bin_op(left, right, operator.mul)
   1983 
   1984     cpdef _mul_(self, right):

/usr/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11710)()
   1246         # We should really include the underlying error.
   1247         # This causes so much headache.
-> 1248         raise bin_op_exception(op, x, y)
   1249 
   1250     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'function'>'
sage:

Example 2

sage: integrate((D*x^3+C*x)/x,x, algorithm="fricas")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-46-cd8aba19a8a6> in <module>
----> 1 integrate((D*x**Integer(3)+C*x)/x,x, algorithm="fricas")

/usr/lib/python3.9/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    757     """
    758     if hasattr(x, 'integral'):
--> 759         return x.integral(*args, **kwds)
    760     else:
    761         from sage.symbolic.ring import SR

/usr/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:66867)()
  12645                     R = SR
  12646             return R(integral(f, v, a, b, **kwds))
> 12647         return integral(self, *args, **kwds)
  12648 
  12649     integrate = integral

/usr/lib/python3.9/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    988         if not integrator:
    989             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 990         return integrator(expression, v, a, b)
    991     if a is None:
    992         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python3.9/site-packages/sage/symbolic/integration/external.py in fricas_integrator(expression, v, a, b, noPole)
    409             result = ex.integrate(seg)
    410 
--> 411     result = result.sage()
    412 
    413     if result == "failed":

/usr/lib/python3.9/site-packages/sage/interfaces/interface.py in sage(self, *args, **kwds)
   1090             [0 0]
   1091         """
-> 1092         return self._sage_(*args, **kwds)
   1093 
   1094     def __repr__(self):

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _sage_(self)
   1966             # we treat Expression Integer and Expression Complex
   1967             # Integer just the same
-> 1968             return FriCASElement._sage_expression(P.get_InputForm(self._name))
   1969 
   1970         if head == 'DistributedMultivariatePolynomial':

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _sage_expression(fricas_InputForm)
   1654         register_symbol(convert_rootOf, {'fricas': 'rootOf'})
   1655 
-> 1656         ex, _ = FriCASElement._parse_and_eval(fricas_InputForm)
   1657         # postprocessing of rootOf
   1658         from sage.rings.all import QQbar, PolynomialRing

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1275         args = []
   1276         while s[a] != FriCASElement._RIGHTBRACKET:
-> 1277             e, a = FriCASElement._parse_and_eval(s, start=a)
   1278             args.append(e)
   1279             a += 1

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_and_eval(s, start)
   1233 
   1234         if s[a] == FriCASElement._LEFTBRACKET:
-> 1235             return FriCASElement._parse_list(s, start=a)
   1236         elif s[a] == FriCASElement._STRINGMARKER:
   1237             return FriCASElement._parse_string(s, start=a)

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in _parse_list(s, start)
   1278             args.append(e)
   1279             a += 1
-> 1280         return fun(*args), a
   1281 
   1282     @staticmethod

/usr/lib/python3.9/site-packages/sage/interfaces/fricas.py in <lambda>(x, y)
   1600         register_symbol(lambda x, y: x + y, {'fricas': '+'})
   1601         register_symbol(lambda x, y: x - y, {'fricas': '-'})
-> 1602         register_symbol(lambda x, y: x * y, {'fricas': '*'})
   1603         register_symbol(lambda x, y: x / y, {'fricas': '/'})
   1604         register_symbol(lambda x, y: x ** y, {'fricas': '^'})

TypeError: unsupported operand type(s) for *: 'function' and 'sage.symbolic.expression.Expression'
sage:

I have many many more such examples. Here is the same examples above, run inside Fricas directly. You can see they work there.

(3) -> ii:=integrate((b*x+a)^3*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(1/2),x);

                                         Type: Union(Expression(Integer),...)
(4) -> unparse(ii::InputForm)

  "((6930*D*b^3*d^6*x^6+((8190*C*b^3+24570*D*a*b^2)*d^6+(-7560)*D*b^3*c*d^5)*x^
  5+((10010*B*b^3+30030*C*a*b^2+30030*D*a^2*b)*d^6+((-9100)*C*b^3+(-27300)*D*a*
  b^2)*c*d^5+8400*D*b^3*c^2*d^4)*x^4+((12870*A*b^3+38610*B*a*b^2+38610*C*a^2*b+
  12870*D*a^3)*d^6+((-11440)*B*b^3+(-34320)*C*a*b^2+(-34320)*D*a^2*b)*c*d^5+(10
  400*C*b^3+31200*D*a*b^2)*c^2*d^4+(-9600)*D*b^3*c^3*d^3)*x^3+((54054*A*a*b^2+5
  4054*B*a^2*b+18018*C*a^3)*d^6+((-15444)*A*b^3+(-46332)*B*a*b^2+(-46332)*C*a^2
  *b+(-15444)*D*a^3)*c*d^5+(13728*B*b^3+41184*C*a*b^2+41184*D*a^2*b)*c^2*d^4+((
  -12480)*C*b^3+(-37440)*D*a*b^2)*c^3*d^3+11520*D*b^3*c^4*d^2)*x^2+((90090*A*a^
  2*b+30030*B*a^3)*d^6+((-72072)*A*a*b^2+(-72072)*B*a^2*b+(-24024)*C*a^3)*c*d^5
  +(20592*A*b^3+61776*B*a*b^2+61776*C*a^2*b+20592*D*a^3)*c^2*d^4+((-18304)*B*b^
  3+(-54912)*C*a*b^2+(-54912)*D*a^2*b)*c^3*d^3+(16640*C*b^3+49920*D*a*b^2)*c^4*
  d^2+(-15360)*D*b^3*c^5*d)*x+(90090*A*a^3*d^6+((-180180)*A*a^2*b+(-60060)*B*a^
  3)*c*d^5+(144144*A*a*b^2+144144*B*a^2*b+48048*C*a^3)*c^2*d^4+((-41184)*A*b^3+
  (-123552)*B*a*b^2+(-123552)*C*a^2*b+(-41184)*D*a^3)*c^3*d^3+(36608*B*b^3+1098
  24*C*a*b^2+109824*D*a^2*b)*c^4*d^2+((-33280)*C*b^3+(-99840)*D*a*b^2)*c^5*d+30
  720*D*b^3*c^6))*(d*x+c)^(1/2))/(45045*d^7)"

 (5) -> ii:=integrate((D*x^3+C*x)/x,x);                              

                                         Type: Union(Expression(Integer),...)
(6) -> unparse(ii::InputForm)         

   (6)  "(D*x^3+3*C*x)/3"
                                                                 Type: String

Here are more examples, all these raise exception TypeError in sage math. I think they are all related to the same problem.

var('b a C D B A d c n m')
integrate((b*x+a)^3*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((b*x+a)^2*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((b*x+a)*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^2/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^3/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^4/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^5/(d*x+c)^(1/2),x, algorithm="fricas")
integrate((b*x+a)^3*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((b*x+a)^2*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((b*x+a)*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^2/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^3/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^4/(d*x+c)^(3/2),x, algorithm="fricas")
integrate((b*x+a)^3*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((b*x+a)^2*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((b*x+a)*(D*x^3+C*x^2+B*x+A)/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^2/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((D*x^3+C*x^2+B*x+A)/(b*x+a)^3/(d*x+c)^(5/2),x, algorithm="fricas")
integrate((b*x+a)^3*(d*x+c)^n*(D*x^3+C*x^2+B*x+A),x, algorithm="fricas")
integrate((b*x+a)^2*(d*x+c)^n*(D*x^3+C*x^2+B*x+A),x, algorithm="fricas")
integrate((b*x+a)*(d*x+c)^n*(D*x^3+C*x^2+B*x+A),x, algorithm="fricas")
integrate((d*x+c)^n*(D*x^3+C*x^2+B*x+A),x, algorithm="fricas")
integrate((d*x+c)^n*(D*x^3+C*x^2+B*x+A)/(b*x+a),x, algorithm="fricas")
integrate((d*x+c)^n*(D*x^3+C*x^2+B*x+A)/(b*x+a)^2,x, algorithm="fricas")
integrate((d*x+c)^n*(D*x^3+C*x^2+B*x+A)/(b*x+a)^3,x, algorithm="fricas")
integrate((b*x+a)^m*(d*x+c)^n*(D*x^3+C*x^2+B*x+A),x, algorithm="fricas")

I wanted to ask if there is a ticket on these issue already, or if I should enter a new ticket? It is hard to know, but may be someone here would know better.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-05-23 04:44:36 +0100

Emmanuel Charpentier gravatar image

updated 2021-05-23 15:29:28 +0100

Note : : the first part of this answer is partly misleading. see the "IMPORTANT EDIT" below for the real explanation...

Partial answer : Fricas output seems to have interleaved "\n" characters garbling the interpretation of the returned strings. The workaround is to somehow obtain Frcas' expression as a string and feed it back to SR. The following horror happens to work :

sage: SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
1/60*(12*D*b^2*d^5*x^5 - 15*(D*b^2*c*d^4 - (2*D*a*b + C*b^2)*d^5)*x^4 + 20*(D*b^2*c^2*d^3 - (2*D*a*b + C*b^2)*c*d^4 + (D*a^2 + 2*C*a*b + B*b^2)*d^5)*x^3 - 30*(D*b^2*c^3*d^2 - (2*D*a*b + C*b^2)*c^2*d^3 + (D*a^2 + 2*C*a*b + B*b^2)*c*d^4 - (C*a^2 + 2*B*a*b + A*b^2)*d^5)*x^2 + 60*(D*b^2*c^4*d - (2*D*a*b + C*b^2)*c^3*d^2 + (D*a^2 + 2*C*a*b + B*b^2)*c^2*d^3 - (C*a^2 + 2*B*a*b + A*b^2)*c*d^4 + (B*a^2 + 2*A*a*b)*d^5)*x - 60*(D*b^2*c^5 - A*a^2*d^5 - (2*D*a*b + C*b^2)*c^4*d + (D*a^2 + 2*C*a*b + B*b^2)*c^3*d^2 - (C*a^2 + 2*B*a*b + A*b^2)*c^2*d^3 + (B*a^2 + 2*A*a*b)*c*d^4)*log(d*x + c))/d^6

but only because This result's input format in Fricas is parseable by Sagemath as a `Symbolic Expression' ; pure happenstance...

It turns out that this expression (a rational fracion with a 42 terms numerator, better seen after expand()sion...) differentiates back to the original integrand:

sage: bar=SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage())
sage: bool(bar.diff(x)==foo)
True

I intend to explore this further before filing a ticket : this recent thread on Fricas' mailing list gives me some hope of filing a useful report, rather than a rant...

HTH,

IMPORTANT EDIT :

It's much simpler (and much more difficult to fix) than that ! Contemplate :

sage: var('x d b c a D C A B')
(x, d, b, c, a, D, C, A, B)
sage: foo = (b*x + a)^2*(D*x^3 + C*x^2 + B*x + A)/(d*x + c)
sage: integrate(foo, x, algorithm="fricas")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

Bandwidth savings : Snip...

TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'function'>'
sage: var("capitalD")
capitalD
sage: integrate(foo.subs({D:capitalD}), x, algorithm="fricas")
1/60*(12*b^2*capitalD*d^5*x^5 - 15*(b^2*c*capitalD*d^4 - (C*b^2 + 2*a*b*capitalD)*d^5)*x^4 + 20*(b^2*c^2*capitalD*d^3 + (2*C*a*b + B*b^2 + a^2*capitalD)*d^5 - (C*b^2*c + 2*a*b*c*capitalD)*d^4)*x^3 - 30*(b^2*c^3*capitalD*d^2 - (C*a^2 + 2*B*a*b + A*b^2)*d^5 + (a^2*c*capitalD + (2*C*a*b + B*b^2)*c)*d^4 - (C*b^2*c^2 + 2*a*b*c^2*capitalD)*d^3)*x^2 + 60*(b^2*c^4*capitalD*d - (C*a^2 + 2*B*a*b + A*b^2)*c*d^4 + (B*a^2 + 2*A*a*b)*d^5 + (a^2*c^2*capitalD + (2*C*a*b + B*b^2)*c^2)*d^3 - (C*b^2*c^3 + 2*a*b*c^3*capitalD)*d^2)*x - 60*(b^2*c^5*capitalD - A*a^2*d^5 - (C*a^2 + 2*B*a*b + A*b^2)*c^2*d^3 + (B*a^2 + 2*A*a*b)*c*d^4 + (a^2*c^3*capitalD + (2*C*a*b + B*b^2)*c^3)*d^2 - (C*b^2*c^4 + 2*a*b*c^4*capitalD)*d)*log(d*x + c))/d^6

The cherry on the pie :

sage: bool(integrate(foo.subs({D:capitalD}), x, algorithm="fricas").diff(x).subs({capitalD:D})==foo)
True

The use of the variable D shadows the Fricas function D, which is not a problem for Fricas, but is not known to the fricas._sage_() method, which uses hardcoded equivalences for categorizing syntactic trees' atoms.

This one will be difficult to solve, but can at least be correctly filed : this is now Trac#31849.

The occurrence of "\n" characters in SR(fricas("unparse(integrate(%s,x)::InputForm)"%foo).sage()) may be happenstance. It was misleading...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-05-23 01:23:09 +0100

Seen: 287 times

Last updated: May 23 '21