Introduction to Lambda Calculus: Com S 342, Study notes of Computer Science

An overview of the lambda calculus, a mathematical formalism for expressing computation by functions. It covers church's thesis, the definition and rules of the lambda calculus, binding, free and bound variables, beta and eta reduction, currying, normal forms, and applicative-order reduction.

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-j5y
koofers-user-j5y 🇺🇸

9 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Com S 342
Introduction to the Lambda Calculus
Overview:
What is Computability? – Church’s Thesis
The Lambda Calculus
Scope and lexical address
The Church-Rosser Property
References:
Daniel P. Friedman et al., “Essentials of Programming Languages”, Second Edition,
MIT Press, 2001
H.P. Barendregt, “The Lambda Calculus – Its Syntax and Semantics”, North-
Holland, 1984
David A. Schmidt, “The Structure of Typed Programming Languages”, MIT Press,
1994
Carl A. Gunter, “Semantics of Programming Languages”, MIT Press, 1992
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Introduction to Lambda Calculus: Com S 342 and more Study notes Computer Science in PDF only on Docsity!

Introduction to the Lambda Calculus

Overview:^ „^

What is Computability? – Church’s Thesis „ The Lambda Calculus „ Scope and lexical address „ The Church-Rosser Property References:^ „^

Daniel P. Friedman et al., “Essentials of Programming Languages”, Second Edition,MIT Press, 2001 „ H.P. Barendregt, “The Lambda Calculus – Its Syntax and Semantics”, North-Holland, 1984 „ David A. Schmidt, “The Structure of Typed Programming Languages”, MIT Press, (^1994) „ Carl A. Gunter, “Semantics of Programming Languages”, MIT Press, 1992

Com S 342

What Is Computable?Problem input „ Computation is usually modeled as a mapping from inputs to outputs,carried out by a formal “machine”, or program, which processes its input ina sequence of steps. „ An “effectively computable” function is one that can be computed in a finiteamount of time using finite resources.

yes no output

“effectivelycomputable”functionprogram/machine

Turing Machine

„^ A Turing machine is an abstract representation of a computingdevice. It consists of a read/write head that scans a (possiblyinfinite) one-dimensional (bi-directional) tape divided intosquares, each of which is inscribed with a 0 or 1. „^ Computation begins with the machine, in a given "state",scanning a square. It erases what it finds there, prints a 0 or 1,moves to an adjacent square, and goes into a new state. „^ This behavior is completely determined by three parameters:^ „^

the state the machine is in, „ the number on the square it is scanning, and „ a table of instructions.

„^ Turing machine is more like a computer program (software) thana computer (hardware).

Com S 342

Example

0/^

Both specification describethe same Turing machine.

Ackermann Function

„^ The Ackermann function is the simplest example of a well-defined totalfunction which is computable but not primitive recursive. „^ The function f(x) = A(x, x), while Turing computable, grows much faster thanpolynomials or exponentials. The definition is:

A(0, y) = y + 1A(m+1, 0) = A(m, 1)A(m+1, n+1) = A(m, A(m+1, n)) Examples:

A(2, 3) = 9A(3, 5) = 253A(4, 1) = 65533A(4, 3) = 2

The Lambda Calculus

„^ Lambda calculus is a language with clear operational and denotationalsemantics capable of expressing algorithms. Also it forms a compactlanguage to denote mathematical proofs. „^ Logic provides a formal language in which mathematical statements can beformulated and provides deductive power to derive these. Type theory is aformal system, based on lambda calculus and logic, in which statements,computable functions and proofs all can be naturally represented. „^ The lambda calculus is a good medium to represent mathematics on acomputer with the aim to exchange and store reliable mathematicalknowledge.

The Scheme Syntax

::=

| (lambda () )| ( )

Examples:id^

= (lambda (x) x)

Ω^

= ((lambda (x) (x x)) (lambda (x) (x x)))

pair(x, y)

= (lambda (x) (lambda (y) (lambda (z) ((z x) y))))

Reference or Declaration

„^ In a program, variables can appear in two different ways:^ „^

as declarations: (lambda (x) …) or (let ((x …)) …)The occurrence of x in both the lambda-abstraction and the let-clauseintroduces the variable as a name for some value. In particular, in thelambda expression, the value of the variable x will be supplied when theprocedure is called, whereas in the let expression the value of the variableis determined by the value of the first “…” (init expression). „ as references: (f x y)Here all variables, f, x, y, appear as references, whose meanings aredefined by an enclosing declaration.

Binding Rules in Lambda Calculus

„^ In (lambda () ), the occurrence of is a declaration that binds all occurrences of thatvariable in unless some intervening declaration ofthe same variable occurs.Examples:(lambda (x) (lambda (y) (y x)))(lambda (x) (lambda (y) ((lambda (x) (lambda (y) (x y))) x) y))

Occurs Free, Occurs Bound

„^ A variable x occurs free in e if and only if there is some use of x in e, that isnot bound by any declaration of x in e. „^ A variable x occurs bound in an expression e if and only if there is some useof x in e that is bound by a declaration of x in e.Examples:((lambda (x) x) y): x is bound, but y is free(lambda (f) (lambda (x) (f x))): both f and x are boundNote: Lambda expressions with no free variables are called combinators. Everyprocedure, when applied to all its necessary arguments, is a combinator.Therefore, procedure calls are called combinations in Scheme.

The Scope of a Variable

„^ Problem:

For each variable reference find the corresponding declarationto which it refers. „^ This problem is easier to solve, when we ask:

Given a declaration, which variable references refer to it? „^ In the definition of programming languages, binding rules for variablestypically associate with each declaration of a variable a region of the programwithin the declaration is effective.Examples:

(lambda (x) …): The region of x is the body of the lambda expression.(define x …): The region of x is the whole program.

Blocks

„^ In lambda-calculus as in many modern programming languages regions canbe nested within each other. We call these languages block-structured, andregions are also called blocks.> (define x

; first declaration of x

(lambda (x)

; second declaration of x

(map(lambda (x)

; third declaration of x (+ x 1))

; refers to third

x)))^

; refers to second

(x `( 1 2 3))

; refers to first

Com S 342

Contour Diagrams

„^ We use contour diagrams to picture the borders of a region: „^ The lexical (or static) depth of a variable reference is the number of contourscrossed to find the associated declaration. „^ The lexical depth is used in compilers to tell how many static links to traverseto find a variable.

Environment

Lexical Address

„^ The declarations associated with a region may be numbered in the order oftheir appearance in the text. Each variable reference may then be associatedwith two numbers: its lexical depth and its position (both start with 0). „^ To illustrate lexical addresses, we replace every variable reference x with anexpression (x : d p), where d is the lexical depth and p is the declarationposition of v.

(lambda (x y)((lambda (a)((x : 1 0) ((a : 0 0) (y : 1 1))))(x : 0 0))) Note: The lexical address can be used by a compiler: lexical depth = number ofstatic links, and the lexical position = offset within activation frame.