From a9aa00567a448746beece0fd605b29fadb64686c Mon Sep 17 00:00:00 2001 From: jim Date: Sat, 7 Feb 2015 13:11:13 -0500 Subject: [PATCH] refine notes --- topics/week2_lambda_intro.mdwn | 85 +++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/topics/week2_lambda_intro.mdwn b/topics/week2_lambda_intro.mdwn index 486a75b4..3718d317 100644 --- a/topics/week2_lambda_intro.mdwn +++ b/topics/week2_lambda_intro.mdwn @@ -1,13 +1,12 @@ -## Syntax of Lambda Calculus ## +# Introduction to the Lambda Calculus # We often talk about "*the* Lambda Calculus", as if there were just one; but in fact, there are many, many variations. The one we will start with, and will explore in some detail, is often called "the pure" -or "the untyped" Lambda Calculus. Actually, there are many variations even under -that heading. But all of the variations share a strong family +or "the untyped" Lambda Calculus. Actually, there are many variations even under that heading. But all of the variations share a strong family resemblance, so what we learn now will apply to all of them. -> Fussy note: calling this/these the "pure" lambda calculus is entrenched terminology, +> Fussy note: calling this the "pure" Lambda Calculus is entrenched terminology, but it coheres imperfectly with other uses of "pure" we'll encounter. There are three respects in which the lambda calculus we'll be presenting might claim to deserve the name "pure": (1) it has no pre-defined constants and a very spare @@ -15,16 +14,12 @@ syntax; (2) it has no types; (3) it has no side-effects, and is insensitive to the order of evaluation. > Sense (3) corresponds most closely to the other uses of "pure" you'll -see in the surrounding literature. With respect to this point, it may be true that -this lambda calculus has no side effects. (Let's revisit that assumption -at the end of term.) But as we'll see next week, it is *not* true that it's insensitive -to the order of evaluation. So if that's what we mean by "pure", this lambda -calculus isn't as pure as you might hope to get. Some *typed* lambda calculi will -turn out to be more pure in that respect. +see in the surrounding literature. With respect to this point, it may be true that the Lambda Calculus has no side effects. (Let's revisit that assumption +at the end of term.) But as we'll see next week, it is *not* true that it's insensitive to the order of evaluation. So if that's what we mean by "pure", this lambda calculus isn't as pure as you might hope to get. Some *typed* lambda calculi will turn out to be more pure in that respect. > But this lambda calculus is at least "pure" in sense (2). At least, it -doesn't *explicitly talk about* any types. Some prefer to say that this -lambda calculus *does* have types implicitly, it's just that +doesn't *explicitly talk about* any types. Some prefer to say that the +Lambda Calculus *does* have types implicitly, it's just that there's only one type, so that every expression is a member of that one type. If you say that, you have to say that functions from this type to this type also belong to this type. Which is weird... In @@ -41,13 +36,15 @@ as you might hope to get. or "the untyped" Lambda Calculus, or even just "the" Lambda Calculus, this is the system that people will understand you to be referring to. +## Syntax ## + Here is its syntax:
-Variables: x, y, z... +Variables: x, y, z ...
-Each variable is an expression. For any expressions M and N and variable a, the following are also expressions: +Each variable is an expression. For any variable `a` and (possibly complex) expressions `M` and `N`, the following are also expressions:
Abstract: (λa M) @@ -66,13 +63,13 @@ Expressions in the lambda calculus are called "terms". Here is the syntax of the lambda calculus given in the form of a context-free grammar: - T --> Var - T --> ( lambda Var T) - T --> ( T T ) - Var --> x - Var --> y - Var --> z - ... +> T --> Var +> T --> ( λ Var T) +> T --> ( T T ) +> Var --> x +> Var --> y +> Var --> z +> ... Very, very simple. @@ -107,11 +104,11 @@ called the **argument**, and `M` is called the **body**. The rule of beta-reduction permits a transition from that expression to the following: - M [a <-- N] +> M [a <-- N] What this means is just `M`, with any *free occurrences* inside `M` of the variable `a` replaced with the term `N` (--- "without capture", which -we'll explain in the [[advanced notes|FIXME]]). +we'll explain in the [[advanced notes|week2_lambda_advanced]]). What is a free occurrence? @@ -160,7 +157,7 @@ say "reduction" for one or more reduction steps. So when we write: M ~~> N -we'll mean that you can get from M to N by one or more reduction +we'll mean that you can get from `M` to `N` by one or more reduction steps. When `M` and `N` are such that there is some common term (perhaps just one @@ -171,9 +168,7 @@ like this: M <~~> N More details about the notation and metatheory of -the lambda calculus here: - -* [[topics/week2_lambda_advanced]] +the lambda calculus are in [[this week's advanced notes|topics/week2_lambda_advanced]]. ## Shorthand ## @@ -204,7 +199,7 @@ and: **Dot notation** Dot means "assume a left paren here, and the matching right -paren as far the right as possible without creating unbalanced +paren as far to the right as possible without creating unbalanced parentheses". So: \x (\y (x y)) @@ -262,10 +257,10 @@ a unique result. The lambda calculus seems to be wonderfully well-suited for representing functions. In fact, the untyped -lambda calculus is Turing Complete (see [[!wikipedia Turing Completeness]]): +lambda calculus is Turing Complete (see [[!wikipedia Turing completeness]]): all (recursively computable) functions can be represented by lambda terms. Which, by most people's lights, means that all functions we can "effectively decide" --- -that is, compute in a mechanical way without requiring any ingenuity or insight --- +that is, always apply in a mechanical way without requiring any ingenuity or insight, and be guaranteed of a correct answer after some finite number of steps --- can be represented by lambda terms. As we'll see, though, it will be fun (that is, not straightforward) unpacking how these things can be so "represented." @@ -306,7 +301,7 @@ and: (\z z) both represent the same function, the identity function. However, we said -(FIXME in the advanced notes) that we would be regarding these expressions as +[[in the advanced notes|week2_lambda_advanced]] that we would be regarding these expressions as synactically equivalent, so they aren't yet really examples of *distinct* lambda expressions representing a single function. However, all three of these are distinct lambda expressions: @@ -346,8 +341,7 @@ embodied in the lambda calculus. mathematical conception permits many *uncomputable* functions, but the lambda calculus can't express those. -2. More problematically, some lambda terms express "functions" that can take -themselves as arguments. If we wanted to represent that set-theoretically, and +2. More problematically, lambda terms express "functions" that can *take themselves* as arguments. If we wanted to represent that set-theoretically, and identified functions with their extensions, then we'd have to have some extension that contained (an ordered pair containing) itself as a member. Which we're not allowed to do in mainstream set-theory. But in the lambda calculus @@ -357,8 +351,9 @@ this is permitted and common --- and in fact will turn out to be indispensable. (\x x) (\x x) - This is a redex that reduces to the identity function (of course). We can -apply the **K** function to another argument and itself: + This is a redex that reduces to the identity function (of course). + + We can apply the **K** function to another argument and itself: > K z K @@ -376,7 +371,7 @@ In fact it *does* turn out to be possible to represent the Lambda Calculus set-theoretically. But not in the straightforward way that identifies functions with their graphs. For years, it wasn't known whether it would be possible to do this. But then [[!wikipedia Dana Scott]] figured out how to do it in late 1969, that is, -he formulated the first "denotational semantics" for this lambda calculus. +he formulated the first "denotational semantics" for this Lambda Calculus. Scott himself had expected that this wouldn't be possible to do. He argued for its unlikelihood in a paper he wrote only a month before the discovery. @@ -413,11 +408,15 @@ also count these functions: as equivalent. This additional move is called **eta-reduction**. It's crucial to eta-reduction that the outermost variable binding in the abstract we begin with (here, `\x`) be of a variable that occurs free -exactly once in the body of that abstract, and that it be in the -rightmost position. +exactly once in the body of that abstract, and that that free occurrence be the rightmost outermost constituent. + +The expression: -In the extended proof theory/theories we get be permitting eta-reduction/conversion -as well as beta-reduction, *all computable functions with the same + (\x (\y (y x)) + +can't be eta-reduced, because the rightmost outermost constituent is not `x` but `(\y (y x)`. + +In the extended proof theory/theories we get be permitting eta-reduction/conversion as well as beta-reduction, *all computable functions with the same extension do turn out to be equivalent*, that is, convertible. However, we still shouldn't assume we're working with functions @@ -437,7 +436,9 @@ evaluates to the ordered pair (2, 2). It may be helpful to think of a redex in the lambda calculus as a particular sort of `let` construction. - ((\x BODY) ARG) is analogous to + ((\x BODY) ARG) + +is analogous to let x match ARG in BODY @@ -461,7 +462,7 @@ calculus, an abstract such as `(\x (x x))` is perfectly well-formed and coherent, but it is not possible to write a `let` expression that does not have an `ARG`. That would be like: -    `let x match` *missing* +    `let x match` *missing*     `in x x` Nevertheless, the correspondence is close enough that it can guide our -- 2.11.0