Skip to content

Commit 5fb0e7b

Browse files
authored
Itex (#241)
* bump recipes base * scale vfield * fix itex (closes #240), other cleanup in display.jl
1 parent 0b1c6e1 commit 5fb0e7b

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
julia 0.7.0
22
PyCall 1.7.1
3-
RecipesBase 0.2.3
3+
RecipesBase 0.5.0
44
SpecialFunctions 0.3.4

src/display.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Examples
1111
```
1212
@vars x
1313
import Base.Docs.doc
14-
doc(sin(x)) #
14+
doc(sin(x)) #
1515
doc(sympy[:sin]) # explicit module lookup
1616
doc(SymPy.mpmath[:hypercomb]) # explicit module lookup
1717
doc(Poly(x^2,x), :coeffs) # coeffs is an object method of the poly instance
@@ -43,9 +43,7 @@ latex(s::SymbolicObject, args...; kwargs...) = sympy_meth(:latex, s, args...; k
4343
"create basic printed output"
4444
function jprint(x::SymbolicObject)
4545
out = PyCall.pycall(pybuiltin("str"), String, PyObject(x))
46-
if occursin(r"\*\*", out)
47-
out = replace(out, "**" => "^")
48-
end
46+
out = replace(out, r"\*\*" => "^")
4947
out
5048
end
5149
jprint(x::AbstractArray) = map(jprint, x)
@@ -58,8 +56,8 @@ Base.show(io::IO, s::Sym) = print(io, jprint(s))
5856

5957
## text/plain
6058
show(io::IO, ::MIME"text/plain", s::SymbolicObject) = print(io, sympy["pretty"](s))
59+
show(io::IO, ::MIME"text/latex", x::Sym) = print(io, latex(x, mode="equation*"))
6160

62-
show(io::IO, ::MIME"text/latex", x::Sym) = print(io, latex(x, mode="equation*", itex=true))
6361
function show(io::IO, ::MIME"text/latex", x::AbstractArray{Sym})
6462
function toeqnarray(x::Vector{Sym})
6563
a = join([latex(x[i]) for i in 1:length(x)], "\\\\")
@@ -76,7 +74,7 @@ end
7674
## Pretty print dicts
7775
function show(io::IO, ::MIME"text/latex", d::Dict{T,S}) where {T<:Sym, S<:Any}
7876
Latex(x::Sym) = latex(x)
79-
Latex(x) = sprint(Base.showcompact, x)
77+
Latex(x) = sprint(io -> show(IOContext(io, :compact => true), x))
8078

8179
out = "\\begin{equation*}\\begin{cases}"
8280
for (k,v) in d
@@ -89,4 +87,4 @@ end
8987

9088

9189
## Convert SymPy symbol to Julia expression
92-
convert(::Type{Expr}, x::SymbolicObject) = parse(jprint(x))
90+
convert(::Type{Expr}, x::SymbolicObject) = Meta.parse(jprint(x))

src/permutations.jl

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ id = Permutation(0:10)
5454
```
5555
5656
Cycle notation can more compactly describe a permuation, it can be passed in as a container of cycles specified through tuples or vectors:
57-
57+
5858
```
5959
p = Permutation([(0,2), (1,3)])
6060
```
@@ -71,7 +71,7 @@ constructor with values separated by commas and the "call" method for
7171
`i -> j` is created (also the notation `i^p` returns this`) *but* if
7272
more than one argument is given, a cycle is created and multiplied on
7373
the *right* by `p`, so that the above becomes `(0,2) * (1,3)`.
74-
74+
7575
Here are two permutations forming the symmetries of square, naturally represented in the two ways:
7676
7777
```
@@ -81,11 +81,11 @@ rotate = Permutation([1,2,3,0]) # or Permutation(0,1,2,3) in cycle notation
8181
8282
Operations on permutations include:
8383
84-
* a function call, `p(i)` to recover `j` where `i -> j`, also `i^p`.
84+
* a function call, `p(i)` to recover `j` where `i -> j`, also `i^p`.
8585
* `*` for multiplication. The convention is `(p*q)(i) = q(p(i))` or with the `^` notation: `i^(p*q) = (i^p)^q`.
8686
* `+` for multiplication when `p` and `q` commute, where a check on commuting is performed.
8787
* `inv` for the inverse permutation.
88-
* `/`, where `p/q` is `p * inv(q)`.
88+
* `/`, where `p/q` is `p * inv(q)`.
8989
* `p^n` for powers. We have `inv(p) = p^(-1)` and `p^order(p)` is the identity.
9090
* `p^q` for conjugate, defined by `inv(q) * p * q`.
9191
@@ -99,7 +99,7 @@ flip^2 # the identity
9999
wheres a rotation is not (as it has order 4)
100100
101101
```
102-
rotate * rotate
102+
rotate * rotate
103103
order(rotate)
104104
```
105105
@@ -122,10 +122,10 @@ We can see this is the correct mapping `1 -> 3` with
122122
We can check that `flip` and `rotate^2` do commute:
123123
124124
```
125-
id = Permutation(3) # (n) is the identify
125+
id = Permutation(3) # (n) is the identify
126126
commutator(flip, rotate^2) == id
127-
```
128-
127+
```
128+
129129
The conjugate for flip and rotate does the inverse of the flip, then rotates, then flips:
130130
131131
```
@@ -136,12 +136,12 @@ This is different than `flip^rotate`. As `flip` commutes with `rotate^2` this wi
136136
137137
```
138138
(rotate^2)^flip
139-
```
139+
```
140140
141141
!!! Differences:
142142
143-
There is no support for the `Cycle` class
144-
143+
There is no support for the `Cycle` class
144+
145145
"""
146146
function Permutation(x; kwargs...)
147147
if typeof(x) <: UnitRange
@@ -218,7 +218,7 @@ for meth in permutations_new_functions
218218
end
219219
eval(Expr(:export, meth))
220220
end
221-
221+
222222

223223

224224
## Base methods of the object
@@ -303,7 +303,7 @@ end
303303

304304
_unflatten_cyclic_form(m::Matrix) = [m[i,:] for i in 1:size(m)[1]]
305305
_unflatten_cyclic_form(m) = m
306-
306+
307307
function cyclic_form(p::SymPermutation)
308308
m = PyCall.PyObject(p)[:cyclic_form]
309309
_unflatten_cyclic_form(m)
@@ -331,12 +331,12 @@ Some pre-defined groups are built-in:
331331
* `DihedralGroup`: Group formed by a flip and rotation
332332
* AlternativeGroup: Subgroup of S_n of even elements
333333
* AbelianGroup: Returns the direct product of cyclic groups with the given orders.
334-
334+
335335
336336
Differences:
337337
338338
* use `collect(generate(G))` in place of `list(G.generate())`
339-
339+
340340
"""
341341
PermutationGroup(args...; kwargs...) = SymPy.combinatorics[:perm_groups][:PermutationGroup](args...; kwargs...)
342342
export PermutationGroup
@@ -366,7 +366,7 @@ SymPy.elements(gp::SymPy.SymPermutationGroup) = [a for a in PyCall.PyObject(gp)[
366366
random_element(gp, ...)
367367
368368
A random group element. Alias to `sympy"random"`.
369-
"""
369+
"""
370370
random_element(gp::SymPy.SymPermutationGroup, args...) = object_meth(gp, :random, args...)
371371

372372
# base_methods
@@ -387,7 +387,7 @@ end
387387

388388
# new methods
389389
permutation_group_methods = (#:baseswap,
390-
:base,
390+
#:base,
391391
:center,
392392
:centralizer,
393393
:commutator,
@@ -479,7 +479,7 @@ permutation_group_properties = (:basic_orbits,
479479
:generators,
480480
:max_div,
481481
:transitivity_degree
482-
482+
483483
)
484484
for prop in permutation_group_properties
485485
prop_name = string(prop)
@@ -494,10 +494,6 @@ for prop in permutation_group_properties
494494
end
495495

496496

497-
if !(VERSION >= v"1.0.0")
498-
import Base: base
499-
end
500-
501497
base(ex::SymPermutationGroup) = PyCall.PyObject(ex)[:base]
502498
export base
503499

src/plot_recipes.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,32 @@ surface(-5:5, -5:5, 25 - x^2 - y^2)
5858
* a vectorfield plot can (inefficiently but directly) be produced following this example:
5959
6060
```
61-
function vfieldplot(fx, fy; xlim=(-5,5), ylim=(-5,5), n=7)
61+
function vfieldplot(fx, fy; xlim=(-5,5), ylim=(-5,5), n=8)
6262
xs = range(xlim[1], stop=xlim[2], length=n)
63-
ys = range(ylim[1], stop=ylim[2], length=n)
63+
ys = range(ylim[1], stop=ylim[2], length=n)
6464
6565
us = vec([x for x in xs, y in ys])
6666
vs = vec([y for x in xs, y in ys])
6767
fxs = vec([fx(x,y) for x in xs, y in ys])
6868
fys = vec([fy(x,y) for x in xs, y in ys])
6969
70-
quiver(us, vs, quiver=(fxs, fys))
70+
mxs = maximum(abs.(filter(!isinf, filter(!isnan, fxs))))
71+
mys = maximum(abs.(filter(!isinf, filter(!isnan, fys))))
72+
d = 1/2 * max((xlim[2]-xlim[1])/mxs, (ylim[2]-ylim[1])/mys) / n
73+
74+
quiver(us, vs, quiver=(fxs.*d, fys.*d))
75+
7176
end
7277
fx = (x + y) / sqrt(x^2 + y^2)
7378
fy = (x - y) / sqrt(x^2 + y^2)
7479
vfieldplot(fx, fy)
75-
```
7680
7781
82+
```
83+
7884
* To plot two or more functions at once, the style `plot([ex1, ex2], a, b)` does not work. Rather, use
7985
`plot(ex1, a, b); plot!(ex2)`, as in:
80-
86+
8187
```
8288
@vars x
8389
plot(sin(x), 0, 2pi)
@@ -185,15 +191,15 @@ export VectorField
185191

186192
xlims = get(plotattributes,:xlims, (-5,5))
187193
ylims = get(plotattributes, :ylims, (-5,5))
188-
194+
189195
xs = repeat(range(xlims[1], stop=xlims[2], length=n), inner=(n,))
190196
ys = repeat(range(ylims[1], stop=ylims[2], length=n), outer=(n,))
191197

192198
us, vs = broadcast(F.fx, xs, ys), broadcast(F.fy, xs, ys)
193199

194200
delta = min((xlims[2]-xlims[1])/n, (ylims[2]-ylims[1])/n)
195201
m = maximum([norm([u,v]) for (u,v) in zip(us, vs)])
196-
202+
197203
lambda = delta / m
198204

199205
x := xs

0 commit comments

Comments
 (0)