• August 02, 2021, 07:47:16 AM

Login with username, password and session length

Author Topic:  Homemade MB Viewer  (Read 368 times)

0 Members and 1 Guest are viewing this topic.

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Homemade MB Viewer
« on: July 08, 2021, 07:07:12 AM »
Hello, I am just a babe in the MB woods.  I have written a Java program that displays the inner landscapes of f(z) = z^2 + c.  But I'm disappointed that I can only achieve a zoom factor of 10^2.  The algorithm breaks down when the width of the viewport is less than approx 1.10017e-13.  There's so much more resolution in the double precision variables I'm using.  How do I tap into it?  A nudge in the right direction would be greatly appreciated.  Thanks for reading.

Linkback: https://fractalforums.org/index.php?topic=4322.0

Offline hobold

  • Fractal Frogurt
  • ******
  • Posts: 479
Re: Homemade MB Viewer
« Reply #1 on: July 08, 2021, 04:58:54 PM »
To me this seems to be the resolution limit of double precision. Quick estimation of the magnitudes:

10^13 is roughly the same magnitude as 2^43  (recall that 10^3 is approximately 2^10)

Now assuming a FullHD picture resolution of approximately 2000 pixels wide, we need another 11 bits to distinguish all pixel positions from each other, bringing the total required precision up to 43 + 11 = 54, which is just a tad above the mantissa size of a 64bit double precision value (52 bits, or 53 if you count the implied leading 1).

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Re: Homemade MB Viewer
« Reply #2 on: July 08, 2021, 11:41:25 PM »
Thank you for your answer!  This is my first question on the first forum I have ever joined.

I understand when you say the range from 2000 to e-13 uses all of the bits of the mantissa.  But can't we just grab more of the exponent to get smaller/larger numbers?  I apologize in advance for the basics I am missing.

Offline youhn

  • Fractal Feline
  • **
  • Posts: 153
  • Shapes only exist in your head
Re: Homemade MB Viewer
« Reply #3 on: July 09, 2021, 06:14:51 PM »
Perhaps this could give some insight?


It's not the exponent but the mantissa that determines the level of precision.

Precision does not equal range. You can go from zero to infinity in 2 steps:

0. nothing
1. something
2. everything

This is a very useful simple number system, as it quickly gives an idea without much calculation. Though it misses a lot of precision.

Slightly more precision:

0. nothing
1. a thing
2. some things
3. many things
4. everything

More precision:

0. nothing
1. nearly nothing
2. almost something
3. a thing
4. pair of things
5. more things
6. most things
7. everything

All examples have the same range (difference between the ultimate limits), but different precision. The number of options can be seen as the number of digits in the mantissa.

I don't know much about java, so cannot show specific examples using those number formats. Though in principle it should all work the same.

Offline hobold

  • Fractal Frogurt
  • ******
  • Posts: 479
Re: Homemade MB Viewer
« Reply #4 on: July 09, 2021, 09:45:27 PM »
I understand when you say the range from 2000 to e-13 uses all of the bits of the mantissa.  But can't we just grab more of the exponent to get smaller/larger numbers?  I apologize in advance for the basics I am missing.
Zooming into the Mandelbrot set means that the coordinates of the image borders come closer and closer together. As an illustration, let's regard the left and right borders of an image rectangle. As they move closer and closer together, more and more of their leading digits become identical. This is true tegardless of decimal or binary representation ... and let me handwave away straddling jumps such as 1.99999 to 2.00000; these are mere technical details.

Anyway, left and right border eventually have so many leading digits in common, that the mantissas of the corresponding floating point values are all used up. The only exception is when all those shared leading digits are zeros (this is the case where the exponent of floating point representation can help), which is not generally the case for interesting regions of the Mandelbrot boundary.

With all the mantissa bits used up, there are none left to distinguish between pixels of the whole image. So the result becomes pixelated.


The true fix for this is rather involved, as it requires handling the shared leading digits separately (this is the basic idea behind a method called "perturbation theory"). But a convenient quick fix might be available depending on the programming language you are using: a data type with higher precision. Computations will be a lot slower, but arriving at a desired image more slowly is a lot better than not being able to produce said image at all.

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Re: Homemade MB Viewer
« Reply #5 on: July 09, 2021, 11:12:55 PM »
Thank you for your time and instruction.  Per your suggestion, I found that Java has a class called BigDouble which has more precision than a double.  I'm going to incorporate it in my program and see how much smaller I can make my image viewport.  This is a fun project! 

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Re: Homemade MB Viewer
« Reply #6 on: July 11, 2021, 04:06:34 AM »
Alas, Java's BigDecimal class didn't work for me.  I tried to use it only where necessary but the program couldn't finish drawing the first top level image.  I let my laptop run for 20 minutes and it eventually ran out of heap.  So I guess I'm done with this project.  I've also coded fractal trees, the Lorentz attractor, and Sierpinski triangles.  Any suggestions on what to try next?  Could I extend my Mandelbrot program to incorporate other similar functions?

