 That's what we'll say to that, and we'll know something happened. In the meantime, should I come to class? There's the list of explanations. Missing all the good jokes. Okay, so let's... Before we start, I'm trying... So, A, have you heard of Lambda Calculus before? Yes. Nose and yeses. Okay. Yeah, I'm recording. No, is this the PowerPoints online? No, not yet. I didn't know if I'd get to it today or not. I'm making good progress. Okay. So, let's try to... We're going to come at this with a completely fresh, new, different mindset. Right? So, it's not bringing packages like, oh my god, Calculus in college, like there's no integrals, something like that. It just describes a way of performing computation. So, then the Lambda is the character that we're going to use. So, actually, this is great. You only need to ever use with this one Greek symbol. And that's Lambda. And it's actually really easy to draw to, right? Yeah. Which is a super awesome benefit. Okay. Also, before we start, I should be very clear. We're actually going to go into some pretty cool, like, formal stuff. So, we're going to... So, you've studied Turing machines. Right? So, why do we study Turing machines? Do you program on a Turing machine? Yeah. Yeah? Do you program on a Turing machine? Yes. I was laughing. Oh. Anybody program on a Turing machine? No. No. Why do we study Turing machines? Because we tell you to have professors. That's what you're supposed to say. But why do we do that? Because they're just as powerful and expressive as the algorithms that we study. Yeah. Right? So, a Turing machine is great because it allows us to have representation without worrying about a machine. Right? And currently, smart people have showed, actually, that awesome HP laptop that you have or your iPhone still can't... Fundamentally, can't do anything more than a Turing machine. It just doesn't quicker. It does it quicker, and it actually exists. Those are two big differences, right? Turing machine has infinite tape and infinite memory, which doesn't exist in any system ever yet. Right? So, it helps us think about what types of things can we compute. Right? We know if we can do it for a Turing machine, then we can write a program to do it. Right? And so that helps us think about what is possible. Right? This is actually getting more into the computer science of computer science. Right? That's like, there's the famous quote that computer science is about computers like astronomy is about telescopes. Right? We're actually talking about computation more abstractly than the computer or programming. Right? We programmed to instantiate that and to get the computers and the machines to actually do something. Right? But that's not necessary. So, why I want to talk about that is Lambda Calculus is a different way of thinking about computations. So, it's actually... People have shown that you can express a Turing machine with Lambda Calculus and you can express Lambda Calculus with a Turing machine. So, it's... In that sense, it is just as expressive, right? So, anything you can do with Lambda Calculus, you can do with a Turing machine, you can do with your computer. And I'll actually make an argument as we go into this that actually Lambda Calculus is a lot closer to some family of programming languages. Right? So, if you can understand kind of how Lambda Calculus works, this actually can help you. It's actually much more applicable. So, you can write programs where you talk about read-in one and move the tape right or left. But here, we talk about function applications and defining functions and invoking functions, calling functions, and we have functions, returning functions, which is kind of what you're doing in homework four. But also, even the syntax is actually very similar to Lisp and the Lisp and Scheme family of languages. That's actually because they're derived from here, but it's actually a real programming language that you can do a lot of really cool stuff in. Okay, question before we get started. So, the other really cool thing that I like about it is that, like I said, Turing machine, right, is like read something and move left or right and read or write something else, right? Those are the fundamental operations. But that really, what applicability does that have to you in your life as a programmer? Almost nothing, right? I mean, you just don't write programs and write zero or one and move in a direction, right? That doesn't really make sense. What do you use most often? Well, what do you hopefully use as a good software engineering technique most often? What was that, a debugger? Okay. But like, how do you construct your programs with your fingers typing, yes? Also that, huh? Incremental, yeah, you incrementally develop it. Do you just have it in like one thing that was like, do all this stuff? Probably. Yes? You're gonna have trouble. Functionally? Yeah, or functionally or object, right? You separate some of that functionality and you encapsulate it so that it can be reused, right? And so, let me calculate this, when you boil it down, the fundamental structure here is functions and function applications. So in this aspect, it actually does mimic programming very well, right? Okay, you can define, can you define functions in a Turing machine? I think kind of you can, but not in the language itself, right? The language doesn't really support that, right? I mean, I think you can have your go-to state and your program go somewhere else, yeah? Yeah, yeah, you can, but it's not, it doesn't feel clean and it doesn't feel like what you do in your daily programming life, right? You define functions, those functions accept parameters and they do some computation and that's all, right? So this is, and this is the crazy thing, is lambda calculus, the only things you can do are define functions and apply functions. That's it. Those are the, there's no addition operator, nothing. But it is still as expressive as a Turing machine. You can still do every, it's actually kind of crazy, right? Everything you want to do on a computer, can be done with using functions and applying functions, which is exactly how you think about programming normally. So the key thing is that you have the ability to apply anonymous functions, right? So what does anonymous function mean? A function without a name, yes. It's kind of like the start of a Western, right? A name with no name, walked into a solar place, right? So these are the two key things. We can define anonymous functions. We actually can't even give functions names, but we can define anonymous functions and we can apply those functions. So what do we see that applying functions mean? Project four, a homework four. There's like a node that says apply, what does that mean? To use or invoke, right? We can define anonymous functions and we can invoke those functions. Those are the only things we can do, but we can still do everything possible that you can do in any programming language. And so ML, Haskell, F-sharp closure, there's a lot of kind of functional programming and also the Lisp family of languages derive and get a lot of inspiration from Lambda calculus. Is Lisp another one of them? Yes, Lisp actually follows almost directly as we'll see. So if you've ever done any Lisp or scheme programming, the syntax is actually exactly the same here with Lambda calculus. We have parentheses that we use to delineate our structures, but we're not there yet, we're still a little bit. Okay, so some history. I should also, did I already say this? I don't think I said it yet. So I don't have a crazy strong theoretical background. I'm a hacker really fundamentally. This is why some of your cries for me to teach 355 or something go unanswered because that is not, I don't have that formal mathematical background. But I still really like Lambda calculus even though we're going to talk about it really formally because it is very intuitive and it has very clear relations to programming languages and I think it's going to help you think about languages and how you program. I think it's going to help you think about it differently. But with all that said, so if you see something that's wrong or you think isn't correct, like ask me. And I'll try to, we'll try to answer it. Okay. So actually the study, this is actually kind of crazy. So back in 19, sorry, 1893 I'm going to butcher all these names. You said you did German, can you Frege? Frege? I think it's a German name. Frege? That sounds French. But anyways he first studied the use of functions in logic. So they were trying to understand logic, right? So you've, I believe you've taken classes on logic, right? First-order logic, Boolean logic, right? And so he was interested in trying to study well how do we, what do functions mean in logic? How can we use that there? Then in the 20s, Schunthengel in the 1920s he studied how combinators which are kind of what we're going to get to are a very specific type of function and how those can be applied to formal logic. And they started to see that like, wow, actually this logic like ands, ors, can actually be applied and used using functions which seems kind of crazy, right? Why would there be a relation between? So what's a mathematical function? Okay, that is an example of a mathematical function. Yes. But what does a function like mean? A set of ordered pairs. A set of ordered pairs. Yeah, so I like to think of it as a mapping, right? So you have you can think about it as ordered pairs, right? Match one thing to another thing. If you have more tuples or whatever, then you're mapping some of the input to some of the output, right? So all a function does is map things, right? And they started to see that like actually with this mapping, you can actually do logic and you can do first-order logic and all kinds of logic. Church in 1930, so Alfonzo Church introduced Lambda Calculus and unfortunately this is what happens sometimes when you do things with research Clean, who remembers Clean, or is it Cleaning? I actually can't remember. Was it Cleaning? Yeah. He did the Cleaning Star, right? From regular expressions. So Cleaning and Rosser, they showed that actually the original Lambda Calculus was logically inconsistent, which kind of sucks because you spent your whole time developing this Calculus that I'm going to show you. So then in 1936, he Church revised it and published Lambda Calculus and that's kind of one of his first relevant to computation. And it's been even refined further. So people have added type systems and done all kinds of additions to Lambda Calculus. And even as we'll see this kind of turned into some modernish programming languages like with Lisp. So the idea is going to stem from here. Okay. So we're going to treat this like we're learning a new programming language. So it's essentially what we're doing. So what do we need to know to learn a new programming language? What does that mean? We need syntax which defines what a valid program looks like and what else? What was that? Semantics. Yeah, we need this semantics, right? Which goes over all those things that everyone was saying, right? We need to understand how to write a valid program in this language which is the syntax, right? And which now you all know how to write a parser to validate the syntax against a grammar. And we also need to know the semantics. What does it actually mean? What does, when I say it defines an anonymous function, what does that actually mean? Oh, I thought that was you had a question. So we're going to start off, our syntax is actually going to be incredibly simple which is actually one of the benefits of, and I'm going to keep talking about Lisp because I actually really like it a lot, but it's actually one of the benefits of a Lisp-like language is that the syntax is incredibly simple, right? Yes, it's incredible, and that actually has really good metaprogramming capabilities in using Lisp with macros, but that's the good thing about that. So an expression can either be an ID, so it's our base case, an expression can be lambda-id dot-expression, or an expression can be expression, space expression, and then we want some disambiguation rules, so we want to be able to use parentheses to group expressions. So an expression can be any one of these four things. These are the only four things that an expression can be. Does anybody recall this syntax for C along that is? Or the syntax for your project 5 language or project 4 language? It's a lot more complex involved, but that's all you need. That's the whole language? This is the entire language, the syntax of the language. And it's... Really, it's crazy. This can do any type of computation you want, just with this. What do these things mean? It doesn't matter yet. We haven't talked about what they mean. We need to make sure that we understand the syntax just like when we learn regular expressions. We need to go over the syntax of regular expressions, and then we get into what do regular expressions mean. So here's our language. So is this an expression in lambda calculus? Yes, by rule 1. Is this a valid expression in lambda calculus? Look how easy the lambda is to do. It's kind of like a crooked H, almost. What was that? Or an upside down Y, that's the other way. But it's a little too... Oh, yeah. And then reversed. It's not quite an upside down Y. Maybe in a mirror. Okay. Is this a lambda expression? An expression in lambda calculus? Yes. Is this... What's missing? What's wrong? What? Right, so we have a first lambda. We need an ID and then a dot. Right? So here, this is not a valid lambda expression. Here we have lambda x dot yz. Yeah, so what's the question? Let's go back to your original question before you answer it. So I was wondering how you could have two ID since you did it. Right. The second rule gives us lambda id dot expression. And we have expression is an expression and an expression. Then we have each of those as an ID. But is that... well, let's kind of peek forward a little bit. Is that the only way to parse that string? What's the other way? I'm not a computer. Right? So it's going to be that we have lambda id dot... What if this is the expression? Right? And so the outer one is expression, expression. So basically the question is, is this y associated with this rule or is that yz associated with this expression, right? So we'll get into actually how to disambiguate this. But I want you to realize that yes, this grammar is incredibly simple, right? Can you tell me? Yes. Yeah, so at the top, rule 3 says this is expression and this whole thing is an expression, right? And then rule 2 says that this is lambda id dot expression. And we know that this is an expression because of rule 4. And then we see we have expression, space expression, because of the parentheses. And then here we have expression and expression. Right? But we have clearly ambiguous syntax, right? So how to parse this, x, y, z? What are the two different ways? Yeah, so we have expression goes to expression z and then expression goes to x, y. Or the other way around. We have expression where x is on the left and then we have expression where y and z. So those that have looked at Project 5 bonus project. Why does the Project 5 bonus project handle this? Versus expression is just like this, right? It never has recursion, right? So like in Project 5, normally you can't have an arbitrary long expression, right? You just have something plus something. Right? You can't do something plus something plus something plus something plus something. Something plus something times something divided by something else. What's the first rule? What first rule? And like what by parsing through each line you take the first rule that applies to that and then you continue on like in the line of Project 5. Yes, but you need to know how I need to know which parser to create from this string, right? So like from 5 plus 2 times 3 I should by my knowledge of math, right? It should be first 5 times 3 because that's higher precedence than the plus. So you either need to specify that specifically, like by having disambiguation rules outside the grammar or you can change the grammar. So good practice. Look at Project 5 grammar, the bonus of Project 5 grammar. See how that supports it. How that grammar supports it. Okay, more examples, right? We saw how to parse this lambda x dot x y. We know that this is a valid is valid by the syntax but we don't know exactly what parser to create, right? One of the examples is we have expression lambda x expression and then we have expression x expression y or expression expression as the first one and then on the right we have y and on the other side we have lambda x x. Does that make sense? This is the example we saw so these are the two different ways to parse that string. The first one is we are going to add some disambiguation rules outside the grammar. So these are important, these are going to be something that we all are going to agree on by fiat because I said so. Right? So the first one, right, if we have e goes to ee it's going to be left associated. So using parentheses to disambiguate x, y, z we know that it's going to first do x, y and then z. This is how it's going to parse. Now remember we don't know exactly what it's going to do, right? But we know this is how we're going to parse it. We're first well, this thing is lower down on the tree, right? x, z and then y. So we can extend this with w, x, y, z this will be what? w, x, y, z so it will be w, x, like this and then y, z. Is that left, left associated? Yeah, so it's going to build it out like this. Right? Left associated just means we always go left most, right? So we do the left most here and we say oh it's still ambiguous, right? So we do the left most of this one. The same rules applies over and over. Okay. So we're going to write lambda id dot expression. So the idea is we're going to extend as far to the right as possible starting with lambda id dot. So for instance here x and y are both going to be part of the expression. Right? When we write it like this lambda dot x, y this means the same thing as lambda x dot parentheses x, y. Just like when we see this lambda x dot, lambda x dot x. Right? This inner one is going to be just x. And the outer one is going to include this expression in here. Let's stop here for now and on Monday we're going to get into more examples of these. Okay, let's preview something really quickly because I want to get why this is really important to understand. We need to be able to understand things like this just by looking at it. What's with the we'll get there when we get there but this is just something like this too. We need to understand exactly what this does syntax. It's like a programming language. You have to understand and know how to parse it. Yes. So I'll do either Monday or Tuesday I will do Monday. On Monday I'll give a practice midterm over that on Wednesday. So if there's anything on the practice midterm for practice this, then you would assume that there will be something like that on the midterm. It just takes a little time. It actually would be really good. This is really good timing because we can get familiar with regular expressions and disambiguation rules first before we get into all this. You don't sound convinced. Let's see, where's another really good one? I'll have the white comment here. Yeah, that's good one. I'll just go on to this.