Skip to content

Commit

Permalink
Issue 504b (JuliaPy#513)
Browse files Browse the repository at this point in the history
* get docs working

* odd error

* odd error 2

* odd error 2

* simplify difference

* push change to POW

* version bump

* run doctest fix=true

* intercept sqrt, cbrt
  • Loading branch information
jverzani authored Aug 14, 2023
1 parent db3d1e2 commit 3214d3b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "1.1.9"
version = "1.1.10"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Tutorial/basic_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ julia> ex = sin(x)^2 + x^2
x + sin (x)
julia> body = convert(Expr, ex)
:(SymPy.__POW__(x, 2) + SymPy.__POW__(sin(x), 2))
:(x ^ 2 + sin(x) ^ 2)
julia> syms = Symbol.(free_symbols(ex))
1-element Vector{Symbol}:
Expand Down
11 changes: 8 additions & 3 deletions src/lambdify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ __ZERO__(xs...) = 0
# not quite a match; NaN not θ(0) when evaluated at 0 w/o second argument
__HEAVISIDE__ = (a...) -> (a[1] < 0 ? 0 : (a[1] > 0 ? 1 : (length(a) > 1 ? a[2] : NaN)))
__POW__(x, y::Int) = Base.literal_pow(^, x, Val(y)) # otherwise
__POW__(a,b) = (a)^(b)
__POW__(a,b) = (@show a, b; (a)^(b))
# __SYMPY__ALL__,
fn_map = Dict(
"Add" => :+,
"Sub" => :-,
"Mul" => :*, # :(SymPy.__PROD__)
"Div" => :/,
# "Pow" => :^,
"Pow" => :(SymPy.__POW__),
"Pow" => :^,
#"Pow" => :(SymPy.__POW__),
"re" => :real,
"im" => :imag,
"Abs" => :abs,
Expand Down Expand Up @@ -134,6 +134,11 @@ function walk_expression(ex; values=Dict(), fns=Dict())
return walk_expression.(Introspection.args(ex), values=values, fns=fns)
elseif fn == "Indexed"
return Expr(:ref, [walk_expression(a, values=values, fns=fns) for a in Introspection.args(ex)]...)
elseif fn == "Pow"
a, b = Introspection.args(ex)
b == 1//2 && return Expr(:call, :sqrt, walk_expression(a, values=values, fns=fns))
b == 1//3 && return Expr(:call, :cbrt, walk_expression(a, values=values, fns=fns))
return Expr(:call, :^, [walk_expression(aᵢ, values=values, fns=fns) for aᵢ in (a,b)]...)
elseif haskey(vals_map, fn)
return vals_map[fn]
end
Expand Down

0 comments on commit 3214d3b

Please sign in to comment.