Offline 3DickUlus

  • Administrator
  • *******
  • Posts: 2348
    • Digilantism
Re: Homemade MB Viewer
« Reply #7 on: July 11, 2021, 06:05:02 AM »
You can find the source (java) for SuprFractalThing (opensource) here http://sourceforge.net/projects/suprfractalthng/files/superfractalthing_0.8.3.jar/download it renders the mandelbrot set using arbitrary precision and perturbation to zoom very deep very fast.

If you convert it to C++ it runs 10X faster than the original java. There's a lot to learn from this source code. ;)

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Re: Homemade MB Viewer
« Reply #8 on: July 16, 2021, 07:41:23 AM »
Wow, there's enough here to keep me busy for quite a while.

So what my program taught me is that, when it gets down to around 10^-12, the following occurs:
X + (4 * n) on one thread does not egual  X + n + n + n + n on another thread.  I use 4 just as an example.

I'm curious.  Is this because of the mixed math ( * vs +'s )?  If I did summations on both sides would they be equal?

I'm coming to terms with my understanding of the role of the mantissa.  From it we get our ability to resolve a range numbers, but it's discrete capacity is finite.  I'm hoping the SuperFractalThing source code will teach me more.
Thanks again!

Offline hobold

  • Fractal Frogurt
  • ******
  • Posts: 479
Re: Homemade MB Viewer
« Reply #9 on: July 16, 2021, 05:43:12 PM »
X + (4 * n) on one thread does not egual  X + n + n + n + n on another thread.
In the left alternative, the term in brackets will be evaluated first. In binary floating point arithmetic 4 * n is (usually) an exact operation, because 4 is a power of two. So this operation is lossless, with respect to rounding error. Then the quadrupled number is added to X, and in the general case (when the exponents of X and of 4*n differ) there is a loss of information when the mantissa of the smaller magnitude number (i.e. the one with the smaller exponent) is aligned with the mantissa of the larger magnitude number.

In other words, the two floating points of the two values cannot float independently for an addition (i.e. for the value of the sum). The larger magnitude number's floating point "wins" (because that number's leading digits are more significant), and the smaller magnitude number effectively loses trailing digits, because those get shifted to the right, beyond the end of the mantissa width.


In the right alternative, most programming languages will evaluate from left to right. So the first addition is of X and n, potentially losing a few trailing digits of the smaller magnitude number. If X is the number of larger magnitude (i.e. the one with the larger exponent), then this loss of precision keeps happening for every further addition of n. So in this case we are effectively using a truncated, lower precision value of 4*n to add to X. (If n is the number of larger magnitude, then the loss of precision happens only once.)

Offline DanKje

  • Fractal Freshman
  • *
  • Posts: 6
Re: Homemade MB Viewer
« Reply #10 on: July 18, 2021, 08:09:41 AM »
When you said "align mantissas" things became clearer.  A double precision variable can range greatly from MIN to MAX, but two doubles need to be close enough in magnitude to fit on the same chalkboard (mantissa), in order to do any math.

I should have learned this back in college, in 1978.

That you would take the time to help teach a stranger speaks volumes.   :thumbs:

Offline hobold

  • Fractal Frogurt
  • ******
  • Posts: 479
Re: Homemade MB Viewer
« Reply #11 on: July 18, 2021, 06:01:15 PM »
I should have learned this back in college, in 1978.
Computers were still fairly niche back then. And floating point numerics is niche today, even as computers are ubiquitous. ^-^


xx
EXR Cube Viewer

Started by 3DickUlus on Downloads

6 Replies
335 Views
Last post July 03, 2021, 09:03:36 PM
by 3DickUlus
xx
Which Mandelbrot Viewer Uses .ifp Files?

Started by Byte11 on Fractal Programs Discussion, Help, & Support

1 Replies
351 Views
Last post April 22, 2019, 09:25:18 PM
by claude
xx
Popup image viewer won't pop up.

Started by pauldelbrot on Forum Help And Support

3 Replies
133 Views
Last post January 04, 2021, 09:56:55 AM
by Caleidoscope