Mandelbrot set: Difference between revisions

Content added Content deleted
(→‎Normalized Counting, Distance Estimation, Mercator Maps and Perturbation Theory: Only Float64x2 are fast, but you need at least Float64x3. Therefore, the MultiFloats example has been replaced and superfluous whitespace has been deleted.)
Line 6,633: Line 6,633:
D = zeros(size(C))
D = zeros(size(C))


for i in 1:h+1
for i in 1:h+1, j in 1:d+1
z, dz, epsilon = Z[i, j], dZ[i, j], E[i, j]
for j in 1:d+1
z, dz, epsilon = Z[i, j], dZ[i, j], E[i, j]
delta, index = C[i, j], 1
delta, index = C[i, j], 1
for k in 1:n
epsilon = (2 * S[index] + epsilon) * epsilon + delta
for k in 1:n
epsilon = (2 * S[index] + epsilon) * epsilon + delta
z, dz = S[index + 1] + epsilon, 2 * z * dz + 1
if abs2(z) > abs2(r)
z, dz = S[index + 1] + epsilon, 2 * z * dz + 1
if abs2(z) > abs2(r)
break
break
end
end
index = index + 1
index = index + 1
if abs2(z) < abs2(epsilon) # rebasing when orbit is near zero
if abs2(z) < abs2(epsilon) # rebasing when orbit is near zero
epsilon, index = z, 1
epsilon, index = z, 1
end
end
end
Z[i, j], dZ[i, j], E[i, j] = z, dz, epsilon
end
end
Z[i, j], dZ[i, j], E[i, j] = z, dz, epsilon
end
end


Line 6,656: Line 6,654:


heatmap(D' .^ 0.025, c=:nipy_spectral)
heatmap(D' .^ 0.025, c=:nipy_spectral)
savefig("Mercator_Mandelbrot_rebasing_map.png")</lang>
savefig("Mercator_Mandelbrot_rebase_map.png")</lang>


The images can be verified by a (slow) calculation with BigFloats. There are libraries that are faster than BigFloats, for example DoubleFloats.jl and MultiFloats.jl. Unfortunately, the precision of the DoubleFloats is not sufficient, and only the double MultiFloats (Float64x2) are fast. For deep zoom images you need at least triple or quadruple MultiFloats (Float64x3, Float64x4), but they are slower than BigFloats.
The MultiFloats.jl library can be used to verify the results. To do this, however, the complex exponential function must be broken down into real cosine and sine functions and these functions must be calculated with BigFloats. However, the one-off calculation with a few BigFloats before and after the loop only has a small impact on the calculation speed. Since the number pi is missing from the library, 2*pi is replaced by acos(0)*4. Although the calculation with MultiFloats is much faster than with BigFloats, it is much slower compared to the perturbation calculation.
<lang julia>using Plots
<lang julia>using Plots
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200)
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200)

setprecision(BigFloat, 256) # set precision to 256 bits (default)
using MultiFloats
setrounding(BigFloat, RoundNearest) # set rounding mode (default)
MultiFloats.use_bigfloat_transcendentals()

d, h = 10, 200 # pixel density (= image width) and image height
d, h = 10, 200 # pixel density (= image width) and image height
n, r = 60000, 100000 # number of iterations and escape radius (r > 2)
n, r = 60000, 100000 # number of iterations and escape radius (r > 2)
a = Float64x3("-1.256827152259138864846434197797294538253477389787308085590211144291")
b = Float64x3(".37933802890364143684096784819544060002129071484943239316486643285025")


a = BigFloat("-1.256827152259138864846434197797294538253477389787308085590211144291")
x = range(zero(a), acos(zero(a)) * 4, length=d+1)
b = BigFloat(".37933802890364143684096784819544060002129071484943239316486643285025")
y = range(zero(b), acos(zero(b)) * 4 * h / d, length=h+1)

x = range(zero(a), one(a) * 2, length=d+1)
y = range(zero(b), one(b) * 2 * h / d, length=h+1)


A, B = collect(x), collect(y)
A, B = collect(x .* pi), collect(y .* pi)
C = (.- 4.0) .* (cos.(A) .- sin.(A) .* im)' .* exp.(.- B) .+ a .+ b .* im
C = (.- 4.0) .* exp.((A' .+ B .* im) .* im) .+ a .+ b .* im


Z, dZ = zero(C), zero(C)
Z, dZ = zero(C), zero(C)
Line 6,691: Line 6,689:


heatmap(D' .^ 0.025, c=:nipy_spectral)
heatmap(D' .^ 0.025, c=:nipy_spectral)
savefig("Mercator_Mandelbrot_multifloats_map.png")</lang>
savefig("Mercator_Mandelbrot_bigfloat_map.png")</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==