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

Whisper Transcript | Transcript Only Page

00:00:00.000 | where are you joining us from oh i'm here from uh Iran there right great yeah
00:00:27.360 | 4 30 in the morning oh wow well that's very impressive but it's good yeah really good
00:00:39.040 | thanks for joining thank you for the session uh codes codes uh uh 67 mines from from capital yeah
00:00:50.080 | well look at that only three of us lots of people watching the vietro videos but
00:00:57.040 | not so many people joining us live i guess it's uh hard to maintain the consistency well thank
00:01:03.360 | you first for joining um that's uh is there anything you wanted to talk about or should we
00:01:09.520 | keep going oh uh yeah ask me uh both of you ah okay i think you were about to finish the
00:01:24.160 | glyph yeah i think you finished the let's go have a look and then share my screen
00:01:31.920 | um so i guess we're doing this one will we the rest
00:01:38.080 | were we in the middle of something
00:01:41.680 | let's see i guess not
00:01:51.520 | is this different to upshoe is this like a bigger version of it or something
00:01:57.920 | oh it's up shoes that is up shoe yeah we've already done that right i think so yeah yeah
00:02:06.080 | i think so i'm just going to type help just in case it's some weird different version of it
00:02:12.640 | oh what has happened that's strange
00:02:20.800 | huh okay never mind um and have we definitely not done iota andaba
00:02:41.840 | i guess if we did it would have been probably here
00:03:08.320 | um okay dialogue language elements
00:03:13.680 | and try and remember what iota andaba does
00:03:20.160 | where interval index
00:03:26.960 | let's put it next to iota
00:03:36.160 | as well
00:03:45.840 | okay so i'm going to guess that it is shift i
00:03:54.320 | correct aota andaba
00:04:07.520 | all right we've already got row at this point so that's good
00:04:27.920 | bmat is two by three
00:04:36.560 | all right so um iota andaba i guess pretty clearly is showing us the locations of
00:04:55.120 | the binary trues
00:05:01.840 | and more than that it is replicating them the number of times according to what the number is
00:05:11.120 | doesn't work on negative numbers doesn't work on floats
00:05:23.920 | okay seems easy enough and then for matrices
00:05:29.440 | it's telling us the coordinates
00:05:33.200 | of each of the binary trues
00:05:38.320 | it would be easier if this was printed out
00:05:51.600 | row one column two two one two three cool
00:05:58.400 | so anything else i should add or anything so it makes sense
00:06:11.680 | what's this one
00:06:31.200 | 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
00:06:42.160 | iota row omega oh okay so just the index of that oh why is x here hi isak i see so iota
00:07:11.120 | iota row of omega
00:07:12.880 | is the indices that were with yeah correspond to that to that array
00:07:22.880 | and okay so um that's our input that's a function that's a function function operator
00:07:37.920 | function okay so that's a function
00:07:42.400 | that's a function that's a function so this is a fork with three functions does that sound right
00:07:56.160 | i'm right hooray so we go row of this and then we go
00:08:07.440 | slash over comma now there's no reason to use over right because it's monadic so we
00:08:18.160 | could just use jot and get the same thing yes um so first
00:08:28.720 | so is this
00:08:40.720 | the column is not necessary is it
00:08:46.640 | uh it's not
00:08:53.440 | i guess this is in case it's like a scalar or something
00:08:58.160 | okay and then can anyone remember what slash does
00:09:09.200 | set the replicate i guess that's the monadic right uh over do
00:09:17.360 | monadic slash is not defined oh so
00:09:24.640 | wait uh wait how is this working because monadic slash is not defined
00:09:37.600 | that's a syntax error
00:10:06.880 | oh no no no it's dyadic because there's a omega here okay so it's dyadic
00:10:16.080 | okay we've got a okay we've got a fork
00:10:22.640 | slash iota row and a dyadic fork
00:10:34.640 | applies the outside functions to both outside arguments
00:10:38.320 | here yep so this is a dyadic fork and it applies the outside functions to both outside arguments
00:10:56.880 | so are they just recreating the monadic iota underbar um let's see so this is going to be oh i see
00:11:08.000 | i think you're right
00:11:20.240 | um so the reason this works is that slash means replicate and
00:11:29.280 | the left hand side tells me how many things times to replicate the right hand side
00:11:36.560 | omega slash omega
00:11:44.320 | okay so there's a mega slash omega so that's doing the replicate
00:11:53.120 | and then you've got row of omega as we discussed
00:12:11.520 | okay and then dyadic iota
00:12:15.200 | dyadic
00:12:21.040 | index of
00:12:35.040 | wait what did i do wrong
00:12:40.800 | oh um it's uh it's
00:12:51.600 | this row is applied to the left down the right
00:12:57.760 | so it's a mega row omega
00:13:12.960 | is that right
00:13:14.960 | no so i can put parentheses here right no okay so i'm pausing it wrong oh i'm pausing it wrong
00:13:29.120 | because of the omegas this is not in parentheses it's not a fork so i'm totally wrong
00:13:36.480 | um so we actually have to be careful about precedence here without parentheses it's
00:13:42.480 | going to be there's actually no operators in this version so we uh bind most tightly on the on the
00:13:49.360 | right so this is actually simply going to be row of omega which is four and then iota which is one
00:13:56.400 | two three four so it's just going to be that which does give us the answer
00:14:08.640 | okay got to be careful of precedence
00:14:25.360 | and i guess you could do that tacitly
00:14:31.040 | by doing
00:14:44.960 | and then what Adam calls selfie
00:14:52.720 | oh look at that
00:14:55.840 | awesome yay
00:15:00.800 | okay that was a bit of a digression
00:15:12.640 | i think we'll line in the docs to say this is how you can define iota underbar
00:15:19.280 | we've made that a bit faster but i guess it'd be less fun okay yeah
00:15:24.160 | biotic iota underbar
00:15:38.820 | thank you for your fast cable stuff by the way is that okay
00:15:46.400 | it was something i wanted for myself i think a lot of people are going to find it really useful
00:15:53.360 | yeah i hope so i'm i'm right now trying to fight with github actions and trying to get it scheduled
00:16:05.040 | run update if any of the libraries are if any of the libraries are
00:16:09.280 | great idea not the latest it'll just update them and then i can
00:16:13.920 | have a big repository that people can just point to so you don't have to upload their own
00:16:21.760 | unless they want to now this one i remember doing with claire it's a bit of an odd one
00:16:52.800 | oh where we are
00:17:14.880 | okay so
00:17:20.560 | hey iou oh there's two things here
00:17:28.720 | what's it doing okay so the number of results is the same as the number on the right hand side
00:17:43.520 | let's start with a numeric one because i think i know this one so what the two four six does
00:18:01.200 | is it creates a number of groups the first group it creates is less than two and then two to less
00:18:09.520 | than four and then four to less than six and then greater than or equal to six and so less than two
00:18:19.920 | will become zero two to less than four will become one four two less than six will become two greater
00:18:32.080 | than or equal to six will become three so that's why one is less than two so it becomes zero two is
00:18:42.560 | two less than four so it becomes one and so forth so just tell to these to find break points
00:18:51.840 | and then it just applies these to those break points and gives you the results
00:18:58.880 | but be very careful because it's a bit weird that it starts at zero instead of one
00:19:04.160 | which when i asked about this on the APL discord Marshall Lockburn told me he considers this an
00:19:13.520 | off by one error in APL although somebody else pointed out it does have some convenient properties
00:19:19.760 | so you can think of it as like the group number one is the bit defined by
00:19:27.360 | when you actually get greater than or equal to two so zero is like less than the minimum value
00:19:34.240 | does that make sense
00:19:36.640 | okay so this is exactly the same thing that for letters these letters are in alphabetical order
00:19:45.360 | so d is between a and e so it's one y is later than u so it's five
00:19:54.640 | that's it
00:19:56.640 | gotcha
00:20:00.660 | okay rank two arrays
00:20:10.640 | i don't know
00:20:29.440 | interval index works with major cells
00:20:39.440 | okay so this is one of these ones with broadcasting built-in
00:20:51.280 | wait is that
00:21:02.080 | higher rank left document
00:21:20.320 | and it compares subarrays in y which is the right argument
00:21:28.240 | with the major cells of x
00:21:51.920 | i'm not quite following uh
00:22:02.400 | what are subarrays of this i guess three three is a subarray
00:22:13.200 | so it's not broadcasting length just three or three three three would give errors right
00:22:20.800 | but what if we did uh
00:22:23.920 | two rows two columns
00:22:29.200 | of three three three five
00:22:39.040 | yeah so it's this is subarray one i guess this is subarray two so this is the same as as
00:22:46.720 | this result concatenated with this result how does it decide that three three is one i guess
00:22:54.560 | it's looking through here to find like a row that contains what exactly would zero three
00:23:03.280 | give you the same result no i think it's like it's trying to it's basically like looking for
00:23:12.720 | the first okay i think the issue is um it's it's it's comparing column one and then column two
00:23:24.000 | and column two would only matter if there was a tie so i think if we went um
00:23:31.520 | okay one two three four three five
00:23:46.080 | so three three is not bigger than three four three four is but then three five is higher still
00:23:57.280 | and then four five is off the end
00:24:00.160 | oh greater than or equal to is always going to be there
00:24:05.840 | yeah so it's saying uh what row which would this slot into by first of all making sure that it's
00:24:14.560 | greater than or equal to the first column and greater than or equal to the second column so
00:24:19.600 | this one would have to go here because the second is not greater than or equal to
00:24:24.480 | but if either of them are greater than the second then it would slot them after right yeah which i
00:24:31.360 | think is i think it's exactly the same as doing 12 34 35 all right that's basically the same thing right
00:24:45.280 | same results
00:25:28.020 | and if you want to learn more about this they've got quite extensive examples
00:25:31.540 | which i suspect means that this is fairly important
00:25:34.740 | i guess in you know anytime you're trying to place a continuous number into a bunch of buckets
00:25:42.100 | you would use this kind of approach
00:25:45.300 | like plotting groups or something like that
00:25:54.520 | histograms
00:25:56.820 | molly you're very quiet i can't quite hear you probably
00:26:01.540 | oh uh yeah my mic was long ways away uh histograms yeah yeah
00:26:08.820 | circle okay i wonder if circle should go in the basic math section
00:26:19.700 | because that's circle functions
00:26:23.060 | i kind of mentioned we're going to need other stuff much
00:26:31.700 | a bit of a big topic i guess circle functions
00:26:43.220 | uh circle here it is
00:26:50.740 | right circle how do we
00:26:58.820 | write circle hey yeah just remembered i've actually installed the
00:27:06.340 | apl keyboard i don't need this thing anymore
00:27:08.820 | oh i guess it's useful to see what button to press anyway okay so it's
00:27:17.460 | oh so i can just press alt o
00:27:19.620 | oh maybe i need to do this
00:27:24.260 | auto there we go cool
00:27:28.740 | auto which i guess is just called circle yep circle
00:27:47.480 | monadic circle
00:27:51.220 | i times so i guess that means we could just go
00:27:57.380 | one at circle one and can we do like that yeah okay seems easy enough
00:28:07.940 | okay nothing weird
00:28:15.940 | oh fun
00:28:30.020 | or illness identity
00:28:41.220 | pi i a to the pi i yeah
00:28:45.460 | i lose identity
00:28:54.500 | although at this point we haven't done any kind of
00:29:09.780 | trainee thing so maybe we should do that in two steps
00:29:24.500 | equals
00:29:35.140 | pi i oops what did i do wrong
00:30:03.060 | oh it's not exact is that what it's saying
00:30:13.780 | something weird going on here
00:30:27.780 | it doesn't sound weird so this is pi i this is pi i
00:30:39.460 | and then this is e to the power of that
00:30:46.500 | yeah that's definitely pi i
00:30:59.380 | that's strange
00:31:03.380 | oh i see it's minus one plus 10 to the negative 16
00:31:21.700 | i which is basically zero so i think what's happened is um i guess is that uh
00:31:29.300 | this is special case or something in APL dialogue APL to remove the annoying floating point
00:31:38.260 | residue leftover bit here basically this is close enough to zero i
00:31:43.300 | for some reason when we do it all in one go it's
00:31:49.620 | gets it exactly right all right well maybe we won't show that then
00:31:58.040 | diatic
00:32:02.900 | circle function
00:32:16.900 | yeah there isn't really a short way to do this so i'm inclined to just provide a link
00:32:40.580 | to this one right here so i'm going to just give you a quick example of what we're going to do.
00:33:23.620 | um but basically the idea is you
00:33:25.700 | put something on the left and whatever you put on the left to find what function you get
00:34:15.960 | and cause is two
00:34:23.960 | and presumably we can do both
00:34:31.800 | yep and can we do it to multiple things
00:34:37.000 | what does that do
00:34:49.800 | what does that do
00:34:55.640 | what does that do
00:34:57.640 | what does that do
00:34:59.640 | what does that do
00:35:01.640 | what does that do
00:35:03.640 | what does that do
00:35:05.640 | what does that do
00:35:07.640 | what does that do
00:35:09.640 | what does that do
00:35:11.640 | what does that do
00:35:13.640 | and not quite clear on what happens when
00:35:15.640 | and not quite clear on what happens when
00:35:17.640 | is an array
00:35:20.280 | oh I guess it's but well no okay that makes sense so if we do pi
00:35:38.760 | okay so that's basically zero zero
00:35:59.880 | or maybe point five
00:36:09.240 | so then what happens if we what does that do
00:36:15.400 | because you kind of I was expecting four results I was expecting sine and cos because
00:36:22.280 | if we do sine and cos of zero
00:36:30.280 | or sine and cos of half pi
00:36:57.560 | so why do you so what do the two numbers mean
00:37:06.520 | I I think you're applying each function to each of the er sorry
00:37:16.280 | each straight function to each of the ones and the right side I need a better vocabulary
00:37:23.720 | you think it's broadcasting
00:37:26.840 | over the scalars
00:37:35.640 | yeah I think uh
00:37:40.840 | oh right that's exactly what happens by default in APL right is a scalar broadcasts over an array
00:37:49.000 | but if they're both arrays then they just broadcast to each other yes yes yes you're exactly right
00:37:56.120 | okay great
00:37:58.120 | okay fine
00:38:20.680 | okay element of we should put with our kind of set related stuff which I guess is where
00:38:28.280 | up and down she were
00:38:53.960 | epsilon
00:39:01.720 | one of the epsilon
00:39:02.760 | means enlist because ml for us is one I remember
00:39:07.880 | and it's just called epsilon yes epsilon
00:39:25.640 | my attic epsilon enlist and dyadic
00:39:34.600 | epsilon is member of
00:40:00.680 | okay see what's going on here
00:40:19.480 | matrix is two by three
00:40:25.000 | row iota six
00:40:38.680 | so what it's doing is it's got zero that's got a matrix from one to six
00:40:43.080 | that's got a array with seven and eight that's got a scalar nine and it just uh flattens them
00:40:49.400 | and sticks them all together flatten and concatenate I wonder if that does that for
00:40:54.920 | more axes yes it does
00:40:58.760 | seems easy enough
00:41:11.640 | uh okay so this is interesting
00:41:21.080 | yeah so this is two by three but this is a single this is oh sorry and then this is
00:41:35.080 | ranks this is a shape three so I guess this is um doing the broadcasting thing kind of it's
00:41:44.280 | applying it to each row
00:41:48.440 | all the elements in rebel order
00:42:01.160 | so this flattens up to the rays
00:42:11.960 | yeah I guess so
00:42:20.680 | yeah it is
00:42:31.160 | uh and also higher rank arrays
00:42:33.240 | but yeah this last one's interesting in that it's uh combining these different shapes
00:42:44.840 | and actually
00:42:52.200 | we've ended up with less ones than we started with right
00:42:58.040 | so it's doing something slightly weird here
00:43:04.760 | oh no uh wait am I doing this right okay now I'm reading it wrong so actually yeah sorry
00:43:22.760 | I forgot I got confused by the precedence yeah so even though there's no space there
00:43:30.200 | we have to remember this is actually that right okay yeah so it's just flattening it out so it's
00:43:35.960 | not weird oh
00:43:50.680 | yeah so you've got to be careful to remember that although it prints this like a word nine it's
00:44:03.640 | actually these are just characters
00:44:06.440 | n i n and e that's why this shape is 13
00:44:51.640 | member of a b c four
00:44:57.560 | is that
00:45:01.880 | 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
00:45:13.400 | yes it is so we get zero one
00:45:16.680 | uh and then this is just saying um is
00:45:25.080 | each element of the matrix an element of this set and it puts them in the same order so
00:45:33.880 | one is not an element two is an element three is not an element so forth
00:45:41.880 | makes sense so if you if you kind of reversed that and did um like one two three epsilon matt
00:45:50.840 | would it be searching like the major cells of if matt was on the um the right hand side
00:45:58.680 | yeah so it's saying okay so still looking cell-wise it's not looking at major cells
00:46:08.840 | saying is six anywhere in that matrix i think yeah two anywhere in the matrix
00:46:17.000 | yeah exactly so i think the right the the rank of the right hand side seems totally meaningless
00:46:23.560 | okay it's just traded as a set
00:46:35.960 | i i also tried with two matrices and got the same behavior that you would expect there cool
00:46:42.360 | thanks boy all right
00:46:46.520 | epsilon underbar
00:47:07.080 | just dyadic
00:47:57.560 | okay where is a in oh is a no uh
00:48:02.840 | 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
00:48:18.840 | and that would be zero and that's zero so it should be so i was wrong
00:48:31.080 | yeah worked for the first two it finds occurrences of x within y
00:48:43.080 | oh okay the whole of x anna is here
00:48:58.760 | and anna is
00:49:02.600 | okay and we're going to try to give the easy examples
00:49:10.600 | okay there we go
00:49:36.520 | yeah okay
00:49:45.000 | how do we create this thing x is
00:49:56.280 | okay x one is two by two
00:50:04.200 | oh one one oh
00:50:10.920 | x two
00:50:16.600 | is four by four oh one oh one one oh oh one oh i see
00:50:33.080 | that's what we want
00:50:41.400 | wait what's
00:50:57.720 | oh that's x and y never mind x
00:51:12.760 | all right oh i see so it's finding where is like this oh where is this like one one diagonal
00:51:24.680 | and you can find it here here and here since there are the ones okay
00:51:40.360 | makes sense yeah i think the the apl wiki seems to have a kind of a
00:51:48.280 | i think a better explanation of it but
00:51:53.880 | the inquiry maybe you guys already talked about that i've been i've been in and out of the
00:51:59.560 | discussions um no we hadn't thanks buddy
00:52:25.160 | great
00:52:32.680 | why is there an n here is that actually the little n
00:52:42.040 | oh no let's see the other shoe on that one and children we've done
00:52:52.680 | this first two might go under the math i think might go in math yeah i think there's the circle
00:53:00.280 | star is um log and natural log and the domino looking thing is matrix division and matrix
00:53:08.280 | inversion i think okay matrix we're going to have to do after we've done rank certainly log we can do
00:53:22.040 | circles oh that's easy
00:53:43.160 | did i have to type it
00:53:49.160 | i think it is um the back tick star thing
00:53:57.080 | oh or alt star now to me
00:54:10.280 | not a great rendering here
00:54:43.800 | i think rather than writing that i'd rather write
00:54:45.720 | a to the power one
00:55:14.040 | there we go
00:55:35.800 | domino quad divi
00:55:37.080 | matrix inverse and matrix division by
00:55:45.720 | but i'll write them down and then we can put them somewhere
00:55:57.880 | all right
00:56:04.040 | and how do i take this one molly no
00:56:13.000 | or anybody i believe it's um the um plus so it's the same as division but with the shift key i think
00:56:25.160 | that one um i think so that doesn't quite look right does it uh that was sorry is that sorry
00:56:37.880 | that was alt shift slash uh alt shift plus or oh sorry cool
00:57:03.400 | is there some way to get a good what's a good easy way to get an identity matrix
00:57:28.520 | i did not have a blog
00:57:31.400 | oh well i i used it i don't know that i uh
00:57:37.800 | and how i got there
00:58:21.240 | here was um i'll put in the chat when my identity function was why is this not working
00:58:27.880 | have i got it the wrong way around i think i do actually yes
00:58:37.560 | oh there's a few things happening in the chat i noticed
00:58:53.480 | i guess it's fine anyway we can see easily enough it's
00:59:05.320 | that's the invert that's the identity
00:59:31.960 | dyadic
00:59:39.080 | i'm not really sure what matrix division means
00:59:44.520 | very few
01:00:27.320 | oh i think i'm using x instead of the dash
01:00:37.720 | okay i haven't quite heard that expression matrix division before but it makes sense
01:00:50.600 | it's just the opposite of matrix modification
01:00:58.760 | oh cool the pseudoinverses as well if there's more rows and columns the least squares result
01:01:17.720 | so i think that's just what's called the pseudo inverse
01:01:19.560 | it's neat okay linear regression on complex numbers why not
01:01:26.840 | oh lots of things to study there
01:01:45.640 | all right probably a good time to stop
01:01:50.280 | i thought we've done dot or if we already done it in
01:01:57.160 | this one situation what do we not do it at all
01:02:02.200 | i'm not sure we've done it um no that's bad because i've definitely referred to it
01:02:15.560 | um yeah i think we talked about it a bit um okay well let's pop it underneath a ray
01:02:23.720 | rank but i don't know that we
01:02:35.320 | linear algebra
01:02:39.320 | algebra
01:02:45.960 | let's quickly do this then
01:02:53.240 | before we finish dot
01:03:00.920 | which is a operator oh it's an operator
01:03:07.720 | so we cut through it here
01:03:22.360 | okay let's put it over here
01:03:37.720 | let's put it over here
01:04:35.160 | all right
01:05:43.180 | okay so this is a dot product one times four plus two times five plus three times six
01:05:49.980 | this is interesting
01:06:08.620 | so this is um and isn't it so this is three equals three and three equals three and three
01:06:15.660 | equals three and three equals three if i did this would be zero
01:06:18.780 | that's cool
01:06:29.260 | for example
01:07:32.140 | and so you could
01:07:34.620 | let's see i'm reading my own blog post trying to figure out what it means so
01:07:48.380 | well let's maybe just put it in the forums right after we do it
01:08:10.220 | and so then they had uh oh yeah then they got a special case
01:08:29.420 | actually didn't we do that in the competition thing
01:08:51.100 | because we were doing that oh or maybe we just played with it but we
01:08:55.100 | ended up getting rid of it
01:08:56.860 | i remember we talked about outer product for that gene example
01:09:06.780 | but um yeah i think i messed it up and didn't quite get it working so that's fine
01:09:17.580 | all right i think that's it thanks all good to see you
01:09:40.380 | bye bye thanks bye