COSE312: Compilers. Lecture 14 Semantic Analysis (4)

Similar documents
AAA616: Program Analysis. Lecture 3 Denotational Semantics

Lecture 2. Least Fixed Points

CS422 - Programming Language Design

What does the partial order "mean"?

Semantics and Verification of Software

Denotational Semantics

CS 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers. 1 Complete partial orders (CPOs) 2 Least fixed points of functions

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Denotational Semantics

Semantics and Verification of Software

Denotational Semantics of Programs. : SimpleExp N.

The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

Formal Techniques for Software Engineering: Denotational Semantics

Denotational Semantics

Denotational Semantics

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Introduction to Axiomatic Semantics

CMSC 631 Program Analysis and Understanding Fall Abstract Interpretation

The Knaster-Tarski Fixed Point Theorem for Complete Partial Orders

Towards a Denotational Semantics for Discrete-Event Systems

Consistency of a Programming Logic for a Version of PCF Using Domain Theory

Reading: Chapter 9.3. Carnegie Mellon

COSE312: Compilers. Lecture 17 Intermediate Representation (2)

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

Appendix A. Definitions for Ordered Sets. The appendices contain all the formal definitions, propositions and proofs for

Goal. Partially-ordered set. Game plan 2/2/2013. Solving fixpoint equations

Complete Partial Orders, PCF, and Control

A strongly rigid binary relation

06 Recursive Definition and Inductive Proof

Lecture 1: Lattice(I)

arxiv: v1 [cs.pl] 19 May 2016

Semantics with Applications: Model-Based Program Analysis

Least Fixpoints Calculationally

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

Logic Michælmas 2003

Functions as Relations

Lecture Notes: Selected Topics in Discrete Structures. Ulf Nilsson

ADVANCED CALCULUS - MTH433 LECTURE 4 - FINITE AND INFINITE SETS

CORES OF ALEXANDROFF SPACES

Exam Practice Problems

CS611 Lecture 18 Fixed Points and CPOs

CVO103: Programming Languages. Lecture 2 Inductive Definitions (2)

Mathematical Foundations of Logic and Functional Programming

AAA615: Formal Methods. Lecture 2 First-Order Logic

Well-Ordering Principle. Axiom: Every nonempty subset of Z + has a least element. That is, if S Z + and S, then S has a smallest element.

MIT Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

1.2 Posets and Zorn s Lemma

Concrete Domains. Gilles Kahn INRIA Sophia Antipolis Gordon D. Plotkin University of Edinburgh

(1) Which of the following are propositions? If it is a proposition, determine its truth value: A propositional function, but not a proposition.

Logical Connectives and Quantifiers

Sets and Motivation for Boolean algebra

MAT 570 REAL ANALYSIS LECTURE NOTES. Contents. 1. Sets Functions Countability Axiom of choice Equivalence relations 9

Economics 204 Fall 2011 Problem Set 2 Suggested Solutions

Chapter-2 Relations and Functions. Miscellaneous

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

1. Introduction and preliminaries

Sets, Models and Proofs. I. Moerdijk and J. van Oosten Department of Mathematics Utrecht University

MATH 409 Advanced Calculus I Lecture 12: Uniform continuity. Exponential functions.

Completeness of Star-Continuity

DEPARTMENT OF MATHEMATICS. MA1301 Discrete Mathematics

A Logician s Toolbox

Closure operators on sets and algebraic lattices

Introduction to Kleene Algebras

3 FUNCTIONS. 3.1 Definition and Basic Properties. c Dr Oksana Shatalov, Spring

Lecture 5: Functions : Images, Compositions, Inverses

Applications of Regular Algebra to Language Theory Problems. Roland Backhouse February 2001

An Abstract Interpretation Framework for Semantics and Diagnosis of Lazy Functional-Logic Languages

Part II. Logic and Set Theory. Year

An Introduction to the Theory of Lattice

Definition: For nonempty sets X and Y, a function, f, from X to Y is a relation that associates with each element of X exactly one element of Y.

