Skip to content

Commit ff52d9b

Browse files
authored
work around for issue #474 (#475)
1 parent 29c5bfd commit ff52d9b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymPy"
22
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
3-
version = "1.1.6"
3+
version = "1.1.7"
44

55
[deps]
66
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"

src/lambdify.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ __ALL__(xs...) = all(xs)
4141
__ZERO__(xs...) = 0
4242
# not quite a match; NaN not θ(0) when evaluated at 0 w/o second argument
4343
__HEAVISIDE__ = (a...) -> (a[1] < 0 ? 0 : (a[1] > 0 ? 1 : (length(a) > 1 ? a[2] : NaN)))
44+
__POW__(x, y::Int) = Base.literal_pow(^, x, Val(y)) # otherwise
45+
__POW__(a,b) = (a)^(b)
4446
# __SYMPY__ALL__,
4547
fn_map = Dict(
4648
"Add" => :+,
4749
"Sub" => :-,
4850
"Mul" => :*, # :(SymPy.__PROD__)
4951
"Div" => :/,
50-
"Pow" => :^,
52+
# "Pow" => :^,
53+
"Pow" => :(SymPy.__POW__),
5154
"re" => :real,
5255
"im" => :imag,
5356
"Abs" => :abs,
@@ -115,8 +118,8 @@ function walk_expression(ex; values=Dict(), fns=Dict())
115118
end
116119

117120
"""
118-
lambdify(ex, vars=free_symbols();
119-
fns=Dict(), values=Dict, use_julia_code=false,
121+
lambdify(ex, vars=free_symbols();
122+
fns=Dict(), values=Dict, use_julia_code=false,
120123
invoke_latest=true)
121124
122125
Take a symbolic expression and return a `Julia` function or expression to build a function.
@@ -140,7 +143,7 @@ julia> @syms x y z
140143
(x, y, z)
141144
142145
julia> ex = x^2 * sin(x)
143-
2
146+
2
144147
x ⋅sin(x)
145148
146149
julia> fn = lambdify(ex);

test/tests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,11 @@ end
768768
@test lambdify(p)(2) == 2
769769
@test lambdify(p)(-2) == (-2)^2
770770

771+
## Issue #474 with rational powers
772+
@syms x
773+
ex = 1/(2*x*sympy.pi^(1//4))
774+
@test N(ex(2)) lambdify(ex)(2)
775+
771776
## Issue catch all for N; floats only
772777
@syms x
773778
ex = integrate(sqrt(1 + (1/x)^2), (x, 1/sympy.E, sympy.E))

0 commit comments

Comments
 (0)