Back to Index

Fast.ai APL study session 16


Chapters

0:0
28:52 Euler's Identity
59:41 Matrix Division
62:38 Lydia Algebra

Transcript

where are you joining us from oh i'm here from uh Iran there right great yeah 4 30 in the morning oh wow well that's very impressive but it's good yeah really good thanks for joining thank you for the session uh codes codes uh uh 67 mines from from capital yeah well look at that only three of us lots of people watching the vietro videos but not so many people joining us live i guess it's uh hard to maintain the consistency well thank you first for joining um that's uh is there anything you wanted to talk about or should we keep going oh uh yeah ask me uh both of you ah okay i think you were about to finish the glyph yeah i think you finished the let's go have a look and then share my screen um so i guess we're doing this one will we the rest were we in the middle of something let's see i guess not yeah is this different to upshoe is this like a bigger version of it or something oh it's up shoes that is up shoe yeah we've already done that right i think so yeah yeah i think so i'm just going to type help just in case it's some weird different version of it oh what has happened that's strange huh okay never mind um and have we definitely not done iota andaba i guess if we did it would have been probably here um okay dialogue language elements and try and remember what iota andaba does where interval index let's put it next to iota as well okay so i'm going to guess that it is shift i correct aota andaba okay all right we've already got row at this point so that's good so bmat is two by three all right so um iota andaba i guess pretty clearly is showing us the locations of the binary trues and more than that it is replicating them the number of times according to what the number is doesn't work on negative numbers doesn't work on floats okay seems easy enough and then for matrices it's telling us the coordinates of each of the binary trues it would be easier if this was printed out row one column two two one two three cool so anything else i should add or anything so it makes sense what's this one uh so we won't put it in our notebook but i'm sure we try to figure out if we can figure out what this is iota row omega oh okay so just the index of that oh why is x here hi isak i see so iota iota row of omega is the indices that were with yeah correspond to that to that array and okay so um that's our input that's a function that's a function function operator function okay so that's a function that's a function that's a function so this is a fork with three functions does that sound right i'm right hooray so we go row of this and then we go slash over comma now there's no reason to use over right because it's monadic so we could just use jot and get the same thing yes um so first so is this the column is not necessary is it uh it's not i guess this is in case it's like a scalar or something okay and then can anyone remember what slash does set the replicate i guess that's the monadic right uh over do monadic slash is not defined oh so wait uh wait how is this working because monadic slash is not defined that's a syntax error oh no no no it's dyadic because there's a omega here okay so it's dyadic okay we've got a okay we've got a fork slash iota row and a dyadic fork applies the outside functions to both outside arguments here yep so this is a dyadic fork and it applies the outside functions to both outside arguments so are they just recreating the monadic iota underbar um let's see so this is going to be oh i see i think you're right um so the reason this works is that slash means replicate and the left hand side tells me how many things times to replicate the right hand side omega slash omega okay so there's a mega slash omega so that's doing the replicate and then you've got row of omega as we discussed okay and then dyadic iota dyadic index of so wait what did i do wrong oh um it's uh it's this row is applied to the left down the right so it's a mega row omega yeah is that right no so i can put parentheses here right no okay so i'm pausing it wrong oh i'm pausing it wrong because of the omegas this is not in parentheses it's not a fork so i'm totally wrong um so we actually have to be careful about precedence here without parentheses it's going to be there's actually no operators in this version so we uh bind most tightly on the on the right so this is actually simply going to be row of omega which is four and then iota which is one two three four so it's just going to be that which does give us the answer okay got to be careful of precedence okay and i guess you could do that tacitly by doing jot and then what Adam calls selfie oh look at that awesome yay okay that was a bit of a digression i think we'll line in the docs to say this is how you can define iota underbar we've made that a bit faster but i guess it'd be less fun okay yeah biotic iota underbar okay thank you for your fast cable stuff by the way is that okay it was something i wanted for myself i think a lot of people are going to find it really useful yeah i hope so i'm i'm right now trying to fight with github actions and trying to get it scheduled run update if any of the libraries are if any of the libraries are great idea not the latest it'll just update them and then i can have a big repository that people can just point to so you don't have to upload their own unless they want to now this one i remember doing with claire it's a bit of an odd one so okay okay oh where we are okay so hey iou oh there's two things here what's it doing okay so the number of results is the same as the number on the right hand side let's start with a numeric one because i think i know this one so what the two four six does is it creates a number of groups the first group it creates is less than two and then two to less than four and then four to less than six and then greater than or equal to six and so less than two will become zero two to less than four will become one four two less than six will become two greater than or equal to six will become three so that's why one is less than two so it becomes zero two is two less than four so it becomes one and so forth so just tell to these to find break points and then it just applies these to those break points and gives you the results but be very careful because it's a bit weird that it starts at zero instead of one which when i asked about this on the APL discord Marshall Lockburn told me he considers this an off by one error in APL although somebody else pointed out it does have some convenient properties so you can think of it as like the group number one is the bit defined by when you actually get greater than or equal to two so zero is like less than the minimum value does that make sense okay so this is exactly the same thing that for letters these letters are in alphabetical order so d is between a and e so it's one y is later than u so it's five that's it gotcha okay rank two arrays i don't know so interval index works with major cells okay so this is one of these ones with broadcasting built-in wait is that higher rank left document and it compares subarrays in y which is the right argument with the major cells of x so i'm not quite following uh what are subarrays of this i guess three three is a subarray so it's not broadcasting length just three or three three three would give errors right but what if we did uh two rows two columns of three three three five yeah so it's this is subarray one i guess this is subarray two so this is the same as as this result concatenated with this result how does it decide that three three is one i guess it's looking through here to find like a row that contains what exactly would zero three give you the same result no i think it's like it's trying to it's basically like looking for the first okay i think the issue is um it's it's it's comparing column one and then column two and column two would only matter if there was a tie so i think if we went um okay one two three four three five so three three is not bigger than three four three four is but then three five is higher still and then four five is off the end oh greater than or equal to is always going to be there yeah so it's saying uh what row which would this slot into by first of all making sure that it's greater than or equal to the first column and greater than or equal to the second column so this one would have to go here because the second is not greater than or equal to but if either of them are greater than the second then it would slot them after right yeah which i think is i think it's exactly the same as doing 12 34 35 all right that's basically the same thing right same results okay okay oh yeah and if you want to learn more about this they've got quite extensive examples which i suspect means that this is fairly important i guess in you know anytime you're trying to place a continuous number into a bunch of buckets you would use this kind of approach like plotting groups or something like that that okay histograms molly you're very quiet i can't quite hear you probably oh uh yeah my mic was long ways away uh histograms yeah yeah circle okay i wonder if circle should go in the basic math section because that's circle functions i kind of mentioned we're going to need other stuff much a bit of a big topic i guess circle functions uh circle here it is uh right circle how do we write circle hey yeah just remembered i've actually installed the apl keyboard i don't need this thing anymore oh i guess it's useful to see what button to press anyway okay so it's oh so i can just press alt o oh maybe i need to do this auto there we go cool auto which i guess is just called circle yep circle or monadic circle i times so i guess that means we could just go one at circle one and can we do like that yeah okay seems easy enough okay nothing weird oh fun uh or illness identity so i pi i a to the pi i yeah i lose identity although at this point we haven't done any kind of trainee thing so maybe we should do that in two steps uh pi i equals pi i oops what did i do wrong oh it's not exact is that what it's saying something weird going on here it doesn't sound weird so this is pi i this is pi i and then this is e to the power of that yeah that's definitely pi i pi that's strange oh i see it's minus one plus 10 to the negative 16 i which is basically zero so i think what's happened is um i guess is that uh this is special case or something in APL dialogue APL to remove the annoying floating point residue leftover bit here basically this is close enough to zero i for some reason when we do it all in one go it's gets it exactly right all right well maybe we won't show that then okay diatic circle function yeah there isn't really a short way to do this so i'm inclined to just provide a link to this one right here so i'm going to just give you a quick example of what we're going to do.

