From: Jim
Date: Sun, 1 Feb 2015 02:03:42 +0000 (-0500)
Subject: post initial week1 notes
X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=cf3002bccf257ebaf9f41d11f57983c35eeac571
post initial week1 notes
---
diff --git a/index.mdwn b/index.mdwn
index b81f3e9e..9a73f126 100644
--- a/index.mdwn
+++ b/index.mdwn
@@ -38,7 +38,7 @@ week's homework, for instance, before the session.
* Here is information about [[How to get the programming languages running on your computer]].
-* Here are Lecture notes for [[Week1]]; [[Assignment1]]. (*Lecture notes will be posted soon.*)
+* Here are Lecture notes for [[Week1]]; [[Assignment1]]. (*Initial lecture notes posted, but are still being written.*)
> Topics: Basics of Functional Programming
diff --git a/week1.mdwn b/week1.mdwn
new file mode 100644
index 00000000..f6595bae
--- /dev/null
+++ b/week1.mdwn
@@ -0,0 +1,102 @@
+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 and relation 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?` is a function that expects a single number argument and returns a boolean corresponding to whether that number is `0`. `odd?` is a function tha 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 rules for symbolic atoms are 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. Functions aren't expressions in the language; 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.
+
+*More to come*