3

I would like to create program in JavaScript (JS) which draws Mandelbrot set with arbitrary precision (zoom). In JS there is build in integer type BigInt which support simple operations like +,*,/,power on arbitrary precision integer numbers. JS not support calculations on arbitrary precision floating point numbers.

Question: Is there a way to perform calculations of Mandelbrot set using calculations based only on integers (with arbitrary precision) - if yes how to do it?

  • https://www.codingame.com/playgrounds/2358/how-to-plot-the-mandelbrot-set/mandelbrot-set – Rushabh Mehta Nov 28 '19 at 22:28
  • @DonThousand calculations using floating point numbers are trivial – Kamil Kiełczewski Nov 28 '19 at 22:30
  • I have voted to close this question, as it doesn't really seem to be about mathematics. Rather, it appears to be a programming or CS problem, which might be more appropriate for [cs.se]. – Xander Henderson Nov 28 '19 at 22:35
  • @XanderHenderson may be you are right, however I'm programer and for me it is really not trivial how to find proper formulas wich allow perform calculations on integers instead floating point numbers – Kamil Kiełczewski Nov 28 '19 at 22:36
  • 3
    It looks to me like you are trying to find a way of implementing an algorithm using a specific data type (arbitrary precision integers, rather than floats). You are much more likely to get help from the kinds of people who are expert in such topics, i.e. computer scientists. There is certainly some overlap with mathematicians, but I think that we are the wrong crowd. I mean, as far as I am concerned, as long as it (1) compiles, (2) runs in less than a week, and (3) produces the expected output, I feel like I've done good. – Xander Henderson Nov 28 '19 at 22:40

1 Answers1

4

You can just define a scaling of your integers. As we know that if the magnitude of $z$ ever exceeds $2$ the iteration will go off to infinity, you only need to support numbers up to, say, $4$ in both dimensions. You are essentially implementing floating point as pairs of integers. Represent a real number as $a\cdot 2^{-n}$ and store $a$ and $n$ as integers. A complex number would be $(a+bi)2^{-n}$. Now write routines that add and multiply these numbers, so if you want $(a+bi)2^{-n} \cdot (c+di)2^{-m}$ you get $(ac-bd+a(ad+bc)i)2^{-(n+m)}$. Now rescale appropriately and go on.

Ross Millikan
  • 374,822
  • Do you have a link to some docs where this is explained in more detail. For example, if I have a point where a = 0.5 and b = 0.000004 how I can continue to compute the Mandelbrot iterations with just 2**-n. I don't see how I can write this with just integers basically – Jeanluca Scaljeri May 03 '20 at 11:18
  • @JeanlucaScaljeri: If you are using $32$ bit ints, you can choose $n=29$. Then $0.5$ would be represented as $2^28 \cdot 2^{-29}$ with $2^28$ stored as an integer as $0x08000000$ and $0.000004$ would be $100 0011 0001 1011 1101 \cdot 2^{-29}$ stored as $0x000431BD$. To square it, write $(a+bi)^2=(a^2-b^2)+2abi$. When you square $a$ into $64$ bits you get $2^56 \cdot 2^{-58}$ so you discard the lowest $29$ bits and the top $3$ to get the new number scaled by $2^{-29}$. No, I don't have a reference. – Ross Millikan May 03 '20 at 14:06