Skip to content

Commit

Permalink
work around for issue #474 (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Aug 8, 2022
1 parent 29c5bfd commit ff52d9b
Show file tree
Hide file tree
Showing 3 changed files with 13 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.6"
version = "1.1.7"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand Down
11 changes: 7 additions & 4 deletions src/lambdify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ __ALL__(xs...) = all(xs)
__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)
# __SYMPY__ALL__,
fn_map = Dict(
"Add" => :+,
"Sub" => :-,
"Mul" => :*, # :(SymPy.__PROD__)
"Div" => :/,
"Pow" => :^,
# "Pow" => :^,
"Pow" => :(SymPy.__POW__),
"re" => :real,
"im" => :imag,
"Abs" => :abs,
Expand Down Expand Up @@ -115,8 +118,8 @@ function walk_expression(ex; values=Dict(), fns=Dict())
end

"""
lambdify(ex, vars=free_symbols();
fns=Dict(), values=Dict, use_julia_code=false,
lambdify(ex, vars=free_symbols();
fns=Dict(), values=Dict, use_julia_code=false,
invoke_latest=true)
Take a symbolic expression and return a `Julia` function or expression to build a function.
Expand All @@ -140,7 +143,7 @@ julia> @syms x y z
(x, y, z)
julia> ex = x^2 * sin(x)
2
2
x ⋅sin(x)
julia> fn = lambdify(ex);
Expand Down
5 changes: 5 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ end
@test lambdify(p)(2) == 2
@test lambdify(p)(-2) == (-2)^2

## Issue #474 with rational powers
@syms x
ex = 1/(2*x*sympy.pi^(1//4))
@test N(ex(2)) lambdify(ex)(2)

## Issue catch all for N; floats only
@syms x
ex = integrate(sqrt(1 + (1/x)^2), (x, 1/sympy.E, sympy.E))
Expand Down

0 comments on commit ff52d9b

Please sign in to comment.