JuliaPy / SymPy.jl

Julia interface to SymPy via PyCall
http://juliapy.github.io/SymPy.jl/
MIT License
269 stars 62 forks source link

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

Closed newptcai closed 5 months ago

newptcai commented 5 months ago

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):

mzaffalon commented 5 months ago

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 commented 5 months ago

Just to add, the function can also be defined through

@syms n y()
newptcai commented 5 months ago

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