you you you you you you you um but basically the idea is you put something on the left and whatever you put on the left to find what function you get you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you and cause is two you you you and presumably we can do both yep and can we do it to multiple things what does that do what does that do what does that do what does that do what does that do what does that do what does that do what does that do what does that do what does that do what does that do and not quite clear on what happens when and not quite clear on what happens when is an array oh I guess it's but well no okay that makes sense so if we do pi hi hi okay so that's basically zero zero or maybe point five okay okay so then what happens if we what does that do because you kind of I was expecting four results I was expecting sine and cos because if we do sine and cos of zero or sine and cos of half pi so why do you so what do the two numbers mean yeah I I think you're applying each function to each of the er sorry each straight function to each of the ones and the right side I need a better vocabulary you think it's broadcasting over the scalars yes yeah I think uh oh right that's exactly what happens by default in APL right is a scalar broadcasts over an array but if they're both arrays then they just broadcast to each other yes yes yes you're exactly right okay great okay fine okay element of we should put with our kind of set related stuff which I guess is where up and down she were okay oh epsilon one of the epsilon means enlist because ml for us is one I remember and it's just called epsilon yes epsilon my attic epsilon enlist and dyadic epsilon is member of okay okay see what's going on here matrix is two by three row iota six so what it's doing is it's got zero that's got a matrix from one to six that's got a array with seven and eight that's got a scalar nine and it just uh flattens them and sticks them all together flatten and concatenate I wonder if that does that for more axes yes it does seems easy enough uh okay so this is interesting um yeah so this is two by three but this is a single this is oh sorry and then this is ranks this is a shape three so I guess this is um doing the broadcasting thing kind of it's applying it to each row all the elements in rebel order so this flattens up to the rays um well yeah I guess so yeah it is uh and also higher rank arrays but yeah this last one's interesting in that it's uh combining these different shapes and actually we've ended up with less ones than we started with right so it's doing something slightly weird here oh no uh wait am I doing this right okay now I'm reading it wrong so actually yeah sorry I forgot I got confused by the precedence yeah so even though there's no space there we have to remember this is actually that right okay yeah so it's just flattening it out so it's not weird oh yeah so you've got to be careful to remember that although it prints this like a word nine it's actually these are just characters n i n and e that's why this shape is 13 okay so member of a b c four is that is it an okay so is a b c an element of this set no it's not is for an element of this set yes it is so we get zero one uh and then this is just saying um is each element of the matrix an element of this set and it puts them in the same order so one is not an element two is an element three is not an element so forth makes sense so if you if you kind of reversed that and did um like one two three epsilon matt would it be searching like the major cells of if matt was on the um the right hand side yeah so it's saying okay so still looking cell-wise it's not looking at major cells saying is six anywhere in that matrix i think yeah two anywhere in the matrix yeah exactly so i think the right the the rank of the right hand side seems totally meaningless okay it's just traded as a set i i also tried with two matrices and got the same behavior that you would expect there cool thanks boy all right epsilon underbar uh just dyadic you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you okay where is a in oh is a no uh is b and um a and a is a and a is and i think it's going okay wait no because n is in both and that would be zero and that's zero so it should be so i was wrong yeah worked for the first two it finds occurrences of x within y oh okay the whole of x anna is here and anna is okay and we're going to try to give the easy examples okay there we go yeah yeah okay how do we create this thing x is okay x one is two by two oh one one oh x two is four by four oh one oh one one oh oh one oh i see that's what we want wait what's oh that's x and y never mind x y all right oh i see so it's finding where is like this oh where is this like one one diagonal and you can find it here here and here since there are the ones okay okay makes sense yeah i think the the apl wiki seems to have a kind of a i think a better explanation of it but the inquiry maybe you guys already talked about that i've been i've been in and out of the discussions um no we hadn't thanks buddy okay great why is there an n here is that actually the little n oh no let's see the other shoe on that one and children we've done this first two might go under the math i think might go in math yeah i think there's the circle star is um log and natural log and the domino looking thing is matrix division and matrix inversion i think okay matrix we're going to have to do after we've done rank certainly log we can do circles oh that's easy did i have to type it i think it is um the back tick star thing oh or alt star now to me not a great rendering here yeah i think rather than writing that i'd rather write a to the power one cool okay there we go domino quad divi matrix inverse and matrix division by okay but i'll write them down and then we can put them somewhere all right and how do i take this one molly no or anybody i believe it's um the um plus so it's the same as division but with the shift key i think that one um i think so that doesn't quite look right does it uh that was sorry is that sorry that was alt shift slash uh alt shift plus or oh sorry cool okay is there some way to get a good what's a good easy way to get an identity matrix um i did not have a blog oh well i i used it i don't know that i uh and how i got there yeah yeah here was um i'll put in the chat when my identity function was why is this not working have i got it the wrong way around i think i do actually yes oh there's a few things happening in the chat i noticed so i guess it's fine anyway we can see easily enough it's that's the invert that's the identity oh okay dyadic i'm not really sure what matrix division means very few okay now so oh i think i'm using x instead of the dash okay i haven't quite heard that expression matrix division before but it makes sense it's just the opposite of matrix modification oh cool the pseudoinverses as well if there's more rows and columns the least squares result so i think that's just what's called the pseudo inverse it's neat okay linear regression on complex numbers why not oh lots of things to study there all right probably a good time to stop i thought we've done dot or if we already done it in this one situation what do we not do it at all i'm not sure we've done it um no that's bad because i've definitely referred to it um yeah i think we talked about it a bit um okay well let's pop it underneath a ray rank but i don't know that we linear algebra algebra let's quickly do this then before we finish dot which is a operator oh it's an operator so we cut through it here okay let's put it over here let's put it over here okay okay so dot dot all right okay so you you you you you you you okay so this is a dot product one times four plus two times five plus three times six this is interesting so this is um and isn't it so this is three equals three and three equals three and three equals three and three equals three if i did this would be zero that's cool for example you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you you and so you could let's see i'm reading my own blog post trying to figure out what it means so good well let's maybe just put it in the forums right after we do it and so then they had uh oh yeah then they got a special case so actually didn't we do that in the competition thing because we were doing that oh or maybe we just played with it but we ended up getting rid of it i remember we talked about outer product for that gene example but um yeah i think i messed it up and didn't quite get it working so that's fine all right i think that's it thanks all good to see you bye bye thanks bye