Back to Index

Fast.ai APL study session 17


Chapters

0:0
3:30 Recursion
4:21 Guard Expressions
5:25 Guard Expression

Transcript

Okay. Okay. Okay. You can see my screen. Okay. I thought we might do this one. Because I actually know what it is. And it's to do with functions. Assuming I got them the right way around, I always forget which triangle is which. One question is, how do I write it upside down triangle.

You see it. Yeah. G. Help. Oh, that's odd. You have them turn on your keyboard. I guess so. Yeah, I didn't even know old G was bound to something. Oh, it's Google Google Drive seems to have stolen that hot way that's control all G. Well, I don't want to talk anyway, save.

Okay. There we go. Why do I keep getting this may help. Now I wonder, let's change. Maybe go right upside down triangle. Actually that might only be in here. For recursion. So maybe we'll try a PL wiki then. Okay, it's called Dell. Reverting resembling an inverted delta. Represented by the nabla.

Okay, so we'll call it. Dell slash nabla that's used to recursion. I think that'd be something about recursion in here. Oh yeah, let's go to this one. Okay, so there's actually a couple of things to note here. Because we haven't done guard expressions either. So let's do that first guard expressions.

Okay. How do we write diamond back to back to back to back to with my keyboard. So factorial is to find such a factorial of Omega equals factorial of Omega minus one. And so here's an example of a factorial if we wanted to write it ourselves, and the thing that's new here.

Is this thing here, it's got a guard expression. And it checks whether this is true. And if it is and it exits with this return value. So in this case factorial of five. This is not true. So then this is a statement separator. So said it's going to return five times factorial of four.

And then factorial of four will do the same thing will be four times factorial three and so forth until it gets to factorial of one. And this will be true. So that's our base case it will return one. And that's why we get. Yes. One thing I'm curious about is can you.

You can't. I think you want to use each. You may. Yeah. You work. Yeah. Yeah. Probably if we're somewhere to do this as a tacit function. Maybe we wouldn't have the problem. Not sure. Okay. Does that make sense to guard expressions. So what if we wanted to define it and use it.

So if we wanted to define factorial and then immediately use it. That's not going to work because this function doesn't have a name. So you need to be able to refer to the current function. Dell simply refers to the current function. So that means call myself. That makes sense.

It's different from the selfie isn't it. So different from the selfie yes so selfie selfie simply. If. Selfie X simply equals X FX. For example. Times. Times selfie three equals three times three. So this line is identical to this line. So this is a function. So we're calling it with let's start by calling it with two.

So calling this function with two. I make it equal to it's not less than or equal to one. So skip this. So it's equal to two times the current function of one. This is the current function. So it goes to do this with one. Yes that is less than or equal to one.

So it returns one. Now we've got this is Dell of one is one. Times two equals two. So it's exactly the same as the factorial one I've just replaced the word fact. With Dell. In. In Python for example if you want to create a recursive function you can't create a recursive Lambda.

There's no way for a Lambda to call itself. But in APL you can create an anonymous recursive function. That makes sense. So we could also cause to find this as fact if we wanted to. Like we don't have to make it anonymous or it still work fine. OK. All right.

Anyone you suggest we do next or should we just randomly pick something. I think maybe it can go through all the boxes together. OK. Do you have any sense of what the boxes are vaguely about. No. Second one. The second one. Yeah. I think that is the current. I think that is the pin out the second one.

So but the rest I don't know. Does that this quad. Yeah. Cool. OK. Well we we've already done quad. Yeah. So quad with a little doobie at the top. I'm guessing they don't have something called quad with to be at top. See. I don't see it. Maybe we'll search the wiki or something.

It's purple rather than blue which makes me suspicious. Maybe it's not a thing. Quote quad. Oh that's the name of the newsletter. It's named after the left quote quad which can be used to print text. Oh OK. So quad is standard output and quote quad is standard input. I wonder how one would use that.

In APL. Probably quite useful. Oh hi Molly. Oh hello. Yeah Jupiter input input through through it is not supported. OK OK but we could do is like get something from student in a script or something. Yeah I think if we did a script it would be supported. Here they're just using it as a normal variable I guess.

It's the array is displayed without the line ending. Oh that's interesting. So this is called quote quad. And it's written. Quote quad. So, print without character 10. That's going to work. Yep. OK fine. I just copy this then. So basically even though it's not going to work I would do.

