Skip to content

Commit 6da489b

Browse files
authored
Merge pull request #203 from JuliaPy/v0.6-7
V0.6 7
2 parents e3fba6f + c3237ff commit 6da489b

37 files changed

+3766
-396
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.4
7-
- 0.5
86
- 0.6
97
- nightly
108
matrix:
119
allow_failures:
12-
- julia: 0.6
1310
- julia: nightly
1411
git:
1512
depth: 99999

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[![SymPy](http://pkg.julialang.org/badges/SymPy_0.4.svg)](http://pkg.julialang.org/?pkg=SymPy&ver=0.4)
2-
 
3-
[![SymPy](http://pkg.julialang.org/badges/SymPy_0.5.svg)](http://pkg.julialang.org/?pkg=SymPy&ver=0.5)
4-
 
51
[![SymPy](http://pkg.julialang.org/badges/SymPy_0.6.svg)](http://pkg.julialang.org/?pkg=SymPy&ver=0.6)
62

73
Linux: [![Build Status](https://travis-ci.org/JuliaPy/SymPy.jl.svg?branch=master)](https://travis-ci.org/JuliaPy/SymPy.jl)
@@ -17,7 +13,7 @@ Windows: [![Build Status](https://ci.appveyor.com/api/projects/status/github/Jul
1713
The `SymPy` package (`http://sympy.org/`) is a Python library for symbolic mathematics.
1814

1915
With the excellent `PyCall` package of `julia`, one has access to the
20-
many features of `SymPy` from a `julia` session.
16+
many features of `SymPy` from within a `Julia` session.
2117

2218
This `SymPy` package provides a light interface for _some_ of the
2319
features of `SymPy` that makes working with `SymPy` objects a bit
@@ -35,7 +31,7 @@ installed on your system. If `PyCall` is installed using `Conda`
3531
underlying `SymPy` library will be installed via `Conda` when the
3632
package is first loaded. Otherwise, installing both `Python` and
3733
`SymPy` (which also requires `mpmath`) can be done by other means.
38-
The `Anaconda` distribution is suggested, as it provides a single
34+
In this case, the `Anaconda` distribution is suggested, as it provides a single
3935
installation of `Python` that includes `SymPy` and many other
4036
scientifice libraries that can be profitably accessed within `Julia`
4137
via `PyCall`. (Otherwise, install `Python` then download the `sympy`
@@ -79,20 +75,20 @@ This gets replaced by a more `julia`n syntax:
7975

8076
```
8177
using SymPy
82-
x = symbols("x") # or @syms x, Sym("x"), or Sym(:x)
78+
x = symbols("x") # or @vars x, Sym("x"), or Sym(:x)
8379
y = sin(pi*x)
8480
y(1) # Does subs(y, x, 1). Use y(x=>1) to be specific as to which symbol to substitute
8581
```
8682

8783
The object `x` we create is of type `Sym`, a simple proxy for the
8884
underlying `PyObject`. We then overload the familiar math functions so
8985
that working with symbolic expressions can use natural `julia`
90-
idioms. The final result is here is a symbolic value of `0`, which
86+
idioms. The final result here is a symbolic value of `0`, which
9187
prints as `0` and not `PyObject 0`. To convert it into a numeric value
9288
within `Julia`, the `N` function may be used, which acts like the
93-
`float` call, only attempts to preserve the variable type.
89+
`float` call, only there is an attempt to preserve the variable type.
9490

95-
(There is a subtlety, the value of `pi` here is converted to the
91+
(There is a subtlety, the value of `pi` here (an `Irrational` in `Julia`) is converted to the
9692
symbolic `PI`, but in general won't be if the math constant is coerced
9793
to a floating point value before it encounters a symbolic object. It
9894
is better to just use the symbolic value `PI`, an alias for `sympy.pi`
@@ -104,9 +100,23 @@ only a portion of the `SymPy` interface is exposed. To call an
104100
underlying SymPy method, the `getindex` method is overloaded for
105101
`symbol` indices so that `ex[:meth_name](...)` dispatches to either to
106102
SymPy's `ex.meth_name(...)` or `meth_name(ex, ...)`, as possible.
103+
104+
107105
There is a `sympy` string macro to simplify this a bit, with the call
108-
looking like: `sympy"meth_name"(...)`, for example `sympy"harmonic"(10)`.
106+
looking like: `sympy"meth_name"(...)`, for example
107+
`sympy"harmonic"(10)`. For example, the above could also be done
108+
through:
109+
110+
```
111+
@vars x
112+
y = sympy"sin"(pi * x)
113+
y(1)
114+
```
109115

116+
As calling the underlying SymPy function is not difficult, the
117+
interface exposed through overloading `Julia`'s methods attempts to
118+
keep similar functionality to the familiar `Julia` method when there is
119+
a discrepancy between conventions.
110120

111121
## Notes
112122

REQUIRE

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
julia 0.4
2-
Compat 0.25.0
1+
julia 0.6.0
2+
Compat 0.33.0
33
PyCall 1.6.0
44
RecipesBase 0.0.4
5-
BaseTestNext 0.2.2
5+
SpecialFunctions 0.3.4
6+

appveyor.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
environment:
22
matrix:
33

4-
# 0.4 - 0.6
4+
# 0.6 - latest
55

6-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
6+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
77
PYTHONDIR: "use_conda"
88
PYTHON: "use_conda"
99

10-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
10+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
1111
PYTHONDIR: "use_conda"
1212
PYTHON: "use_conda"
1313

14-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
15-
PYTHONDIR: "use_conda"
16-
PYTHON: "use_conda"
17-
18-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
19-
PYTHONDIR: "use_conda"
20-
PYTHON: "use_conda"
21-
22-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
14+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
2315
PYTHONDIR: "use_conda"
2416
PYTHON: "use_conda"
2517

26-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
18+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
2719
PYTHONDIR: "use_conda"
2820
PYTHON: "use_conda"
2921

22+
matrix:
23+
allow_failures:
24+
- channel: nightly
25+
26+
3027
branches:
3128
only:
3229
- master

src/SymPy.jl

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ __precompile__()
55

66
module SymPy
77

8-
using Compat
9-
import Compat: @compat, invokelatest
108

119
"""
1210
@@ -77,12 +75,8 @@ import Base: div
7775
import Base: trunc
7876
import Base: isinf, isnan
7977
import Base: real, imag
80-
import Base: expm
8178
import Base: nullspace
8279

83-
if VERSION < v"0.6.0-dev"
84-
import Base: factor, isprime
85-
end
8680

8781
export sympy, sympy_meth, @sympy_str, object_meth, call_matrix_meth
8882
export Sym, @syms, @vars, symbols
@@ -115,7 +109,7 @@ export members, doc, _str
115109
## Following PyPlot, we initialize our variables outside _init_
116110
const sympy = PyCall.PyNULL()
117111
const mpmath = PyCall.PyNULL()
118-
112+
const combinatorics = PyCall.PyNULL()
119113

120114
include("types.jl")
121115
include("utils.jl")
@@ -124,7 +118,6 @@ include("core.jl")
124118
include("logical.jl")
125119
include("math.jl")
126120
include("mpmath.jl")
127-
include("specialfuns.jl")
128121
include("solve.jl")
129122
include("dsolve.jl")
130123
include("subs.jl")
@@ -139,13 +132,14 @@ include("ntheory.jl")
139132
include("sets.jl")
140133
include("display.jl")
141134
include("lambdify.jl")
142-
include("physics.jl")
135+
include("call.jl")
136+
include("plot_recipes.jl") # hook into Plots
143137

144-
## add call interface depends on version
145-
VERSION >= v"0.5.0-" && include("call.jl")
146-
v"0.4.0" <= VERSION < v"0.5.0-" && include("call-0.4.jl")
138+
## optional modules
139+
include("permutations.jl")
140+
include("physics.jl")
141+
include("specialfuns.jl")
147142

148-
include("plot_recipes.jl") # hook into Plots
149143

150144
## create some methods
151145

@@ -169,6 +163,8 @@ The SymPy documentation can be found through: http://docs.sympy.org/latest/searc
169163
end
170164
end
171165

166+
167+
172168
## These are *added*, so exported
173169
for meth in union(core_sympy_methods,
174170
math_sympy_methods,
@@ -182,6 +178,7 @@ for meth in union(core_sympy_methods,
182178
logic_sympy_methods,
183179
polynomial_sympy_methods,
184180
ntheory_sympy_methods,
181+
combinatoric_sympy_methods,
185182
solveset_sympy_methods
186183
)
187184

@@ -191,7 +188,7 @@ for meth in union(core_sympy_methods,
191188
`$($meth_name)`: a SymPy function.
192189
The SymPy documentation can be found through: http://docs.sympy.org/latest/search.html?q=$($meth_name)
193190
""" ->
194-
($meth){T<:SymbolicObject}(ex::T, args...; kwargs...) = sympy_meth($meth_name, ex, args...; kwargs...)
191+
($meth)(ex::T, args...; kwargs...) where {T<:SymbolicObject} = sympy_meth($meth_name, ex, args...; kwargs...)
195192

196193
end
197194
eval(Expr(:export, meth))
@@ -239,7 +236,7 @@ for prop in union(core_object_properties,
239236
polynomial_predicates)
240237

241238
prop_name = string(prop)
242-
@eval ($prop)(ex::Sym) = PyObject(ex)[@compat(Symbol($prop_name))]
239+
@eval ($prop)(ex::SymbolicObject) = PyObject(ex)[Symbol($prop_name)]
243240
eval(Expr(:export, prop))
244241
end
245242

@@ -279,18 +276,9 @@ end
279276
# sympy"integrate"(x^2, (x, 0, 1))
280277
# ```
281278
# """
282-
283-
sympy_str_v0_5 = quote
284279
macro sympy_str(s)
285280
(args...; kwargs...) -> _sympy_str(Symbol(s), args...; kwargs...)
286281
end
287-
end
288-
sympy_str_v0_4 = quote
289-
macro sympy_str(s)
290-
(args...) -> _sympy_str(Symbol(s), args...)
291-
end
292-
end
293-
VERSION < v"0.5.0" ? eval(sympy_str_v0_4) : eval(sympy_str_v0_5)
294282

295283
"""
296284
@@ -325,32 +313,43 @@ end
325313

326314

327315
global object_meth(object::SymbolicObject, meth, args...; kwargs...) = begin
328-
call_sympy_fun(PyObject(object)[@compat(Symbol(meth))], args...; kwargs...)
329-
316+
meth_or_prop = PyObject(object)[Symbol(meth)]
317+
if isa(meth_or_prop, PyCall.PyObject)
318+
call_sympy_fun(meth_or_prop, args...; kwargs...) # method
319+
else
320+
meth_or_prop # property
321+
end
330322
end
331323

332-
333-
324+
334325
## For precompilation we must put PyCall instances in __init__:
335326
function __init__()
336327

337328
## Define sympy, mpmath, ...
338329
copy!(sympy, PyCall.pyimport_conda("sympy", "sympy"))
339330

331+
332+
340333
## mappings from PyObjects to types.
341-
basictype = sympy["basic"]["Basic"]
342-
pytype_mapping(basictype, Sym)
343334

335+
copy!(combinatorics, PyCall.pyimport_conda("sympy.combinatorics", "sympy"))
336+
pytype_mapping(combinatorics["permutations"]["Permutation"], SymPermutation)
337+
pytype_mapping(combinatorics["perm_groups"]["PermutationGroup"], SymPermutationGroup)
344338
polytype = sympy["polys"]["polytools"]["Poly"]
345339
pytype_mapping(polytype, Sym)
346340

347341
try
348-
matrixtype = sympy["matrices"]["MatrixBase"]
349-
pytype_mapping(matrixtype, Array{Sym})
350-
pytype_mapping(sympy["Matrix"], Array{Sym})
342+
pytype_mapping(sympy["Matrix"], Array{Sym})
343+
pytype_mapping(sympy["matrices"]["MatrixBase"], Array{Sym})
351344
catch e
352345
end
353346

347+
348+
basictype = sympy["basic"]["Basic"]
349+
pytype_mapping(basictype, Sym)
350+
351+
352+
354353
##
355354
init_logical()
356355
init_math()

0 commit comments

Comments
 (0)