Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Muhammed Al-Mulhem 1ICS535-101 ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2) ICS 535 Design and Implementation.

Similar presentations


Presentation on theme: "Dr. Muhammed Al-Mulhem 1ICS535-101 ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2) ICS 535 Design and Implementation."— Presentation transcript:

1 Dr. Muhammed Al-Mulhem 1ICS535-101 ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2) ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2)

2 Dr. Muhammed Al-Mulhem 2ICS535-101 Computability From a mathematical point of view, a computer program defines a function. From a mathematical point of view, a computer program defines a function. The output of a program is computed as a function of: The output of a program is computed as a function of: The program input, and The program input, and The state of the machine before the program starts. The state of the machine before the program starts. In practice In practice Some mathematical functions are computable while others are not. Some mathematical functions are computable while others are not. The goal of computability theory is to answer the question: The goal of computability theory is to answer the question: Can we define a formal sense in which we can understand how hard a particular problem is to solve on a computer?

3 Dr. Muhammed Al-Mulhem 3ICS535-101 Computability In order to answer the previous question of computability theory, it is necessary to define in a formal way what a computer is. In order to answer the previous question of computability theory, it is necessary to define in a formal way what a computer is. Models of computation includes: Models of computation includes: Deterministic finite automaton (DFA) Deterministic finite automaton (DFA) Pushdown automaton Pushdown automaton Turing machine Turing machine With these computational models in hand, we can determine what their limits are. That is, what classes of languages can they accept? With these computational models in hand, we can determine what their limits are. That is, what classes of languages can they accept?

4 Dr. Muhammed Al-Mulhem 4ICS535-101 Computability A central question of computer science is to address the limits of computing devices by understanding the problems we can solve using them. A central question of computer science is to address the limits of computing devices by understanding the problems we can solve using them. In all general-purpose programming languages, it is possible to write a program for each function that is computable in principle. In all general-purpose programming languages, it is possible to write a program for each function that is computable in principle. However, the limits of computability also limit the kinds of things that programming language implementation can do. However, the limits of computability also limit the kinds of things that programming language implementation can do.

5 Dr. Muhammed Al-Mulhem 5ICS535-101 Limits Value of an expression may be undefined Value of an expression may be undefined Undefined operation, e.g., division by zero Undefined operation, e.g., division by zero 3/0 has no value 3/0 has no value Implementation may halt with error condition Implementation may halt with error condition Non-termination Non-termination f(x) = if (x == 0) then 1 else f(x-2) f(x) = if (x == 0) then 1 else f(x-2) This is a partial function: not defined on all arguments This is a partial function: not defined on all arguments Cannot be detected at compile-time; this is halting problem Cannot be detected at compile-time; this is halting problem These two cases are “Mathematically” equivalent but “Operationally” different These two cases are “Mathematically” equivalent but “Operationally” different

6 Dr. Muhammed Al-Mulhem 6ICS535-101 Partial and Total Functions Total function: f(x) has a value for every x Total function: f(x) has a value for every x Partial function: g(x) does not have a value for every x Partial function: g(x) does not have a value for every x x g(x) f(x)

7 Dr. Muhammed Al-Mulhem 7ICS535-101 Partial and Total Functions Total function f:A  B is a set of ordered pairs  x,y  satisfying the following conditions: Total function f:A  B is a set of ordered pairs  x,y  satisfying the following conditions: For every x  A, there is some y  B with  x,y   f (total) For every x  A, there is some y  B with  x,y   f (total) If  x,y   f and  x,z   f then y=z (single-valued) If  x,y   f and  x,z   f then y=z (single-valued) Partial function f:A  B is a set of ordered pairs  x,y  satisfying the following condition: Partial function f:A  B is a set of ordered pairs  x,y  satisfying the following condition: If  x,y   f and  x,z   f then y=z (single-valued) If  x,y   f and  x,z   f then y=z (single-valued) Programs define partial functions for two reasons Programs define partial functions for two reasons Undefined operations (like division) Undefined operations (like division) Non-termination Non-termination f(x) = if (x==0) then 1 else f(x-2) f(x) = if (x==0) then 1 else f(x-2)

8 Dr. Muhammed Al-Mulhem 8ICS535-101 Computability Definition Definition Function f is computable if some program P computes it: For any input x, the computation P(x) halts with output f(x)

9 Dr. Muhammed Al-Mulhem 9ICS535-101 Halting function Decide whether program halts on input Decide whether program halts on input Given program P and input x to P, Given program P and input x to P, Halt (P,x) = Halt (P,x) = Fact: There is no program for Halt Fact: There is no program for Halt Halts if P(x) halts Does not halt otherwise

10 Dr. Muhammed Al-Mulhem 10ICS535-101 Undecidability of the halting problem - Proof Read the book Page 14 -15 Read the book Page 14 -15

11 Dr. Muhammed Al-Mulhem 11ICS535-101 Main points about computability Some functions are computable, some are not Some functions are computable, some are not Halting problem Halting problem Programming language implementation Programming language implementation Can report error if program result is undefined due to division by zero, or other undefined basic operation Can report error if program result is undefined due to division by zero, or other undefined basic operation Cannot report error if program will not terminate Cannot report error if program will not terminate


Download ppt "Dr. Muhammed Al-Mulhem 1ICS535-101 ICS 535 Design and Implementation of Programming Languages Part 1 Computability (Chapter 2) ICS 535 Design and Implementation."

Similar presentations


Ads by Google