back to indexfast.ai APL study session 1
Chapters
0:0
19:59 How To Read the Help
22:50 Install Anaconda
26:43 Monetic Form
52:59 Complex Number
00:00:12.800 |
So if there's any explosions in the background 00:00:15.000 |
while I'm talking, it's 'cause it's the Fourth of July. 00:00:23.520 |
- I don't think I've ever said that to anybody. 00:00:56.680 |
- I'm in Lucknow, near Delhi, northern India. 00:01:27.280 |
I've always wanted to visit, but haven't yet. 00:01:38.120 |
- So I want you to try aloo parathas in Delhi, Jeremy, 00:01:45.440 |
because I know that's the Indian bread you like. 00:02:02.840 |
I don't think I've ever had an Indian meal I didn't like. 00:03:03.400 |
- And I guess we'll see what there's any fireworks 00:03:29.080 |
Has anybody here had any experience with APL or J? 00:03:42.720 |
I feel like, where are you coming to us from? 00:04:14.880 |
through a linear algebra course, chapter one in APL. 00:04:23.560 |
or you're just like doing a linear algebra course 00:04:36.320 |
- Oh, wow, can you share a link to it in the chat? 00:04:42.880 |
- You got any Independence Day things happening today, Isaac? 00:04:49.320 |
I'm sure there'll be fireworks going on sometime, 00:04:52.920 |
but I don't know that we're gonna go watch them or anything. 00:04:55.520 |
- All right, well, I'm glad there's some folks 00:05:00.800 |
'cause I've got very little background in this, 00:05:05.320 |
other than teaching my kids some math using APL, 00:05:10.840 |
I was actually on the ArrayCast podcast this morning, 00:05:15.840 |
so lots of APL things happening in my life today. 00:05:31.160 |
So this is one of the things I like about APL 00:05:35.200 |
is that there is a bunch of books and whatever around 00:06:00.560 |
so I'm not even completely through chapter one, 00:06:03.120 |
but if I'm gonna further along, I'll let you know. 00:06:08.640 |
All right, so hopefully everybody's done step one. 00:06:12.200 |
If you haven't yet, that is to install dialogue APL. 00:06:16.640 |
There is a bunch of different APL interpreters around, 00:06:27.440 |
that it's by far the most heavily invested in, 00:06:37.800 |
And I do recommend installing it from their website. 00:06:44.520 |
There is a option to download an unregistered version 00:06:51.040 |
So I'm on Windows, but there's also a Mac one, 00:07:02.320 |
and Red Hat, RPM, whatever, options for Linux. 00:07:06.800 |
I think some Linux one doesn't come with a GUI. 00:07:17.160 |
Linux at the moment, so I haven't tried this. 00:07:34.040 |
if you go to the latest release here for Ride, 00:07:37.600 |
you'll find there's RPM and dev for AMD and ARM platforms. 00:07:41.680 |
So I think you have to install dialogue first 00:08:01.760 |
or on Windows, hit the Windows button and type dialogue. 00:08:05.480 |
Now, one thing I found a little hard to find, 00:08:17.360 |
You just do it in the toolbar up here, like so. 00:09:06.800 |
so there's a language bar with all the different glyphs, 00:09:12.680 |
and press the keyboard button to get a glyph. 00:09:15.720 |
So there's control A, control J, control hyphen. 00:09:27.760 |
So what I did is there's a few ways you can do this. 00:09:36.040 |
On Windows, I can't remember if Mac does this as well. 00:09:41.840 |
If you wave your mouse over something in the toolbar, 00:10:03.480 |
oh, that doesn't work 'cause of my background thing. 00:10:08.200 |
I printed out just a picture of an APL keyboard. 00:10:17.560 |
Which honestly, I haven't referred to too much 00:10:27.840 |
We have that little tool tip thing showing up too. 00:10:35.360 |
but if you want to, in Windows, you can use back tick instead. 00:10:45.840 |
you can have it activate a keyboard when you start, 00:11:03.440 |
Well, this is working before I was able to turn on back tick, 00:11:14.760 |
Well, you should be able to click configure layout 00:11:27.280 |
will just automatically work when you go into the app. 00:12:02.760 |
if I go into some other dialog box or some other program, 00:12:12.720 |
So I just get my normal control, I select all. 00:12:18.640 |
if you want to use the dialog keyboard elsewhere, 00:12:22.880 |
you can hold down the Windows button and press space, 00:12:25.440 |
and it'll pop up a list and keep holding down Windows. 00:12:50.560 |
so then you'll just have to hold down Windows 00:12:52.120 |
and press space to go back to a non-APL keyboard. 00:12:59.720 |
just go to this APL fonts and keyboards dialog page, 00:13:09.480 |
and it'll show you how to enable the keyboard, 00:13:30.080 |
This is just if you want to use them outside. 00:13:32.280 |
So has anybody had any issues with installing? 00:14:11.800 |
'cause you do have to install at least one extra thing 00:14:17.920 |
And then I see Adam, who actually works at dialog, 00:14:27.880 |
which we've already mentioned, so that's good. 00:14:35.160 |
Yeah, did anybody have any issues with installing 00:15:29.160 |
Oh, I see there's multiple ways to type this. 00:15:35.600 |
Okay, so that's how you can read those little thingies, 00:15:52.040 |
- I guess with APL, it's not like the conciseness 00:15:58.640 |
and expressiveness of it means that it's not like 00:16:00.920 |
you're typing at a hundred words per minute anyway, so. 00:16:13.640 |
Charles says going to an obscure programming language course 00:16:27.400 |
So everybody here will not be able to empathize 00:16:48.880 |
And I don't know if there's a way to turn these off 00:16:52.160 |
by default, but you can get a bit more space back 00:16:54.400 |
by clicking on these little various Xs around the place. 00:16:58.040 |
I do feel like it would be nice to get some more space 00:17:00.120 |
by removing the word language bar above the language bar, 00:17:02.840 |
I'm not showing that much, not much doing much for us, 00:17:15.000 |
So I can type numbers, I can type expressions. 00:17:19.800 |
So yeah, the answer from dialogue APO appears on the left 00:17:43.960 |
and then this, and it'll put my new thing on a new line, 00:17:48.280 |
So I think that's my number one tip that I've found so far. 00:17:57.680 |
- You can also bind scrolling through history to a hotkey. 00:18:06.200 |
And I thought it might've even have come with one. 00:18:39.000 |
- Yes, and it is called backward or undo, I believe. 00:19:22.720 |
Most array programming tutorials, books I've seen 00:19:32.640 |
which is not the first AI way to teach things. 00:19:37.160 |
And I think it's particularly not the right way 00:19:40.560 |
And the reason for that is that when I look up stuff 00:20:01.520 |
The help tells you, it shows me up here what the glyph is. 00:20:11.440 |
And we'll talk about this soon in more detail, 00:20:16.280 |
but generally speaking, each glyph does two things. 00:20:38.320 |
is that the examples all use glyphs that we don't know. 00:20:47.000 |
to learn how to read Chinese when you don't know Chinese. 00:20:50.880 |
So my plan is to first learn every single glyph, 00:21:01.440 |
So I think this is something that I haven't seen done before 00:21:07.080 |
and I'm quite enthused about learning all the glyphs. 00:21:20.360 |
and they're just very excited about the idea of like, 00:21:26.000 |
that we understand and there won't be weird symbols anymore. 00:21:29.160 |
So for me, most of these are still weird symbols, 00:21:37.080 |
Like a lot of them probably won't take long to learn, 00:21:47.000 |
So we'll start with the ones that we can recognize. 00:21:49.560 |
So yeah, one reason I wanna get Jupyter going 00:22:25.160 |
So I've already got Jupyter installed on Windows. 00:22:43.600 |
And so now, let's see if this is the right button. 00:22:53.760 |
They haven't actually got a pip or condor installer 00:23:13.440 |
And just recently I found my downloads in Chrome 00:23:18.440 |
have started taking a ridiculously long time, 00:23:53.880 |
Okay, let's see if what we wanted to happen happens. 00:24:27.520 |
So I'm probably gonna have to hit windows space 00:25:54.640 |
at least these are not in a bad order to learn about them. 00:26:02.720 |
And let's start by learning to read these things. 00:26:11.200 |
So up in the top right here, we've got the glyph. 00:26:18.640 |
they're gonna show us the two things that they can do. 00:26:31.840 |
Monadic means that you're gonna put something 00:26:45.280 |
If you've heard the word monad before and stuff 00:26:49.560 |
This simply means a function that takes one argument. 00:26:53.000 |
And in APL, you don't write functions like that. 00:27:11.240 |
So it looks more like math than normal computing. 00:27:25.120 |
when applied to three returns like upper hyphen three. 00:27:40.880 |
And this is how you write a minus sign in APL, 00:27:52.880 |
This is a function that negates its argument. 00:28:07.240 |
and the number negative three are the same thing, 00:28:10.800 |
but they're different, conceptually different. 00:28:20.720 |
Okay, so monadic, monadic means it takes one argument 00:28:33.640 |
Otherwise, we're gonna keep looking at the help 00:28:39.000 |
'cause I wanna show you how I look at the help. 00:28:44.520 |
And the idea is that you can kind of figure things out 00:28:49.280 |
So if you copy the indented bit of the example 00:28:53.080 |
and paste it, you should get the same result. 00:28:58.080 |
Now this looks pretty similar to the example we just gave, 00:29:04.160 |
but you'll see that they've got multiple numbers 00:29:20.560 |
or in kind of PyTorch speak, a rank one tensor 00:29:27.080 |
You just chuck spaces between them, between numbers. 00:29:34.240 |
So there's some controversy about whether this is accurate, 00:29:40.480 |
but I'm just gonna use the word array for everything. 00:29:56.480 |
So when I say array, I'm gonna include scalars, okay. 00:30:14.600 |
- Okay, so that is a list or this is an array 00:30:18.280 |
containing the numbers 3.2, negative seven and zero. 00:30:22.640 |
And this is the function that you're applying to it. 00:30:35.840 |
It's applying the function to every element of the array. 00:30:38.960 |
So the negative function, negate function by the 3.2 00:30:42.280 |
is negative 3.2 applied to negative seven is seven 00:30:48.360 |
- So it is a negative function, it's not the minus. 00:30:53.360 |
- Correct, this is the minus that's part of a literal number. 00:31:17.760 |
- The control two is for the special negative number symbol. 00:31:48.880 |
Do you know a way to do this automatically, by the way, 00:32:07.560 |
I think this arrow is saying that there is a dimension here. 00:32:23.200 |
there's a one and two, they have a boxes there. 00:32:48.080 |
- If you just are dealing with larger arrays. 00:32:51.600 |
So I don't know if this one is the men or the max, 00:33:18.360 |
I think you made a rank one array or a vector. 00:33:30.000 |
you can kind of see what the boxes are really about. 00:33:41.600 |
to understand the first piece of documentation. 00:34:47.360 |
And I guess we could link that to the documentation. 00:34:59.840 |
we're gonna get more information about monadic minus. 00:35:13.720 |
I'm not used to saying things with two names. 00:35:20.720 |
So when people talk about like read out APL expressions, 00:35:50.840 |
Now, notice here, this does not mean minus four to zero. 00:36:06.440 |
but space doesn't have meaning after a function. 00:36:19.480 |
And it would be more obvious if there was a space here. 00:36:43.160 |
And its whole right-hand side is a rank one array. 00:36:46.560 |
And that's why we get two goes to negative two, 00:36:52.760 |
Okay, so Isaac's just added in the chat something useful, 00:37:17.360 |
And somebody, by the way, maybe as we do these things, 00:37:19.800 |
could add these to the forum thread, to the forum wiki. 00:38:11.120 |
Okay, minus applied to four, minus applied to negative four. 00:38:16.120 |
The kind of the APL way and the AERA programming way 00:38:35.000 |
which I quite like, does involve a lot of examples. 00:38:41.000 |
Which does like require the reader to like look at the example 00:38:51.400 |
And this is what I've been doing in teaching the kids 00:38:53.320 |
some math and APL, is we look at the examples, 00:38:57.040 |
we paste them into dialogue, and then we say like, 00:39:01.880 |
And it's actually quite a good, it's quite a good exercise, 00:39:11.320 |
Okay, we got decimals, rank one arrays, one attic minus. 00:39:40.040 |
- You could temporarily close the JavaScript bar, I guess. 00:40:43.360 |
Somehow I just pressed a button to put up a terminal. 00:40:56.200 |
- And that gave me a backtick with an underline 00:40:58.640 |
and if I entered, turned into a regular backtick. 00:42:06.200 |
Okay, so normally two arguments in a function 00:42:16.840 |
looks like this unless you do what we call infix notation, 00:42:53.680 |
So just like in NumPy, you've probably noticed 00:43:09.640 |
and the function is applied to each element of the array. 00:43:12.600 |
Negative of four, negative of two, negative of zero, 00:43:16.680 |
negative of minus three, negative of minus five. 00:43:19.440 |
So we can do the same thing when it's got two arguments. 00:43:36.120 |
Three minus four, two minus five, one minus one. 00:43:51.440 |
this also works is you can have a rank one array 00:43:56.440 |
minus a scalar and just like NumPy, it'll broadcast this. 00:44:09.440 |
One minus three, one minus two, one minus one. 00:44:19.260 |
- Is there much of a culture of using brackets in this world? 00:44:24.260 |
- I wouldn't say there's a culture of using parentheses, 00:44:34.320 |
but I would say there are times you have to use parentheses. 00:44:37.540 |
I would say, I can't imagine anybody would use parentheses 00:44:42.660 |
around this, just like in Python, if you were writing, 00:44:46.940 |
oopsie dozy, if you were writing 1.5 times 6.2, 00:44:51.940 |
we know perfectly well that dot binds tighter than times. 00:44:56.300 |
So in Python, nobody would write this, right? 00:45:00.540 |
Well, somebody who didn't know that dot binds tighter 00:45:04.420 |
than asterix would say like, well, this is much clearer, 00:45:08.660 |
but like, yeah, you know, only the first three times 00:45:12.500 |
after that, you know perfectly well that this means 1.5 times 00:45:25.620 |
so the idea of parenthesizing this in such an expression 00:45:28.520 |
would be weird and I've never seen that done. 00:45:36.420 |
because the kind of parsing and precedence rules in APL, 00:45:46.460 |
parentheses generally only seem to be used in real code 00:45:52.820 |
when they're actually necessary rather than just for clarity. 00:46:00.060 |
we see parentheses used for clarity a lot more 00:46:02.660 |
because for example, in C++ or even in Python, 00:46:13.880 |
All right, so I feel like we've probably done 00:46:34.780 |
So maybe I'll just do some copying and pasting 00:46:40.500 |
in fact, that's a good way to get a back tick 00:47:07.940 |
and the overall thing is called plus sign, that's easy, 00:47:12.500 |
plus sign and monadic is called conjugate, conjugate 00:47:17.500 |
and this is called, oh, got it the wrong way. 00:47:30.940 |
I know that's fine, I just have to write dyadic, dyadic. 00:47:37.840 |
Maybe I'll make a copy of this underneath the next time. 00:47:41.520 |
Okay, so we can basically do the same thing as last time, 00:47:46.520 |
paste those here and we will replace dash with plus 00:48:05.380 |
rank one array plus a scalar which is a rank zero array 00:48:20.340 |
So it's pretty normal in APL to provide a rank one array 00:48:34.680 |
to an example, because that way you kind of get 00:48:40.400 |
So it's important to just look at them one at a time. 00:48:50.460 |
we can like do that, but like we shouldn't need 00:48:56.600 |
to do this for too long because hopefully we've got the idea 00:48:59.920 |
that to read this, it means plus 1.2 plus zero J4 00:49:11.560 |
which means I think we need to talk about complex numbers, 00:49:14.600 |
which is cool because we get to talk about some math. 00:49:57.200 |
that the square root of minus one is something called I? 00:50:22.080 |
we can square things, which means multiply by itself. 00:50:41.520 |
We'll get ahead of ourselves a little bit and no, 00:50:49.220 |
So to write squared, we can also say to the power of two. 00:50:54.220 |
Be very careful, this means power of in APL, not times. 00:51:23.680 |
'cause negative four, negative four squared is also 16. 00:51:34.600 |
Okay, so the question of like, what do you have to square 00:51:41.320 |
So the square root of 16, and we always take the positive, 00:51:47.880 |
So then the question is, what's the square root of minus one? 00:51:51.040 |
And the answer is, oh, it's the number that you would have 00:51:54.760 |
Which of course doesn't exist as a real number. 00:51:58.400 |
Because minus one times minus one is positive one. 00:52:06.840 |
I'm gonna invent a number, I'm gonna call it I. 00:52:17.680 |
but I also can't show you negative three pineapples, 00:52:24.220 |
I mean, I can't even show you the number two. 00:52:27.000 |
I can show you the digit two, I can show you two things, 00:52:29.360 |
but the idea of the number two is a mathematical concept. 00:52:37.260 |
And so a lot of mathematicians say I is considered, 00:52:45.020 |
but it's not any more imaginary than any other number 00:52:49.880 |
Okay, so you can then create something called 00:52:57.320 |
a complex number, which is an imaginary number 00:53:04.960 |
A real number being anything that doesn't have I in it. 00:53:14.880 |
And so that means that this here is a complex number 00:53:17.560 |
and there's no way to like reduce that further. 00:53:25.720 |
You can do things with I, you can multiply it by four 00:53:31.480 |
and then four times I is four I, that's a number. 00:53:36.480 |
You can square it and of course you'd get minus one, 00:53:41.040 |
I squared is minus one, you can multiply I by four 00:53:46.040 |
and then add three and that gives you the number 00:53:51.360 |
So here is the real part and here's the imaginary part. 00:53:55.680 |
And the whole thing is called a complex number. 00:54:18.080 |
On the right-hand side is the imaginary part. 00:54:20.360 |
So this is zero plus four I, also known as four I. 00:54:53.080 |
oh, there's a second bunch of things in the world. 00:55:02.520 |
is because you take the number line that we all learned, 00:55:05.720 |
like my daughter learned the lumber line in prep, right? 00:55:11.000 |
to get bigger numbers and backward to get smaller numbers. 00:55:22.480 |
you move from a number line to a number plane. 00:55:30.040 |
And the Y-axis represents how many I's do you have? 00:55:33.400 |
And the X-axis represents what the real number is. 00:55:37.460 |
And so then you can graph it on a Cartesian plane. 00:55:53.000 |
- Jeremy, I think you're not sharing the screen. 00:55:58.800 |
That's just how I am until you're surrounded, tell me to. 00:57:10.120 |
which kind of expand the world of math to two dimensions. 00:57:20.440 |
And they let us work with tuples of two things at a time. 00:57:35.660 |
it turns out that our actual real physical world 00:57:38.860 |
operates according to the laws of complex numbers, 00:57:56.320 |
- Sure, it kind of feels like a complex number. 00:57:58.680 |
It's like a shorthand for representing like a 2D 00:58:40.320 |
we should add a forum thread about complex numbers 00:58:54.240 |
which I think is an interesting and good one, 00:58:55.800 |
which is, can you explain what your motivations are 00:59:01.440 |
What kind of real world applications are there? 00:59:05.280 |
Where this being array programming and APL, I guess. 00:59:22.900 |
which is what are the real world applications of this? 00:59:26.260 |
There certainly are some, at least indirectly, 00:59:31.340 |
but I'd also say, yeah, it's not my only reason 00:59:35.260 |
for being interested is not just real world applications, 00:59:46.420 |
I think it's like a field that can contain a lot of beauty 00:59:56.900 |
but I'd also say it's an area that frustrates me. 01:00:02.140 |
Math frustrates me because I find it very kind of inconsistent, 01:00:10.500 |
and the notation is often very hard to look up, 01:00:24.900 |
So one thing for me is it helps me understand math. 01:00:36.140 |
and there are things which I was finding difficult 01:00:38.660 |
to teach her until I started teaching her with APL 01:00:46.940 |
In particular, sequences in series was the first one 01:00:57.060 |
I did a whole hour on it, then we made no progress at all, 01:01:04.780 |
some NumPy and some APL and then coming back a week later 01:01:10.420 |
So yeah, so one is, you know, I think a way into math, 01:01:28.100 |
In our last study group we talked about the power 01:01:32.100 |
of the notation that is regular expressions, for example. 01:01:35.180 |
Now APL is a much deeper notation than regular expressions, 01:01:40.180 |
but like notation, a powerful notation is a key thing used 01:01:45.820 |
to further human intellectual development, you know? 01:01:49.420 |
And you'll see this repeatedly, particularly in mathematics, 01:02:00.860 |
then somebody finds a notation for that thing 01:02:12.260 |
The notation of numerals that includes the digit zero 01:02:23.500 |
But you know, other areas like juggling, you know, 01:02:28.380 |
there was a development of a notation for juggling 01:02:30.620 |
a few years ago and suddenly there was huge developments 01:02:34.500 |
in what people were doing 'cause they were able 01:02:41.100 |
Or you know, you start to create ways to manipulate 01:02:44.620 |
the symbols in the notation to develop new ideas. 01:02:48.500 |
So you know, APL is a very powerful notation, 01:02:56.100 |
that can be represented using the similar kind of concepts 01:03:00.540 |
For example, one guy has built a GPU compiler using APL 01:03:05.100 |
and they did their PhD essentially in like APL 01:03:14.740 |
At a more pragmatic level, so I learned a little bit of J 01:03:19.380 |
before I did any APL, but J is much the same thing. 01:03:23.420 |
Yeah, I definitely felt like learning J did more 01:03:26.940 |
for my programming skills than any other language 01:03:30.420 |
I've learned because APL as a notation was developed 01:03:35.420 |
in the late 1950s and so it's been continually developed 01:03:47.180 |
of independent branch to all the other computer languages. 01:03:52.100 |
So APL, JK, the array languages have their own little world. 01:03:56.020 |
And so if you've not worked with languages from that branch, 01:04:01.020 |
you miss out on that entire development of thinking. 01:04:08.180 |
Now we'll say nowadays, numpy and derivatives of that 01:04:25.380 |
So I would say also like for somebody doing deep learning 01:04:35.380 |
yeah, I think you'll discover better ways of thinking 01:04:46.180 |
like Einstein notation or INOPS or stuff like that. 01:04:53.580 |
Does anybody else have any other kind of reasons 01:04:55.220 |
that were interested in this or questions about that 01:05:02.300 |
- I guess for me, it's just a different way of thinking. 01:05:12.700 |
I mean, it's always a case you get a big speed up 01:05:17.780 |
if you can remove a loop and vectorize things 01:06:07.380 |
which are really interestingly kind of thoughtfully 01:06:16.300 |
some pretty interesting mind bending ideas for mathematics. 01:06:57.420 |
We've already done, not sharing the screen of course. 01:07:03.980 |
I'm not sharing my screen 'cause I never remember. 01:07:41.700 |
And basically it shows that we start with a number y, 01:07:46.300 |
we apply plus to it and the return value of it 01:07:50.380 |
is something called r for result or return value. 01:07:55.260 |
it's gonna tell me what each of these things are. 01:08:00.860 |
then r the result is y with the imaginary part 01:08:18.100 |
So the return value should be unchanged, it is. 01:08:34.740 |
and this is the imaginary part and here that is negated. 01:08:38.940 |
So if you think about it on the number plane, 01:09:09.780 |
Does anybody have any questions, issues, anything else? 01:09:17.380 |
Anything you wanna make sure we cover next time? 01:09:32.460 |
What do we got, 21 participants, that's good. 01:09:35.940 |
- Yeah, I think this is gonna be a lot of fun 01:09:40.780 |
Yeah, so I think, you know, like we actually got through 01:09:46.940 |
And I do think we might be able to zip through the glyphs 01:09:59.700 |
have some reasonable Python background, by the way. 01:10:03.620 |
And so sometimes we'll be relying on analogies to Python. 01:10:08.620 |
And that should make things a bit faster as well. 01:10:14.700 |
All right, I'm gonna, yeah, I'll pop the videos up on YouTube. 01:10:38.180 |
related to array programming that aren't necessarily 01:10:41.140 |
directly related to anything we've talked about, whatever.