Skip to content

Commit

Permalink
widen signature for simplify, add not to solve documentation (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored May 9, 2020
1 parent 45920c7 commit 6ddb9ba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 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.0.19"
version = "1.0.20"


[deps]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ easier.

The [tutorial](examples/tutorial.md) provides an overview. It is
viewable as an `IJulia` notebook
[here](http://nbviewer.ipython.org/github/JuliaPy/SymPy.jl/blob/master/examples/tutorial.ipynb). In addition, most of the SymPy tutorial has the `julia` counterparts illustrated starting from [index.html](http://htmlpreview.github.io/?https://github.com/JuliaPy/SymPy.jl/blob/master/examples/index.html)
[here](http://nbviewer.ipython.org/github/JuliaPy/SymPy.jl/blob/master/examples/tutorial.ipynb). In addition, most of the SymPy tutorial has the `julia` counterparts illustrated starting from [index.html](http://htmlpreview.github.io/?https://github.com/JuliaPy/SymPy.jl/blob/master/examples/index.html).

### Installation

Expand Down
17 changes: 17 additions & 0 deletions src/mathfuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ end


## Add interfaces for solve, nonlinsolve when vector of equations passed in
"""
solve
Use `solve` to solve algebraic equations.
Examples:
```
@vars x y a b c d
solve(x^2 + 2x + 1, x) # [-1]
solve(x^2 + 2a*x + a^2, x) # [-a]
solve([a*x + b*y-3, c*x + b*y - 1], [x,y]) # Dict(y => (a - 3*c)/(b*(a - c)),x => 2/(a - c))
```
!!! Note
A very nice example using `solve` is a [blog](https://newptcai.github.io/euclidean-plane-geometry-with-julia.html) entry on [Napolean's theorem](https://en.wikipedia.org/wiki/Napoleon%27s_theorem) by Xing Shi Cai.
"""
solve() = ()
solve(V::Vector{T}, args...; kwargs...) where {T <: SymbolicObject} =
sympy.solve(V, args...; kwargs...)

Expand Down
9 changes: 9 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ subs(;kwargs...) = ex -> subs(ex; kwargs...)
subs(dict::Dict; kwargs...) = ex -> subs(ex, dict...; kwargs...)
subs(d::Pair...; kwargs...) = ex -> subs(ex, [(p.first, p.second) for p in d]...; kwargs...)

## simplify(ex::SymbolicObject, ...) is exported
"""
simplify
SymPy has dozens of functions to perform various kinds of simplification. There is also one general function called `simplify` that attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression. (See [Simplification](https://docs.sympy.org/latest/tutorial/simplification.html) for details on `simplify` and other related functionality).
For non-symbolic expressions, `simplify` returns its first argument.
"""
simplify(x,args...;kwargs...) = x

##################################################
# avoid type piracy. After we call `pytype` mappings, some
Expand Down
7 changes: 7 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ import PyCall
ex = line(10)
@test ex(sol) == ex(sol...) == 11

## Simplify (issue 343)
@vars x
@test simplify(sin(x)^2 + cos(x)^2) == 1
@test simplify(sympy.gamma(x)/sympy.gamma(x-2)) == (x-1)*(x-2)
_ones = (1, 1.0, big"1", "1", one)
@test simplify.(_ones) == _ones

## Conversion
x = Sym("x")
p = x.subs(x,pi)
Expand Down

2 comments on commit 6ddb9ba

@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/14486

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.0.20 -m "<description of version>" 6ddb9ba4aab6dc74ac3170b046e59d7303b4cc3a
git push origin v1.0.20

Please sign in to comment.