Lecture5 - Hoare's Logic
Lecture5 - Hoare's Logic
Sajjad Ali
Outlines
• Hoare’s Logic
• Initial State
• Statement(s)
• Final State
• Weakest Pre-Condition
Reviews
• Propositional Logic
• Implication
• Logical Equivalences
• Set Theory
Formal Methods in SE
• Coming Lectures will focus on
• With the help of Logic, we will construct the model for
computer programs
• He worked in 60’s
• Example:
• Sorted Data in Binary Search
Examples:
• 1)
Let us say our final state a = 10
So pre-conditional might be a=10
• 2)
Final State n<0 (Desired output)
Statement = n=n-1
Pre-condition?
Wp = weakest pre-condition
Example:
wp((x:= x+1; y := y+1), x = y)
Rule of Sequential Composition
Example:
Example:
Example:
Example:
Example:
wp((x:= 2*x+1; y := y-1), y = 3*x)
Rule of Sequential Composition
• Let us take another Example
Example:
wp((x:= 2*x+1; y := y-1), y = 3*x)
wp(x := 2*x+1, wp(y := y-1, y = 3*x))
Rule of Sequential Composition
• Let us take another Example
Example:
wp((x:= 2*x+1; y := y-1), y = 3*x)
Example:
wp((x:= 2*x+1; y := y-1), y = 3*x)
y-1 = 3*(2*x+1)
Rule of Sequential Composition
• Let us take another Example
Example:
wp((x:= 2*x+1; y := y-1), y = 3*x)
y-1 = 3*(2*x+1)
y = 6*x + 4
Hoare’s Triple
• We have discussed Hoare’s Triple
{p} S {Q}