1

I have written a program in python to plot the Mandelbrot set using pygame, multithreading and numba. Unfortunately, I can't zoom more than 1e-15 because of the limit of floats precision. When I do it become all pixelated. I heard about the decimal library that is more precise but it is not supported by numba.

Is there a way to represent very precise float simply enough to works with numba?

Edit : Forgot to mention it but I'm using double and tried using numpy longdouble but it doesn't seem to change anything.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
Biloba
  • 23
  • 4
  • Can you use `double` precision type? In C I can do a doubling 2x zoom of more than 50 steps before losing definition. The single precision `float` type is all but useless for this task. But as an interpreted language, python isn't the best choice for serious M-set manipulation, which can require billions of arithmetic operations to create one image. – Weather Vane Jul 14 '21 at 11:25
  • Forgot to mention it but yes, I'm using double and tried using numpy longdouble but ut doesn't seem to change anything. – Biloba Jul 14 '21 at 11:28
  • Perhpas the gpu is the limitation then. – Weather Vane Jul 14 '21 at 11:29
  • 2
    you do not need a better precision to zoom. You can just apply some math tricks. The mandelbrot set is [self-similar](https://en.wikipedia.org/wiki/Self-similarity) so you can renormalize the values. Moreover, note that using double precision is very slow on mainstream GPUs. – Jérôme Richard Jul 14 '21 at 13:07
  • Biloba "Is there a way to represent very precise float ..." --> How precise do you want? 1e-15 sounds precise for most folks. – chux - Reinstate Monica Jul 14 '21 at 13:29
  • @JérômeRichard not to mention that floats are just integers with a scale factor. You can just remove the DC offset and do integer math to whatever precision you want – Mad Physicist Jul 14 '21 at 13:49
  • 1
    @JérômeRichard can you give me a link or a reference to those math tricks ? – Biloba Jul 17 '21 at 07:01
  • @chux-ReinstateMonica I would like to be able to go as far as I want, but I think I will go there easier with said math tricks – Biloba Jul 17 '21 at 07:02
  • @MadPhysicist I really don't have the same idea of float representation. From what I understand, floats have an integer part and a decimal part. The decimal part is an addition of fraction. [Link to the wikipedia scheme](https://en.wikipedia.org/wiki/Single-precision_floating-point_format#/media/File:Float_example.svg) – Biloba Jul 17 '21 at 07:03
  • 1
    @Biloba All common floating point values are some limited integer time a power of 2, not "integer part and a decimal part". Nothing decimal about them. – chux - Reinstate Monica Jul 17 '21 at 12:19
  • 3
    Sorry, but I think @JérômeRichard is mistaken here. The Mandelbrot set is not perfectly self-similar in the way that something like the Koch curve is (e.g., via linear affine transformations), and you _do_ need better precision to zoom beyond a certain point. If there are mathematical tricks that remove that need, then those mathematical tricks don't seem to be known to the experts. See for example: https://randomascii.wordpress.com/2011/08/13/faster-fractals-through-algebra/ – Mark Dickinson Jul 18 '21 at 14:14
  • @MarkDickinson agreed, but with the **Julia set** if you have previously visited the *exact* location, then the iteration continues as before (because *c* is constant across the plane). I tried an implementation where if a *pixel* (encountered on the orbit) had been previously calculated I would simply add its depth to the current depth count, and stop the iteration. Of course, the actual coordinates were not exact, so it was very fast but not all that accurate. – Weather Vane Jul 18 '21 at 18:51

0 Answers0