Author Topic: Decimals and Graphing Fractals  (Read 23682 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Decimals and Graphing Fractals
« on: June 25, 2010, 06:19:02 pm »
Last year, I made a program in TI BASIC to graph the Mandelbrot set.  There was already one out there, but I wanted to make my own as a kind of educational challenge to myself.  (Woah, that sounds so nerdy, but you guys can probably relate)

Well, it worked.  But it takes 30 minutes to graph.  I'm not ready to learn assembly at this point, so until Axe came out I resigned myself to half-hour waits.  But now, my new project is to make a fast, axe Mandelbrot set grapher.  The plan is the have it display the time a BASIC program would take, and then the (hopefully significantly shorter) time the axe program will take.  It would be a great way of showing the difference between the speeds of Axe and BASIC.  If it is fast enough, I could even throw in a grayscale layer at a higher iteration for visual effect. 

The problem, is that the Mandelbrot set is tiny.  It only reaches from -2 to about .6 on the real axis, and -.8 to .8 on the imaginary axis.  Checking the points would require numbers with decimals, and a method of multiplying them together.

To check a complex number c to see if it lies in the Mandelbrot set, you follow this pattern.
c , c^2 + c , (c^2 + c)^2 +c , [(c^2 + c)^2 +c]^2 + c ... and so on.  If c is unbounded, it is not in the Mandelbrot set.  The easiest way to check this is to see if c's real and imaginary parts are less than a very large number.  Now the program requires support for very small numbers and very large numbers!

Is devising a system for handling decimals even possible?  TI did it, but does anyone know how?  (their method may not be plausible for an assembly program anyway)  If only axe's variables could store decimals... *sigh*

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Decimals and Graphing Fractals
« Reply #1 on: June 25, 2010, 06:26:48 pm »
It would be nice to see such program. I always wanted to see with more kind of programs how BASIC and Axe compares.

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #2 on: June 25, 2010, 06:38:32 pm »
very large numbers? if you have a complex number c = a + bi, as soon as sqrt(a^2 + b^2) > 2, you know its unbounded. it's a very nice property about the mandelbrot set that makes computing a lot faster. if the magnitude of the complex number has not exceeded 2 after your max_iters, then you assume it's a part of the set.

Edit: as for decimals, the author of Axe would just have to add support to tap into TI-OS's built in FP b_calls and store 9-byte vars
« Last Edit: June 25, 2010, 06:42:27 pm by quasi_Phthalo »

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #3 on: June 25, 2010, 07:28:05 pm »
very large numbers? if you have a complex number c = a + bi, as soon as sqrt(a^2 + b^2) > 2, you know its unbounded. it's a very nice property about the mandelbrot set that makes computing a lot faster. if the magnitude of the complex number has not exceeded 2 after your max_iters, then you assume it's a part of the set.

Well, that takes care of the large numbers, but I am still at a loss of how to implement sub-integer numbers with the current version.  Can anyone think of a way of doing this with expanded values?
« Last Edit: June 25, 2010, 07:28:26 pm by Michael.3545 »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #4 on: June 25, 2010, 07:29:44 pm »
Floating points are just as slow as BASIC basically.  I did indeed make a Mandelbrot set program in assembly using the OS's floating point bcalls and it still took about 10 minutes to graph.  The only way I was able to graph the set with Axe Parser in under a minute was to use fixed point math instead of floating point math.  8.8 is really really fast and fits into a normal Axe Variable, however the resolution is low, you can't make the pixels any closer than .0039 apart (which is 1/256th) or else the image breaks down and pixelates.  You can increase the accuracy to 8.16 or 16.16 which are a little bit slower, but it would allow the pixels to have spacings as small as .000015.  If you're really daring, you can have an arbitrarily long fixed point number which is referenced by a pointer.  I'm going to be adding a new command soon that makes multiplication easier to do as soon as I can figure out an efficient way to do it.
« Last Edit: June 25, 2010, 07:30:37 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #5 on: June 25, 2010, 08:00:31 pm »
Cool, built in fixed point support will be nice!
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #6 on: June 25, 2010, 08:07:21 pm »
While I was drawing out my ideas, much to my surprise I found that squaring a complex number (integers only :() is relatively easy to do with a four-column array. 

@Quigibo
Is this 10 minute grapher available for download anywhere?

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #7 on: June 25, 2010, 08:12:52 pm »
The 10-minute one? I'm not sure where that one is, but I can get you the link for the 1-minute one.
Edit: 1-minute Mandelbrot set is at http://ourl.ca/4129/97657 I'm not sure if the 10-minute one was ever released, you may have to ask Quigibo personally, if he even has it still.
« Last Edit: June 25, 2010, 08:15:36 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #8 on: June 25, 2010, 08:32:52 pm »
I never released it becasue it was slow x_x  I still have the source code, but I tried it and it doesn't seem to be working.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #9 on: June 25, 2010, 10:41:57 pm »
Floating point numbers would be very difficult, but also possible.  You would just need routines for the operations you want, that would take pointers as arguments, and have it do the math on the pointers.

For storage, I presume that you could set the first byte to be the power of ten, and store the rest as BCD. (Binary-Coded-Decimal).  The math would probably be the hard part.  Any ideas for libraries, Quigibo?  Possibly using the OpenLib( and ExecLib commands.  (ti-84 only, I think, so those wouldn't work.)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Decimals and Graphing Fractals
« Reply #10 on: June 25, 2010, 10:51:24 pm »
Floating point numbers would be very difficult, but also possible.  You would just need routines for the operations you want, that would take pointers as arguments, and have it do the math on the pointers.

For storage, I presume that you could set the first byte to be the power of ten, and store the rest as BCD. (Binary-Coded-Decimal).  The math would probably be the hard part.  Any ideas for libraries, Quigibo?  Possibly using the OpenLib( and ExecLib commands.  (ti-84 only, I think, so those wouldn't work.)
For a fractal program where the values are never going to be displayed onscreen, I think a binary floating-point method would be more efficient than decimal.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #11 on: June 26, 2010, 01:43:40 pm »
Quote
I think a binary floating-point method would be more efficient than decimal.

agreed. It's actually kind of silly that TI stores it's floats as decimal. It wastes a lot of memory having lots of bytes that will never use A-F. The only reason for it was to may the number displaying routines faster and easier to code. Who needs that?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Decimals and Graphing Fractals
« Reply #12 on: June 26, 2010, 01:52:54 pm »
what would be the binary floating-point method? Would it use base 10 or 16?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #13 on: June 26, 2010, 01:56:02 pm »
Base 2 I belive.  It makes all the arithmetic a lot easier because instead of multiplying by 10, you would be multiplying by 2, which is a lot faster in axe :)

Offline quasi_Phthalo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 90
  • Rating: +1/-1
    • View Profile
Re: Decimals and Graphing Fractals
« Reply #14 on: June 26, 2010, 02:02:15 pm »
think of binary fractional numbers this way:
0.10000000b = half
0.01000000b = fourth
0.11000000b = three fourths
0.00100000b = eight
etc.
then you can translate it into hex, taking them in 8-bit chunks:
00.01h = 1/256
00.10h = 16/256 = 1/16
00.FFh = 255/256
C9.A9EB07h = 201 + 169/256 + 235/65536 + 7/16777216 = 201.663742482662200927734375

Edit:
it's interesting how numbers like one third are:
0.333333333... in base 10
0.555555555... in base 16

Edit2: fixed something misleading
« Last Edit: June 26, 2010, 06:37:09 pm by quasi_Phthalo »