Integration of formal functions

155 views
Skip to first unread message

Victor Miller

unread,
Jul 25, 2013, 12:16:01 PM7/25/13
to sage-s...@googlegroups.com
In the latest version of sage (at least what cloud.sagemath.org is running), there is a problem with substituting constants into the formal integrals of formal functions.  See the examples below.

Victor

sage: var('a'); function('f',a)
sage: g = f(a).integrate(a,0,a^2)
sage: g
integrate(f(a),0,a^2)

sage: g.derivative(a)
Error in lines 1-1
Traceback (most recent call last):
  File "/mnt/home/lQoU8m2s/.sagemathcloud/sage_server.py", line 498, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "expression.pyx", line 3006, in sage.symbolic.expression.Expression.derivative (sage/symbolic/expression.cpp:15855)
  File "derivative.pyx", line 216, in sage.misc.derivative.multi_derivative (sage/misc/derivative.c:2715)
  File "expression.pyx", line 3078, in sage.symbolic.expression.Expression._derivative (sage/symbolic/expression.cpp:16245)
  File "/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 224, in _tderivative_
    - f.subs(x==a)*a.diff(diff_param)
  File "element.pyx", line 344, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:3871)
  File "misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (sage/structure/misc.c:1696)
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'diff'

sage: g1 = f(a).integrate(a)
sage: g1(0)
Error in lines 1-1 Traceback (most recent call last): File "/mnt/home/lQoU8m2s/.sagemathcloud/sage_server.py", line 498, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "expression.pyx", line 3973, in sage.symbolic.expression.Expression.__call__ (sage/symbolic/expression.cpp:19900) File "ring.pyx", line 685, in sage.symbolic.ring.SymbolicRing._call_element_ (sage/symbolic/ring.cpp:7672) File "expression.pyx", line 3824, in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:19177) File "/usr/local/sage/sage-5.10.rc1/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 75, in _eval_ if len(x.variables()) == 1: File "element.pyx", line 344, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:3871) File "misc.pyx", line 257, in sage.structure.misc.getattr_from_other_class (sage/structure/misc.c:1696) AttributeError: 'sage.rings.integer.Integer' object has no attribute 'variables'

William Stein

unread,
Jul 25, 2013, 2:10:42 PM7/25/13
to sage-s...@googlegroups.com
On Thu, Jul 25, 2013 at 9:16 AM, Victor Miller <victor...@gmail.com> wrote:
> In the latest version of sage (at least what cloud.sagemath.org is running),

... which is sage-5.10, the latest released version. However, the
same happens with 'Sage Version 5.11.beta2, Release Date: 2013-06-19'.
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Burcin Erocal

unread,
Jul 26, 2013, 5:15:10 AM7/26/13
to sage-s...@googlegroups.com
On Thu, 25 Jul 2013 11:10:42 -0700
William Stein <wst...@gmail.com> wrote:

> On Thu, Jul 25, 2013 at 9:16 AM, Victor Miller
> <victor...@gmail.com> wrote:
> > In the latest version of sage (at least what cloud.sagemath.org is
> > running),
>
> ... which is sage-5.10, the latest released version. However, the
> same happens with 'Sage Version 5.11.beta2, Release Date: 2013-06-19'.

This is now #14976:

http://trac.sagemath.org/ticket/14976

Cheers,
Burcin

Emmanuel Charpentier

unread,
Jul 27, 2013, 5:43:41 AM7/27/13
to sage-s...@googlegroups.com
The problem seems to lie on Sage's side. In the "native" version of sage :

using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) define(g(a),integrate(f(t),t,0,a^2));
                                        2
                                       a
                                      /
                                      [
(%o1)                         g(a) := I   f(t) dt
                                      ]
                                      /
                                       0
(%i2) diff(g(a),a);
                                          2
(%o2)                              2 a f(a )

which looks reasonable.

In Sage's version of maxima :

charpent@portable-ec:~$ sage -maxima
;;; Loading #P"/usr/local/sage-5.10/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/local/sage-5.10/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/local/sage-5.10/local/lib/ecl/defsystem.fas"
;;; Loading #P"/usr/local/sage-5.10/local/lib/ecl/cmp.fas"
using Lisp ECL 12.12.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) define(g(a),integrate(f(t),t,0,a^2));
                                        2
                                       a
                                      /
                                      [
(%o1)                         g(a) := I   f(t) dt
                                      ]
                                      /
                                       0
(%i2) diff(g(a),a);
                                          2
(%o2)                              2 a f(a )

which is the same. Therefore, neither native maxima nor Sage's maxima  seem to be the culprit.

The same behaviour is observed on Sage 5.4 as running on www.sagenb.org ; its maxima gives sane answers (checked by a %maxima cell in the notebook), its "native answer is the same error.

Therefore, this bug is old...

HTH

                                                          Emmanuel Charpentier

Emmanuel Charpentier

unread,
Jul 27, 2013, 8:27:04 AM7/27/13
to sage-s...@googlegroups.com
By the way, the problem *might* be larger than that. In Maxima, one can do :