Walker Ray Econ 204 Problem Set 3 Suggested Solutions August 6, 2015

Axioms of separation

Dataflow Analysis. Chapter 9, Section 9.2, 9.3, 9.4

Algebras. Larry Moss Indiana University, Bloomington. TACL 13 Summer School, Vanderbilt University

«Mathematical foundations: (6) Abstraction Part II» Exact fixpoint abstraction. Property transformer abstraction

D-MATH Algebra I HS18 Prof. Rahul Pandharipande. Solution 1. Arithmetic, Zorn s Lemma.

Properties of the Integers

a + b = b + a and a b = b a. (a + b) + c = a + (b + c) and (a b) c = a (b c). a (b + c) = a b + a c and (a + b) c = a c + b c.

Cardinality and ordinal numbers

1 Initial Notation and Definitions

CMSC 631 Program Analysis and Understanding. Spring Data Flow Analysis

Class Notes on Poset Theory Johan G. Belinfante Revised 1995 May 21

Group. Orders. Review. Orders: example. Subgroups. Theorem: Let x be an element of G. The order of x divides the order of G

0 Sets and Induction. Sets

Discrete Mathematics. Spring 2017

MATH 104: INTRODUCTORY ANALYSIS SPRING 2008/09 PROBLEM SET 8 SOLUTIONS

Denotational semantics

2. Isometries and Rigid Motions of the Real Line

Monoids of languages, monoids of reflexive. relations and ordered monoids. Ganna Kudryavtseva. June 22, 2010

Conceptual Connections of Circularity and Category Theory

Abstract Interpretation (Non-Standard Semantics) a.k.a. Picking The Right Abstraction

Semantics of Higher-Order Functional Programming

Structure of R. Chapter Algebraic and Order Properties of R

ASSIGNMENT 1 SOLUTIONS

Math 455 Some notes on Cardinality and Transfinite Induction

(Pre-)Algebras for Linguistics

arxiv: v4 [math.fa] 27 Jan 2010

MAD 3105 PRACTICE TEST 2 SOLUTIONS

Mathematical Background and Basic Notations

Transcription:

COSE312: Compilers Lecture 14 Semantic Analysis (4) Hakjoo Oh 2017 Spring Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 1 / 30

Denotational Semantics In denotational semantics, we are interested in the mathematical meaning of a program. Compositional semantics: The meaning of an expression is defined with the meanings of its immediate subexpressions. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 2 / 30

Denotational Semantics of Expressions a n x a 1 + a 2 a 1 a 2 a 1 a 2 b true false a 1 = a 2 a 1 a 2 b b 1 b 2 c x := a skip c 1; c 2 if b c 1 c 2 while b c A[[ a ]] : State Z A[[ n ]](s) = n A[[ x ]](s) = s(x) A[[ a 1 + a 2 ]](s) = A[[ a 1 ]](s) + A[[ a 2 ]](s) A[[ a 1 a 2 ]](s) = A[[ a 1 ]](s) A[[ a 2 ]](s) A[[ a 1 a 2 ]](s) = A[[ a 1 ]](s) A[[ a 2 ]](s) B[[ b ]] : State T B[[ true ]](s) = true B[[ false ]](s) = false B[[ a 1 = a 2 ]](s) = A[[ a 1 ]](s) = A[[ a 2 ]](s) B[[ a 1 a 2 ]](s) = A[[ a 1 ]](s) A[[ a 2 ]](s) B[[ b ]](s) = B[[ b ]](s) = false B[[ b 1 b 2 ]](s) = B[[ b 1 ]](s) B[[ b 2 ]](s) Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 3 / 30

