How (and why) to take a logarithm of an image
3Blue1Brown
0:00 [Submit subtitle corrections at criblate.com] Whenever
0:01 I'm making one of these videos,
0:02 there's sometimes a special moment where the act of animating
0:05 involves solving a whole bunch of little technical puzzlers,
0:07 and then the underlying math I'm trying to explain clicks for me
0:10 in a way that it hadn't before once I see it alive on screen.
0:14 The best versions of those moments often tell me when
0:16 a video is going to be one of my favorites,
0:18 and putting together the end of this piece right
0:21 here was one such time when I got that feeling.
0:27 Our story doesn't actually start in the math classroom today.
0:30 We begin in the art room.
0:32 Imagine standing in a gallery, looking at a picture of a boat in a harbour,
0:36 and the whole world warps as your gaze shifts upwards and to the right,
0:40 where you see a village on this waterfront.
0:43 Among the tightly clustered buildings, the world warps even more as your gaze
0:47 shifts downwards to the entrance of one building,
0:50 leading to a hallway full of artwork.
0:53 And at the end of this hall, here you are again, staring at a picture of a boat.
0:58 This is M.C.
0:59 Escher's 1956 lithograph, the Print Gallery, or in Dutch, Prentendentunstelling.
1:05 In a letter that he wrote to his son,
1:08 describing his creation of a young man looking
1:10 with interest at a print that features himself,
1:13 Escher called this the most peculiar thing I have ever done,
1:16 which for him is saying a lot.
1:18 Escher's art is widely loved around the world,
1:21 frequently featuring paradoxical themes or uniquely satisfying
1:24 geometric patterns with some kind of character.
1:27 This love is especially pronounced among mathematicians,
1:30 since his art often touches on surprisingly deep concepts within math,
1:34 despite the fact that Escher himself had no formal training in the field.
1:39 The Print Gallery offers a perfect example of this unexpected depth.
1:43 In 2003, the mathematicians De Smit and Lenstra
1:46 offered a delightful analysis of what's really
1:48 going on in this piece and the mind-bending
1:50 self-contained loop that Escher managed to achieve.
1:54 One of my main goals with this video
1:56 is to offer a visual unpacking of their analysis,
1:59 aiming as always to give you a feeling
2:02 that you could have rediscovered this yourself.
2:05 Something that unexpectedly pops out of this analysis is an answer
2:08 to the question of what exactly should go in the middle of this picture.
2:12 At first, that might sound like an incoherent question.
2:15 If you come at it from the upper right,
2:17 it feels like it should be featuring buildings in the village,
2:19 but coming at it from the left, it looks more like part of the picture frame.
2:23 Come at it from below, though,
2:24 and it feels more fitting to be part of the gallery itself.
2:28 Somehow all of the ambiguity about where exactly you are
2:31 in this whole scene is compressed into that blank circle in the middle.
2:36 And just for fun, since we're in the 2020s,
2:38 I let a diffusion model take a stab at filling this in.
2:41 Unsurprisingly, it struggles immensely.
2:43 It just doesn't get it at all.
2:45 And giving the poor machine some credit, of course it struggles.
2:48 This feels like an intrinsically ambiguous and ill-defined part of the scene.
2:52 But nevertheless, by the end, I hope you'll agree there is one,
2:56 and really only one,
2:57 completion that feels like the right puzzle piece you can slot in.
3:02 Before diving into the math, I want to give you a purely intuitive
3:05 description for how Escher actually made this piece,
3:07 which breaks up into three different steps.
3:10 Step one is to start out with a straightened
3:13 out version of the same general concept, where a man is looking at a picture.
3:17 That picture contains a harbor,
3:19 which contains a town, that contains a print gallery,
3:22 that contains that same man, and so on and so forth.
3:26 You could zoom in forever to your heart's content.
3:30 This idea of a self-similar image, where the picture is contained inside itself,
3:34 has a special name to graphic designers.
3:37 It's known as the Droste effect,
3:38 named after a cocoa company that featured it in its branding.
3:42 In fact, this seems to have been a somewhat common
3:45 marketing gimmick for all kinds of early 20th century products.
3:48 The self-similar Droste image that Escher was using, though, involves a much,
3:53 much deeper zoom than any of these, where
3:56 the self-similar copy is 256 times smaller than the original.
4:00 You'll see where that number comes from in just a minute.
4:03 The genius of Escher is that he somehow intuitively realized there
4:06 must be a way to take this concept of a picture nested
4:10 inside itself and turn it into this warped loop where the zooming
4:15 in happens implicitly as a viewer's gaze wanders around the circle.
4:21 By the way, you might be wondering where I got this straightened out version,
4:24 and the answer is that those two
4:26 mathematicians I referenced generously let us use it.
4:28 This is something they actually reverse engineered from the original
4:32 Escher piece using the help of two Dutch artists,
4:35 Hans Richter and Jacqueline Hofstra.
4:37 The way they reverse engineered it is actually super interesting.
4:40 In a certain manner of speaking,
4:41 it involves taking the logarithm of the original piece.
4:44 I recognize that sentence probably sounds like nonsense right now,
4:48 but later on in this video, I promise that will make abundant sense.
4:52 To outline the basic idea for how Escher made this loop,
4:55 I want to use an example that's simpler than the one
4:58 he was working with, so we'll pull up this custom
5:00 self-similar Drasta image which has a pie creature looking at a framed
5:04 picture of a house where that same pie creature lives.
5:08 In this example, the self-similar copy is
5:10 only 16 times smaller than the original,
5:12 and this just makes everything much easier to see all at once.
5:15 What I'll do is keep a separate workspace on the right
5:18 here to sketch out the general goal we have in mind,
5:21 where the way you might think about it is that you want
5:25 to distribute that 16-fold zoom-in factor across the four corners of the square.
5:30 For example, let's say you want the pie creature itself
5:33 to appear about at the same size in the lower left corner.
5:36 Then if you zoom in by a factor of 2 in the original,
5:39 we'll take what would be in the upper left of that zoomed
5:43 version and then place it in the upper left of our workspace.
5:47 Similarly, zoom in by another factor of 2
5:49 and then take the upper right of that zoomed-in
5:52 version and now place an expanded version
5:54 of that in the upper right of our workspace.
5:58 Finally, one more step, zoom in by another factor of 2,
6:01 take what's in the lower right of that zoomed-in version,
6:04 blow it up, and place it in the lower right of our workspace.
6:08 These four cut-out corners give a rough idea of what we want to create here.
6:13 As long as you can find a smooth way to fill in the gaps between them,
6:17 then as the onlooker's gaze wanders around a circle on this image,
6:21 what they're seeing will zoom in and in and in until it
6:24 elegantly joins up with the self-similar part of the image 16 times smaller.
6:29 We could just try joining it all up naively,
6:32 something like this, but frankly that doesn't really look very good,
6:35 and it's certainly not as smooth
6:37 and as elegant as what Escher managed to achieve,
6:39 so we still have some work ahead of us.
6:42 This book that I've been pawing through by the way, The Magic of M.C.
6:46 Escher, is something that I got on a delightful
6:48 visit to the Escher Museum in The Hague,
6:50 which, if you're ever in the Netherlands, I would highly recommend,
6:53 and when we turn to the section about the print gallery,
6:56 it offers us a little peek into what Escher's process actually was.
6:59 For him, step two was to create this warped grid.
7:03 For the animations here, I'm going to pull up a slight modification of that grid
7:07 that is basically just a little nicer mathematically to generate,
7:09 but it illustrates the same key point.
7:11 In his case, the self-similar Droste image he
7:14 was working with has a scaling factor of 256,
7:17 so to distribute that across the four corners,
7:20 for him it would involve scaling by a factor
7:22 of four as you walk from one corner to the next.
7:26 And if you look closely at his grid,
7:28 say at one of the squares on the lower right,
7:30 notice how if you follow the top and bottom lines
7:33 bounding that square over to the lower left of the image,
7:36 those same lines end up enclosing a square that is now four times as big.
7:40 And then similarly, if you look at the lines bounding
7:43 the left and right of a small square from that region,
7:45 and you follow them upward,
7:47 they end up nestled around a square that's nicely four times as big.
7:50 So the grid kind of encodes the scaling
7:52 from one corner to the next that we want.
7:55 Now for our pet project,
7:56 where we only need to scale up by a factor of two from each corner to the next,
8:00 we're going to use a modified version
8:02 of this, but it'll be the same general idea.
8:05 You might naturally wonder where on earth does this grid come from, but I
8:09 actually want to postpone that question and skip ahead to step three,
8:12 which is how you can actually use this grid together
8:15 with the self- similar Drosse image to create Escher's final effect.
8:19 The way this works is to first lay
8:21 down an ordinary square grid on the original image,
8:23 and then let's say you want this portion here
8:26 to end up in this corner of our final version.
8:29 What you would do is take each tiny square inside it and then copy
8:32 over its contents to the corresponding tiny
8:35 square in the warped version of the grid.
8:38 From there, each neighboring square in our original grid is forced
8:41 to go to the corresponding neighboring square in the warped version,
8:46 so you can kind of just keep following
8:48 where the image must go by following the grid.
8:52 And the fact that the grid lines on the warped version space
8:55 out by a factor of two as you go from the lower left
8:58 to the upper left means that the scale of our scene automatically gets
9:01 scaled up by that factor of two as you walk up that line.
9:06 The idea of this process is that as an artist,
9:09 it's relatively straightforward to go piece by piece,
9:12 copying over what's inside one tiny square to another tiny square,
9:15 because at this small scale things are undistorted.
9:19 It's certainly way, way easier than trying to dream up and draw the appropriate
9:23 warped final image starting with nothing but a blank page in front of you.
9:28 So basically with this warped grid in hand,
9:31 the process of copying over each little square is pleasantly automatic,
9:35 and if we let this automatic process run all the way around,
9:38 it nicely closes up with the initial position, and for that to happen,
9:43 it requires that our original image had this self-similarity
9:46 when you zoom in by a factor of 16.
9:49 I hope you'll agree the final result we have is pretty nice,
9:52 it recreates the same general effect, but more than anything I think it gives
9:56 cause to more deeply appreciate Escher's own composition.
9:59 He was actually very deliberate about the choice
10:01 of imagery at all of the distinct scales.
10:03 To quote, I quite intentionally chose serial types of objects,
10:07 such for instance as a row of prints along the wall,
10:11 or blocks of houses in a town.
10:13 Without the cyclic elements,
10:14 it would be all the more difficult to get my meaning over to the random viewer.
10:20 This idea where you have a straight reference image and then a warped grid,
10:23 and you use the two together to create a warped scene,
10:26 is a common process in graphic design.
10:29 It's known as a mesh warp, and Escher didn't invent it for this case,
10:32 it's something that he had used multiple times before for other pieces.
10:36 For our story, the point is that all of the logic for turning
10:40 a Drasta zoom into a loop is abstracted and purified into this grid,
10:44 raising the natural question, where does it come from?
10:48 How do you make this?
10:49 You can kind of imagine as an initial naive approach you
10:53 might try linearly scaling everything from one corner to the next,
10:57 but if you did that right away you would see a conflict.
11:01 These two scaling processes are placing
11:03 distinct pressures on the individual squares,
11:05 where for example this square wants to get flared out
11:08 in this direction based on the zooming in from the right,
11:11 but it also wants to get flared in this direction
11:14 based on the zooming out as you go up.
11:16 Escher was evidently pulled to resolve this by curving
11:19 all of the lines to relieve this tension.
11:23 But there's one other crucial constraint that it seems he was
11:26 guided by, one that presumably made the image transfer process easier,
11:30 which made the final result look more natural,
11:32 and which will make the ears of any
11:34 mathematician immersed in complex analysis immediately perk up.
11:38 In his final warped grid, the tiny squares are, well, squares.
11:43 To be clear, this is not at all true for most mesh warps.
11:46 In most cases, the warped grid lines
11:48 that you draw don't necessarily intersect at right angles,
11:51 and the little regions that they bound will in general be little parallelograms.
11:56 This can still be workable for an artist, you can still kind of do the transfer,
12:00 but presumably the act of copying over from the original
12:03 to the warped version is more awkward when you have that distortion,
12:07 so it would be much nicer if in the warped grid,
12:10 little squares remained at least approximately square.
12:13 And when you look closely at the grid that Escher used for his print gallery,
12:17 it has this property.
12:18 All the lines are intersecting at right angles, and at a small enough scale,
12:22 the regions they bound really are approximately squares.
12:25 Artistically, this has the nice effect that even though the whole
12:29 scene is dramatically warped and distorted at a global scale,
12:32 zoomed in at a local scale, everything is relatively undistorted.
12:36 This is what makes each local part of Escher's image easily recognizable.
12:41 And mathematically, this is where the story really gets interesting.
12:45 You see, this idea of a function
12:47 from two dimensional space to two dimensional space,
12:49 where tiny squares remain approximately square,
12:52 plays a special role and has a special name in math.
12:55 It's called a conformal map, and one area where it comes up all the time is
12:59 in the study of functions with complex number inputs and complex number outputs.
13:04 At this point, we're going to step back and walk out
13:07 of the art classroom and wander over into the math department,
13:10 where I want to offer you a mini lesson
13:12 on some of the core ideas from this field.
13:16 The basic game plan from here is that I want to first do a little refresher,
13:20 go over some of the basics of complex numbers and complex functions,
13:23 and then I want to spend some meaningful time building up
13:26 an intuition for what logarithms look like in this context of complex numbers.
13:30 And then once you have that in hand,
13:32 we're going to step through a completely different way that you can
13:35 think about recreating this effect that Escher had in his print gallery.
13:38 Let's warm up with a review of the basics.
13:41 We typically think about real numbers as living on a one dimensional line,
13:44 the real number line, and complex numbers are two dimensional.
13:48 Specifically, we think of the imaginary constant i,
13:51 defined to be the square root of negative one as being one unit above zero,
13:56 end every other point on this plane represents some combination
13:59 of a real number with some real multiple of i.
14:03 It's typical to use the variable z in referring to a general complex number,
14:07 and the game we want to play is to understand various functions of z.
14:11 A very simple but important example is to multiply z by some constant.
14:16 The function f of z equals two times z has
14:18 the effect of scaling everything up by a factor of two.
14:23 But what about multiplying by something imaginary,
14:25 like i, the square root of negative one?
14:27 Well you know that multiplying one by i gives you i,
14:31 and by definition, i times i is negative one.
14:34 Both of these you'll notice are in 90 degree rotation, and more generally,
14:38 multiplying any value z by i has the effect of a 90 degree rotation.
14:42 And more general than that, when you multiply by any complex constant,
14:46 the effect is some combination of scaling and rotating.
14:50 And there's a nice way to think about
14:51 exactly how much it should scale and rotate.
14:54 Zero times anything is zero, so the origin has to stay fixed in place,
14:58 and then one times any constant c is that same constant c.
15:02 So that means this point at one has to be dragged over
15:05 to land on whatever that constant c is that we're talking about,
15:08 and that fully determines the amount of scaling and rotating.
15:12 From there, the rest of the grid stays as rigid as it can.
15:15 A key point to emphasize for our story is
15:17 that if all you're doing is multiplying by some constant,
15:20 shapes are always preserved.
15:22 Anything you might want to draw, like a square,
15:24 can get scaled or rotated, but beyond that, there are no distortions.
15:29 Now things get more interesting for more complicated functions.
15:32 A simple but non-trivial example would be mapping each number z to z squared.
15:37 So the input two is going to have to move to two squared, which is four.
15:41 The input i is going to have to move to i squared, which is negative one.
15:45 Negative one itself would have to get mapped to positive one.
15:48 And in its fullness, here's what it looks like if I let every point among
15:52 the grid lines of this input space move over to their corresponding outputs.
15:57 It's a pretty nice effect, and unlike multiplying by a constant,
16:00 shape is absolutely no longer preserved.
16:02 The grid lines get curved and warped.
16:05 However, and this is a key point,
16:06 pay attention to what happens at a small scale.
16:09 For example, just focusing on this little square from the input space.
16:12 As you watch the transformation happen again,
16:15 you can see that shape is approximately preserved,
16:17 at least at a small enough scale.
16:20 Little squares from our original grid remain approximately
16:23 square even after getting processed by the function.
16:26 To use the lingo, the function z squared gives a conformal map.
16:30 And the choice of z squared is really not special here.
16:33 Here's what it looks like if you transform each point z over to z cubed.
16:37 Squares remain approximately square.
16:40 Okay, maybe this example square that I'm
16:42 highlighting doesn't exactly look square in the output,
16:44 but really it's just because it started off too big.
16:46 To be clear, this conformal property that I'm talking about is a limiting one.
16:50 A particular square might not exactly become square,
16:53 but the idea is that as you zoom in more and more,
16:55 choosing square regions from the input space that are smaller and smaller,
16:59 the resulting output will indeed be better and better approximated by a square.
17:04 And there's also nothing all that special about
17:05 the choice of polynomials like z squared or z cubed.
17:08 For just about any function of complex numbers you could think to write down,
17:12 this property holds.
17:13 Shape is preserved at a small enough scale.
17:15 It's almost like magic.
17:17 The use of complex numbers is very relevant here.
17:20 If instead you were thinking of points in 2D space
17:22 simply as a pair of real numbers with some xy coordinates,
17:25 and you write down some arbitrary function of x
17:28 and y to get a new pair of numbers,
17:30 what is way, way more typical as you let points in that input space
17:34 get transformed is that the outputs
17:36 of those tiny squares get squished and distorted.
17:39 Even as you zoom in more and more,
17:41 the resulting limiting shape typically looks like a parallelogram,
17:44 not necessarily a square.
17:46 So, complex functions really are special in this way.
17:50 And the basic reason that tiny squares remain square comes down to calculus.
17:54 What you're looking at is what it means for these functions to have derivatives.
17:59 That might sound a little strange,
18:00 but the analogy you can think of is that for most functions of real numbers,
18:05 if you visualize them the ordinary way,
18:07 just with a graph of inputs on the x-axis, outputs on the y-axis,
18:11 as you zoom in more and more to any particular point on that graph,
18:14 it looks more and more like a straight line.
18:17 That is, the rate of change,
18:19 how much delta f you get for a given delta x, approaches a constant.
18:24 This is literally what it means for a function to have a derivative,
18:27 but it's not the only way to visualize it.
18:29 Here's a different way to see the same concept.
18:32 Instead of looking at the graph of a function,
18:34 let's think of the same function but as a transformation.
18:37 That is, you're going to let each of these points on the real
18:40 number line move over to their corresponding outputs on this other number line.
18:45 What you'll notice is that evenly spaced dots
18:47 from the input space can get warped in the output space,
18:50 meaning the rate of change of the function in general is not constant.
18:55 This spacing between our dots can change from one part of the image to the next.
18:59 But we know that as you zoom in more and more to a particular output,
19:03 the rate of change approaches a constant.
19:06 The dots look more and more evenly spaced.
19:09 Specifically, if you take a tiny patch of dots around a particular input
19:13 and you copy them over to the output space around the corresponding output,
19:17 you can approximately line up all the dots
19:20 just by scaling everything by a certain constant factor.
19:23 This is the same analytical fact as what the slope of a graph is telling you,
19:28 it's just in a different visual context.
19:30 But this context carries over much more easily to thinking
19:33 about complex valued functions as transformations in the complex plane.
19:38 There we're going to think of the neighborhood around
19:41 a given input as a tiny little grid of points, like we were before,
19:44 and we let each point on that grid move over to its corresponding output.
19:49 In this case, what it means for the rate of change
19:52 to approach a constant is basically the exact same equation.
19:56 The visual to have in your head is that if you take that tiny
19:59 patch of squares around the input and copy it over to the corresponding output,
20:04 you can approximately match this up with the output
20:06 grid lines by multiplying by a certain constant, which remember,
20:10 in the setting of complex numbers, means rotating and scaling it in some way,
20:14 depending on the value of that complex constant.
20:17 Since rotation and scaling preserve shape,
20:19 it means that all the tiny squares from the input
20:22 space remain at least approximately square under this transformation.
20:27 So, stepping back, here's the key point,
20:28 the reason for talking about any of this at all.
20:31 Even though conformal maps like the one
20:33 that Escher was using for his print gallery are
20:36 incredibly constrained and highly unusual among the general
20:39 ways that you could continuously squish about two-dimensional space,
20:43 nevertheless, as if by magic, simply by speaking a language of complex numbers,
20:47 you can somehow create entire families
20:49 of these conformal maps without even really trying.
20:52 All you do is mix and match standard functions of complex numbers.
20:56 The one constraint is that these functions have to have derivatives,
20:59 but this will be true for most of the functions you think to write down.
21:03 For our story, decoding what's happening with the print gallery,
21:06 this means that we have an entirely new way to reframe the key question.
21:10 Can you construct some deliberately tailored complex
21:13 function so that the act of zooming
21:15 in around the inputs looks like walking around a loop among the outputs?
21:21 Now, at this point, with only the bare
21:23 minimum crash course of complex analysis under our belts,
21:26 it's hard to know where to start without
21:28 first building up a larger palette of functions
21:30 to work with and gaining some familiarity
21:32 with how they actually behave for complex numbers.
21:35 In this case, there are really only two functions that you need to understand,
21:40 e to the z and the natural log.
21:42 I want to settle in and spend some meaningful time understanding both
21:45 of these, and I think you'll agree that it's time well spent.
21:48 Everybody deserves, in my opinion, at least one time in their life
21:51 to experience the joy of understanding a complex logarithm.
21:55 First though, a necessary prerequisite is to understand the complex exponential.
22:00 Regular viewers will be familiar with what it looks like
22:03 to raise e to the power of a complex number, but a review just never hurts.
22:07 We can start scaffolding the transformation
22:09 just by focusing on the more familiar
22:12 examples of real number inputs and the real number outputs they correspond to.
22:16 For example, e to the 0 is 1, so this point at 0 maps over to this point at 1.
22:22 And then every time you let that input increase by 1,
22:25 the output grows by a factor of e,
22:27 meaning it runs away from us actually quite quickly.
22:31 And then on the flip side, as you decrease that input,
22:34 letting it get into the negative numbers,
22:36 every step to the left corresponds to shrinking the output,
22:38 again by a factor of e.
22:40 In particular, you'll notice in this case
22:42 that output is always a positive number.
22:44 This of course gets much more interesting when we
22:47 let the inputs and the outputs both be complex numbers.
22:50 And here, everything you need to know comes down to what
22:52 happens as you let the imaginary part of that input increase.
22:56 And what happens there is that the corresponding output walks around a circle.
23:02 If you're wondering why imaginary inputs to an exponential walk
23:05 you around a circle like this, we have discussed it many,
23:08 many other times on this channel.
23:10 See some of the links on screen and in the description.
23:13 A key point that I'll reiterate here is that what
23:16 makes the function e to the z very nice,
23:19 as opposed to exponentials with other bases,
23:21 is that as your input walks up at a rate of 1 unit per second,
23:25 the output walks around its circle at a rate of exactly 1 radian per second.
23:30 So in particular, increasing the imaginary part by exactly
23:33 2 pi causes one full rotation in the output.
23:37 Phrased another way,
23:38 these vertical line segments that I've been drawing with heights of exactly 2
23:43 pi each get mapped neatly onto one complete circle when you apply the function.
23:48 You'll notice how I've drawn these particular vertical line
23:51 segments to be spaced out evenly in the real direction,
23:53 where the real part from 1 to the next increases by 1.
23:57 The corresponding circles on the right each differ by a constant scaling factor,
24:01 specifically the scaling factor e.
24:04 Earlier for the simpler function z squared, I showed it as a transformation,
24:08 moving all of the inputs to the outputs.
24:11 And in this case, for e to the z, if you're curious how that same idea looks,
24:14 it's easiest to take a subset of the grid,
24:17 like this one here from the input space, and here's what it looks like to move
24:21 each square over to the corresponding output.
24:24 As we actually use this function for our print gallery goals,
24:27 it'll be very helpful to anchor your mind by thinking
24:29 of these vertical lines and the circles they turn into.
24:33 In fact, there's a very playful way
24:35 that I like to think about how these vertical
24:37 lines turn into concentric circles and how they
24:39 can carry the full input space along with them.
24:41 What I like to imagine is sort of rolling up that entire z-plane into a tube,
24:46 such that all of those vertical lines end up as circles.
24:50 Specifically, each circle would have a circumference of 2 pi.
24:54 Next, imagine taking this tube,
24:55 lining it up above the origin of the output space,
24:58 and then kind of squishing it down onto that output space,
25:02 turning all the circles from that tube
25:04 into these concentric rings of exponentially growing size.
25:08 That's just what I like, but however you choose to think about it,
25:11 what I want to be etched into your brain
25:13 is the idea of vertical lines turning into circles.
25:16 Now, the other very important point to emphasize here is
25:19 that multiple different inputs can land on the same output.
25:23 For example, e to the zero is one, but e to the 2 pi i is also one.
25:29 So is e to the negative 2 pi i and e to the 4 pi i and so on.
25:34 In fact, the infinite sequence along any given
25:37 vertical line spaced out by 2 pi will
25:39 all get collapsed together as that vertical line
25:42 gets kind of rolled up into a circle.
25:45 We say that the exponential map is many to one,
25:47 although it might not be obvious how this repetition in the vertical direction
25:51 is going to be key to our final recreation of the print gallery effect.
25:56 Okay, so exponentials give us the first ingredient,
25:59 characterized by turning lines into circles,
26:01 and the second ingredient we need is the inverse of such an exponential,
26:05 known as the natural log,
26:07 where basically the idea is that it unravels those circles back into lines.
26:11 Now, this will be especially fun
26:13 to visualize and especially relevant to our story
26:16 if we imagine painting this complex plane on the right with a Droste image,
26:20 say the example we were working with earlier with the pi creature
26:24 looking at a picture of a house where that same pi creature lives.
26:28 In other words, it is finally time for you and me to answer
26:31 that question of what it means to take the natural log of a picture.
26:36 Okay, so think about this for a second.
26:38 You already know that a vertical line segment
26:40 like this one on the left with a height
26:43 of 2 pi gets turned into a circle when you apply the map e to the z.
26:47 So the natural log is going to take a circle of points
26:50 on this image and then straighten them out into one of those lines.
26:55 Similarly, if you looked at a circle which was exactly e times smaller,
26:59 that would also get straightened out into a line
27:02 with the same height positioned one unit to the left.
27:05 And then similarly, every circle in between these two is going to get
27:09 unwrapped into one of these vertical lines
27:11 between those last two, and more generally,
27:14 smaller and smaller rings from the picture will
27:16 all get unwrapped into these vertical line segments,
27:19 each one with a height of 2 pi, farther and farther to the left in the image.
27:24 The result we get is a bit trippy, but it's pretty cool when you think about it,
27:27 and there's a number of important things that I want you to notice.
27:30 You've probably noticed that it repeats as you move to the left,
27:33 and I'll invite you to ponder why that might be
27:35 the case in the back of your mind for a minute, but before that repetition,
27:39 I want to talk about a different direction in which it repeats.
27:42 The way I've drawn it so far,
27:44 the imaginary part for the values on the left are ranging from 0 up to 2 pi,
27:48 but that's actually kind of an arbitrary choice.
27:51 Remember, if you keep letting that value z
27:53 on the left walk up by another 2 pi units,
27:56 the corresponding value e to the z on the right
27:59 would just keep walking around that same circle again,
28:02 so I hope you'll agree it feels at least enticing to let
28:05 our image repeat in this vertical direction
28:08 along every one of those vertical lines.
28:12 And it goes the other way too,
28:14 as you let the imaginary part on the left get smaller going down,
28:17 the corresponding value on that right
28:19 just keeps walking around that same circle,
28:22 so the pattern that you see should perhaps repeat in that way too.
28:26 To be more explicit, the rule that I'm using to draw this image on the left
28:30 is that for every point z in that plane on the left,
28:33 you look at the corresponding value e to the z on the right,
28:37 and then you assign it a matching color.
28:40 So for example, this warped pi creature and this one and this one
28:44 all really correspond to the same part of the image on the right,
28:48 the big pi creature in the lower left.
28:51 Another way to think about this is that because
28:53 the function e to the z is many to one,
28:56 the feeling we get is that the natural logarithm, its inverse,
28:59 wants to be a multi-valued function,
29:01 something where one input maps to multiple different outputs.
29:06 Now in practice, many times you don't want a function to have multiple outputs,
29:10 sometimes that even defies the definition of a function in your context,
29:14 so people will often just choose a band of this plane
29:16 on the left to be the outputs of the natural log.
29:20 In complex analysis, this is called choosing a branch cut for the function.
29:24 For our purposes though,
29:25 where we want to recreate and understand Escher's piece,
29:28 it's actually nice as to think of the log as a multi-valued function,
29:32 where each point on the right corresponds
29:34 to a repeating sequence of points on the left,
29:37 spaced out two pi vertically, going infinitely in both directions.
29:41 Now in our special case,
29:42 you also see this repeating pattern as you move to the left,
29:46 but that is something different entirely.
29:48 You would not see this for most images.
29:51 It arises specifically because we're working with a self-similar Droste image,
29:55 one that looks identical as you zoom in by a certain factor.
29:59 This falls straight out of a core property of logarithms and exponentials.
30:04 Exponentials turn addition into multiplication,
30:08 and logarithms turn multiplication back into addition.
30:12 For example, imagine taking some small value w on this plane on the right,
30:17 and also considering 16 times that value,
30:19 which is scaled up 16 times farther away from the origin.
30:24 Now if we look at the corresponding value, log of w on the left,
30:28 that act of multiplying by 16 now looks like addition,
30:32 specifically shifting to the right by the natural log of 16,
30:36 which is just some real number.
30:39 In fact, this rectangle here in our bizarre
30:41 warped log image that has a width of log 16 and a height of 2 pi contains
30:47 all the information about the image on the right.
30:50 It corresponds to this annulus of the Droste image,
30:54 and if you were to shift that rectangle exactly log of 16 units to the left,
30:58 you would get a scaled-down version of that annulus exactly
31:02 16 times smaller that nestles in perfectly like a puzzle piece.
31:07 And if you repeat that infinitely many times,
31:09 it gives you this infinite nesting that characterizes the Droste zoom.
31:14 The way I've drawn things so far,
31:16 we have this cutoff to the log image on the right side,
31:19 and at this point you know well that vertical
31:21 lines on the left correspond to circles on the right,
31:24 so you can probably guess that this corresponds to the fact
31:26 that I gave a maximum radius to that Droste image,
31:29 but of course you don't need to do that.
31:31 In principle, it can extend out infinitely far in all directions,
31:35 following the same self-similar pattern as you scale up,
31:38 and the result for the log image on the left
31:41 would be to extend as far rightward as you want,
31:44 again with a repeated tiling pattern.
31:47 So to conclude, the logarithm image on the left is periodic vertically,
31:51 basically because rotation on the right is periodic.
31:54 This would happen for any image.
31:56 And then in this special case of a Droste image,
32:00 it's also periodic horizontally,
32:01 because the Droste image repeats as you zoom in.
32:04 This doubly periodic property is what we'll
32:07 ultimately take advantage of for the final result.
32:10 And we now have all the foundation we need.
32:13 I can now finally describe for you the function
32:15 that turns the Droste zoom into this Escher-style self-contained loop.
32:20 Before just jumping right into it, we have been kind of covering a lot,
32:23 so it might be worth giving some space to let this digest.
32:26 And I was meaning to take 30 quick seconds
32:28 at some point in this video to talk about 3b1b talent,
32:30 so now might be as good a time as any.
32:32 This is the virtual career fair that I'm experimenting with this year,
32:36 and the basic idea is that you, a person who spends their free
32:39 time learning about things like complex logarithms,
32:42 are probably interested in working with like-minded,
32:44 curious, and technical teams.
32:46 So if you're seeking or open to a new job,
32:49 check out the organizations at 3b1b.co.
32:52 talent.
32:52 When you explore that page,
32:54 you'll find interviews between me and the relevant teams,
32:56 technical puzzles and challenges that they've chosen to feature for you,
32:59 and various other things aimed at giving
33:01 you a feel for the technical team culture.
33:04 And I just kind of like the idea
33:06 of exposing this audience to aligned career opportunities,
33:08 so whenever you are looking for a job,
33:10 whether that's now or later, be sure to check it out.
33:14 Okay, so back to our main goal.
33:16 How is it that we can use everything that we've
33:18 built up about complex functions and transformations that give
33:21 conformal maps and everything like that to construct some
33:24 kind of function that recreates Escher's print gallery effect?
33:28 Maybe it's easiest if I just throw down the whole outline of the function,
33:31 and then we can go through each step in more detail.
33:34 First, take a logarithm, giving this bizarre doubly periodic tiling pattern,
33:38 and then you rotate and scale that tiling pattern in just the right way,
33:43 and then from there you take an exponential,
33:46 which unworps it, but this time with a certain twist.
33:50 This might seem a little bizarre,
33:51 but there's actually a really nice way to motivate
33:53 and to understand what's really going on here.
33:56 Take a look back at that original Droste image,
33:59 and remember how we want to take this big pie creature
34:02 and somehow identify it with the smaller self-similar copy, 16 times zoomed in.
34:07 I want you to think about a line connecting both of those.
34:11 One way to frame the goal that we have is that we want the final
34:14 function to transform such a line into a closed loop in the final space.
34:19 The endpoints of the line on the top
34:21 represent the big and the small pie creatures,
34:24 so whatever function identifies those creatures should,
34:26 at the very least, close up this line.
34:29 Now think about what this line looks like in the logarithm of the image.
34:33 The big pie creature corresponds to all
34:35 these multiple copies here next to the imaginary line.
34:39 As we talked about, when you scale down the image,
34:42 it corresponds to shifting to the left in the log,
34:45 so these copies in the log image represent that small pie creature.
34:50 And actually, instead of using this horizontal line,
34:52 we're going to want to take advantage of the fact
34:55 that this log image is periodic in two separate directions.
34:58 So instead, what we'll work with is a diagonal line that connects this copy
35:03 of the big character to this lower left copy of the small one.
35:07 That might seem unmotivated at the moment, and it is,
35:10 but the best way to explain why is just to show you how this plays out,
35:13 and afterwards, if you want, we can contrast with what would have
35:16 happened if you tried using the horizontal line.
35:19 Now this new downward component in the log image corresponds
35:22 to adding some clockwise rotation to the path in the original image.
35:26 Remember, our goal is to turn this into a loop in the final image,
35:30 but you and I just spent like 10 minutes talking extensively about
35:34 a function that turns line segments into circles, namely e to the z.
35:39 What you need to do is get that line segment
35:42 to end up perfectly vertical with a height of 2 pi,
35:45 and doing this basically comes down to rotating and scaling it
35:48 in just the right way to give it that length and direction.
35:52 Now if you remember, as we were warming up with complex numbers,
35:56 we talked about how multiplication by a constant
35:58 gives you some combination of rotation and scaling,
36:01 and in this case, one artistic feature we might like is for our big
36:05 pi creature on the lower left to stay fixed in that position,
36:08 and that would mean that this point
36:10 in our log image needs to stay fixed in place,
36:12 so instead of pivoting around the origin,
36:14 we really want everything to pivot about that point.
36:18 Let's say we label that point something like z naught,
36:21 then here's how the updated formula would look for that rotation and scaling,
36:25 but really most of the content comes down to choosing this constant
36:28 c that you're going to multiply by, and if you like exercises,
36:32 you might enjoy actually taking a moment to work
36:34 out what specific value that constant should take on.
36:38 But right here, since we're being very visual and I want to have a little fun,
36:42 let me show you that constant in its own little complex plane,
36:45 and then also show what happens if I kind
36:47 of grab it and move it around a little bit.
36:50 Different choices give you different scaling and rotation,
36:53 which after exponentiating gives you
36:55 all these completely bizarre kaleidoscopic images.
36:58 One way you could think about the whole operation
37:00 is as a game where you're trying to find just
37:03 the right value that corresponds everything to line up as you
37:06 need them to in that image of the lower right.
37:09 When it is set to that appropriate
37:10 value and we get this recreated Escher effect,
37:12 in that final image on the lower right,
37:14 I've been showing this hole in the middle,
37:16 analogous to the hole that Escher had in his original piece.
37:20 But that's actually entirely artificial.
37:22 The output image of the function naturally fills
37:25 that in with its own repeating spiral inward.
37:28 After all, the rotated tiling pattern
37:30 on the left extends infinitely through the whole plane,
37:33 so when you take its exponential,
37:35 it also fills in everything, except for the point at zero.
37:39 And that's it!
37:40 That is the basic operation.
37:42 Translate to this bizarre looking log space,
37:45 rotate and scale to realign things, and then translate back with an exponential.
37:51 At this point, having recreated our own variation on Escher,
37:54 it might be nice to step through what
37:57 that same process looks like for Escher's specific example,
37:59 that seaside Maltese town containing a print gallery
38:02 with a person looking at a picture of the town.
38:06 As before, step number one is to place
38:08 this scene on its own little complex plane,
38:10 where the infinite limiting point about
38:12 which everything scales is positioned at zero.
38:16 Step two, take a logarithm of this, which in this case
38:19 gives us a similarly bizarre transformation of the whole scene,
38:22 but there is a little difference this time.
38:24 Because Escher was working with a much deeper zoom, with a scale factor of 256,
38:29 the repeating tiles in this new example actually
38:32 span a wider part of the complex plane.
38:36 Step three, again, is to rotate and scale this, which
38:39 depends on multiplying by the appropriate choice of a complex constant.
38:43 The constraint is to ensure that this rotated
38:46 image still repeats every 2 pi units vertically,
38:48 but along a part of the image that was previously diagonal.
38:53 And then step four, plug this all through e to the z,
38:56 and what you get is something very similar to Escher's final picture,
39:00 an image where walking around a loop corresponds
39:03 to zooming in by a factor of 256.
39:07 And again, when we frame it this way with complex functions,
39:10 there is no hole in the middle.
39:12 That final result is itself a Droste image, albeit this time with a twist,
39:16 where there's a kind of self-similarity spiraling down infinitely
39:19 far as much as you want to zoom in.
39:24 There are a couple things worth noticing about this whole process.
39:27 First off, if you write this idea down as a formula,
39:29 where you take a log, multiply it by a constant, and then exponentiate,
39:33 that can actually be simplified to simply look like
39:36 raising your input to the power of some complex constant.
39:39 And if you reintroduce that offset factor, it just introduces another constant.
39:43 On the one hand, it's very pleasing that this entire complicated
39:46 process can be boiled down to so few symbols on the page,
39:49 but I do think this risks kind of obscuring what's actually going on.
39:53 And then, I had mentioned things would not
39:55 work if you only tried using those horizontal lines.
39:58 If you're curious, here's what it looks like if you try that, which
40:01 would mean rotating everything by 90
40:02 degrees and scaling it the appropriate amount.
40:05 You do get something kind of interesting,
40:06 but it's just not what we're going for.
40:09 And if you think about it, what's basically going on is that you are
40:12 swapping the roles of rotation and of scaling.
40:16 Stepping back from all this, this second perspective where
40:19 the piece is all about rotating in a log
40:22 space feels completely different from Escher's more intuitive
40:25 approach using his distorted grid and the mesh warp.
40:28 But there is a through line connecting both perspectives.
40:31 For one thing, you can now understand how exactly
40:34 we've been recreating and modifying the grid that Escher had.
40:37 You basically take that same function that we've built up,
40:40 but instead of applying it to an image, you apply it to an ordinary square grid.
40:45 Well, actually not quite an ordinary square grid.
40:48 It's nicest to work with one that gets more dense as you
40:50 zoom in so that it looks the same at all scales.
40:54 When you do this, the logarithm gives
40:56 you this very beautiful curved tiling pattern.
40:58 And then from there,
40:59 you do the same trick of rotating things in just the right way and then taking
41:03 an exponential with the result of something quite
41:06 close to what Escher spent many arduous hours constructing.
41:09 And remember, the entire reason that we're using
41:12 the language of complex numbers is the motivation
41:14 for me having you jump through those hoops is
41:17 that this conformal property falls out as a byproduct.
41:20 Tiny squares from the original grid remain,
41:22 at least approximately, square in the final result.
41:26 Escher said that making this piece gave him some almighty headaches,
41:29 and though maybe you and I had to endure
41:31 a few headaches ourselves for very different reasons,
41:33 the payoff is that this property is one that we get with no added effort.
41:39 Now to be clear, you certainly don't need
41:41 to understand complex derivatives or logarithms to enjoy Escher's work,
41:44 and I wouldn't want to imply that you do.
41:46 However, when you understand that more mathematical side,
41:49 it gives you the capacity for a very different
41:52 kind of appreciation for what Escher was really doing.
41:55 And this is what I find fascinating about all
41:57 of this, the real connection I want to give between the two storylines.
42:01 If you look at Escher's career, throughout it he was drawn to certain concepts,
42:05 things like representing infinity in a finite space.
42:08 And at the same time, he seemed to be guided by a certain aesthetic,
42:11 often some implicit rigid rule like the idea
42:14 of little squares remaining little squares for this mesh.
42:17 The end result when concept and aesthetic are combined like this is
42:21 that a given piece from Escher often feels like a solution to a puzzle,
42:25 but one where it's not even obvious that a solution should exist.
42:29 Now what I find so thought-provoking is that these visual puzzles that he
42:33 landed on are not merely analogous to the act of doing math.
42:36 The specific structures that he was intuitively drawn to often
42:40 hide within them very real and very deep mathematics.
42:44 In our example, the deeper structure is not just
42:46 that the piece can be described with complex functions.
42:50 The ideas that we've touched on in this storyline are actually
42:53 a lot closer than you might expect to the research frontiers.
42:56 If you look back at our approach in the second half,
42:59 remember how it relied on using
43:01 this doubly periodic pattern in the complex plane,
43:04 something that repeats in two separate directions.
43:07 There's actually a special name for functions
43:09 of complex numbers that are doubly periodic like this.
43:12 They're known as elliptic functions.
43:14 It would be way too much to explain
43:17 right here exactly why these functions are so useful,
43:19 but one thing I want to highlight is
43:21 that those two mathematicians I referenced at the start,
43:24 the ones who provided the analysis of this piece,
43:26 De Smit and Lenstra, are both number theorists,
43:28 and elliptic functions play a very prominent role in modern number theory,
43:32 providing a kind of bridge to other parts of mathematics.
43:36 This may at least partially explain how it is that they could look
43:39 at this piece and think to construct that function that we laid out here.
43:44 When I look at Escher's work,
43:46 whether it's the print gallery or many other favorites,
43:48 the reason I love these pieces so much is that they
43:51 awaken within me a very specific feeling that's hard to find elsewhere.
43:55 It's a feeling of things perfectly fitting into place.
43:58 But that's not exactly it.
43:59 It's something more than just the pleasure of seeing a puzzle solved.
44:02 It's an appreciation for the creative genius required
44:05 to even dream up the puzzle in the first place.
44:08 The only other place where I get that feeling is in doing math.
44:11 So the fact that an artist and a mathematician
44:14 can be drawn to the same structures, but for completely different reasons,
44:18 suggests to me that there's something universal in what exactly
44:21 it is that both of them seem to be drawn to.