diff --git a/Project.toml b/Project.toml index d1f1d3de..a06b3e42 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "SymPy" uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" -version = "1.0.19" +version = "1.0.20" [deps] diff --git a/README.md b/README.md index 290eafdc..b76d2cfa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/mathfuns.jl b/src/mathfuns.jl index 1546aaa3..03e106b9 100644 --- a/src/mathfuns.jl +++ b/src/mathfuns.jl @@ -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...) diff --git a/src/utils.jl b/src/utils.jl index d9f5563d..1a3cb44b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 diff --git a/test/tests.jl b/test/tests.jl index c907c2e9..8e8a0c6b 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -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)