Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object is not subscriptable from call to integrate #12993

Open
nasser1 opened this issue Jul 18, 2017 · 2 comments
Open

Comments

@nasser1
Copy link

nasser1 commented Jul 18, 2017

Copied from

https://stackoverflow.com/questions/45173987/typeerror-nonetype-object-is-not-subscriptable-from-call-to-integrate

Error using integrate. Here is the MWE

python
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

from sympy import *
A,B,y=symbols('A B y')
integrate(-(A2+B2*(-y2+1))(1/2)/(-y**2+1),y)

Traceback (most recent call last):
File "", line 1, in
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 1295, in integrate
risch=risch, manual=manual)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 486, in doit
conds=conds)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 919, in _eval_integral
result = manualintegrate(g, x)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1223, in manualintegrate
return _manualintegrate(integral_steps(f, var))
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 212, in _alternatives
result = rule(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 33, in conditioned_rl
return rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 176, in _rewriter
substep = integral_steps(rewritten, symbol)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 95, in switch_rl
return rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 335, in mul_rule
next_step = integral_steps(f, symbol)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 743, in trig_substitution_rule
a = match[a]
TypeError: 'NoneType' object is not subscriptable

Interesting thing is that, if I issue the same command right again, the error do not show up

integrate(-(A2+B2*(-y2+1))(1/2)/(-y2+1),y)
Integral((A
2 - B2*y2 + B**2)**0.5/((y - 1)*(y + 1)), y)

It only shows up first time it is used! It looks like using it first time loads something to memory and hence next time the error do not show up.

@jksuom
Copy link
Member

jksuom commented Jul 19, 2017

There is a bug in manualintegrate.trig_substitution_rule:

def trig_substitution_rule(integral):
    integrand, symbol = integral
    a = sympy.Wild('a', exclude=[0, symbol])
    b = sympy.Wild('b', exclude=[0, symbol])
    theta = sympy.Dummy("theta")

    matches = integrand.find(a + b*symbol**2)
    if matches:
        for expr in matches:
            match = expr.match(a + b*symbol**2)
            a = match[a]
            b = match[b]

The wild symbols a and b are reassigned in the loop and, if the loop is repeated, expr.match will fail and return None.

@normalhuman
Copy link
Contributor

The error no longer occurs (a and b have been changed to A and B in Wild matches), but the integral returns unevaluated:

>>> A, B, y = symbols('A B y', positive=True)
>>> integrate(-(A**2 + B**2*(-y**2 + 1))**(S(1)/2) / (-y**2 + 1), y)
Integral(sqrt(A**2 - B**2*y**2 + B**2)/((y - 1)*(y + 1)), y)

Wolfram Alpha can do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants