These notes will recapitulate, make more precise, and to some degree expand what we did in the last hour of our first meeting, leading up to the definitions of the `factorial` and `length` functions. We begin with a decidable fragment of arithmetic. Our language has some primitive literal values: 0, 1, 2, 3, ... In fact we could get by with just the primitive literal `0` and the `succ` function, but we will make things a bit more convenient by allowing literal expressions of any natural number. We won't worry about numbers being too big for our finite computers to handle. We also have some predefined functions: succ, +, *, pred, - Again, we might be able to get by with just `succ`, and define the others in terms of it, but we'll be a bit more relaxed. Since we want to stick with natural numbers, not the whole range of integers, we'll make `pred 0` just be `0`, and `2-4` also be `0`. Here's another set of functions: ==, <, >, <=, >=, != `==` is just what we non-programmers normally express by `=`. It's a relation that holds or not between two values. Here we'll treat it as a function that takes two values as arguments and returns a *boolean* value, that is a truth-value, as a result. The reason for using the doubled `=` symbol is that the single `=` symbol tends to get used in lots of different roles in programming, so we reserve `==` to express this meaning. I will deliberately try to minimize the uses of single `=` in this made-up language (but not eliminate it entirely), to reduce ambiguity and confusion. The `==` relation---or as we're treating it here, the `==` *function* that returns a boolean value---can at least take two numbers as arguments. Probably it makes sense for it to take other kinds of values as arguments, too. For example, it should operate on two truth-values as well. Maybe we'd want it to operate on a number and a truth-value, too? and always return false in that case? What about operating on two functions? Here we encounter the difficulty that the computer can't in general *decide* when two functions are equivalent. Let's not try to sort this all out just yet. We'll suppose that `==` can at least take two numbers as arguments, or two truth-values. As mentioned in class, we represent the truth-values like this: 'true, 'false These are instances of a broader class of literal values that I called *symbolic atoms*. We'll return to them shortly. The reason we write them with an initial `'` will also be explained shortly. For now, it's enough to note that the expression: 1 + 2 == 3 evaluates to `'true`, and the expression: 1 + 0 == 3 evaluates to `'false`. Something else that evaluates to `'false` is the simple expression: 'false That is, literal values are a limiting case of expression, that evaluate to just themselves. More complex expressions like `1 + 0` don't evaluate to themselves, but rather down to literal values. The functions `succ` and `pred` come before their arguments, like this: succ 1 On the other hand, the functions `+`, `*`, `-`, `==`, and so on come in between their arguments, like this: x < y Functions of this latter sort are said to have an "infix" syntax. This is just a convenience for how we write them. Our language will have to keep rigorous track of which functions have infix syntax and which don't, but we'll just rely on context and our brains to make sense of this for now. Functions with the ordinary, non-infix syntax can take two arguments, as well. If we had defined the less-than relation (boolean function) in that style, we'd write it like this instead: lessthan? (x, y) or perhaps like this: lessthan? x y We'll get more acquainted with the difference between these next week. For now, I'll just stick to the first form. Another set of operations we have are: and, or, not The first two of these are infix functions that expect two boolean arguments, and gives a boolean result. The third is a function that expects only one boolean argument. Our earlier function `!=` means "doesn't equal", and: x != y will in general be just another way to write: not (x == y) You see that you can use parentheses in the standard way. I've started throwing in some variables. We'll say variables are any expression that starts with a lower-case letter, then is followed by a sequence of 0 or more upper- or lower-case letters, or underscores (`_`). Then at the end you can optionally have a `?` or `!` or a sequence of `'`s, understood as "prime" symbols. Hence, all of these are legal variables: x x1 x_not_y xUBERANT x' x'' x? xs We'll follow a *convention* of using variables with short names and a final `s` to represent collections like sequences (to be discussed below). But this is just a convention to help us remember what we're up to, not a strict rule of the language. We'll also follow a convention of only using variables ending in `?` to represent functions that return a boolean value. Thus, for example, `zero?` will be a function that expects a single number argument and returns a boolean corresponding to whether that number is `0`. `odd?` will be a function that expects a single number argument and returns a boolean corresponding to whether than number is odd. Above, I suggested we might use `lessthan?` to represent a function that expects *two* number arguments, and again returns a boolean result. We also conventionally reserve variables ending in `!` for a different special class of functions, that we will explain later in the course. In fact you can think of `succ` and `pred` and `not` and all the rest as also being variables; it's just that these variables have been pre-defined in our language to be bound to special functions we designated in advance. You can even think of `==` and `<` as being variables, too, bound to other functions. But I haven't given you rules yet which would make them legal variables, because they don't start with a lower-case letter. We can make the rules more liberal later. Only a few things in our language aren't variables. These include the **keywords** like `let` and `case` and so on that we'll discuss below. You can't use `let` as a variable, else the syntax of our language would become too hard to mechanically parse. (And probably too hard for our meager brains to parse, too.) The rule for symbolic atoms is that a single quote `'` followed by any single word that could be a legal variable is a symbolic atom. Thus `'false` is a symbolic atom, but so too are `'x` and `'succ`. For the time being, I'll restrict myself to only talking about the symbolic atoms `'true` and `'false`. These are a special subgroup of symbolic atoms that we call the *booleans* or *truth-values*. Nothing deep hangs on these being a subclass of a larger category in this way; it just seems elegant. Other languages sometimes make booleans their own special type, not a subclass of any other limited type. Others make them a subclass of the numbers (yuck). We will think of them this way. Note that in symbolic atoms there is no closing `'`, just a `'` at the beginning. That's enough to make the whole word, up to the next space (or whatever) count as naming a symbolic atom. We call these things symbolic *atoms* because they aren't collections. Thus numbers are also atoms, just not symbolic ones. And functions are also atoms, but again, not symbolic ones. Functions are another class of values we'll have in our language. They aren't "literal" values, though. Numbers and symbolic atoms are simple expressions in the language that evaluate to themselves. That's what we mean by calling them "literals." Functions aren't expressions in the language at all; they have to be generated from the evaluation of more complex expressions. (By the way, I really am serious about thinking of *the numbers themselves* as being expressions in this language; rather than some "numerals" that aren't themselves numbers. We can talk about this down the road. For now, don't worry about it too much.) I said we wanted to be starting with a fragment of arithmetic, so we'll keep the function values off-stage for the moment, and also all the symbolic atoms except for `'true` and `'false`. So we've got numbers, truth-values, and some functions and relations (that is, boolean functions) defined on them. We also help ourselves to a notion of bounded quantification, as in ∀`x < M.` φ, where `M` and φ are (simple or complex) expressions that evaluate to a number and a boolean, respectively. We limit ourselves to *bounded* quantification so that the fragment we're dealing with can be "effectively" or mechanically decided. (As we extend the language, we will lose that property, but it will be a topic for later discussion exactly when that happens.) As I mentioned in class, I will sometimes write ∀ x : ψ . φ in my informal metalanguage, where the ψ clause represents the quantifier's *restrictor*. Other people write this like `[`∀ x : ψ `]` φ, or in various other ways. My notation is meant to parallel the notation some linguists (for example, Heim & Kratzer) use in writing λ x : ψ . φ, where ψ clause restricts the range of arguments over which the function designated by the λ-expression is defined. Later we will see the colon used in a somewhat similar (but also somewhat different) way in our programming languages. But that's just foreshadowing. So we have bounded quantification as in ∀ `x < 10.` φ. Obviously we could also make sense of ∀ `x == 5.` φ in just the same way. This would evaluate φ but with the variable `x` now bound to the value `5`, ignoring whatever it may be bound to in broader contexts. I will express this idea in a more perspicuous vocabulary, like this: `let x be 5 in` φ. (I say `be` rather than `=` because, as I mentioned before, it's too easy for the `=` sign to get used for too many subtly different jobs.) As one of you was quick to notice in class, though, when I shift to the `let`-vocabulary, I no longer restricted myself to just the case where φ evaluates to a boolean. I also permitted myself expressions like this: let x be 5 in x + 1 which evaluates to `6`. Okay, fair enough, so I am moving beyond the ∀ `x==5.` φ idea when I do this. But the rules for how to interpret this are just a straightforward generalization of our existing understanding for how to interpret bound variables. So there's nothing fundamentally novel here. We can have multiple `let`-expressions embedded, as in: let y be (let x be 5 in x + 1) in 2 * y let x be 5 in let y be x + 1 in 2 * y both of which evaluate to `12`. When we have a stack of `let`-expressions as in the second example, I will write it like this: let x be 5; y be x + 1 in 2 * y It's okay to also write it all inline, like so: `let x be 5; y be x + 1 in 2 * y`. The `;` represents that we have a couple of `let`-bindings coming in sequence. The earlier bindings in the sequence are considered to be in effect for the later right-hand expressions in the sequence. Thus in: let x be 0 in (let x be 5; y be x + 1 in 2 * y) The `x + 1` that is evaluated to give the value that `y` gets bound to uses the (more local) binding of `x` to `5`, not the (previous, less local) binding of `x` to `0`. By the way, the parentheses in that displayed expression were just to focus your attention. It would have parsed and meant the same without them. Now we can allow ourselves to introduce λ-expressions in the following way. If a λ-expression is applied to an argument, as in: `(`λ `x.` φ`) M`, for any (simple or complex) expressions φ and `M`, this means the same as: `let x be M in` φ. That is, the argument to the λ-expression provides (when evaluated) a value for the variable `x` to be bound to, and then the result of the whole thing is whatever φ evaluates to, under that binding to `x`. If we restricted ourselves to only that usage of λ-expressions, that is when they were applied to all the arguments they're expecting, then we wouldn't have moved very far from the decidable fragment of arithmetic we began with. However, it's tempting to help ourselves to the notion (at least partly) *unapplied* λ-expressions, too. If I can make sense of what: `(`λ `x. x + 1) 5` means, then I can make sense of what: `(`λ `x. x + 1)` means, too. It's just *the function* that waits for an argument and then returns the result of `x + 1` with `x` bound to that argument. *More to come.*