Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Correctness William Groesbeck, Sam Delaney.

Similar presentations


Presentation on theme: "Program Correctness William Groesbeck, Sam Delaney."— Presentation transcript:

1 Program Correctness William Groesbeck, Sam Delaney

2 Program Correctness What is program correctness? What is program correctness?

3 Program Correctness What is program correctness? What is program correctness? A program is said to be correct if it produces the correct output for every possible inputA program is said to be correct if it produces the correct output for every possible input

4 Program Correctness Two types of correctness: Two types of correctness: Total – algorithm always returns at least one correct solutionTotal – algorithm always returns at least one correct solution Partial – if a solution is returned, it will be correctPartial – if a solution is returned, it will be correct

5 Program Correctness Tony Hoare – Tony Hoare – Introduced the idea of partial correctnessIntroduced the idea of partial correctness Also the creator of the quick sort – one of the most commonly used and studied sorting algorithmsAlso the creator of the quick sort – one of the most commonly used and studied sorting algorithms

6 Program Correctness Partial correctness with respect to assertions: Partial correctness with respect to assertions: A program can be partially correct with respect to the initial assertion (represented with p) and the final assertion (represented by q).A program can be partially correct with respect to the initial assertion (represented with p) and the final assertion (represented by q). Notation: p{S}q – Hoare tripleNotation: p{S}q – Hoare triple

7 Program Correctness Example 1, Section 4.5: Example 1, Section 4.5: Show that the program segment y := 2, z := x+y is correct with respect to the initial assertion p: x=1 and the final assertion q: z=3

8 Program Correctness Solution: Solution: Suppose that p is true, so x=1. According to the program segment, y is then assigned 2. Then z is assigned x+y, or 1+2 making z=3. Thus, S is correct with respect to both the initial and the final assertions.Suppose that p is true, so x=1. According to the program segment, y is then assigned 2. Then z is assigned x+y, or 1+2 making z=3. Thus, S is correct with respect to both the initial and the final assertions. p{S}q is true.

9 Program Correctness Example 2: Example 2: int identity(int x){ x=x*1; x=x*1; return x; }

10 Program Correctness Curry-Howard Correspondence Curry-Howard Correspondence Deep result in proof theory that states that a proof of functional correctness in constructive logic corresponds to a certain program in the lambda calculusDeep result in proof theory that states that a proof of functional correctness in constructive logic corresponds to a certain program in the lambda calculus Converting a proof in this way is called program extraction.Converting a proof in this way is called program extraction.

11 Program Correctness Lambda Calculus: Lambda Calculus: Formal system designed to investigate function definitionFormal system designed to investigate function definition Greatly influenced functional programming language including Lisp, ML, and HaskellGreatly influenced functional programming language including Lisp, ML, and Haskell Consists of a single variable substitution and a single function definition scheme.Consists of a single variable substitution and a single function definition scheme. UndecidabilityUndecidabilityUndecidability

12 Program Correctness Lambda Calculus Expressions Lambda Calculus Expressions f(x) = x + 2f(x) = x + 2 λ x. x+2λ x. x+2 f(3) = (λ x. x+2) 3f(3) = (λ x. x+2) 3 (λ f. f 3)(λ x. x+2)(λ f. f 3)(λ x. x+2) = (λ x. x+2)3 = 3+2 =5 = (λ x. x+2)3 = 3+2 =5

13 Program Correctness Example 2 (Revised): Example 2 (Revised): int identity(int x){ x=x*2; x=x*2; return x; } = (λ x. x*2) = (λ x. x*2)

14 Program Correctness Example 3 : Example 3 : int identity(int x){ x=x*2; x=x*2; return x; } = (λ x. x*2) = (λ x. x*2) If x=3? (λ f. f 3) (λ x. x*2) (λ f. f 3) (λ x. x*2)

15 Program Correctness Conclusion: Conclusion: Partial / Total CorrectnessPartial / Total Correctness Tony HoareTony Hoare Partial correctness with respect to…Partial correctness with respect to… Curry-Howard CorrespondenceCurry-Howard Correspondence Lambda CalculusLambda Calculus Bonus!Bonus! Name two things that Tony Hoare was best known for Name two things that Tony Hoare was best known for

16 Program Correctness Questions? Questions?


Download ppt "Program Correctness William Groesbeck, Sam Delaney."

Similar presentations


Ads by Google