AAA616: Program Analysis. Lecture 3 Denotational Semantics

Similar documents
COSE312: Compilers. Lecture 14 Semantic Analysis (4)

Lecture 2. Least Fixed Points

What does the partial order "mean"?

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

Semantics and Verification of Software

CS422 - Programming Language Design

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

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

Denotational Semantics

Denotational Semantics

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

CMSC 631 Program Analysis and Understanding Fall Abstract Interpretation

Introduction to Axiomatic Semantics

Lecture Notes: Selected Topics in Discrete Structures. Ulf Nilsson

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

Semantics and Verification of Software

Formal Techniques for Software Engineering: Denotational Semantics

Denotational Semantics

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

Denotational Semantics

Chapter-2 Relations and Functions. Miscellaneous

Denotational Semantics of Programs. : SimpleExp N.

Towards a Denotational Semantics for Discrete-Event Systems

The Knaster-Tarski Fixed Point Theorem for Complete Partial Orders

Reading: Chapter 9.3. Carnegie Mellon

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

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

arxiv: v1 [cs.pl] 19 May 2016

(Pre-)Algebras for Linguistics

{a, b, c} {a, b} {a, c} {b, c} {a}

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

1. Introduction and preliminaries

Complete Partial Orders, PCF, and Control

0 Sets and Induction. Sets

Tense Operators on Basic Algebras

Introduction to Abstract Interpretation. ECE 584 Sayan Mitra Lecture 18

Sets and Motivation for Boolean algebra

Lecture 1: Lattice(I)

Discrete Fixpoint Approximation Methods in Program Static Analysis

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

Mathematical Foundations of Logic and Functional Programming

Relations, Functions, Binary Relations (Chapter 1, Sections 1.2, 1.3)

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

An Introduction to the Theory of Lattice

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

arxiv: v4 [math.fa] 27 Jan 2010

Discrete Mathematics. 2. Relations

CS611 Lecture 18 Fixed Points and CPOs

A strongly rigid binary relation

MIT Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

Introduction to Kleene Algebras

Answer: A. Answer: C. 3. If (G,.) is a group such that a2 = e, a G, then G is A. abelian group B. non-abelian group C. semi group D.

Axioms of Kleene Algebra

A Logician s Toolbox

Least Fixpoints Calculationally

Structure of R. Chapter Algebraic and Order Properties of R

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

Week Some Warm-up Questions

Abstract Interpretation: Fixpoints, widening, and narrowing

Part II. Logic and Set Theory. Year

DEPARTMENT OF MATHEMATICS. MA1301 Discrete Mathematics

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

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

{x : P (x)} P (x) = x is a cat

Denotational semantics

COMP 182 Algorithmic Thinking. Relations. Luay Nakhleh Computer Science Rice University

06 Recursive Definition and Inductive Proof

G54FOP: Lecture 17 & 18 Denotational Semantics and Domain Theory III & IV

Economics 204 Fall 2011 Problem Set 2 Suggested Solutions

CORES OF ALEXANDROFF SPACES

Stipulations, multivalued logic, and De Morgan algebras

ANNIHILATOR IDEALS IN ALMOST SEMILATTICE

Topology. Xiaolong Han. Department of Mathematics, California State University, Northridge, CA 91330, USA address:

Semantics with Applications: Model-Based Program Analysis

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.

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

Solutions for Homework Assignment 2

1 Initial Notation and Definitions

Logical Connectives and Quantifiers

where A, B, C N, a Σ, S ϵ is in P iff ϵ L(G), and S does not occur on the right-hand side of any production. 3.6 The Greibach Normal Form

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

GENERALIZED DIFFERENCE POSETS AND ORTHOALGEBRAS. 0. Introduction

Monoids. Definition: A binary operation on a set M is a function : M M M. Examples:

Functions as Relations

MAD 3105 PRACTICE TEST 2 SOLUTIONS

Completeness of Star-Continuity

AAA615: Formal Methods. Lecture 2 First-Order Logic

