Skip to content

Commit

Permalink
fix substitution variable order (#490)
Browse files Browse the repository at this point in the history
* fix substitution variable order

* fix doctests
  • Loading branch information
jverzani authored Feb 11, 2023
1 parent 86c72a4 commit 407f7b4
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 10 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.7"
version = "1.1.8"

[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)
:(x ^ 2 + sin(x) ^ 2)
:(SymPy.__POW__(x, 2) + SymPy.__POW__(sin(x), 2))
julia> syms = Symbol.(free_symbols(ex))
1-element Vector{Symbol}:
Expand Down
1 change: 1 addition & 0 deletions docs/src/Tutorial/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ spherical Bessel function $j_\nu(z)$.
```jldoctest intro
julia> using SpecialFunctions
julia> @syms ν z
(ν, z)
Expand Down
3 changes: 1 addition & 2 deletions docs/src/Tutorial/matrices.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ julia> using Test
julia> @test_throws Exception M1^-1
Test Passed
Expression: M1 ^ -1
Thrown: PyCall.PyError
```
Expand Down Expand Up @@ -798,7 +797,7 @@ There is no reason to, but generic `Julia` methods could be used:

```jldoctest matrices
julia> out = lu(A)
LU{Sym, Matrix{Sym}}
LU{Sym, Matrix{Sym}, Vector{Int64}}
L factor:
2×2 Matrix{Sym}:
1 0
Expand Down
1 change: 1 addition & 0 deletions docs/src/Tutorial/simplification.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ x - 1
julia> using SpecialFunctions
julia> simplify(gamma(x)/gamma(x - 2))
(x - 2)⋅(x - 1)
Expand Down
1 change: 1 addition & 0 deletions docs/src/Tutorial/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ julia> aug = [A b]
1 1 2 3
julia> linsolve(aug, (x,y,z)) # {(-y - 1, y, 2)};
{(-y - 1, y, 2)}
```

Expand Down
2 changes: 1 addition & 1 deletion src/lambdify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ x ⋅sin(x)
julia> fn = lambdify(ex);
julia> fn(pi)
1.2086779438644711e-15
0.0
julia> ex = x + 2y + 3z
x + 2⋅y + 3⋅z
Expand Down
6 changes: 2 additions & 4 deletions src/mathfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ julia> dsolve(eqns, ics = Dict(x(0) => 1, y(0) => 2))
Eq(x(t), 3*exp(t)/2 - exp(-t)/2)
Eq(y(t), 3*exp(t)/2 + exp(-t)/2)
julia> eqns = [∂(∂(x(t))) ~ 0, ∂(∂(y(t))) ~ -g]
2-element Vector{Sym}:
Eq(Derivative(x(t), (t, 2)), 0)
Eq(Derivative(y(t), (t, 2)), -g)
julia> eqns = (∂(∂(x(t))) ~ 0, ∂(∂(y(t))) ~ -g)
(Eq(Derivative(x(t), (t, 2)), 0), Eq(Derivative(y(t), (t, 2)), -g))
julia> dsolve(eqns) # can't solve for initial conditions though! (NotAlgebraic)
2-element Vector{Sym}:
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end

## without specification, variables to substitute for come from ordering of `free_symbols`:
function (ex::Sym)(args...)
xs = ex.free_symbols
xs = free_symbols(ex)
for (var, val) in zip(xs, args)
ex = ex.subs(var, Sym(val))
end
Expand Down
5 changes: 5 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,11 @@ end
## Issue #433 add sympy docstrings, clean up docstring
sprint(io -> show(io, SymPy.Doc(:sin)))

## Issue 456 use free_symbols() not .free_symbols in call
@syms x y
df = sympy.diff(sin(y-x),x)
@test df(x, PI/2) == -sin(x)

end

@test SymPy.convert_expr(sympy.Indexed(sympy.IndexedBase(:x), 1, -2)) == :(x[1, -2])

2 comments on commit 407f7b4

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77501

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.8 -m "<description of version>" 407f7b44e694cdd39bbfdfe0d4024aaa7d983bdc
git push origin v1.1.8

Please sign in to comment.