<p>Probably the easiest way to get an arbitrary precision Mandelbrot set using full-precision integers is to combine two integers into a rational number <span class="math-container">$p/q$</span>. These numbers are added by finding the common denominator:
<span class="math-container">$$ \frac{m}{n} + \frac{p}{q} = \frac{mq + np}{nq} $$</span>
and multiplied by just multiplying the respective numerators and denominators:
<span class="math-container">$$ \frac{m}{n} * \frac{p}{q} = \frac{mp}{nq} $$</span>
Then a single point <span class="math-container">$\vec{p}$</span> would be represented in rational coordinates by
<span class="math-container">$$ \vec{p} = \left( \frac{n_x}{d_x} , \frac{n_y}{d_y} \right) $$</span>
and the iteration for the point would proceed
<span class="math-container">\begin{eqnarray*}
\vec{z} &amp;\rightarrow&amp; \vec{z}^2 + \vec{p} \\
\left( \frac{a_x}{b_x} , \frac{a_y}{b_y} \right) &amp;\rightarrow&amp;
\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)\\
&amp;=&amp;
\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) \\
&amp;=&amp; \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*}</span>
Easy this may be, but I can't claim it'll be <em>fast</em>; 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.</p>

CC BY-SA 4.0
2019-11-29T13:24:23.223Z
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...)
Kamil Kiełczewski
CC BY-SA 4.0
2019-11-29T08:09:58.340Z
2019-11-29T08:09:58.340Z
gilgamec
<p>I would like to create program in JavaScript (JS) which draws <a href="https://en.wikipedia.org/wiki/Mandelbrot_set" rel="nofollow noreferrer">Mandelbrot set</a> with arbitrary precision (zoom). In JS there is build in integer type <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" rel="nofollow noreferrer">BigInt</a> which support simple operations like +,*,/,power on arbitrary precision integer numbers. JS not support calculations on arbitrary precision floating point numbers. </p>

<p><strong>Question</strong>: 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?</p>

CC BY-SA 4.0
2024-03-07T13:32:30.827Z
You might find https://github.com/rahra/intfract interesting
Thorbjørn Ravn Andersen
<rendering>
Is there a way to perform calculations of Mandelbrot set using only integer numbers?
Kamil Kiełczewski
# Is there a way to perform calculations of Mandelbrot set using only integer numbers?

(Asked by: username_0 on 2019-11-29)

I would like to create program in JavaScript (JS) which draws [Mandelbrot set](https://en.wikipedia.org/wiki/Mandelbrot_set) with arbitrary precision (zoom). In JS there is build in integer type [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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?

**Tags:** rendering

> **Comments:**
> **username_1**: You might find https://github.com/rahra/intfract interesting  

---

## 1 answers

### Answer by username_2 on 2019-11-29. Score: 4 | Accepted 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.

> **Comments:**
> **username_0**: 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...)  

---