By that, every path can be analyzed :-) A given program may admit several paths :-( For any given input, another path may be chosen :-((

Diskrete Mathematik Solution 6

Closure operators on sets and algebraic lattices

Analysis I. Classroom Notes. H.-D. Alber

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

Introduction. Chapter 1

Lecture 4. Algebra, continued Section 2: Lattices and Boolean algebras

Do not open this exam until you are told to begin. You will have 75 minutes for the exam.

Data Cleaning and Query Answering with Matching Dependencies and Matching Functions

Fixed point. The function q revisited. Function q. graph F factorial graph factorial. factorial is a fixed point of F, since

Introduction to Restriction Categories

Transcription:

AAA616: Program Analysis Lecture 3 Denotational Semantics Hakjoo Oh 2018 Spring Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 1 / 33

Denotational Semantics In denotational semantics, we are interested in the mathematical meaning of a program. Also called compositional semantics: The meaning of an expression is defined with the meanings of its immediate subexpressions. Denotational semantics for While: 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 Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 2 / 33

Denotational Semantics of Expressions 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 AAA616 2018 Spring, Lecture 3 March 28, 2018 3 / 33

Denotational Semantics of Commands where C [c ] : State State 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(s) f(s) = false F (g) = cond(b [b ], g C [c ], id) Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 4 / 33

Denotational Semantics of Loops 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). 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 as the least fixed point of F : C [while b c ] = fix F where fix F denotes the least fixed point of F. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 5 / 33

Example while (x = 0) skip F fix F Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 6 / 33

Questions Does the least fixed point fix F exist? Is fix F unique? How to compute fix F? Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 7 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 8 / 33

Plan Complete Partial Order Continuous Functions Least Fixed Point Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 9 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 10 / 33

Exercise 1 Let S be a non-empty set. Prove that ( (S), ) is a partially ordered set. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 11 / 33

Exercise 2 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 AAA616 2018 Spring, Lecture 3 March 28, 2018 12 / 33

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. The least upper bound (lub, join) of a and b is written as a b. Lemma If Y has a least upper bound d, then d is unique. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 13 / 33

Greatest Lower Bound Definition (Greatest Lower Bound) Let (D, ) be a partially ordered set and let Y be a subset of D. A lower bound of Y is an element d of D such that d Y. d d. An lower bound d of Y is a greatest lower bound if and only if d d for every lower bound d of Y. The greatest lower bound of Y is denoted by Y. The greatest lower bound (glb, meet) of a and b is written as a b. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 14 / 33

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 ( ({a, b, c}), ). Y 1 = {, {a}, {a, c}} Y 2 = {, {a}, {c}, {a, c}} Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 15 / 33

Complete Partial Order (CPO) Definition (CPO) A poset (D, ) is a CPO, if every chain Y D has Y D. Lemma If (D, ) is a CPO, then it has a least element given by =. * We denote the least element and the greatest element in a poset as and, respectively, if they exist. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 16 / 33

Examples Example Let S be a non-empty set. Then, ( (S), ) is a CPO. The lub Y for Y is Y. The least element is. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 17 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 18 / 33

Lattices Ordered sets with richer structures. Definition (Lattice) A lattice (D,,, ) is a poset where the lub and glb always exist: a, b D. a b D a b D. Definition (Complete Lattice) A complete lattice (D,,,,, ) is a poset such that every subset Y D has Y D and Y D, and D has a least element = = D and a greatest element = = D. * A complete lattice is a CPO. Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 19 / 33

Derived Ordered Structures When (D 1, 1, 1, 1, 1, 1 ) and (D 2, 2, 2, 2, 2, 2 ) are complete lattices (resp., CPO), so are the following ordered sets: Lifting: (D 1 { },,,,, ) D1 is a new element a b a = a 1 b a = a = a and otherwise a b = a 1 b (similar for ) = 1 Cartesian product: (D 1 D 2,,,,, ). Pointwise lifting: (S D,,,,, ) (S is a set) a b s S. a(s) 1 b(s) s S. (a b)(s) a(s) 1 b(s) s S. (s) = 1 Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 20 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 21 / 33

Example Consider ( ({a, b, c}), ) and ( ({d, e}), ) and two functions f 1, f 2 : ({a, b, c}) ({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 AAA616 2018 Spring, Lecture 3 March 28, 2018 22 / 33

Exercise Determine which of the following functionals of are monotone: 1 F 0 (g) = g. (State State) (State State) { g1 g = g 2 F 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 AAA616 2018 Spring, Lecture 3 March 28, 2018 23 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 24 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 25 / 33

Continuous Functions Definition (Continuous Functions) A function f : D 1 D 2 defined on CPOs (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 AAA616 2018 Spring, Lecture 3 March 28, 2018 26 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 27 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 28 / 33

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 * More notations: x is a fixed point of f if f(x) = x. Let fp(f) = {x f(x) = x} be the set of fixed points. x is a pre-fixed point of f if x f(x). x is a post-fixed point of f if x f(x). lfp(f): the least fixed point gfp(f): the greatest fixed point Hakjoo Oh AAA616 2018 Spring, Lecture 3 March 28, 2018 29 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 30 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 31 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 32 / 33

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 AAA616 2018 Spring, Lecture 3 March 28, 2018 33 / 33