Denotational Semantics of Commands where C [ x := a ](s) = s[x A [ a ](s)] C [ skip ] = id C [ c 1 ; c 2 ] = C [ c 2 ] C [ c 1 ] C [ if b c 1 c 2 ] = cond(b [ b ], C [ c 1 ], C [ c 2 ]) C [ while b c ] = fix F { g(s) f(s) = true cond(f, g, h) = λs. h(h) f(s) = false F (g) = cond(b [ b ], g C [ c ], id) Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 4 / 30

Denotational Semantics of Loops Note that the meaning of the while loop is the mathematical object (i.e. partial function in State State) that satisfies the equation: C [ while b c ] = cond(b [ b ], C [ while b c ] C [ c ], id). We can rewrite the equation: where C [ while b c ] = F (C [ while b c ]) F (g) = cond(b [ b ], g C [ c ], id). The meaning of the while loop is defined to be the fixed point of F : C [ while b c ] = fix F where fix F denotes the least fixed point of F. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 5 / 30

Example while (x = 0) skip F fix F Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 6 / 30

Some Questions Does the least fixed point fix F exist? Is fix F unique? How to compute fix F? Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 7 / 30

Fixed Point Theory Theorem Let f : D D be a continuous function on a CPO D. Then f has a (unique) least fixed point, fix (f), and fix (f) = n 0 The denotational semantics is well-defined if State State is a CPO, and f n ( ). F : (State State) (State State) is a continuous function. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 8 / 30

Plan Complete Partial Order Continuous Functions Least Fixed Point Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 9 / 30

Partially Ordered Set Definition (Partial Order) We say a binary relation is a partial order on a set D iff is reflexive: p D. p p transitive: p, q, r D. p q q r = p r anti-symmetric: p, q D. p q q p = p = q We call such a pair (D, ) partially ordered set, or poset. Lemma If a partially ordered set (D, ) has a least element d, then d is unique. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 10 / 30

Exercise Let S be a non-empty set. Prove that (P(S), ) is a partially ordered set. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 11 / 30

Exercise Let X Y be the set of all partial functions from a set X to a set Y, and define f g iff Dom(f) Dom(g) x Dom(f). f(x) = g(x). Prove that (X Y, ) is a partially ordered set. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 12 / 30

Least Upper Bound Definition (Least Upper Bound) Let (D, ) be a partially ordered set and let Y be a subset of D. An upper bound of Y is an element d of D such that d Y. d d. An upper bound d of Y is a least upper bound if and only if d d for every upper bound d of Y. The least upper bound of Y is denoted by Y. Lemma If Y has a least upper bound d, then d is unique. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 13 / 30

Chain Definition (Chain) Let (D, ) be a poset and Y a subset of D. Y is called a chain if Y is totally ordered: Example y 1, y 2 Y.y 1 y 2 or y 2 y 1. Consider the poset (P({a, b, c}), ). Y 1 = {, {a}, {a, c}} Y 2 = {, {a}, {c}, {a, c}} Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 14 / 30

Complete Partial Order (CPO) Definition (CPO) A poset (D, ) is a CPO, if every chain Y D has Y D. Definition (Complete Lattice) A poset (D, ) is a complete lattice, if every subset Y D has Y D. Lemma If (D, ) is a CPO, then it has a least element given by =. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 15 / 30

Examples Example Let S be a non-empty set. Then, (P(S), ) is a CPO. The lub Y for Y is Y. The least element is. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 16 / 30

Examples Example The poset (X Y, ) of all partial functions from a set X to a set Y, equipped with the partial order Dom(f) Dom(g) x Dom(f). f(x) = g(x) is a CPO (but not a complete lattice). The lub of a chain Y is the partial function f with Dom(f) = f i Y Dom(f i) and { fn (x) x Dom(f f(x) = i ) for some f i Y undef otherwise The least element = λx.undef. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 17 / 30

Monotone Functions Definition (Monotone Functions) A function f : D E between posets is monotone iff d, d D. d d = f(d) f(d ). Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 18 / 30

Example Consider (P({a, b, c}), ) and (P({d, e}), ) and two functions f 1, f 2 : P({a, b, c}) P({d, e}) X {a, b, c} {a, b} {a, c} {b, c} {a} {b} {c} f 1 (X) {d, e} {d} {d, e} {d, e} {d} {d} {e} X {a, b, c} {a, b} {a, c} {b, c} {a} {b} {c} f 2 (X) {d} {d} {d} {e} {d} {e} {e} {e} Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 19 / 30

Exercise Determine which of the following functionals of are monotone: 1 F 0 (g) = g. (State State) (State State) { g1 g 2 F 1 (g) = 1 = g 2 where g g 2 otherwise 1 g 2. { 3 g(s) s(x) 0 F 2 (g) = λs. s s(x) = 0 Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 20 / 30

Properties of Monotone Functions Lemma Let (D 1, 1 ), (D 2, 2 ), and (D 3, 3 ) be CPOs. Let f : D 1 D 2 and g : D 2 D 3 be monotone functions. Then, g f : D 1 D 3 is a monotone function. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 21 / 30

Properties of Monotone Functions Lemma Let (D 1, 1 ) and (D 2, 2 ) be CPOs. Let f : D 1 D 2 be a monotone function. If Y is a chain in D 1, then f(y ) = {f(d) d Y } is a chain in D 2. Furthermore, f(y ) f( Y ). Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 22 / 30

Continuous Functions Definition (Continuous Functions) A function f : D 1 D 2 defined on posets (D 1, 1 ) and (D 2, 2 ) is continuous if it is monotone and it preserves least upper bounds of chains: f(y ) = f( Y ) for all non-empty chains Y in D 1. If f( Y ) = f(y ) holds for the empty chain (that is, = f( )), then we say that f is strict. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 23 / 30

Properties of Continuous Functions Lemma Let f : D 1 D 2 be a monotone function defined on posets (D 1, 1 ) and (D 2, 2 ) and D 1 is a finite set. Then, f is continuous. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 24 / 30

Properties of Continuous Functions Lemma Let (D 1, 1 ), (D 2, 2 ), and (D 3, 3 ) be CPOs. Let f : D 1 D 2 and g : D 2 D 3 be continuous functions. Then, g f : D 1 D 3 is a continuous function. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 25 / 30

Least Fixed Points Definition (Fixed Point) Let (D, ) be a poset. A fixed point of a function f : D D is an element d D such that f(d) = d. We write fix (f) for the least fixed point of f, if it exists, such that f(fix (f)) = fix (f) d D. f(d) = d = fix (f) d Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 26 / 30

Fixed Point Theorem Theorem (Kleene Fixed Point) Let f : D D be a continuous function on a CPO D. Then f has a least fixed point, fix (f), and where f n ( ) = fix (f) = n 0 f n ( ) { n = 0 f(f n 1 ( )) n > 0 Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 27 / 30

Proof We show the claims of the theorem by showing that n 0 f n ( ) exists and it is indeed equivalent to fix (f). First note that n 0 f n ( ) exists because f 0 ( ) f 1 ( ) f 2 ( )... is a chain. We show by induction that n N.f n ( ) f n+1 ( ): f( ) ( is the least element) f n ( ) f n+1 ( ) = f n+1 ( ) f n+2 ( ) (monotonicity of f) Now, we show that fix (f) = n 0 f n ( ) in two steps: We show that n 0 f n ( ) is a fixed point of f: f( f n ( )) = f(f n ( )) n 0 n 0 = n 0 = n 0 f n+1 ( ) f n ( ) continuity of f Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 28 / 30

Proofs We show that n 0 f n ( ) is smaller than all the other fixed points. Suppose d is a fixed point, i.e., f(d) = d. Then, f n ( ) d since n N.f n ( ) d: n 0 f 0 ( ) = d, f n ( ) d = f n+1 ( ) f(d) = d. Therefore, we conclude fix (f) = n 0 f n ( ). Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 29 / 30

Well-definedness of the Semantics The function F F (g) = cond(b [ b ], g C [ c ], id) is continuous. Lemma Let g 0 : State State, p : State T, and define F (g) = cond(p, g, g 0 ). Then, F is continuous. Lemma Let g 0 : State State, and define F (g) = g g 0. Then F is continuous. Hakjoo Oh COSE312 2017 Spring, Lecture 14 May 8, 2017 30 / 30