In this video we're gonna be talking about
how we can use this ChatGPT for debugging.
Now let's just go ahead and ask
ChatGPT to create something for us
and then we're gonna intentionally mess it up
just to kind of simulate what it would've been like
if we had written something ourselves
that was maybe incorrect
or missing a crucial line of code
or a piece of logic that we just,
'cause we're humans, we're subject to mistakes.
Just maybe we just forgot about something, right?
So let's see if ChatGPT can actually help us
with the debugging process
and kind of reading through our code
with knowledge of the problem spec.
And then just trying to figure out
what could have possibly went wrong.
So first let's ask it an interesting question.
Let's see if, could you
generate the Mandelbrot set?
Or rather could you generate a visualization
of the Mandelbrot set in Python?
Now this is, so the, if you don't know,
the Mandelbrot set is a fractal,
which is basically when viewed, it's like
infinite complexity as you continue to zoom in and zoom in
and it's basically a mathematical function.
And yeah, so it's able to do that.
So if you go ahead and copy the code here,
this is some beautiful code right here.
It's literally telling us, it's giving us comments
for everything and telling us what
each and every line of code is doing.
But yeah, let's go ahead
and create a file for that real quick.
So, Mandelbrot.py
and, oh, I think I stole it when it was
not done generating stuff.
So let's go ahead and wait for that to finish writing.
So now it's gonna go ahead and tell us what's going on.
Generates a square image of the set with 500 by 500 pixels.
So if we go and take that
and we run it, let's see
what it gives us without like kind of messing with anything.
So we actually know what we're working with here.
Well, that looks really cool.
Yeah, so that's the Mandelbrot set.
I can go ahead and zoom in here.
As you can see, it's a, it's not really infinitely detailed
as I've not made the size too large,
but that's something I can tweak here.
Let's see if we can kind of mess with this thing, right?
So this is like a very crucial part of the math here.
So if I, let's say mess with this, let's say 1.
I'm, I'm interested in what this will look like.
Probably wrong.
Yeah, so that looks very strange
and that's definitely not what we expected.
Let's, let's mess it up even more.
So if we do that, this will definitely, oh yeah, we've,
we've completely destroyed it.
So let's, let's ask it.
This is my code for displaying the Mandelbrot set.
What is wrong with it?
And then let's go ahead and copy that in here.
Your code looks mostly correct,
but there is a small issue with the formula used
to calculate the iterative sequence for each point.
The Mandelbrot set is defined as a set
of complex number C versus the sequence Z times N plus 1
is equivalent to Z of N to the power of 2
plus C does not diverge.
So this is basically just the math
behind this really beautiful fractal,
but yeah, it, it's able to point out exactly,
so like, it's saying you've modified the formula
to be this instead,
which changes the nature of the set being generated.
So if you go ahead and fix that real quick,
it should give us the right answer again.
And that's, that's really funny 'cause it almost
knows exactly what we did.
We've modified the formula.
That's, that's a funny way of wording it.
But yeah, we can see
that it's once again giving us the code
pretty much the same thing as what it gave before.
I don't see any really big changes here,
but yeah, we can see that,
that the two numbers we had modified,
this became 1.5, this became 1, I believe.
Those, those are back to normal, right?
And that's funny, that it's able to kind of
just pick out on exactly what was wrong
'cause it knew what was right.