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

Problem with solving linear recurrence: missing 1 required positional argument: 'other' #544

Closed
newptcai opened this issue Apr 23, 2024 · 3 comments · Fixed by jverzani/SymPyCore.jl#51

Comments

@newptcai
Copy link

newptcai commented Apr 23, 2024

Describe the bug

When I tried the following code in order to solve a linear recurrence, I got an error (as shown below).

julia> using SymPy

julia> @syms n
(n,)

julia> y = sympy.Function("y")
y

julia> f = y(n+2)-y(n+1)-y(n)
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/xing/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'TypeError'>
TypeError("Expr.__sub__() missing 1 required positional argument: 'other'")

Stacktrace:
  [1] pyerr_check
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:75 [inlined]
  [2] pyerr_check
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:79 [inlined]
  [3] _handle_error(msg::String)
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/exception.jl:96
  [4] macro expansion
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:110 [inlined]
  [5] #107
    @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 [inlined]
  [6] disable_sigint
    @ ./c.jl:473 [inlined]
  [7] __pycall!
    @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:42 [inlined]
  [8] _pycall!(ret::PyCall.PyObject, o::PyCall.PyObject, args::Tuple{PyCall.PyObject}, nargs::Int64, kw::Ptr{Nothing})
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:29
  [9] _pycall!
    @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:11 [inlined]
 [10] (::PyCall.PyObject)(args::PyCall.PyObject)
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
 [11] -(x::Sym{PyCall.PyObject}, y::Sym{PyCall.PyObject})
    @ SymPyCore ~/.julia/packages/SymPyCore/yYiXE/src/mathops.jl:16
 [12] top-level scope
    @ REPL[4]:1

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • Version: v2.0.1
@mzaffalon
Copy link
Contributor

Use SymFunction: https://jverzani.github.io/SymPyCore.jl/dev/reference/#SymPyCore.SymFunction

using SymPy
@syms n
y = SymFunction("y")
f = y(n+2)-y(n+1)-y(n)

@jverzani
Copy link
Collaborator

Just to add, the function can also be defined through

@syms n y()

@newptcai
Copy link
Author

I see. Thanks. Hope solving linear recurrence can be added to the documentations!

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

Successfully merging a pull request may close this issue.

3 participants