JuliaPy / SymPy.jl

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

Error when calling `sympy.Function()` #470

Closed ketch closed 2 years ago

ketch commented 2 years ago

The following code raises an error:

import SymPy; sp=SymPy;
sp.Function('q')

I get

MethodError: no method matching Function(::Char)
Closest candidates are:
  Function(::SymPy.SymbolicObject, ::Any...; kwargs...) at ~/.julia/packages/SymPy/5GXQf/src/importexport.jl:24

This code runs fine in Sympy in Python.

I'm aware that I can first create f as a Sympy symbol and then assign it to a function, but this does not accomplish what I need (see e.g. https://stackoverflow.com/questions/51547474/replacing-composed-functions-in-sympy).

mzaffalon commented 2 years ago

You should use SymFunction: import SymPy; SymPy.SymFunction("q"). Function is one of Julia's datatypes.

jverzani commented 2 years ago

To elaborate, you need " not ' for quoting in Julia. If you call sympy.Function("q") you will get a pyobject, as the implicit conversion does not work. Calling SymFunction, as @mzaffalon describes does this conversion. For convenience, you also have @syms q() for surface syntax.

ketch commented 2 years ago

Thank you!