Ask Your Question
1

type error when calculating a limit

asked 2022-05-08 18:31:13 +0200

Tintin1 gravatar image

I am trying to calculate a limit:

print(limit(1/x,x=0))

Why do I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_26364/2811025272.py in <module>
 ---> ... print(limit(Integer(1)/x,x=Integer(0)))

 TypeError: limit() got an unexpected keyword argument 'x'
edit retag flag offensive close merge delete

Comments

works for me

sage: limit(1/x,x=0)
Infinity
FrédéricC gravatar imageFrédéricC ( 2022-05-08 19:54:35 +0200 )edit

are you messing with some other definition of limit ? importing sympy ?

FrédéricC gravatar imageFrédéricC ( 2022-05-08 20:18:51 +0200 )edit

yes, I imported sympy. you found the bug. Now it works, after removing the import of sympy. How do I avoid the conflicting naming?

Tintin1 gravatar imageTintin1 ( 2022-05-08 21:53:55 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2022-05-09 00:00:30 +0200

Emmanuel Charpentier gravatar image

For the record (i. e. future users erusing past answers) : as guessed by @Frederic C, the problem is that Sage's definition of limit by Sympi's :

sage: limit(1/x, x=0)
Infinity
sage: import sympy
sage: limit(1/x, x=0)
Infinity
sage: from sympy import limit
sage: limit(1/x, x=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-ba76f96e233b> in <module>
----> 1 limit(Integer(1)/x, x=Integer(0))

TypeError: limit() got an unexpected keyword argument 'x'
sage: reset("limit")
sage: limit(1/x, x=0)
Infinity

So don't import limit from sympy if you want to keep Sage's definition.

And don't from sympy import *, which is a swell way to royally bugger a Sage session... and is deprecated (= no longer recommended and advised against) by Sympy's authors even in a pure Python session.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-08 18:31:13 +0200

Seen: 128 times

Last updated: May 09 '22