Ask Your Question
4

Simple Integration Problem

asked 2020-01-06 01:01:26 +0200

bso gravatar image

Hi, these simple steps used to work in Sage 8.0. They now give an error in 8.9. I tried in CoCalc, same problem. Do I need to change anything? If this is a Sage regression, how can I work around it? Thanks.

Sage 8.0 behavior:

sage: var('x t')
(x, t)

sage: psi = function('psi')(x, t)

sage: integrate(conjugate(psi) * diff(psi, x), x)
integrate(conjugate(psi(x, t))*diff(psi(x, t), x), x)

In 8.9 it gives:

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.9, Release Date: 2019-09-29                     │
│ Using Python 2.7.15. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: var('x t')
(x, t)
sage: psi = function('psi')(x, t)
sage: integrate(conjugate(psi) * diff(psi, x), x)
---------------------------------------------------------------------------
...
ValueError: No differentiation variable specified.

Posting the complete trace below:

sage: var('x t')
(x, t)
sage: psi = function('psi')(x, t)
sage: integrate(conjugate(psi) * diff(psi, x), x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-13afb3c477cd> in <module>()
----> 1 integrate(conjugate(psi) * diff(psi, x), x)

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/misc/functional.pyc in integral
(x, *args, **kwds)
    751     """
    752     if hasattr(x, 'integral'):
--> 753         return x.integral(*args, **kwds)
    754     else:
    755         from sage.symbolic.ring import SR

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage
.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:64036
)()
  12360                     R = ring.SR
  12361             return R(integral(f, v, a, b, **kwds))
> 12362         return integral(self, *args, **kwds)
  12363
  12364     integrate = integral

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.p
yc in integrate(expression, v, a, b, algorithm, hold)
    912         return integrator(expression, v, a, b)
    913     if a is None:
--> 914         return indefinite_integral(expression, v, hold=hold)
    915     else:
    916         return definite_integral(expression, v, a, b, hold=hold)

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.s
ymbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11847)
()
    996             res = self._evalf_try_(*args)
    997             if res is None:
--> 998                 res = super(BuiltinFunction, self).__call__(
    999                         *args, coerce=coerce, hold=hold)
   1000

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.s
ymbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6927)()
    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:

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.p
yc in _eval_(self, f, x)
     92         for integrator in self.integrators:
     93             try:
---> 94                 A = integrator(f, x)
     95             except (NotImplementedError, TypeError):
     96                 pass

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/integration/external.p
yc in sympy_integrator(expression, v, a, b)
     66     else:
     67         result = sympy.integrate(ex, (v, a._sympy_(), b._sympy_()))
---> 68     return result._sage_()
     69
     70 def mma_free_integrator(expression, v, a=None, b=None):

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/interfaces/sympy.pyc in _sympys
age_integral(self)
    307     """
    308     from sage.misc.functional import integral
--> 309     f, limits = self.function._sage_(), list(self.limits)
    310     for limit in limits:
    311         if len(limit) == 1:

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/interfaces/sympy.pyc in _sympys
age_mul(self)
    204     s = 1
    205     for x in self.args:
--> 206         s *= x._sage_()
    207     return s
    208

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/interfaces/sympy.pyc in _sympys
age_derivative(self)
    333     f = self.args[0]._sage_()
    334     args = [[a._sage_() for a in arg] if isinstance(arg,tuple) else arg._sage_() for
arg in self.args[2:]]
--> 335     return derivative(f, *args)
    336
    337 def _sympysage_order(self):

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/calculus/functional.pyc in deri
vative(f, *args, **kwds)
    129     """
    130     try:
--> 131         return f.derivative(*args, **kwds)
    132     except AttributeError:
    133         pass

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage
.symbolic.expression.Expression.derivative (build/cythonized/sage/symbolic/expression.cpp:255
45)()
   4172             ValueError: No differentiation variable specified.
   4173         """
-> 4174         return multi_derivative(self, args)
   4175
   4176     diff = differentiate = derivative

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/misc/derivative.pyx in sage.mis
c.derivative.multi_derivative (build/cythonized/sage/misc/derivative.c:3016)()
    217     if not args:
    218         # fast version where no arguments supplied
--> 219         return F._derivative()
    220
    221     for arg in derivative_parse(args):

/home/bryanso/sage-8.9/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage
.symbolic.expression.Expression._derivative (build/cythonized/sage/symbolic/expression.cpp:25
887)()
   4234                 return self.gradient()
   4235             else:
-> 4236                 raise ValueError("No differentiation variable specified.")
   4237         if not isinstance(deg, (int, long, sage.rings.integer.Integer)) \
   4238                 or deg < 1:

ValueError: No differentiation variable specified.
edit retag flag offensive close merge delete

Comments

1

This:

sage: reset()
sage: f=function("f")
sage: var("x,t")
(x, t)
sage: diff(f(x,t),x).integrate(x)
f(x, t)
sage: diff(f(x,t),x).integrate(t)
f(x, t)

Is highly suspicious...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-01-06 07:55:24 +0200 )edit

That clearly looks like a bug.

But I am not sure if it is directly related to my problem, which has the same variable x for diff and integrate.

But thanks for pointing out this new situation.

bso gravatar imagebso ( 2020-01-06 20:42:02 +0200 )edit

Maybe this can help to pinpoint the bug:

diff(psi, x)(x,t)

returns

diff(psi(t, x), t)

Similarly,

(conjugate(psi) * diff(psi, x))(x,t)

returns

conjugate(psi(t, x))*diff(psi(t, x), t)
dsejas gravatar imagedsejas ( 2020-01-07 05:51:57 +0200 )edit

Here are a couple of more to-the-point examples:

psi = function('psi')(x,t)
d   = psi.derivative(x)
print(d)

This shows the correct result: diff(psi(x, t), x). However, that's where things go wrong:

d(x,t)

returns

diff(psi(t, x), t)

This behavior can be reduced even to the following:

psi = function('psi')(x,t)
psi(x,t)

This returns

psi(t, x)

So maybe the bug is where this evaluation is defined or maybe somewhere in the definition of function. However, I must point out that

psi = function('psi')(x,t)
psi

returns

psi(x, t)

so I'd check the evaluation part of the code.

Also, the following work:

psi.subs(x=x, t=t)
psi(x, t)(x, t)
dsejas gravatar imagedsejas ( 2020-01-07 06:12:01 +0200 )edit

Hi desjas, all of your test cases return the same way in Sage 8.0 My problem does not happen in 8.0. I actually tried a few versions up to 8.8. All good. It started in 8.9. So logically I tend to think your test cases may not help pinpoint the error I observed.

The follow also errors out. This test does not have conjugate.

var('x t')
f = function('f')(x, t)
g = function('g')(x, t)
integrate(g * diff(f, x), x)
bso gravatar imagebso ( 2020-01-07 06:56:49 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-01-07 08:14:19 +0200

Emmanuel Charpentier gravatar image

This is now Trac#28964.

edit flag offensive delete link more

Comments

Thanks a lot.

bso gravatar imagebso ( 2020-01-07 16:13:12 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2020-01-06 01:01:26 +0200

Seen: 327 times

Last updated: Jan 07 '20