Skip to content

Commit

Permalink
compatability with 0.6 world counter
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Aug 25, 2017
1 parent 5c4c00d commit 6bbd1d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ os:
- osx
julia:
- 0.5
# - nightly
- 0.6
notifications:
email: false
# uncomment the following lines to override the default test script
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,8 @@ environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
12 changes: 6 additions & 6 deletions src/Fatou.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 86,8 @@ immutable FilledSet <: AbstractFatou
iter::Matrix{UInt8}
mix::Matrix{Float64}
function FilledSet(K::Define); (i,s)=Compute(K)
m(z::Complex{Float64},n::Number,p::Number) = K.C(z,n,p)::Float64
return new(K,s,i,m.(s,float.(i./K.N),K.p)); end; end
m(z::Complex{Float64},n::Number,p::Number) = invokelatest(K.C,z,n,p)::Float64
return new(K,s,i,broadcast(m,s,broadcast(float,i./K.N),K.p)); end; end

"""
fatou(::Fatou.Define)
Expand Down Expand Up @@ -248,8 248,8 @@ basin(K::Define,j) = K.newt ? nrset(K.O,K.m,j) : jset(K.F,j)
"""
function Compute(K::Define)::Tuple{Matrix{UInt8},Matrix{Complex{Float64}}}
# define Complex{Float64} versions of polynomial and constant for speed
f = (sym2fun(K.F(Sym(:a),Sym(:b)),:(Complex{Float64})) |> eval)::Function
h = (sym2fun(K.Q(Sym(:a),Sym(:b)),:(Complex{Float64})) |> eval)::Function
f = (sym2fun(invokelatest(K.F,Sym(:a),Sym(:b)),:(Complex{Float64})) |> eval)::Function
h = (sym2fun(invokelatest(K.Q,Sym(:a),Sym(:b)),:(Complex{Float64})) |> eval)::Function
# define function for computing orbit of a z0 input
function nf(z0::Complex{Float64})::Tuple{UInt8,Complex{Float64}}
K.mandel ? (z = K.seed): (z = z0); zn = 0x00
Expand All @@ -264,7 264,7 @@ function Compute(K::Define)::Tuple{Matrix{UInt8},Matrix{Complex{Float64}}}
(matU,matF) = (Array{UInt8,2}(Kyn,K.n),Array{Complex{Float64},2}(Kyn,K.n))
#mat = Array{Tuple{UInt8,Complex{Float64}},2}(Kyn,K.n)
@time @threads for j = 1:length(y); for k = 1:length(x);
(matU[j,k],matF[j,k]) = nf(Z[j,k]); end; end; return (matU,matF); end
(matU[j,k],matF[j,k]) = invokelatest(nf,Z[j,k]); end; end; return (matU,matF); end
#mat[j,:] = nf.(Z[j,:]); end; return (matU.(mat),matF.(mat)); end

import PyPlot: plot
Expand All @@ -279,7 279,7 @@ function plot(K::FilledSet;c::String="",bare::Bool=false)
typeof(K.meta.iter ? K.iter : K.mix) == Matrix{UInt8} ? t = L"iter. " :
K.meta.m==1 ? t = L"roots" : t = L"limit"
# annotate title using LaTeX
ttext = "f:z\\mapsto $(SymPy.latex(K.meta.O(Sym(:z),Sym(:c)))),\\,"
ttext = "f:z\\mapsto $(SymPy.latex(invokelatest(K.meta.O,Sym(:z),Sym(:c)))),\\,"
if K.meta.newt; title(latexstring("$ttext m = $(K.meta.m), ")*t)
# annotate y-axis with Newton's method
ylabel(L"Fatou\,set:\,"*L"z\,\,z-m\,×\,f(z)\,/\,f\,'(z)")
Expand Down
13 changes: 8 additions & 5 deletions src/internals.jl
Original file line number Diff line number Diff line change
@@ -1,6 1,10 @@
# This file is part of Fatou.jl. It is licensed under the MIT license
# Copyright (C) 2017 Michael Reed

import Base: invokelatest

tfun = nothing; tm = nothing

funk(r::String) = :((z,c)->$(parse(r))) # unleash the funK
funK(r::String) = :((z,n,p)->$(parse(r))) # double funky

Expand All @@ -24,14 28,13 @@ sym2fun(expr,typ) = Expr(:function, Expr(:call, gensym(),
map(s->Expr(:(::),s,typ),sort!(Symbol.(free_symbols(expr))))..., Expr(:(...),:zargs)),
SymPy.walk_expression(expr))

# evaluate the differentiated expression and assign to a handle
p1(f::Function) = sym2fun(diff(f(Sym(:a),Sym(:b))),:Any) |> eval

# we can substitute the expression into Newton's method and display it with LaTeX
newton_raphson(f::Function,m) = (z,c) -> z - m*f(z,c)/p1(f)(z,c)
function newton_raphson(f::Function,m)
sym2fun(Sym(:z)-m*invokelatest(f,Sym(:z),Sym(:c))/diff(invokelatest(f,Sym(:z),Sym(:c))),:Any) |> eval; end

# define recursive composition on functions
recomp(f::Function,x::Number,j::Int) = j > 1 ? f(recomp(f,x,j-1),0) : f(x,0)
function recomp(f::Function,x::Number,j::Int)
return j > 1 ? invokelatest(f,recomp(f,x,j-1),0) : invokelatest(f,x,0); end

# we can convert the j-th function composition into a latex expresion
nL(f::Function,m,j) = recomp(newton_raphson(f,m),Sym(:z),j) |> SymPy.latex
Expand Down
7 changes: 4 additions & 3 deletions src/orbitplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 19,8 @@ function orbit(K::Define)
orbit(z->K.F(z,0),convert(Array{Float64},bi),K.orbit,K.depth,Int(K.n)); end

function orbit(u::Function,bi::Matrix{Float64},orb::Int=0,depth::Int=1,incr::Int=384; plt::Function=plot)
f = sym2fun(u(Sym(:x)),:Float64) |> eval
ff = sym2fun(invokelatest(u,Sym(:x)),:Float64) |> eval
f(x::Float64) = invokelatest(ff,x)
# prepare for next figure
figure()
# initalize array to depth
Expand All @@ -30,7 31,7 @@ function orbit(u::Function,bi::Matrix{Float64},orb::Int=0,depth::Int=1,incr::Int
# loop over all discrete x-axis points in set
# loop function composition at x val
for t 1:depth
N[:,t 1] = f.(N[:,t])
N[:,t 1] = broadcast(f,N[:,t])
end
# plot background lines
plot(x[:],N[:,1],"k--",x[:],N[:,2])
Expand Down Expand Up @@ -67,7 68,7 @@ function orbit(u::Function,bi::Matrix{Float64},orb::Int=0,depth::Int=1,incr::Int
d=1.07; xlim(bi[1],bi[2])
ylim(minimum([d*minimum(N[:,2]),0]),maximum([d*maximum(N[:,2]),0]))
# set title
fune = SymPy.latex(u(Sym("x")));
fune = SymPy.latex(invokelatest(u,Sym("x")));
title(latexstring("\$ x \\mapsto $fune\$$funt"))
# set legend
legend(vcat([L"$y=x$",L"$\phi(x)$",L"(x_n,\phi(x_n))"],[latexstring("\\phi^{$x}(x)") for x 2:depth],funs))
Expand Down

0 comments on commit 6bbd1d9

Please sign in to comment.