On Thu, Nov 15, 2018 at 11:46 AM Erik Bray <erik.m.b...@gmail.com> wrote: > > On Thu, Nov 15, 2018 at 8:39 AM Emmanuel Charpentier > <emanuel.charpent...@gmail.com> wrote: > > > > > > > > Le mercredi 14 novembre 2018 12:29:36 UTC+1, Erik Bray a écrit : > > > >> > >> However, one thing I do find surprising about the global sqrt > >> function, which is different from some other global functions (I > >> think, needlessly) is that it does not work as a symbolic function. > >> By contrast, the exp function also exhibits the above behavior, in > >> that it will reduce to an exact (integer) value where possible: > > > > > > This is more general than that : the support for "hold" argument is > > inconstant. Compare : > > sage: sin(x).integrate(x,hold=True) > > integrate(sin(x), x) > > sage: sin(x).diff(x,hold=True) > > --------------------------------------------------------------------------- > > TypeError Traceback (most recent call last) > > <ipython-input-6-e4a6278fd746> in <module>() > > ----> 1 sin(x).diff(x,hold=True) > > > > TypeError: derivative() got an unexpected keyword argument 'hold' > > > > Sage has some analogous inconsistencies : > > > > sage: f(x)=piecewise([((-oo,-1),x^3),([-1,1],x),((1,oo),x^2)],var=x); f > > x |--> piecewise(x|-->x^3 on (-oo, -1), x|-->x on [-1, 1], x|-->x^2 on (1, > > +oo); x) > > sage: f(x).integral(x) > > piecewise(x|-->1/4*x^4 - 1/4 on (-oo, -1), x|-->1/2*x^2 - 1/2 on [-1, 1], > > x|-->1/3*x^3 - 1/3 on (1, +oo); x) > > sage: f(x).integrate(x) > > --------------------------------------------------------------------------- > > TypeError Traceback (most recent call last) > > <ipython-input-20-470e0b723c76> in <module>() > > ----> 1 f(x).integrate(x) > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx > > in sage.symbolic.expression.Expression.integral > > (build/cythonized/sage/symbolic/expression.cpp:69368)() > > 12399 R = ring.SR > > 12400 return R(integral(f, v, a, b, **kwds)) > > > 12401 return integral(self, *args, **kwds) > > 12402 > > 12403 integrate = integral > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc > > in integrate(expression, v, a, b, algorithm, hold) > > 816 return integrator(expression, v, a, b) > > 817 if a is None: > > --> 818 return indefinite_integral(expression, v, hold=hold) > > 819 else: > > 820 return definite_integral(expression, v, a, b, hold=hold) > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/function.pyx > > in sage.symbolic.function.BuiltinFunction.__call__ > > (build/cythonized/sage/symbolic/function.cpp:11950)() > > 996 res = self._evalf_try_(*args) > > 997 if res is None: > > --> 998 res = super(BuiltinFunction, self).__call__( > > 999 *args, coerce=coerce, hold=hold) > > 1000 > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/function.pyx > > in sage.symbolic.function.Function.__call__ > > (build/cythonized/sage/symbolic/function.cpp:6977)() > > 490 (<Expression>args[0])._gobj, hold) > > 491 elif self._nargs == 2: > > --> 492 res = g_function_eval2(self._serial, > > (<Expression>args[0])._gobj, > > 493 (<Expression>args[1])._gobj, hold) > > 494 elif self._nargs == 3: > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc > > in _eval_(self, f, x) > > 88 for integrator in self.integrators: > > 89 try: > > ---> 90 return integrator(f, x) > > 91 except NotImplementedError: > > 92 pass > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/integration/external.pyc > > in maxima_integrator(expression, v, a, b) > > 30 expression = SR(expression) > > 31 if a is None: > > ---> 32 result = maxima.sr_integral(expression,v) > > 33 else: > > 34 result = maxima.sr_integral(expression, v, a, b) > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc > > in sr_integral(self, *args) > > 807 """ > > 808 try: > > --> 809 return > > max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args]))) > > 810 except RuntimeError as error: > > 811 s = str(error) > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc > > in max_to_sr(expr) > > 1684 op_max=caar(expr) > > 1685 if op_max in special_max_to_sage: > > -> 1686 return special_max_to_sage[op_max](expr) > > 1687 if not(op_max in max_op_dict): > > 1688 op_max_str=maxprint(op_max).python()[1:-1] > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc > > in dummy_integrate(expr) > > 1461 integrate(f(x), x, 0, 10) > > 1462 """ > > -> 1463 args=[max_to_sr(a) for a in cdr(expr)] > > 1464 if len(args) == 4 : > > 1465 return > > sage.symbolic.integration.integral.definite_integral(*args, > > > > /usr/local/sage-8/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc > > in max_to_sr(expr) > > 1702 max_args=cdr(expr) > > 1703 args=[max_to_sr(a) for a in max_args] > > -> 1704 return op(*args) > > 1705 elif expr.symbolp(): > > 1706 if not(expr in max_sym_dict): > > > > TypeError: __call__() takes exactly 2 arguments (3 given) > > > > Why those two variants are treated so dofferently s beyond me.. > > > > [BTW, not totally related : I can't make head nor tail of this : > > > > > > sage: f(x).diff(x) > > (0, 0, 0)*D[0]piecewise(x|-->x^3 on (-oo, -1), x|-->x on [-1, 1], x|-->x^2 > > on (1, +oo); x) + D[1]piecewise(x|-->x^3 on (-oo, -1), x|-->x on [-1, 1], > > x|-->x^2 on (1, +oo); x) > > ] > > Perhaps there should be a common suite of unit tests applicable to > symbolic functions / functions that can return symbolic expressions in > order to help ensure a consistent interface. This is all pretty > embarrassing :(
Perhaps it's even trickier, as it's often more desirable - meaningful to return an algebraic extension of the field where these roots live, but not an element of SR. -- You received this message because you are subscribed to the Google Groups "sage-release" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-release+unsubscr...@googlegroups.com. To post to this group, send email to sage-release@googlegroups.com. Visit this group at https://groups.google.com/group/sage-release. For more options, visit https://groups.google.com/d/optout.