This. OK. No worries. Right. What about this one. Quote box with two dots. It's a print operator. What on earth does that mean. OK. Like this is used for normal appeal. So probably not really part of our notation. Although I guess it's useful to know what it's talking about.

So I think knowing how to use JSON is nice. How do we create this character matrix. OK. This is I guess we could just go 1 2 3 4 5 6 2 3 4 5. So wait. Do we use double quotes or single quotes. We use single quotes. OK so if we did 1 2 3 4 5 6.

So four rows of six columns. J. Oh Jeremy I saw at the mention using the square back and then the input for multi line but I haven't tried in Jupiter. Maybe we can try. Hang on. Hang on. Hang on. I'm not quite sure. Let me let me come back to you.

Oh I see that one's got a comma and that one doesn't. OK. So we can do six and then you can tell me about this multi line idea. OK sorry. I put it in the chat. Maybe you can copy me at the at the top of the multi line.

Check. Oh yes. Right right. So OK. And do you think I might then be able to like hear something. Yeah. Oh. Okay. So we can do Jason. Matrix. It's funny they're using this rather than the usual quad gets thing. I think. We had fun issue. Nevermind. Okay. All right so.

How do we write this thing. Question mark. And what's the name of the symbol just called variant is it. All right so if we search for Jason. Yes. These are called system functions. And so we could use quad gets here. Tick back tick. Now that's time and how do I forget that.

All right. Cool. We're definitely getting to some of the weird ones huh. Okay so that's that one quad diamond. Oh this is stencil. Yes. I think this is what we can use for like convolutions and stuff. Okay and how do we write that. Okay. Okay. Oh hi Isaac. Hey it's working on fast Kaggle and I totally lost track of the last couple hours so fast Kaggle can do that to people.

I looked up and I was like oh it's halfway through the session soon. Percent is wrong. Oh yeah no that's part of our. That's one of those. You haven't missed much as we've only been doing weird ones. Quickly. Quickly. And then we'll go back to the next slide. Okay.

Yes it does sound a lot convolution a lot like a convolution. It's going to be applied to possibly overlapping rectangular views of the right. It's also for cellular automata. It's back to a dictionary of APL which we saw the other day. Okay so we're going to pass it two rows.

The first row is the dimensions of the rectangles and the second is the movement which I guess is like the stride. Okay this is the rank Tally row is rank. The right argument has an upper end as rank Y columns. Okay so you're going to be saying for each access.

What's the kernel size and stride. As you can use fewer. We'll worry about that special case later. Okay. This dried as defaults to one. Okay so this is starting. Okay this looks like a good way to do it. Okay so we started with a three by four. Matrix the numbers from one to 12.

And the function we're doing is. This is in close isn't it. Yes. Okay. I'm confused as to why they used to do fun for it. Okay interesting. What's going on with the day fun. It's making it's ensuring it's monadic I guess it's what it's doing. It just seems like a really clunky way to do that.

I'll come back to that. Well, maybe stencil put something on its left. Okay, just a tick. I gotta go check on my daughter. All right. You guys solved it now. Without the nest it doesn't keep the shape of the input, so like it becomes kind of a list. I don't know.

That's all I found so far. So if we add the assignment to the materialize, you know, both with the defund, and then without. So if we do the left arrow to materialize. Oh, so and then. Yeah. Sure. I don't think it gets. I don't think I know these parentheses, but I guess I meant right between the defund and the stencil.

So then we can see what is going into the function and then if we take away the defund we can see what's going into the enclosed. Okay, I don't know if that makes sense though. I'm not sure if it does right because the thing on the left of the stencil is the function.

That's right, which is a defund. And we do kind of know what it is because we can see it's been printed. Oh, you know what we could do is we could do alpha comma. Whoa, what is that. I've got something else running. Maybe it's power toys. Let's try this.

Oh, it's that thing. Screenshot program. Let's close that too. Okay. We use the statement separator to enclose Omega and material and print alpha, or do two statements in that defense. Okay. Yes, so we are getting alphas, which presumably this documentation will tell us. So F F is invoked diatically and the vector left argument indicates the number of fill elements that's useful.

Okay, so you can see that for this first one we've got fills along the top and left. Hence the one one and then for the next one we've got to fill along the top only. Hence the one zero. And the fourth one. Yes, it's the top right and one negative one.

