Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento.

Slides:



Advertisements
Similar presentations
Completeness and Expressiveness
Advertisements

Introduction The concept of transform appears often in the literature of image processing and data compression. Indeed a suitable discrete representation.
6.896: Topics in Algorithmic Game Theory Lecture 20 Yang Cai.
Chapter 3 Direct Proof and Proof by Contrapositive
Primitive Recursive Functions (Chapter 3)
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
The Engineering Design of Systems: Models and Methods
ISBN Chapter 3 Describing Syntax and Semantics.
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
Functions Section 2.3 of Rosen Fall 2008
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 Based on a lecture by Martin Abadi.
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.
November 10, 2009Theory of Computation Lecture 16: Computation on Strings I 1Diagonalization Another example: Let TOT be the set of all numbers p such.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Sorting networks Efficient Parallel Algorithms COMP308.
Prof. Aiken CS 294 Lecture 21 Abstract Interpretation Part 2.
September 17, 2009Theory of Computation Lecture 4: Programs and Computable Functions III 1 Macros Now we want to use macros of the form: W  f(V 1, …,
Describing Syntax and Semantics
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 6 Limitations of propositional logic Introduction to predicate logic Symbols, terms and formulae, Parse.
October 1, 2009Theory of Computation Lecture 8: Primitive Recursive Functions IV 1 Primitive Recursive Predicates Theorem 6.1: Let C be a PRC class. If.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
Section 1.8: Functions A function is a mapping from one set to another that satisfies certain properties. We will first introduce the notion of a mapping.
FUNCTION Discrete Mathematics Asst. Prof. Dr. Choopan Rattanapoka.
Solving fixpoint equations
Machine-Independent Optimizations Ⅱ CS308 Compiler Theory1.
Math Review Data Structures & File Management Computer Science Dept Va Tech July 2000 ©2000 McQuain WD 1 Summation Formulas Let N > 0, let A, B, and C.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Discrete Mathematics Math Review. Math Review: Exponents, logarithms, polynomials, limits, floors and ceilings* * This background review is useful for.
3 DERIVATIVES. In this section, we will learn about: Differentiating composite functions using the Chain Rule. DERIVATIVES 3.5 The Chain Rule.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFunctions.
1 Annoucement n Skills you need: (1) (In Thinking) You think and move by Logic Definitions Mathematical properties (Basic algebra etc.) (2) (In Exploration)
Functions Section 2.3 of Rosen Spring 2012 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions: Use Piazza.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Discrete Mathematics R. Johnsonbaugh
CS 267: Automated Verification Lecture 3: Fixpoints and Temporal Properties Instructor: Tevfik Bultan.
Naïve Set Theory. Basic Definitions Naïve set theory is the non-axiomatic treatment of set theory. In the axiomatic treatment, which we will only allude.
Elements of Coding and Encryption 1. Encryption In the modern word, it is crucial that the information is transmitted safely. For example, Internet purchases,
CS 285- Discrete Mathematics Lecture 4. Section 1.3 Predicate logic Predicate logic is an extension of propositional logic that permits concisely reasoning.
September 29, 2009Theory of Computation Lecture 7: Primitive Recursive Functions III 1 Some Primitive Recursive Functions Example 3: h(x) = x! Here are.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
Foundations of Discrete Mathematics Chapter 1 By Dr. Dalia M. Gil, Ph.D.
Theory of Computational Complexity Probability and Computing Ryosuke Sasanuma Iwama and Ito lab M1.
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.
SEQUENCES A function whose domain is the set of all integers greater than or equal to some integer n 0 is called a sequence. Usually the initial number.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
October 4, 2016Theory of Computation Lecture 9: A Universal Program I 1Minimalization Example 15: R(x, y) R(x, y) is the remainder when x is divided by.
Chapter 2: Lambda Calculus
Fixpoints and Reachability
Relations, Functions, and Matrices
Modeling Arithmetic, Computation, and Languages
Diagonalization and Reducibility
Theory of Computation Lecture 14: A Universal Program V
Complex Variables. Complex Variables Open Disks or Neighborhoods Definition. The set of all points z which satisfy the inequality |z – z0|
Mathematical Induction Recursion
Chapter 5 Induction and Recursion
Lecture 7 Functions.
Copyright © Cengage Learning. All rights reserved.
Theory Of Computer Science
MA/CSSE 474 More Math Review Theory of Computation
Applied Discrete Mathematics Week 9: Integer Properties
Diagonalization and Reducibility
Primitive Recursive Predicates
Some Primitive Recursive Functions
Theory of Computation Lecture 17: Calculations on Strings II
Presentation transcript:

Universidad Nacional de ColombiaUniversidad Nacional de Colombia Facultad de IngenieríaFacultad de Ingeniería Departamento de Sistemas- 2002Departamento de Sistemas nalysis of lgorithms

lgorithms Correctness of Recursive Programs

Introduction We shall present and discuss methods for proving properties of recursive programs. We shall consider a very restricted class of recursive programs. The semantic of recursive programs is not a matter of study in regular courses of Algorithms. Here, we prove that an algorithm is correct using only the running time, but does this algorithm really do what we want it to do? How can we interpret a recursive definition and determine what does it really do?

We shall attempt to show the mathematical techniques in order to establish on a theoretical basis the recursive definitions and we shall show both the basis theory and one of the techniques to prove that an recursive algorithm is correct

All recursive definition can be expressed as: Therefore, we can think in as a “function” what takes f as a parameter, where f is a fix point of Before talking about fix points, we have to define what are the functions and structures that allow us to build a theory about fix points. Fortunately, the partial ordered sets theory and the functions that keep this order may help us with this. Monotonic Functions

We let D + denote D U { }, assuming  D by convention. Partial Ordering on D + To define monotonicity, we must introduce the partial ordering on every domain D +. The partial ordering is intended to correspond to the notion is less defined than or equal to, and accordingly we let For (D + ) n =D + xD + x…xD +, we define

Example: If D={a,b}, then D + ={a, b,  } and the partial ordering on D + is    ;   a;   b; a  a; and b  b    ;   a;   b; a  a; and b  b If D={a,b}; a alternative way to describe the partial ordering over D + x D + is ( ,  ) ( , b ) ( b,  ) ( a,  ) ( , a ) ( b, b ) (a, b ) ( b, a ) ( a, a )

Monotonic functions An n-ary function f from (D 1 + ) n into D 2 + is said to be monotonic if x  y implies f(x)  f(y) for all x,y  (D 1 + ) n Example: 1.The identity n-ary function I mapping any x in (D 1 + ) n into itself is monotonic 2.The totally undefined function  mapping any x in (D 1 + ) n into  is monotonic 3.Every 0-ary function is monotonic 4.Every n-ary constant function mapping any x in (D 1 + ) n into a fixed element c of D 2 + is monotonic

Properties of monotonic functions 1.If f is a unary function mapping D 1 + into D 2 +, then f is monotonic if and only if either f(  ) is  or f(a) is c for all a  D For n  2, if an n-ary function f mapping (D 1 + ) n into D 2 + is monotonic, then either f( ,…,  ) is  or f(a 1,…,a n ) is c for all (a 1,…,a n )  (D 1 + ) n Natural Extension An n-ary (n  1) function f mapping (D 1 + ) n into D 2 + is said to be naturally extended if it has the following property: f(a 1,…,a n ) is  whenever at least one the a i ’s is .

Lemma (the natural extension lemma) Every naturally extended function is monotonic Examples: The quotient function mapping (x,y)  R 2 into x/y  R, extended to a total function by letting x/0 be  for any x in R, becomes monotonic by the natural extension: Let x/  and  / y be  for any x and y in R +The quotient function mapping (x,y)  R 2 into x/y  R, extended to a total function by letting x/0 be  for any x in R, becomes monotonic by the natural extension: Let x/  and  / y be  for any x and y in R + The is-defined function def mapping D + into {true,false} +, defined by def(d) is true for any d  D, def(  ) is false; is not monotonic: for we have   d while def(  ) def(d) (that is, false true)The is-defined function def mapping D + into {true,false} +, defined by def(d) is true for any d  D, def(  ) is false; is not monotonic: for we have   d while def(  ) def(d) (that is, false true) 

Composition of monotonic functions: An important operation on functions is composition, which allows functions to be defined in terms of simpler functions. If f, g are monotonic functions (f: D 1  D 2, g: D 2  D 3 ) then g(f(x)) is monotonic. Example: The function mapping N + into N + given by f(x): if x=0 then 1 else x Is defined by composition of 0-ary functions 0 an 1, the identity function I, the weak equality predicate =, and the if-then-else function. Since all these function are monotonic, then so is f. Remark: We let ITE(par1, par2, par3) denote if par1 then par2 else par3

Distribution of monotonic functions over conditionals: Finally, we shall discuss an important corollary which follows from the properties of monotonic functions. Let us consider two functions f 1 and f 2 given by f 1 : g(ITE(p(x), h 1 (x), h 2 (x))) f 2 : ITE(p(x), g(h 1 (x)), g(h 2 (x))) Where p, g, h 1, and h 2 are monotonic functions. Both f 1 and f 2 are monotonic (Why?). There is very interesting relation between these two functions: 1.f 2 (x)  f 1 (x) for any x  (D 1 + ) n 2.If g(  ) is , then f 2 (x)  f 1 (x) for any x  (D 1 + ) n

Least Upper Bound In order to introduce and discuss functionals, we must first define a few additional notions regarding monotonic functions. let [(D 1 + ) n  D 2 + ] denote the set of all monotonic functions mapping (D 1 + ) n into D Let f, g  [(D 1 + ) n  D 2 + ]. We say that f  g if f(x)  g(x) for all x in (D 1 + ) n 2.Let f, g  [(D 1 + ) n  D 2 + ]. We say that f  g if f(x)  g(x) for all x in (D 1 + ) n 3.Let f 0, f 1, … be a sequence of functions in [(D 1 + ) n  D 2 + ], denoted {f i }; {f i } is called a chain if f 0  f 1  f 2  … [(D 1 + ) n  D 2 + ], denoted {f i }; {f i } is called a chain if f 0  f 1  f 2  … 4. Let {f i } be a sequence of functions in [(D 1 + ) n  D 2 + ], and let f  [(D 1 + ) n  D 2 + ]. We say that f is an upper bound of {f i } if f  f i for every i  0

Lemma (The lub lemma) Every chain {f i } has a least upper bound. Example: Consider the sequence of functions f 0,f 1, f 2, … in [N +  N + ] defined by f i (x): ITE(x<i, x!,  ) This sequence is clearly a chain because f i  f i+1 for every i. (Note that f 0 is  ) By the lub lemma it follows that the sequence has an lub; it is the factorial function x!

A functional  over [(D 1 + ) n  D 2 + ] maps the set functions [(D 1 + ) n  D 2 + ] into itself, that is,  takes any monotonic function f as its argument and yields a monotonic function  [f] as its value. Two interesting properties of functionals are monotonicity and continuity: 1.A functional  over [(D 1 + ) n  D 2 + ] is said to be monotonic if f  g implies  [f ]   [g] for all f, g  [(D 1 + ) n  D 2 + ] 2.A monotonic functional  over [(D 1 + ) n  D 2 + ] is said to be continuous is for any chain of functions {f i }, we have  [lub{f i }]  lub {  [f i ]} Continuous Functionals

Theorem (continuous functionals): Any functional  defined by composition of monotonic functions and the function variable F, is continuous Example: the functional  over [N +  N + ] defined by  [F](x) : ITE(x=0, 1, F(x+1)) is constructed by the composition of monotonic functions (If-Then-Else, identity, addition, weak equality, and the 0-ary functions 0 an 1) and the function variable F; therefore it is continuous

Let  be any monotonic functional over [(D 1 + ) n  D 2 + ]. Let us consider the sequence of functions  0 [  ],  1 [  ], …, where  0 [  ] stands for  and  i+1 [  ] is  [  i [  ]] for i  0. Each function  i [  ] is in [(D 1 + ) n  D 2 + ]; moreover, since    [  ], and since  is monotonic, {  i [  ]} must be a chain; therefore, by the lub lemma, lub{  i [  ]} must exist. Theorem (first recursion theorem, Kleene) every continuous functional  has a least fixpoint denoted by f . Actually f  is lub{  i [  ]} Fixpoints of functionals

Example: The functional  over [I +  I + ] given by  [F](x): ITE(x>100, x-10, F (F (x+11))) has only fix point ITE(x>100, x-10, 91) Which is therefore the least fixpoint f 

In our class a program called a recursive definition, o recursive program, over D is of the form F(x)   [F](x) F(x)   [F](x) Where  [F](x) is a functional over [(D 1 + ) n  D 2 + ] expressed by composition of known monotonic functions and predicates (called base functions and predicates) and the function variable F. We agree that the function defined by a recursive program P P: F(x)   [F](x) Is f  (the least fix point of  ) and denote it by f P. For example, the following recursive program over the natural numbers P: F(x)  ITE(x=0, 1, x*F(x-1)) Defines the factorial function (that is f P =x!) Recursive Programs