Re: [sympy] ntegrate does not know the sign of abs()

23 views
Skip to first unread message

Aaron Meurer

unread,
Jun 18, 2012, 3:12:16 PM6/18/12
to sy...@googlegroups.com
It's definitely a bug. integrate should catch NotImplementedError from limit() and return an unevaluated Integral. 

Also, not knowing the sign of abs is definitely a bug as well. Please open an issue for this at http://code.google.com/p/sympy/issues/list

Aaron Meurer

On Jun 18, 2012, at 12:53 PM, Barak Yair Reif <barak...@gmail.com> wrote:

I tried to look for this bug and haven't found it (maybe my lacking search skills), still I felt uncomfortable to open an issue. 

Here is the code:

x=Symbol("x")

f1=2*E**(-2*x)
F1=integrate(f1,(x,0,oo))
print F1 #Works great:

a=Symbol("a")
f2=abs(a)*E**(-abs(a)*x)
F2=integrate(f2,(x,0,oo)) #fails

and the output is:

Traceback (most recent call last):
  File "C:/Users/Barak/Desktop/python/temp", line 18, in <module>
    F2=integrate(f2,(x,0,oo))
  File "C:\Python27\lib\site-packages\sympy\utilities\decorator.py", line 24, in threaded_func
    return func(expr, *args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\integrals\integrals.py", line 847, in integrate
    return integral.doit(deep = False)
  File "C:\Python27\lib\site-packages\sympy\integrals\integrals.py", line 393, in doit
    function = antideriv._eval_interval(x, a, b)
  File "C:\Python27\lib\site-packages\sympy\core\expr.py", line 229, in _eval_interval
    B = limit(self, x, b)
  File "C:\Python27\lib\site-packages\sympy\series\limits.py", line 116, in limit
    return i*limit(d, z, z0, dir)
  File "C:\Python27\lib\site-packages\sympy\series\limits.py", line 192, in limit
    r = gruntz(e, z, z0, dir)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 678, in gruntz
    r = limitinf(e, z)
  File "C:\Python27\lib\site-packages\sympy\core\cache.py", line 101, in wrapper
    func_cache_it_cache[k] = r = func(*args, **kw_args)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 480, in limitinf
    c0, e0 = mrv_leadterm(e, x)
  File "C:\Python27\lib\site-packages\sympy\core\cache.py", line 101, in wrapper
    func_cache_it_cache[k] = r = func(*args, **kw_args)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 562, in mrv_leadterm
    f, logw = rewrite(exps, Omega, x, w)
  File "C:\Python27\lib\site-packages\sympy\series\gruntz.py", line 627, in rewrite
    raise NotImplementedError('Result depends on the sign of %s' % sig)
NotImplementedError: Result depends on the sign of -sign(Abs(a))


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/W6WpoV5C5DUJ.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

Aaron Meurer

unread,
Jun 18, 2012, 3:32:55 PM6/18/12
to sy...@googlegroups.com
It looks like in the git master the integral works:

In [1]: var('a')
Out[1]: a

In [2]: integrate(abs(a)*exp(-abs(a)*x), (x, 0, oo))
Out[2]:
⎧ π
⎪ 1 for │periodic_argument(│a│, ∞)│ < ─
⎪ 2

⎪∞
⎨⌠
⎪⎮ -x⋅│a│
⎪⎮ ℯ ⋅│a│ dx otherwise
⎪⌡
⎪0


But the limit bug still exists (it's simply bypassed by the new
integration algorithm), so if you could still open an issue for that,
that would be great.

Aaron Meurer

Tom Bachmann

unread,
Jun 18, 2012, 3:34:34 PM6/18/12
to sy...@googlegroups.com
> But the limit bug still exists (it's simply bypassed by the new
> integration algorithm)

Are you sure of that? I vaguely remember fixing an issue related to
limits and integral evaluation. Not sure, though.

Barak Yair Reif

unread,
Jun 18, 2012, 3:45:39 PM6/18/12
to sy...@googlegroups.com

Aaron Meurer

unread,
Jun 18, 2012, 4:27:53 PM6/18/12
to sy...@googlegroups.com
I meant the other bug:

In [5]: limit(integrate(abs(a)*exp(-abs(a)*x), x), x, oo)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-5-bb74dd8ee8de> in <module>()
----> 1 limit(integrate(abs(a)*exp(-abs(a)*x), x), x, oo)

/home/asmeurer/Dropbox/sympy/sympy/series/limits.pyc in limit(e, z, z0, dir)
134 i, d = e.as_independent(z)
135 if i is not S.One and i.is_bounded:
--> 136 return i*limit(d, z, z0, dir)
137 else:
138 i, d = S.One, e

/home/asmeurer/Dropbox/sympy/sympy/series/limits.pyc in limit(e, z, z0, dir)
260
261 try:
--> 262 r = gruntz(e, z, z0, dir)
263 if r is S.NaN:
264 raise PoleError()

/home/asmeurer/Dropbox/sympy/sympy/series/gruntz.pyc in gruntz(e, z, z0, dir)
676 r = None
677 if z0 == oo:
--> 678 r = limitinf(e, z)
679 elif z0 == -oo:
680 r = limitinf(e.subs(z, -z), z)

/home/asmeurer/Dropbox/sympy/sympy/core/cache.pyc in wrapper(*args, **kw_args)
89 except KeyError:
90 pass
---> 91 func_cache_it_cache[k] = r = func(*args, **kw_args)
92 return r
93 return wrapper

/home/asmeurer/Dropbox/sympy/sympy/series/gruntz.pyc in limitinf(e, x)
470 e = e.subs(x, p)
471 x = p
--> 472 c0, e0 = mrv_leadterm(e, x)
473 sig = sign(e0, x)
474 if sig == 1:

/home/asmeurer/Dropbox/sympy/sympy/core/cache.pyc in wrapper(*args, **kw_args)
89 except KeyError:
90 pass
---> 91 func_cache_it_cache[k] = r = func(*args, **kw_args)
92 return r
93 return wrapper

/home/asmeurer/Dropbox/sympy/sympy/series/gruntz.pyc in mrv_leadterm(e, x)
548 #
549 w = Dummy("w", real=True, positive=True, bounded=True)
--> 550 f, logw = rewrite(exps, Omega, x, w)
551 series = calculate_series(f, w, logx=logw)
552 series = series.subs(log(w), logw) # this should not be necessary

/home/asmeurer/Dropbox/sympy/sympy/series/gruntz.pyc in rewrite(e,
Omega, x, wsym)
616 wsym = 1/wsym #if g goes to oo, substitute 1/w
617 elif sig != -1:
--> 618 raise NotImplementedError('Result depends on the sign
of %s' % sig)
619 #O2 is a list, which results by rewriting each item in
Omega using "w"
620 O2 = []

NotImplementedError: Result depends on the sign of -sign(Abs(a))

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.

Tom Bachmann

unread,
Jun 19, 2012, 4:34:50 AM6/19/12
to sy...@googlegroups.com
ah yes, the sign of -abs(a) not being known.

Chris Smith

unread,
Jun 19, 2012, 10:38:18 PM6/19/12
to sy...@googlegroups.com
Since the sign can be 0 or 1 maybe that's why it's confused. If you
give `a` a sign it works:

>>> var('a',positive=True)
a
>>> f2=abs(a)*E**(-abs(a)*x)
>>> integrate(f2,(x,0,oo))
1
>>> limit(integrate(abs(a)*exp(-abs(a)*x), x), x, oo)
0

/c

Chris Smith

unread,
Jun 19, 2012, 11:28:44 PM6/19/12
to sy...@googlegroups.com
One way to help integrate out would be to replace all Abs(foo) with
positive dummies, do the integration, then restore the original Abs
instances.

Aaron Meurer

unread,
Jun 20, 2012, 6:21:11 AM6/20/12
to sy...@googlegroups.com
On Jun 19, 2012, at 8:38 PM, Chris Smith <smi...@gmail.com> wrote:

> Since the sign can be 0 or 1 maybe that's why it's confused. If you
> give `a` a sign it works:

Ah, so this is actually not a bug, because if a is zero, then the
values of both the integral and the limit at infinity are different.
Not sure why I didn't notice that before...

Moral of the story: if you want something to be positive, define it
using Symbol(positive=True). abs() will give you nonnegative, which
is a little different...

Aaron Meurer

>
>>>> var('a',positive=True)
> a
>>>> f2=abs(a)*E**(-abs(a)*x)
>>>> integrate(f2,(x,0,oo))
> 1
>>>> limit(integrate(abs(a)*exp(-abs(a)*x), x), x, oo)
> 0
>
> /c
>
Reply all
Reply to author
Forward
0 new messages