If I recall correctly, this is what I did for the FriCAS interface. It would be nice to factor out any common functionality, if possible.
On Wednesday, 26 April 2023 at 21:06:30 UTC+2 Oscar Benjamin wrote: > One thing Sage could do with SymPy's RootSum is to call doit which > will expand using radical formulae if possible: > > x**2/(3*a**2 + 3*a*b*x**3) + RootSum(729*_t**3*a**4*b**2 + 1, > Lambda(_t, _t*log(81*_t**2*a**3*b + x))) > > In [37]: x, a, b, _t = symbols('x, a, b, _t') > > In [38]: expr = x**2/(3*a**2 + 3*a*b*x**3) + > RootSum(Poly(729*_t**3*a**4*b**2 + 1, _t), Lambda(_t, > _t*log(81*_t**2*a**3*b + x))) > > In [39]: print(expr) > x**2/(3*a**2 + 3*a*b*x**3) + RootSum(729*_t**3*a**4*b**2 + 1, > Lambda(_t, _t*log(81*_t**2*a**3*b + x))) > > In [40]: print(expr.doit()) > x**2/(3*a**2 + 3*a*b*x**3) + > (-1/(a**4*b**2))**(1/3)*log(a**3*b*(-1/(a**4*b**2))**(2/3) + x)/9 + > (-(-1/(a**4*b**2))**(1/3)/18 - > > sqrt(3)*I*(-1/(a**4*b**2))**(1/3)/18)*log(81*a**3*b*(-(-1/(a**4*b**2))**(1/3)/18 > - sqrt(3)*I*(-1/(a**4*b**2))**(1/3)/18)**2 + x) + > (-(-1/(a**4*b**2))**(1/3)/18 + > > sqrt(3)*I*(-1/(a**4*b**2))**(1/3)/18)*log(81*a**3*b*(-(-1/(a**4*b**2))**(1/3)/18 > + sqrt(3)*I*(-1/(a**4*b**2))**(1/3)/18)**2 + x) > > A more precise instruction would be: > > expr.replace(lambda e: isinstance(e, RootSum), lambda e: > e.doit(deep=False)) > > -- > Oscar > > On Wed, 26 Apr 2023 at 19:26, Dima Pasechnik <dim...@gmail.com> wrote: > > > > Thanks for showing this. As far as I know, the problem is that Sage does > not support RootSum expressions - although they are very useful for > integration in particular. > > > > > > On Wed, 26 Apr 2023, 19:22 'Nasser M. Abbasi' via sage-devel, < > sage-...@googlegroups.com> wrote: > >> > >> I use sagemath to run the independent CAS integrations tests for > Fricas, Giac and Maxima, since it is much easier to use the same script to > all CAS systems instead of learning how to use each separate CAS. The > result is put on this page. > >> > >> I found that sympy now can be used from sagemath. > >> > >> So I said, great. Instead of having separate script for sympy in python > will use the same sagemath script and just change the name of the algorithm > to 'sympy'. Makes life easier. > >> > >> But when I tried this on one test file, I found many integrals now > fail, where they work using sympy directly in Python. > >> > >> I am not sure if this is because sympy is not yet fully yet supported > in sagemath or if this is just a bug and overlooked support. > >> > >> For example, on this one file, sympy used to score 84.66% passing score > when used directly, but now in sagemath it scores 65.64%. > >> > >> This translates to about 30 more integrals failing in this file of 163 > integrals. > >> > >> Below will give one example. All seem to give the same exception > >> > >> NotImplementedError('conversion to SageMath is not implemented') > >> > >> Here is one example in sagemath 9.8 > >> > >> var('A B a alpha b beta m n x ') > >> integrate(x/((b*x^2+a)^m),x, algorithm='sympy') > >> > >> > --------------------------------------------------------------------------- > >> NotImplementedError Traceback (most recent call last) > >> Cell In [2], line 1 > >> ----> 1 integrate(x/(b*x**Integer(3)+a)**Integer(2),x, > algorithm='sympy') > >> > >> File ~/TMP/sage-9.8/src/sage/misc/functional.py:773, in integral(x, > *args, **kwds) > >> 648 """ > >> 649 Return an indefinite or definite integral of an object ``x``. > >> 650 > >> (...) > >> 770 > >> 771 """ > >> 772 if hasattr(x, 'integral'): > >> --> 773 return x.integral(*args, **kwds) > >> 774 else: > >> 775 from sage.symbolic.ring import SR > >> > >> File ~/TMP/sage-9.8/src/sage/symbolic/expression.pyx:13211, in > sage.symbolic.expression.Expression.integral() > >> 13209 R = SR > >> 13210 return R(integral(f, v, a, b, **kwds)) > >> > 13211 return integral(self, *args, **kwds) > >> 13212 > >> 13213 integrate = integral > >> > >> File ~/TMP/sage-9.8/src/sage/symbolic/integration/integral.py:1063, in > integrate(expression, v, a, b, algorithm, hold) > >> 1061 if not integrator: > >> 1062 raise ValueError("Unknown algorithm: %s" % algorithm) > >> -> 1063 return integrator(expression, v, a, b) > >> 1064 if a is None: > >> 1065 return indefinite_integral(expression, v, hold=hold) > >> > >> File ~/TMP/sage-9.8/src/sage/symbolic/integration/external.py:69, in > sympy_integrator(expression, v, a, b) > >> 67 else: > >> 68 result = sympy.integrate(ex, (v, a._sympy_(), b._sympy_())) > >> ---> 69 return result._sage_() > >> > >> File ~/TMP/sage-9.8/src/sage/interfaces/sympy.py:216, in > _sympysage_add(self) > >> 214 s = 0 > >> 215 for x in self.args: > >> --> 216 s += x._sage_() > >> 217 return s > >> > >> File > ~/TMP/sage-9.8/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sympy/core/basic.py:1959, > > in Basic._sage_(self) > >> 1957 sympy_init() # may monkey-patch _sage_ method into self's class or > superclasses > >> 1958 if old_method == self._sage_: > >> -> 1959 raise NotImplementedError('conversion to SageMath is not > implemented') > >> 1960 else: > >> 1961 # call the freshly monkey-patched method > >> 1962 return self._sage_() > >> > >> > >> Here is same integral in sympy itself. You see it works. > >> > >> >python > >> Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] on linux > >> >>> from sympy import * > >> >>> A,B,a,alpha,b,beta,m,n,x= symbols('A B a alpha b beta m n x ') > >> >>> integrate(x/(b*x**3+a)**2,x) > >> > >> x**2/(3*a**2 + 3*a*b*x**3) + RootSum(729*_t**3*a**4*b**2 + 1, > Lambda(_t, _t*log(81*_t**2*a**3*b + x))) > >> > >> > >> The sympy version is 1.11.1 in both cases, all on Linux. > >> > >> age: ver = installed_packages() > >> sage: ver['sympy'] > >> '1.11.1' > >> > >> Will give the list of failed integrals in this one file in a follow up > post. > >> > >> --Nasser > >> > >> > >> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "sage-devel" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to sage-devel+...@googlegroups.com. > >> To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-devel/f756dced-6c0b-41cd-b510-6df90906629an%40googlegroups.com > . > > > > -- > > You received this message because you are subscribed to the Google > Groups "sage-devel" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to sage-devel+...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-devel/CAAWYfq35yV9jK1mH5%3Dq_AHwr5DgGaYe5JQuwhnwGanjoYK4ajw%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/64f679d2-e859-4f63-9a6d-67ca7e35fab7n%40googlegroups.com.