Back to Index

fast.ai APL study session 2


Chapters

0:0
8:27 How Did You Get the Apl Keyboard on Top of Jupiter Notebook
18:51 Complex Numbers
19:26 Complex Number Plane
24:16 The Unit Circle
29:40 Trigonometry
37:11 Basic Math Operators
56:16 Euler's Identity

Transcript

tell me on the topic of learning new things you mentioned today that your colleagues are peeved when you spent half of half of the time learning new things uh-huh how did you how did you stand your ground I don't know just buddy-minded I don't know was it because you're so productive that didn't matter no no I mean it matters I mean most of that time I was either the manager of a management consulting team or I was CEO of a company or whatever so like I mean my first two startups I wasn't exactly CEO nobody had titles I had co-founders but yeah in the end it's like this is how I do things you know so but I'm not gonna say it didn't create friction I mean I don't know what do you think Hamill like you work with me and you see how I jump onto totally different things when we're meant to be focused on something like um I actually don't see you I don't see you getting distracted that much at least for me like we're talking about apl right now when we're meant to actually be focused on releasing nb dev and I'm going to be doing the course you know it's like okay no yeah okay okay yeah like um in in hindsight it looks like it was all part of a like a genius plan how like while you're doing it it's like why are we doing this that's how I feel sometimes but then it's kind of like that thing we did with rich I don't know if you remember that with a with the GH top with with your old CEO we yeah yeah yeah this thing using rich yeah like we spent so much time doing that and while we're doing it I was like why are we you know at some point I was like I don't know if this is worth it or you know but then like you know Will mentioned that he started his company based upon this that project and I thought wow that that's a really big impact it's so like lies yeah yeah so then I just kind of learned over time that it actually you can pivot these things into something productive usually yeah so this this company textualized on ao well who created it said came out of ammo and I refactoring there we go still the most recent one so nobody's touched it since this rather megapia which yet basically talk rich and made it do things that we all hadn't exactly expected it to do this is quite funny because I think yesterday or two days ago I went to this website textualized that I owe and I was thinking hmm what does this do like how are they planning on sending it or what's the plan I mean that the website is beautifully designed so I thought that there must be some business entity behind it and yeah that's yeah so it's basically you know one guy although I think he might have he's got some funding so I think he's hired somebody to help now who loves building CLIs and so what Hamill and I showed with our GH top thing was that actually you can like use another tool he's created called rich to kind of get a long way towards building terminal user interfaces and yeah this is something it's come full circle now now that somebody's using textualized to build a notebook in the terminal that's true which is great alright so since I'm on the Mac today let me just check something if I switch to a different virtual screen you guys can now see my terminal is that correct yep okay great yeah so since I'm on the Mac I just downloaded that Jupyter kernel and I unzipped it in the ran install.sh and it looks like I now have a dialogue APL thing here so one thing that's happened since yesterday is we now have a GitHub repo which let's have a look APL study there you go so I don't have that over here so let's grab it so I'll go copy yeah so we've got a fast AI / APL - study and really all this in it at the moment is my notebook and so I should be able to now get clone that there we go and so I should now be able to open that good and very I should be going to run it right okay oh and then the other thing we did was we installed that toolbar widget thingy oh which I've actually already got here so that's good so I guess I have to go bookmarks shift Apple B okay APL great so let's see if I can type back tick - yep that works okay so I'm back up to where we were on the different computer so let's do times and divide shall we and I guess I should also run dialogue and we should also get up our help which was called dialogue language comments cool all right let's do times so at first it feels a bit weird that times and divide are actually on - and equals but then you realize that like plus minus times and divide are all kind of next to each other on the keyboard so it's not quite that weird I seem to have got used to it pretty quickly so we can do two times three and so that makes sense how did you get the APL keyboard on top of chapter notebook it's it's if you go to the forum oh I think did we discuss it yesterday I don't quite remember maybe we do it yeah but I just didn't know where to take it from yeah okay so specifically the steps are you area is the bookmarklet so you click here and then you as it says you drag this to your bookmarks bar is this link and then you go to the Jupiter webpage and you click that link in your bookmarks bar and it will appear okay and this thing is called not surprisingly time sign and the two forms of it okay direction and multiply obviously called times okay so obviously we can multiply a scalar by a scalar we can multiply a scalar by a list and we can multiply a list by a list and remember just because there's no space here doesn't mean this is one times two this is this list times this list so space binds more tightly that makes sense so far yep okay now monadic times is taking us into complex weld again which is fun let's see what it says direction so again we look over to the top right get it says our is the result of doing times on y y is any numeric array okay when an element of y is real the corresponding element of the result is an integer whose value indicates whether the value is negative 0 or positive so this is what we'd normally call the sine function and most languages and often in math it's called that as well and so just to check here 3.1 is positive so that returns 1 negative 2 is negative so that returns negative 1 and 0 is neither so that returns 0 okay so those ones okay so this is showing us the sign which they call direction complex numbers the corresponding element is a number with the same phase but with magnitude of 1 it's equivalent to this so let's find out what this does I think that'll give you the absolute value yeah magnitude they call it the absolute value so direction is what does that mean for complex they're going to give either I or negative I I guess we should try it is that just a regular bar see it is okay so it's actually something a bit more interesting I think this is gonna yeah I mean if you visualize it as a vector right it's just gonna normalize the vector to magnitude 1 yes that's gonna require some drawing I think I just want to get up the documentation to see how to describe it magnitude of a complex number okay great so we're going to do some more complex number stuff which is cool I have a quick question yeah I think so far the gloves for monadic and dyadic are the same for all the gloves that we've looked at except for Nick and minus sign which uses a different one do you know why that is no that they're always the same always the same yeah I think what you might be getting confused about is the difference between the thing that lets you specify a negative number which is that versus the function which takes the negative of an array which is that oh that's not a function this binds more tightly than a function this is actually this is more like the dot here is not a function right it's part of the literal number 2.3 is it the same as the negative is not part of it's not a function it's part of the number negative 2.3 okay thanks no worries so if I do this this is not saying apply the negative function to these four things it's saying this is a list containing this negative number and this and this and this positive number so if I wanted to negate those four things I would have to do this yeah so hyphen is a function and this upper bar thing is just part of a number not a function just like dot is part of a number just like J is part of a number Jeremy so this JavaScript keyboard it gives when you hover over a symbol it gives these key bindings that work with a regular keyboard not a PL keyboard but it would be preferred to use the APL keyboard right no not at all they're the same this the difference is an APL keyboard has pictures of those letters on them but they produce the same things you still have to have the same software whatever so the only reason to have an APL physical keyboard is so that you can look at the keyboard and see them you know I got it I was thinking about the APL keyboard in Windows oh in Windows okay these things the JavaScript applet thing here it gives you other key bindings that work with the regular keyboard like you know like XX tab is for multiplication yeah oh okay so don't I suggest not using those instead use at the very bottom it says back tick - use that one because those are identical to the Windows keyboard so you just use back tick followed by the same letter you would use in the Windows keyboard and so here this one is back tick equals yeah I would ignore those tab ones okay but this also works with just a regular Windows keyboard should I be using the APL keyboard like yeah you can use the Windows APL keyboard if you want I so I'm not using that right now because I am not on Windows but be even on Windows I actually prefer not to use it because it takes away my control key and I like my control key yes so the back tick notation the one of them on the bottom here will be the the preferred one it's what I'm liking so far but obviously I'm very new to this so I don't take my word for it but yeah I like the back tick approach because it continues that as well that's because copy and paste and everything in the usual way yeah okay let's talk about complex numbers some more shall we so yeah this is one of those things I didn't really get into much University I mean I wish somebody told me how cool they are okay so the thing I guess we talked about yesterday is how we can create this like complex number plane right and so along this axis you've got the real number line and then along this axis you've got the imaginary number line okay so you can put numbers there for example here's the number 2 and here's the number minus 3i but you could also create the number here 2 plus 2i okay so that's the complex number 2 plus 2i okay there and you can think of that as a vector right it goes from the origin and it goes up to there there's another way of thinking of 2 plus 2i and that vector has a length and we can calculate its length because it is we have here a right angle triangle oh we have a right angle triangle and its height is 2 and its base is 2 so it's length here we can get from the Pythagorean theorem that makes sense so far so that is the magnitude of this complex number so the magnitude of real numbers is easy right because like what's the magnitude of this number here well it's how far away is it from the origin and the answer is 3 you know what's the magnitude of this number here well that's easy it's 1 right this one's also easy 3i what's its magnitude what's distance from the origin is also 3 right but yeah the ones where you've got a mixture of imaginary and real you have to use the Pythagorean theorem to find out their magnitude a single number which is like how big is it and if we take a number so this number the number we were dealing with here was 2 plus 2i which APL writes like this it's the same thing and they have this thing called direction which is basically saying take a number for example like 3 and 3 the direction of 3 is plus 1 and the direction of negative 3 is negative 1 and basically what we're doing is we're taking the number 3 and dividing it by its magnitude and that's another way of thinking about this sine function okay so like what what do you do in for a complex number well you take the number and divide it by its magnitude to do the same thing and so that's going to give you something that is going to be you know around about here so it's going to be pointing it's going to be pointing in the same direction no excuse me it's going to be pointing in the same direction but it's going to be shorter and specifically we can draw this really important thing which is called the unit circle and the unit circle is something that has a radius of 1 right and it's centered on the origin and so the direction any time we get the direction of a real we're going to get something that points in the same direction as the original number but is actually sits on the unit circle it's like will be one does that make sense so we could try it right so so what's the square root of 8 so we could do 8 to the power of negative 2 that's not right sorry you need to be one half rather okay and so we thought if we took 2j2 and divide that by 8 the power half we get that and if we get the direction times of 2j2 array it's the same so and rather than writing 8 times 5 what I could have written here is magnitude of 2j2 because that's what magnitude means okay so does that make sense what it's doing you'll notice that like although complex numbers are about this by the square root of minus 1 we don't think about that at all right when we're doing this complex number stuff we we just treat it as a pair of numbers which therefore can represent a point in Cartesian space and therefore that can represent a vector and is that 0.7 radians like what is that value no this is a this is a complex number 0.7 j 0.7 so it's 0.7 plus 0.7 i because remember 2 plus 2i is written as 2j2 in in APL so this is 0.7 plus 0.7 i so it's a complex number and so it's this it's this point here it's the complex number that has the same direction as 2j2 but has a magnitude of 1 and therefore it sits on the unit circle and like we really like to do things on the unit circle because on the unit circle if we kind of draw that out a little bit more if we stick to things that are on the unit circle so here's 1 1 1 - 1 - 1 so these points are nice because you can pick any one of those points like here right and if you create that triangle then this hypotenuse here the length of it is one which is really convenient right because if you're doing like trigonometry or something right you've got like sine theta circuit OA equals opposite over hypotenuse well that's always one on the unit circle so we can we can delete that part entirely instead we get sine theta equals opposite you know so it's it's it's nice to deal with stuff it's on the unit circle things become more convenient we can ignore the whole magnitude slash hypotenuse piece entirely trigonometry coming back huh probably a lot of us haven't seen it since high school all right so what do we say about monadic times we haven't introduced magnitude yet so let's put that away down here for later and for now I guess we'll just say that the magnitude of 3j4 is equal to I guess we don't have a way of even doing a square root so we'll just have to kind of do it with prose so the magnitude of 3j4 is equal to the square root of 3 squared plus 4 squared so that's 9 plus 16 oh yeah of course 3 4 5 is a Pythagorean triple so it's basically going to be we're going to be dividing by 5 yeah so so basically three 3j4 means 3 plus 4i which has a magnitude of 25 because it has a magnitude of 5 because 3 times I guess we should use this 3 times 3 plus 4 times 4 equals 5 times 5 so 0.6 j 0.8 represents a vector in the same direction as as 3j4 3j4 but is a magnitude of 5 since it's 3j4 divided by 5 okay how's that so that's dyadic times now that does mean that we just use divide and I don't want to use anything until we've introduced it so probably do divide first and divide I think is actually a bit of an easier one okay so divide which is on the equals sign on the APL keyboard but yeah okay so that's quite divide sign divide sign the magnetic version called reciprocal reciprocal reciprocal reciprocal today spell that right no reciprocal recall and the dyadic version is called divided by divided by okay and I guess what we could do is grab all of those and paste them in here and I wonder if this works can we go find times and replace with divide oh lovely there we go okay so divided by is easy does anybody here not know what reciprocal does maybe we don't oh we can't do zero okay let's change system and as a side note I found the reciprocal to be kind of handy when I'm doing any square roots or cube roots or anything like that because then you can do rather than doing 0.5 power you can do 16 to the reciprocal to the power of three reciprocal reach for example yes or cube root you could do the cube root of 8 like so yeah exactly I don't think we need the parentheses because first it does it one at a time right so it's going to do divide so this is going to be the first thing it does is divide 3 this is reciprocal of 3 and then it's going to be time power of on the left will be 8 and on the right will be reciprocal 3 which is cool so it's like function composition yes it it is which is actually a great time to talk about the hat because we've now got our four basic operators from math and so we should now talk about precedence and I think I want to change my headings a little bit back on a rain going to create a section called basic math operators oops right what have I got here I've got plus sign twice I do something weird I had it - monadic - plus sign monadic plus okay this dyadic plus by attic dyadic times monadic dyadic okay precedence so here is the formula 3 times 2 plus 1 okay so in regular math we would go 3 times 2 first get 6 and then we'd add 1 and get 7 and there's a couple of reasons we do that the first is that times is a higher precedence than plus and even if it wasn't we go left to right so is this 7 no it's not and that's because APL makes things much simpler for us by having no concept of precedence of different functions they all have the same precedence and the rule is we always go right to left not left to right so this is the same as this and that's good because you wouldn't want to remember precedence rules for all what are these like 50 or 60 or whatever glyphs right so they all have the same precedence that doesn't mean all symbols have the same precedence we've learned of a few symbols that have different precedence so for example space right 3 plus 4 space 2 space between numbers binds more tightly because this would be better to explain like this this binds more tightly so this is the list 3 5 added to 4 or the array 3 5 added to 4 which is the same as that so when I say we're doing things right to left I'm only talking about functions right and remember that upper bar thing is not a function right that's part of the number and this space here is not a function that's part of this array so functions specifically you can tell something's a function because you look it up in the help and I'll tell you it's a function okay we can see here it's listed under the section called primitive functions okay so we can tell that this is a function because in the functions part of the help most of the things up here are going to be functions as we'll learn shortly some of them are operators and the rules are different for operators but most of these of everything we've seen so far in terms of times divide plus and minus are all functions so that's the rule we go right to left so in this version here right we go right to left so okay we've got the number three now we've got three divide okay well that means the reciprocal of three and then we keep going left we come across this time this power of and it has a right-hand side and it has a left-hand side and that's why this is eight to the power of a third so it makes sense so we could do that with a list and so remember the symbol space finds the most tightly so this is the list one two three multiplied by two plus one because we go right to left so we go one plus two times this list that'll be three times that list and we could also do this so this will be this list to this array two four six plus two they're all that in brackets and then multiplied by the array one two three so two plus two is four two plus four is six two plus six is eight eight times three is twenty four six times two is twelve four times one is four that makes sense yes so I'm not sure if that's related but that function for giving us the magnitude direction it was I think that would offer an array it still works on each component it it doesn't normalize the whole array right right basically pretty much all the functions in their normal forms work element wise like numpy does including power and reciprocal and magnitude and so forth it's a good point uh did you go over the power of symbol I don't know okay I thought we might do that now I think that kind of counts as a basic math operator kind of so yeah so let's do okay so this is confusing this is shift 8 the normal multiply sign from Python doesn't mean multiply it means exponential or power so and it's called star you you you you you you you you you you you you you you you okay and dyadic power so exponential means e to the power of so this is e to the power of 0 is 1 e to the power of 1 is 2.718 and e to the power of 2 apparently is 7.389 does anybody not know what e is or want a refresher what e is a refresher would be great sure refreshers are always great sure the only reason I can do all these refreshers off top of my head is because I've done all this stuff with my you know my daughter and her friend recently so I can I can do math refreshers like this I'm ready about a month ago I couldn't because I'd forgotten everything so a the basic idea is like if you put $100 in the bank right at a hundred percent interest then after one year you'll get $200 and specifically that's your original hundred plus sorry I should say times one plus the interest and a hundred percent is a hundred over a hundred so it's one but the bank might not give you the whole you don't might not calculate the whole thing at the end of the year if they want to be a bit more generous they could calculate it twice they could calculate it once at six months and and again after another six months so you take your hundred dollars and after six months they would give you half of your interest so that's 50% so after six months you would have 150 and then at another six months they'll give you the other 50% but the other 50% is now going to be calculated on this right so this is times 1.5 and then again times 1.5 to 25 which is 100 times 1 plus 0.5 squared if they're really generous they could pay it quarterly and if they paid it quarterly then the amount of money you're going to make is a hundred times one plus actually let's do this as a fraction rather than as a decimal a quarter therefore or they could pay it daily 100 times 1 plus 1 over 365 to the 365 okay so we should be able to calculate these things in APL right no promises we could give it a go now let's do this 100 plus 100 times 1 plus a quarter to the 4 100 times 1 plus a quarter now a quarter is that it's a reciprocal of 4 1 plus a quarter okay to the power of is this and so this is going to happen first because we go right to left I should say you don't have a hundred dollars in the bank let's say you've got one dollar in the bank okay so in that case your one dollar would become two dollars if it was paid just at the end of the year or it become two dollars and twenty-five cents if it was played every six months or it become two dollars and forty-four cents if it was paid every quarter or we could do 365 5 it was paid every day it would be this number and you can see the more often it's paid the more money you're going to get right but like and this you know initially this went up pretty quickly but now it's going up pretty slowly so let's say it was paid hourly that's paid a hundred times per day and it's not really making much difference at this point a is the limit of this as this number gets really really really high so we could write that in math then we can say e is the limit as whatever X goes to infinity so as X gets really big that never hits infinity of okay and the one times we can just ignore right so it's a limit of 1 plus 1 divided by X to the power of X that makes sense that's a how's that radic I just remembered the definition of limit well it's something I have not seen in ages yeah I kind of say the kids loved seeing limit you know and of course they're immediately like well just get rid of it and put infinity there okay let's put infinity there one plus one divided by infinity okay kids what's one divided by infinity zero okay what's one plus zero one what's one to the power of infinity one okay so does he equal one no say okay well what do we do they're like well what about infinity minus one that's still infinity so this is our first introduction to limits and they they were just like they were partly like wow that's so cool and they were partly like never show me anything like this again this is wrong yeah it shouldn't happen get it out of my life but this is beautiful because like they're trying to make it concrete and somehow relates to these ideas that's amazing and they will understand it at a much deeper level than people you know just you know going through this reading theorems in in a classroom and yeah that there's something deeply disturbing about limit yeah and I guess like like the takeaway is that this is just something that people agree to right this is well I mean it's a it's it's I think it's more than just something people agree to like it's it's it's some kind of reality you know like it's it's a true it's a true thing that there exists independently about discovery of it right but how do you make the jump from something getting closer to something being that value that it gets closer to this is a definition this is like yeah I don't know anyway I mean I think it's really cool yeah all right so that is that is monadic monadic star and he is named after oiler I think oiler as more specifically oiler named it after himself famous blind Swiss mathematician but oiler did not discover a I don't know who did but it won't it wasn't him even though he got to name it somehow for those of you that remember calculus you know you can take the derivative of various functions for example we saw in the fast AI class that the derivative of x squared is 2x one of the things that's interesting about a is that the derivative of e to the x is e to the x it has a lot of crazy things going on with a and comes up a lot the maybe the most cool beautiful formula in the world is oilers identity which brings together a lot of the things we've seen so far and it's e to the i pi plus 1 equals 0 put another way e to the i pi equals negative 1 which is like total madness that this thing which is about circles and this thing which is about imaginary numbers and this thing which is about compound interest somehow combined to create negative one but that's mind blowing and so that's what that's why monadic star is e to the power of e to the power of is a pretty important thing and so we don't need a special symbol for a right because anytime you want a you just write this all right and then okay dyadic star is power of so 49 to the power of a half is square root of 49 5 to the power of 2 is 5 squared minus 4 square root is 2i because it's equal to minus 1 times 4 so you get the square root of minus 1 which is i times the square root of 4 which is 2 2i all right is that place to see yeah I think this is the first time e to the i pi has actually made sense to me because I did make the connection that pi is essentially like I think like a half like a half circle and radians or something yeah and so I is just that other you know I guess like the y on the plane yes all you're doing is you're just curving that around to the other side to turn it to a negative one add one on for that and I got zero yes exactly and maybe Wayne you can try to find like a really good video or something that explains that for people that have never seen that before because I think that'd be a great thing to put in there oh yeah I think there's a channel three blue one Brown may have some stuff if I see anything I'll put it up yeah ideally something that doesn't use any concepts that we haven't come across yet you know mm-hmm I keep my eye open for that yeah I mean the key thing around complex numbers to me I think is this idea that if you multiply it by negative one you flip something from one side of the you flip something from one side of the number line to the other on the real plane ditto if you multiply by negative one for a complex for a imaginary number it flips it to the other side of the number line but if you multiply something by I it rotates it by 90 degrees you go from two to two I to negative two to negative two I back to and so yeah I think a lot of these ideas end up basically being these kind of rotations around this number plane yeah you see stuff like that all over in engineering I think for me when I made the connection that if you look at the eye as kind of a shorthand for having an array of two numbers like basically just coordinates on a plane and that's just a way to kind of have that mapping to your number line all of a sudden everything else starts to fall into place and then when you're talking about magnitudes and stuff like oh wait I've seen this before as like you know magnitudes in I mean weird is it like the L2 norm or something like that it's like even if we're just having like the magnitude of like absolutely effective is the exact same thing it's likely it is well I seem put this in the chat what's this about was him can you tell us oh so it looks like the Jupiter kernel has a way of rendering I'm not to call it like function composition so if I type this into Jupiter yeah like that mm-hmm and what am I missing around this all do you mean the the parenthesis execute just that okay it gives us the expression tree that's beautiful okay we will come back to learning about that about that later but yeah you can basically put a bunch of functions in a row and it does interesting things if you get rid of the parenthesis they favor goodness me all right thanks gang enjoy the rest of your day thank you very much everybody thank you thank you bye yeah