# Is there a way to perform calculations of Mandelbrot set using only integer numbers?

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?

## 1 Answer

Probably the easiest way to get an arbitrary precision Mandelbrot set using full-precision integers is to combine two integers into a rational number $$p/q$$. These numbers are added by finding the common denominator: $$\frac{m}{n} + \frac{p}{q} = \frac{mq + np}{nq}$$ and multiplied by just multiplying the respective numerators and denominators: $$\frac{m}{n} * \frac{p}{q} = \frac{mp}{nq}$$ Then a single point $$\vec{p}$$ would be represented in rational coordinates by $$\vec{p} = \left( \frac{n_x}{d_x} , \frac{n_y}{d_y} \right)$$ and the iteration for the point would proceed $$\begin{eqnarray*} \vec{z} &\rightarrow& \vec{z}^2 + \vec{p} \\ \left( \frac{a_x}{b_x} , \frac{a_y}{b_y} \right) &\rightarrow& \left( \frac{a_x^2}{b_x^2} - \frac{a_y^2}{b_y^2} , \frac{2 a_x a_y}{b_x b_y} \right) + \left( \frac{n_x}{d_x} , \frac{n_y}{d_y} \right)\\ &=& \left( \frac{a_x^2 b_y^2 - a_y^2 b_x^2}{b_x^2 b_y^2} + \frac{n_x}{d_x} , \frac{2 a_x a_y}{b_x b_y} + \frac{n_y}{d_y} \right) \\ &=& \left( \frac{(a_x^2 b_y^2 - a_y^2 b_x^2)d_x + n_x b_x^2 b_y^2} {b_x^2 b_y^2 d_x}, \frac{2 a_x a_y d_y + b_x b_y n_y}{b_x b_y d_y} \right). \end{eqnarray*}$$ Easy this may be, but I can't claim it'll be fast; near the boundaries of the Mandelbrot set, the numerators and denominators in the iteration will get pretty big fairly soon, even if you reduce the rationals by dividing by the greatest common denominator.

• Nice Idea. In your calculations on every iteration you calculate FULL precision - in floating point calculation calculations are never done in full precision (multiplication of 2 numbers usually create 2x more digits and half of this digits are cut off) - may be there is a way to introduce such 'cut off' in your idea - probably such cut off should be dynamic (and smaller in big zoom to not lost precision...) Nov 29, 2019 at 13:24