Okay. Cool. I'm still trying to think of the convey, you know, the tacit way to just turn something into a monadic function. Composition. Okay. We could do a top. Okay, top is Jay. Yeah, it's kind of like a big job. Makes sense. And then right tack. Oh, I got to point in the wrong direction.

Oh, I see. That's right. There we go. So that's, first of all, applies this function to Alpha and Omega. And then it applies this function, which is obviously much uglier than the. Defund version they've already got. Okay, so this is getting a three by three section of this array and passing it to this function.

And so if we wanted a stride to version of that we could say create something which would be a two by two matrix where we're doing a three by three convolution with a two by two stride. Yep. That's cool. If there's somewhere to get nice images and stuff onto a PLG but a notebook so it would be cool to do like just a simple Gaussian blur kernel or something to display this.

If anybody feels like trying that out. Images are the way that was recommended to get images and it's to convert your images beforehand the bitmaps and then loaded them. Okay. It's just kind of a there's a section on images in the mastering dialogue APL PDF that I haven't gone through yet, but it's going to look there but.

Well, jpeg is your results. That's not good. Yeah, kind of everyone at PNG is the same, but pretty much. There's a make PNG. There's a bitmap. Oh, no, you can use gift for PNG. Okay, well, I never got the PNG is working right but. Okay. Yeah, it seems like there's there's a lot of it's been several projects where people do like neural nets on images, using minced.

And I'm not sure the format that they're in, they're behind a young look on young with guns website, but it's password protected so I can't actually see the data set but. Oh, weird. Ask if he's willing to share what that data set at some point but it looks like it's just minced in some format.

Yeah, maybe you should send them a message and ask. Okay. Anything else we need to know about stencil. This is doing both. This is actually probably better. Okay. Anybody I presume there's an APL stencil version of game of life. There you go. Life. Nifty. Oh, a Dom 17 character solution.

Cool. So here's our three by three neighborhood. And here is the count. Cool. All right. It's like, it's not quite linear algebra, just not quite sure where to put this. And now I guess we'll call it other other lifts, other function, other operators. Okay. Yeah, what are these things.

One of those hydrants is an execute statement. I think that's the first one second one third one. I think the second one is. Experimental stuff. I can't imagine that's going to come up too often so we can definitely put that in the. Weird special bit. I think that triangle is self reference for recursion.

We've already done that. Oh, okay. Yeah, we did that a little bit earlier just before you arrived, I guess. Okay, do any of them look interesting. I see his execute expression. Actually as it would be executed by the monadic execute primitive function. Oh, I see. Syntax coloring. All kinds of stuff.

Probability distributions at the bottom. Oh. What about an SVD. I started reading from the bottom knobs. Yeah, it's a good idea that way we're not overlapping. Not available on Mac. Well, I'm not on my max that's okay. I wonder why it's not on Mac though. We have more officially available wouldn't it.

That was it occurred. Why do we use chat wizards. Such a weird thing to do an API. SVD at August. 2022 Services include SVD probability probability distributions. And much more. Okay. Fine. So then this is going to be our execute expression thing as well. Hydrant symbol. Yep. Cool. Working a different process.

Do you think it does or. Oh, no, sorry. There's another one that forks a new process. Did you move to the new another. Oh, sorry. Hydrant. Oh, I see. There's a, there's a fork thing in the. Yeah. Yeah. I was still reading through them. Sorry. No, no, that's good.

Can somebody tell me the keyboard shortcut for this one. Hydrant it's the semi colon. I think. Okay, that looks pretty straightforward. Okay. That's interesting. But. It's printing the first thing. Is the result of the last executed sub expression. The non shy results of all proceeding expressions are displayed. Okay.

So that's the opposite of. If you don't use it right. Sounds like hydrant. Right. Okay. Okay. Oh, we haven't done namespaces. Okay. Okay. Okay. Is that what this is? Yep. Okay. I'm going to put this one into the. We had special symbol section. Okay. Not upside down hydrant. That is what I've been following it until I just looked it up.

Just the other day, just a few minutes ago. Okay. And where do I type it? That was not right. It's a single quote. Okay. Okay. So the only way you can tell these different is from the lack of the name. I thought there's supposed to be dots between the four, five and six to.

That must be at a different display format. Yeah. Well, it's characters versus numbers. Okay. So, so I think it's converted to a string of characters. Okay. Okay. Text with, with a number of decimal places. Okay. Cool. Okay. I put this in the weird lift section as well. Okay. All right.

