This does not seem to be reproducible for points within the Mandelbrot set:
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def mandelbrot(a):
... z = 0
... for i in range(50):
... z = z**2 + a
... return z
...
>>> mandelbrot(-0.75)
-0.40274177046812404
>>> mandelbrot(0.1)
0.11270166537925831
>>> mandelbrot(0.2)
0.2763932022500072
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.6.1 (2021-04-23)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> function mandelbrot(a)
z = 0
for i=1:50
z = z^2 + a
end
return z
end
mandelbrot (generic function with 1 method)
julia> mandelbrot(-0.75)
-0.40274177046812404
julia> mandelbrot(0.1)
0.11270166537925831
julia> mandelbrot(0.2)
0.2763932022500072
The only difference I have been able to observe thus far is that for points outside the set, Python may return an OverflowError where Julia returns Inf
.
>>> mandelbrot(0.3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in mandelbrot
OverflowError: (34, 'Result too large')
julia> mandelbrot(0.3)
Inf
presumably due to the two languages making somewhat different decisions as regards handling floating point special values such as Inf
.
In particular, Python by default does not appear to follow the standard rules for IEEE 754 floating point arithmetic, wherein the following should return +
and -
Inf
, respectively (c.f. IEEE 754, division by zero)
>>> 1.0/+0.0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero
>>> 1.0/-0.0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero
whereas Julia does:
julia> 1.0/+0.0
Inf
julia> 1.0/-0.0
-Inf