(%i1)  display2d:false;

(%o1) false
(%i2) define(h(x),integrate(f(t),t,g1(x),g2(x)));

defint: lower limit of integration must be real; found g1(x)
 -- an error. To debug this try: debugmode(true);
(%i3) declare(g1,real,g2,real);

(%o3) done
(%i4) define(h(x),integrate(f(t),t,g1(x),g2(x)));

(%o4) h(x):='integrate(f(t),t,g1(x),g2(x))
(%i5) diff(h(x),x);

(%o5) f(g2(x))*'diff(g2(x),x,1)-f(g1(x))*'diff(g1(x),x,1)

which is both correct and useful.

As far as I know, one cannot declare a function as real-valued in Sage :

sage: g1=function("g1",x,domain="real")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-43-ab6717b797c7> in <module>()
----> 1 g1=function("g1",x,domain="real")

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/calculus/var.so in sage.calculus.var.function (sage/calculus/var.c:1253)()

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/calculus/var.so in sage.calculus.var.function (sage/calculus/var.c:1299)()

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/function_factory.pyc in function(s, *args, **kwds)
    310         names = [s]
    311 
--> 312     funcs = [function_factory(name, **kwds) for name in names]
    313 
    314     if len(args) > 0:

TypeError: function_factory() got an unexpected keyword argument 'domain'

But also :

sage: g1=function("g1",x)
sage: assume(g1,"real")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-45-bd761ce74d13> in <module>()
----> 1 assume(g1,"real")

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/assumptions.pyc in assume(*args)
    410         else:
    411             try:
--> 412                 x.assume()
    413             except KeyError:
    414                 raise TypeError, "assume not defined for objects of type '%s'"%type(x)

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.assume (sage/symbolic/expression.cpp:8750)()

TypeError: self (=g1(x)) must be a relational expression
but also :

sage: assume(g1(x),"real")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-46-0d7aa50473b1> in <module>()
----> 1 assume(g1(x),"real")

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/assumptions.pyc in assume(*args)
    410         else:
    411             try:
--> 412                 x.assume()
    413             except KeyError:
    414                 raise TypeError, "assume not defined for objects of type '%s'"%type(x)

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.assume (sage/symbolic/expression.cpp:8750)()

TypeError: self (=g1(x)) must be a relational expression

hence :
sage: g2(x)=function("g2",x)
sage: h(x)=integrate(f(t),t,g1(x), g2(x))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-48-fdf29d67d922> in <module>()
----> 1 __tmp__=var("x"); h = symbolic_expression(integrate(f(t),t,g1(x), g2(x))).function(x)

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/misc/functional.pyc in integral(x, *args, **kwds)
    738     """
    739     if hasattr(x, 'integral'):
--> 740         return x.integral(*args, **kwds)
    741     else:
    742         from sage.symbolic.ring import SR

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.integral (sage/symbolic/expression.cpp:39592)()

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in integrate(expression, v, a, b, algorithm)
    686         return indefinite_integral(expression, v)
    687     else:
--> 688         return definite_integral(expression, v, a, b)
    689 
    690 integral= integrate

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:5114)()

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.pyc in _eval_(self, f, x, a, b)
    171         for integrator in self.integrators:
    172             try:
--> 173                 return integrator(*args)
    174             except NotImplementedError:
    175                 pass

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/symbolic/integration/external.pyc in maxima_integrator(expression, v, a, b)
     19         result = maxima.sr_integral(expression,v)
     20     else:
---> 21         result = maxima.sr_integral(expression, v, a, b)
     22     return result._sage_()
     23 

/usr/local/sage-5.10/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in sr_integral(self, *args)
    745                 raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(" + s[4:k] +">0)', see `assume?` for more details)\n" + s
    746             else:
--> 747                 raise error
    748 
    749     def sr_sum(self,*args):

RuntimeError: ECL says: Error executing code in Maxima: defint: lower limit of integration must be real; found g1(x)

Should this problem be added to Trac#14976 or reported elsewhere ?

                                                                   Emmanuel Charpentier 

[ Snip... ]

Robert Dodier

unread,
Jul 27, 2013, 7:34:10 PM7/27/13
to sage-s...@googlegroups.com
On 2013-07-27, Emmanuel Charpentier <emanuel.c...@gmail.com> wrote:

> (%i2) define(h(x),integrate(f(t),t,g1(x),g2(x)));
>
> defint: lower limit of integration must be real; found g1(x)
> -- an error. To debug this try: debugmode(true);

Well, a way to make this work is to write define(h(x), 'integrate(...)).
'integrate is a formal integral -- it doesn't invoke the code to solve
definite integrals -- so it won't bump into that error.

best

Robert Dodier

Emmanuel Charpentier

unread,
Jul 28, 2013, 5:18:38 AM7/28/13
to sage-s...@googlegroups.com
Comments and (horrible !) workaround in Trac#14976.

HTH,
                                                                                   Emmanuel Charpentier
[ Snip ... ]

Reply all
Reply to author
Forward
0 new messages