Section 6 Recursively defined functions. Semantics of Loops B: Boolean­expression C: Command... C ::=... | while B do C |...... C[[while B do C]] = 

Slides:



Advertisements
Similar presentations
Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Advertisements

CSCI 115 Chapter 6 Order Relations and Structures.
Models of Concurrency Manna, Pnueli.
Primitive Recursive Functions (Chapter 3)
Relations Relations on a Set. Properties of Relations.
Determinization of Büchi Automata
Tutorial on Widening (and Narrowing) Hongseok Yang Seoul National University.
Equivalence, Order, and Inductive Proof
Week 21 Basic Set Theory A set is a collection of elements. Use capital letters, A, B, C to denotes sets and small letters a 1, a 2, … to denote the elements.
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Foundations of Data-Flow Analysis. Basic Questions Under what circumstances is the iterative algorithm used in the data-flow analysis correct? How precise.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Programming Language Semantics Denotational Semantics Chapter 5.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
Worklist algorithm Initialize all d i to the empty set Store all nodes onto a worklist while worklist is not empty: –remove node n from worklist –apply.
Programming Language Semantics Denotational Semantics Chapter 5 Based on a lecture by Martin Abadi.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
FSM Decomposition using Partitions on States 290N: The Unknown Component Problem Lecture 24.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Administrative stuff Office hours: After class on Tuesday.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Recap: Reaching defns algorithm From last time: reaching defns worklist algo We want to avoid using structure of the domain outside of the flow functions.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Section 6 Recursively defined functions. Semantics of Loops B: Boolean­expression C: Command... C ::=... | while B do C | C[[while B do C]] = 
1 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
Relations Chapter 9.
Sets, POSets, and Lattice © Marcelo d’Amorim 2010.
Solving fixpoint equations
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
ICS 253: Discrete Structures I
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
April 14, 2015Applied Discrete Mathematics Week 10: Equivalence Relations 1 Properties of Relations Definition: A relation R on a set A is called transitive.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento.
Language: Set of Strings
CS 267: Automated Verification Lecture 3: Fixpoints and Temporal Properties Instructor: Tevfik Bultan.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
1 Section 4.3 Order Relations A binary relation is an partial order if it transitive and antisymmetric. If R is a partial order over the set S, we also.
Analysis of Algorithm Lecture 2 Basics of Algorithms and Mathematics
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
Sequence Control Syntax and Semantics Jian Xu March 3, 2004 CS706, CAS McMaster.
1 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
FUNCTIONS.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Chapter 6 Order Relations and Structures
Relations.
Chapter 3 The Real Numbers.
Fixpoints and Reachability
Unit-III Algebraic Structures
Relations Chapter 9.
Applied Discrete Mathematics Week 9: Equivalence Relations
Mathematical Induction Recursion
Proving Properties of Recursive List Functions
THEORY OF COMPUTATION Lecture One: Automata Theory Automata Theory.
Concurrent Models of Computation
Denotational Semantics (Denotational Semantics)
Properties of Relations
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Presentation transcript:

Section 6 Recursively defined functions

Semantics of Loops B: Boolean­expression C: Command... C ::=... | while B do C | C[[while B do C]] =  s: B[[B]]s  C[[while B do C]](C[[C]]s)[]s Problem: meaning of a syntax phrase may be defined only in terms of its proper sub­ parts.

C[[while B do C]] = w where w: Store   Store  w = s:B[[B]]s  w(C[[C]]s) [] s Recursion in syntax exchanged for recursion in function notation!

Recursive Function Definitions Function Definition –q = n:n equals zero  one [] q(n plus one) Possible Function Graphs: -- {(zero, one)} = {(zero, one), (one,  ), (two,  ),... } -- {(zero, one), (one, six), (two, six),... } -- {(zero, one), (one, k), (two, k),... } Several functions satisfy specification; which one shall we choose?

Least Fixed Point Semantics Establishes meaning of recursive specifications: Guarantees that every specification has a function satisfying it. Provides means for choosing the ``best'' function out of the set of possibilities. Ensures that the selected function corresponds to the conventional operational treatment of recursion. Argument is mapped to defined answer iff simplification of the specification yields a result in a finite number of recursive invocations.

The Factorial Function fac(n) = n equals zero  one [] n times (fac(n minus one)) Only one function satisfies specification: graph(factorial) = {(zero, one), (one, one), (two, two), (three, six),..., (i, i!),...}

