Skip to content

Commit 3de07a6

Browse files
authored
Issue 319 320 (#321)
* close #319; close #320 * continue fixing issue 320 * version bump
1 parent cb73faf commit 3de07a6

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.0.11"
3+
version = "1.0.12"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/lambdify.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ function _piecewise(args...)
3232
ex
3333
end
3434

35+
## Hack to avoid Expr(:call, :*,2, x) being 2x and not 2*x
36+
__prod__(args...) = prod(args)
37+
export __prod__
3538

3639
fn_map = Dict(
3740
"Add" => :+,
3841
"Sub" => :-,
39-
"Mul" => :*,
42+
"Mul" => :__prod__,
4043
"Div" => :/,
4144
"Pow" => :^,
4245
"re" => :real,
@@ -78,7 +81,7 @@ function walk_expression(ex; values=Dict(), fns=Dict())
7881
return walk_expression(rhs(ex), values=values, fns=fns)
7982
end
8083

81-
if fn == "Symbol"
84+
if fn == "Symbol" || fn == "Dummy"
8285
str_ex = string(ex)
8386
return get(vals_map, str_ex, Symbol(str_ex))
8487
elseif fn in ["Integer" , "Float"]

src/mathfuns.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ Base.log10(x::SymbolicObject) = log(10,x)
4949
## use a pair for limit x=>0
5050
limit(x::SymbolicObject, xc::Pair, args...;kwargs...) = limit(x, xc[1], xc[2], args...;kwargs...)
5151
## allow a function
52-
limit(f::Function, x::Sym, c;kwargs...) = limit(f(x), x, c;kwargs...)
53-
limit(f::Function, c;kwargs...) = limit(f, symbols("x"), c;kwargs...)
54-
52+
limit(f::Function, x::Sym, c;kwargs...) = sympy.limit(f(x), x, c;kwargs...)
53+
limit(f::Function, c;kwargs...) = limit(f, sympy.Dummy("x"), c;kwargs...)
5554

55+
## This is type piracy and a bad idea
5656
function Base.diff(f::Function, n::Int=1)
57-
x = symbols("x")
58-
diff(f(x), x, n)
57+
x = sympy.Dummy("x")
58+
sympy.diff(f(x), x, n)
5959
end
6060

6161
## integrate(ex,a,b)
@@ -68,12 +68,12 @@ function integrate(ex::SymbolicObject, a::Number, b::Number)
6868
integrate(ex, (fs[1], a, b))
6969
end
7070
function integrate(f::Function, a::Number, b::Number)
71-
x = symbols("x")
72-
integrate(f(x), (x, a, b))
71+
x = sympy.Dummy("x")
72+
sympy.integrate(f(x), (x, a, b))
7373
end
7474
function integrate(f::Function)
75-
x = symbols("x")
76-
integrate(f(x))
75+
x = sympy.Dummy("x")
76+
sympy.integrate(f(x), x)
7777
end
7878

7979

test/tests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,21 @@ end
569569
a = Sym(45)
570570
@test sind(a) == sin(PI/4)
571571

572+
# issue #319 with use of Dummy, but
573+
# really a lambdify issue
574+
dummy = sympy.Dummy
575+
# Symbolic differentiation of functions
576+
function D(f)
577+
x = dummy("x")
578+
lambdify(diff.(f(x), x), (x,))
579+
end
580+
@test D(t -> t^2)(1) == 2
581+
582+
# issue #320 with integrate(f) when
583+
# f is consant
584+
@test integrate(x -> 1, 0, 1) == 1
585+
@test limit(x->1, x, 0) == 1
586+
@test diff(x->1) == 0
572587
end
573588

574589
@testset "generic programming, issue 223" begin

0 commit comments

Comments
 (0)