I wonder if we can finish these. I can't replace this stuff. It means that. Okay. If it's an operator. Okay. But it can create monadic and dyadic function. You can tell because of the curly brackets on the X. Okay. This is replacing two and four with zero. Oh, you can replace it with a function call.

That's neat. Okay. So this one's replacing two or four with zero in iota five. And I'm guessing this is replacing two and four with times applied to the right hand side and 10. That's very cool. The right upper end identifies which items. Oh, and you can also use a function on the right hand side.

That's neat. Okay. So this can be the array for placement or the function to be applied and the left argument is X call. So this is iota five. This is replacing. Okay. You can also replace like one and two with two and four. That didn't one two. Oh, yeah, this is what replacing replacing two gets replaced with three and four gets replaced with one.

Okay. Makes sense. Okay. There's all kinds of weird indexing things that we haven't talked about. Choose indexing or reach indexing. Okay. So this is the monadic version of the function one. Replace with reciprocal and positions two and four. Oh, I like this. Replace odd elements with zero. So two, there are two modulo two, this basically means.

What does this mean? Replace odd items with themselves reversed. I don't understand how that works. I can see what it's done. But it's not applying this to each element. That's clever, isn't it? It's actually applying it to the whole array and then deciding which elements to replace. So that's that's quite clever.

Five, three, one, two, four, six. Wow. Nice. Okay, let's move this into the main operator sections. It seems really useful. Oh, except we haven't done that one yet. All right, because we want them. So we will move this section out of the way because it's less interesting. Okay, that's at all right, right arrow.

Okay, it's superseded by more modern control structures. So maybe we should not really spend much time on that. I think we should do it in the weird section. Okay, that was easy. It's born. Wow. Okay. Okay. So that's like in like bash basically spawns it in the background. Okay.

Okay. Oh, but it doesn't print anything. Okay, that's it. I don't think that's worth spending time on particularly, so I don't think we're going to be using APL as our main parallel programming tool. Oh my god, two more. Triangle. I don't see it. Oh, what is this thing. Okay, I don't think that's the thing about this one.

I don't think that's the thing either. We finished. Nice. Amazing. All right. Well, if people feel motivated, then I think we should, you know, start adding crows to these notebooks. If any of you decides to do that, what I suggest you do is open an issue in the APL study repo and say, I'm working on crows for this notebook.

That way, people will know not to do the same notebook to avoid doubling up. Does that make sense? Yes. All right. Is there. What do you think, or have you planned out what what you're going to work on what we're going to work on in the next session or are these continuing I guess that's the first question.

I think my plan is to. Yes, stop this week so there won't be one tomorrow. And my plan is to switch to some nb dev sessions. Yes, APL. Probably come back to it after part two of the course. Yeah, in the meantime if anybody's, you know, got a really good Anki deck that covers all the glyphs, I would love a copy of it.

So at least I don't forget what I've learned. Did you have you been kind of keeping up with adding the glyphs to your Anki deck. I do. Perhaps that I think I run it, it will be updated I haven't been updating it all the time but I probably do quite a bit of editing though, because not everything's very Anki friendly, you know, it'd probably be a good starting point, like.

Yeah, particularly if you like spits out a CSV or something like that you could open up in a spreadsheet and then you could just like delete the rows that don't make sense or combine some or something important. Right now it's the books for those looking. We will see how consistent the structure is but I did handle some ed cases around looking for markdown cells that are at least a certain number of header like a header three or above and it looks for the back of the text afterwards.

I think you've been pretty consistent with that scheme so yeah recently it's just like there'd be a bunch of cards that aren't necessary and some that don't really stand alone and some which like have too many examples and, you know, but yeah I mean that would be a great, great start we could certainly use.

Yeah, that'd be cool if you could do that. Yeah, we're kind of this week son. Yeah, no hurry. Otherwise we're all going to forget everything. That's for practicing. And I've also got a deck of the keyboard shortcuts. I have one that was. That's some kind of a deck of symbols from the dialogue docs so yeah be useful to add the mnemonics to that too if you have time to or anybody else has time to.

Oh yeah yeah. Otherwise we're just going to have to look them up. Okay, well thanks for sticking with me to the end. You are the tenacious ones. And yeah anybody interested in nb dev, probably, probably start doing the same time next week, see how things go. After next week Monday, Monday US Tuesday Australia.

Yeah. Oh, right. Alright bye gang. Bye. Thank you.