fac(three)  three equals zero  one [] three times fac(three minus one) = three times fac(three minus one) = three times fac(two)  three times (two equals zero  one [] two times fac(two minus one)) = three times (two times fac(one))  three times (two times (one equals zero  one [] one times fac(one minus one))) = three times (two times one (times fac(zero)))  three times(two times(one times(zero equals zero  one [] zero times fac(zero minus one)))) = three times (two times one (times one)) = six

Partial Functions Answer is produced in a finite number of unfolding steps. Idea: place limit on number of unfoldings and investigate resulting graphs –zero: {} –one: {(zero, one)} –two: {(zero, one), (one, one)} –i + 1: {(zero, one), (one, one),... (i, i!)}

Graph at stage i defines function fac i. –Consistency with each other: graph(fac i)  graph(fac i+1) –Consistency with ultimate solution: graph(fac i)  graph(factorial) –Consequently  i=0 … infinity: graph(fac i )  graph(factorial)

Partial Functions Any result is computed in a finite number of unfoldings. (a, b)  graph(factorial)  (a; b)  graph(faci) (for some i) Consequently graph(factorial)   i=0 … infinity: graph(fac i ) Factorial function can be totally understood in terms of the finite subfunctions fac i !

Partial Functions Representations of sub­functions –fac 0 = n:  –fac i+1 = n: n equals zero  one [] n times fac i (n minus one) Each definition is non­recursive –Recursive specification can be understood in terms of a family of non­recursive ones.

Common format can be extracted –``Functional'' F –F: (Nat  Nat  )  (Nat  Nat  ) –F = f: n: n equals zero  one [] n times f(n minus one) Each subfunction is an instance of the functional!

Functional and Fixed Point Partial functions fac i+1 = F(fac i ) = F i (  )  := ( n:  ) Function graph graph(factorial) =  i=0 … infinity: graph(F i (  )) Fixed point property graph(F(factorial)) = graph(factorial) F(factorial) = factorial The function factorial is a fixed point of the functional F!

q Function Q = q: n:n equals zero  one [] q(n plus one) Q 0 (  ) = ( n:  ) graph(Q 0 (  )) = {} Q 1 (  ) = n:n equals zero  one [] ( n:  )(n plus one) = n:n equals zero  one []  graph(Q 1 (  )) = {(zero, one)} Q 2 (  )= Q(Q 1 (  ))) = n:n equals zero  one []((n plus one) equals zero  one []  ) graph(Q 2 (  )) = {(zero, one)}

q Function Convergence has occured –graph(Q i (  )) = {(zero, one)}, i >= 1 Resulting graph –  i=0 … inf: graph(Q i (  )) = {(zero; one)} Fix point property –Q(qlimit) = qlimit Still many solutions possible –graph(qk) = {(zero, one), (one, k),..., (i, k),... } Least fixed point property –graph(qlimit)  graph(qk) The function qlimit is the least fixed point of the functional Q!

Recursive Specifications The meaning of a recursive specification f = F (f) is taken to be fix(F ), the least fixed point of the functional denoted by F. –graph(fix F) =  i=0 … inf: graph(F i (  )) The domain D of F must be a pointed cpo –partial ordering on D, –every chain in D has a least upper bound in D –D has a least element.

F must be continuous –Preserves limits of chains. Semantic domains are cpos and their operations are continuous. –Pointed cpos are created from primitive domains and union domains by lifting.

Partial Ordering The theory is formalised if the subset relation used within the fct graphs is generalised to a partial ordering. Then elements of semantic domains can be directly involved in set theoretical reasoning A relation <= : D x D  B is a PO upon D iff it is –reflexive –antisymetric –transitive This allows us to treat the members of the domain D as if they are sets. The partial ordering relation is read is “ is less defined than” The symbol  denotes the element in a PO domain that corresponds to the empty set.

Definitions: Join/ least upper bound(lub): produces the smallest element that is larger than both of its arguments Meet/greatest lower bound(glb): produces the largest (ie best defined) element that is smaller than both of its arguments. Chain: A subset of a PO set is a chain iff the subset Is not empty and all elements of the subset are in a PO relation. Complete Partial Ordering: a PO set D is a CPO iff every chain in D has a lub in D. Pointed CPO: A partially ordered set D, is pointed cpo iff it is a complete partial ordering and it has a least element. Monotonic: a f(a) <= f(b) Continuous functions: Preserve limits on chains.

Join For a partial ordering <= on Domain D, for all a,b  D, a UNION b denotes the element of D if it exists such that: –a<= a UNION b and b <= a UNION b –for all d  D, a <=d and b<= d imply a UNION b <=d –a UNION b id the join of a and b. The join operations produces the smallest element that is larger that both of its arguments. A PO might not have joins for all of its pairs. Meet is defined in a similar way - with x INTER y denoting the best defined element that is smaller than both x and y

