JuliaPy / SymPy.jl

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

Piecewise not defined in SymPy #469

Closed dgomezcastro closed 2 years ago

dgomezcastro commented 2 years ago

I am using SymPy v1.1.6 over Julia v1.7.2 and the piecewise function does not seem to exist, either in lower case or upper case.

It seems that it was implemented at some point: see link

julia> using SymPy

julia> x = Sym("x")
x

julia> piecewise((1, x < 1), (3, x >= 1))
ERROR: UndefVarError: piecewise not defined
Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

julia> Piecewise((1, x < 1), (3, x >= 1))
ERROR: UndefVarError: Piecewise not defined
Stacktrace:
 [1] top-level scope
   @ REPL[15]:1
mzaffalon commented 2 years ago
sympy.Piecewise((1, Lt(x, 1)), (3, Ge(x, 1)))

See here for example.

dgomezcastro commented 2 years ago

Great! That works!. Is there some documentation for this? I cannot find any.

jverzani commented 2 years ago

Maybe the README, but it isn't very front and center. The basic idea is here:

The basic usage follows these points:

generic methods from Julia and imported functions in the sympy namespace are called through fn(object)

SymPy methods are called through Python's dot-call syntax: object.fn(...)

Constructors, like sympy.Symbol, and other non-function calls from sympy are qualified with sympy.Constructor(...). Such qualified calls are also useful when the first argument is not symbolic.

dgomezcastro commented 2 years ago

Perfect. Now I understood the logic. This is very useful.