# How would you calculate the Mandelbrot set in hardware? [closed]

I'd like to build a small novelty circuit that calculates the Mandelbrot set and displays it on an array of LEDs. The minimum floating point math would not necessarily require complex numbers (just calculate $x$ and $y$ separately) and the total number of individual calculations of $z_{n+1}=z_n^2+c$ would be under one million, so even something as slow as ten million FLOPS per hour would be OK in this case. At this level, it looks like 16 bit math is almost enough with clever programming, 32-bits is enough to make it work. Floats rather than ints would make life a heck of a lot easier, but not required.

I believe that a Raspberry Pi would be overkill as would a high-end Arduino, so an Uno, or a Basic Stamp II with its FP coprocessor perhaps.

That exhausts my knowledge of the possibilities, but there must be other options out there. How would you go about designing a small circuit to do this? What type of circuit would you use?

Background question, and the first ever published image of the Mandelbrot set (1978):

• .. or Atmel even have it as an example program asf.atmel.com/docs/latest/uc3c/html/… Jul 15, 2017 at 8:18
• Just pointing out that every AVR chip (as far as I know, it's all, thanks to a library) can do division and FP(floating point) arithmetic (FPU), yet there's no assembler command for division, and there's no FPU to deal with the FP arithmetic. It's all done in software, there's no hardware solution for FP arithmetic on Arduinos. And I'm very certain that you can include a similar library for picXX or any other microcontroller. Check out this link Jul 15, 2017 at 8:37
• Hmmm, I'm not 100% sure if it will work with every tinyAVR, some only got 512B flash, it might be difficult to fit everything onto that. And sorry for asking this question, but why can't you just store the mandelbrot image in a lookup table? Or are you going to make some super duper mega slow animation zooming in forever? Jul 15, 2017 at 8:46
• You don't need to change the grid spacing if you use a lookup table. You would only need 35x75 bits => 35x80 bits => 35x10 bytes => a list of 350 bytes. But it doesn't matter ;) I assume that you've gotten all the answers you need ;) Also, I'm very very sure that a tinyAVR that got 2kB flash could fit the FPU library on it without any problems + your own code. As long as you use atmelstudio as your coding environment... The Arduino IDE injects so much weird crap onto the controllers... Jul 15, 2017 at 8:57
• Well I have gone through it again. I haven't found anything calling for a small micro to do your plots. But I shall admit I overlooked one very good reason to your point: It's a challenge I want do it with as little as can be done. In this I do agree with you. Jul 15, 2017 at 11:20

I think the moset obvious solution for your requirements is using a FPGA and writing HDL code that calculates $z_{i+1} = z_i^2 + c$.

• A search for "smallest FPGA" certainly comes up with several very small ones. I wouldn't have even considered it, but ya, this is downright elegant!
– uhoh
Jul 15, 2017 at 8:56

Any Cortex M4F can easily do single-precision floating point math (ie. float, not double). Here is a summary how long each instruction takes.

Example: Kinetis MK02FN128 running at 100MHz can theoretically do 100 million floating point multiplications a second.

You would write code in C with floats as you would do on a PC. Some tips. Just look for microcontrollers with Cortex M4F core or "with FPU".

• Thanks for the links!! What's the smallest option here? The speed is amazing, but I'm looking for "small".
– uhoh
Jul 15, 2017 at 9:35
• There is a myriad of ARM MCUs to choose from.... some better-known families to look at: Kinetis, STM32, EFM32, Renesas Synergy, TM4C. You can even get a Bluetooth system on chip with FPU - nrf52 (in a module eg. BL652).
– filo
Jul 15, 2017 at 9:59
• Do you mean "small" as in chip package size, or some other metric? The Kinetis is a whole 5mm x 5mm, and the really small packages can't be hand-assembled. Jul 16, 2017 at 21:05