A functional F is a continuous function The meaning of a recursive specification f = F(f) is taken to be fix F, the least fixpoint of the functional denoted by f.

Factorial Function F = f. n. n equals zero  one [] n times (f(n minus one)) Simplification rule fix F = F(fix F) (fix F)(three) = (F (fix F))(three) = ( f. n. n equals zero  one[]n times(f(n minus one))(fix F))(three) = ( n. n equals zero  one [] n times (fix F)(n minus one))(three) =

three equals zero  one [] three times (fix F)(three minus one) = three times (fix F)(two) = three times (F (fix F))(two) =... = three times (two times (fix F)(two)) Fixed point property justifies rec. unfolding!

Copyout function Interactive text editor –copyout: Openfile  File  –copyout = (front, back). null front  back [] copyout((tl front),((hd front) cons back)) Functional C, copyout = fix C. With i unfoldings, list pairs of length i-1 can be appended. Codomain is lifted because least fixed point semantics requires that the codomain of any recursively defined function be pointed. –ispointed(A  B) = ispointed(B) –min(A  B) = a.min(B)

Double Recursion g = n. n equals zero  one [](g(n minus one) plus g(n minus one)) minus one graph(F 0 (  )) = {} graph(F 1 (  )) = {(zero, one)} graph(F 2 (  )) = {(zero, one), (one, one)} graph(F 3 (  )) = {(zero, one),(one, one),(two, one)} … graph(F i+1 (  )) = {(zero, one),..., (i, one)} fix F = n. one Stepwise construction of graph yields insight!

While Loops C[[while B do C]] = fix( f. s. B[[B]]s  f(C[[C]]s) [] s) Function: Store   Store  Example: C[[while A>0 do (A:=A­1; B:=B+1)]] = fix F where F = f. s: test s  f(adjust s) [] s test = B[[A > 0]] adjust = C[[A:=A­1; B:=B+1]]

Partial function graphs: Each pair in graph shows store prior to loop entry and after loop exit. Each graph F i+1 (  ) contains those pairs whose input stores finish processing in at most i iterations.

While Loops Representation by finite subfunctions C[[while B do C]] = UNION { s. , s.B[[B]]s   [] s, s.B[[B]]s  (B[[B]](C[[C]]s)  [] C[[C]]s)[]s, s.B[[B]]s  (B[[B]](C[[C]]s)  (B[[B]](C[[C]](C[[C]]s))   [] C[[C]](C[[C]]s)) [] C[[C]]s) [] s,…} i.e. no guard evaluation, one guard evaluation, two guard evaluations etc.

= UNION { C[[diverge]], C[[if B then diverge else skip]], C [[ if B then (C; if B then diverge else skip) else skip]], C[[if B then (C; if B then (C; if B then diverge else skip) else skip) else skip]], …} Loop iteration can be understood by sequence of non­iterating programs.

Reasoning about Least Fixed Points Fixed Point Induction Principle: To prove P (fix F ), it suffices to prove 1. P (  ) 2. P (d)  P (F (d)), for arbitrary d  D for pointed cpo D, continuous functional F :D  D, and inclusive predicate P : D  B. Inclusiveness of predicates If predicate holds for every element of chain, it also holds for its least upper bound.

All universally quantified combinations of conjunctions/disjunctions that use only partial ordering over functional expressions are inclusive. Mainly useful for showing equivalences of program constructs.

Reasoning about Least Fixed Points C[[repeat C until B]] = fix( f. s. let s’= C[[C]]s in B[[B]]s’!s’[](f s’)) C[[C;while ¬B do C]] = C[[repeat C until B]]? Proof: P(f,g) =  s:f(C[[C]]s) = (gs) 1. P( ,  ) holds. 2. Prove P (F(f), G(g)) F = ( f. s. B[[¬ B]]s  f(C[[C]]s) [] s) G = ( f. s. let s’ = C[[C]]s in B[[B]]s’  s’ [] (fs’ ))

(a) F (f)(C[[C]]  ) =  = G(g)(  ). (b) s <>  : i. C[[C]]s =  : F (f)(  ) =  = (let s’ =  in B[[B]]s’  s' [] (gs’ )) = G(g)(  ). ii. C[[C]]s = s0 <>  : F (f)(s0 ) = B[[¬B]]s0  f(C[[C]]s0 )[]s0 = B[[B]]s0  s0 [] f(C[[C]]s0 ) = B[[B]]s0  s0 [] f(gs0 ) = G(g)(s)