CORNELL CS 611 - Lecture 1 Introduction

Unformatted text preview:

CS611 Lecture 1 Introduction 25 August 2006Lecturer: Dexter Kozen1 IntroductionWhat is a program? Is it just something that tells the computer what to do? Yes, but there is much moreto it than that. The basic expressions in a program must be interpreted somehow, and a program’s behaviordepends on how they are interpreted. We must have a good understanding of this interpretation, otherwiseit would be impossible to write programs that do what is intended.It may seem like a straightforward task to specify what a program is supposed to do when it executes.After all, basic instructions are pretty simple. But in fact this task is often quite subtle and difficult.Programming language features often interact in ways that are unexpected or hard to predict. Ideally itwould seem desirable to be able to determine the meaning of a program completely by the program text, butthat is not always true, as you well know if you have ever tried to port a C program from one platform toanother. Even for languages that are nominally platform-indep e ndent, meaning is not necessarily determinedby program text. For example, consider the following Java fragment.class A { static int a = B.b + 1; }class B { static int b = A.a + 1; }First of all, is this even legal Java? Yes , although no sane programmer would ever write it. So whathapp e ns when the classes are initialized? A reasonable educated guess might be that the program goes intoan infinite loop trying to initialize A.a and B.b from each other. But no, the initialization terminates withinitial values for A.a and B.b. So what are the initial values? Try it and find out, you may be surprised.Can you explain what is going on?This simple bit of pathology illustrates the difficulties that can arise in describing the meaning of pro-grams. Luckily, for the most part, these are the exception, not the rule.Programs describe computation, but they are more than just lists of instructions. They are mathemat-ical objects as well, with properties and behavior that we can attempt to described formally. For mostmathematical structures we encounter, familiar mathematical tools like sets and sequences are adequate todescribe the properties of the structure. In this course we will see some of the formal tools that have beendevelope d for describing precisely what programs are and what they do.This course is mostly about the semantics of programs and programming languages. “Semantics” isa synonym for “meaning” or “interpretation”. We want to be very precise about this notion, bec auseit is necessary for understanding the behavior of programs. It is essential not only for writing c orrectprograms, but also for building tools like compilers, optimizers, and interpreters. Understanding the meaningof programs allows us to ascertain whether these tools are implemented correctly.There are three major components to this course.• Dynamic semantics. We will study methods for describing and reasoning about what happens when aprogram runs.• Static semantics. We will also study methods for reasoning about programs before they run. Suchmethods include type checking, type inference, and static analysis. We would like to find errors inprograms as early as possible. By doing so, we can often detect errors that would otherwise show uponly at runtime, perhaps after significant damage has already been done.• Language features. We will apply methods for dynamic and static semantics to study actual languagefeatures of interest, including some interesting features that many students may have not seen before.At the start, we will mostly be characterizing the semantics of a program as a function that producesan output value(s) based on some input value(s). More generally, real programs are reac tive and interactwith their inputs arriving from the environment. Describing reactive programs is more challenging, althoughwe can view the reactive behavior of the program again as a function of the inputs it receives from theenvironment as it runs. Thus, to describe program s em antics, we will build up some mathematical tools forconstructing and reasoning about functions.11.1 Binary Relations and FunctionsDenote by A × B the set of all ordered pairs (a, b) with a ∈ A and b ∈ B. A binary relation on A × B is justa subset R ⊆ A × B. The sets A and B can be the same, but they do not have to be. The set A is calledthe domain and B the codomain (or range) of R. The smallest binary relation on A × B is the null relation∅ consisting of no pairs, and the largest binary relation on A × B is A × B itself. The identity relation on Ais ID = {(a, a) | a ∈ A} ⊆ A × A.An imp ortant operation on binary relations is relational compositionR; S = {(a, c) | ∃b (a, b) ∈ R ∧ (b, c) ∈ S},where the codomain of R is the same as the domain of S.A (tot al) function (or map) is a binary relation f ⊆ A × B in which each ele ment of A is associated withexactly one element of B. There can be more than one element of A associated with the same element of B.If f is such a function, we write:f : A → BIn other words, a function f : A → B is a binary relation f ⊆ A × B such that for each element a ∈ A, thereis exactly one pair (a, b) ∈ f with first component a.The set A is the domain and B is the codomain or range of f. The image of f is the set of elements inB that come from at least one element in A under f:image(f) = {x ∈ B | x = f(a) for some a ∈ A}= {f(a) | a ∈ A}.This is also sometimes denoted f(A), although this is an abuse of notation.A partial function f : A * B is a function f : A0→ B defined on some subset A0⊆ A. The notationdom(f) refers to A0, the domain of f.A function f : A → B is said to be one-to-one (or injective) if a 6= b implies f (a) 6= f (b) and onto (orsurjective) if every b ∈ B is f (a) for some a ∈ A.1.2 Representation of FunctionsMathematically, a function is equal to its extension, which is the set of all its (input, output) pairs. Oneway to describe a function is to describe its extension directly, usually by specifying some mathematicalrelationship between the inputs and outputs. This is called an extensional representation. Another way isto give an intensional1representation, which is essentially a program or evaluation procedure to computethe output corresponding to a given input. The main differences are1. there can be more than one intensional representation of the same function, but there is only oneextension;2. intensional


View Full Document

CORNELL CS 611 - Lecture 1 Introduction

Download Lecture 1 Introduction
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 1 Introduction and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 1 Introduction 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?