Newton-Raphson Fractals with ChatGPT
Daniel Morton PhD
Senior Data Scientist | Builder | MS Analytics | PhD Mathematics | Machine Learning | Data Science | Deep Learning | Ad Tech
I am proficient in seven programming languages. Javascript is not one of them. Neither is HTML. And my mathematical mind has always read CSS as C-- (S -> subtract -> minus sign) and thus somehow the opposite of C++, which is way off the mark. That means this little project with ChatGPT (version 4o, I think) is not just my first foray into any sort of web development but also an exploration with languages about which I know next to nothing.
The premise is simple. Anyone with a background in mathematics knows that fractals are stunningly complex patterns created from simple formulas. (They're really geometric objects with "fractional" dimension, but let's not go down that tangent.) One popular way of creating fractals is using the Newton-Raphson method for finding polynomial roots. Since the math for creating these "Newton Fractals" is very simple, it makes a good test case for ChatGPT. Since my ability to evaluate Javascript is limited, it makes a good test case for debugging by prompt engineering and intuition.
ChatGPT struggled in two areas.
领英推荐
I mostly ignored the text surrounding the code. As a rule, I don't need ChatGPT telling me what it's going to do before writing the code and, after the code is written, what it's done. I suppose I'll have to wait for ShakeGPT for an LLM that realizes brevity is the soul of wit.
The code comments were pretty good. Certainly better than I would have bothered with. The only editing I had to do for index.html was to switch out styles.css for style.css. ChatGPT had a little confusion with plurals. (Thanks to Dave Holmes-Kinsella for catching that bug.)
The code can be found here. The page can be tested here. I'm no artist; I stuck with the default color template, which works better with some polynomials than others. Plenty of other bells and whistles, such as changing the scaling or adding a zoom feature. I'll get to those at some point. As a PoC, and less than an hour's work, it's pretty decent.
Warning: Might be a bit slow. If you try it, give it a few seconds.