Formal Program Verification Using Hoare’s Logic
Transcript of Formal Program Verification Using Hoare’s Logic
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Formal Program VerificationUsing Hoare’s Logic
Mahmudul Faisal Al Ameen
July 10, 2014
Mahmudul Faisal Al Ameen — Formal Program Verification 1/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Contents
1 Programming
2 Bug
3 VerificationDynamic VerificationStatic Verification
4 Formal Verification
5 LanguageExpressionsLanguages
6 Hoare’s Logic
7 Example
8 Correctness
9 Conclusion
Mahmudul Faisal Al Ameen — Formal Program Verification 2/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Core is Programming
Programming
DigitalFun
SocialNet-
working
MultimediaPro-
ductionEntertainment
Games
SoftwareDevel-opments
SystemSoftware
ApplicationSoftware
E-commerce
System
FirmwireCommunication
System
AnalysisFinance
Statistics History
Linguistics
(Simu/Emu)lation
MultiagentSystem
SoftwareTesting
MathematicalProblem
ArtificialBiologicalElements
Chemistry
Mahmudul Faisal Al Ameen — Formal Program Verification 3/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Core is Programming
Programming
Digital FunSocial
Networking
Multimedia
ProductionEntertainment
Games
SoftwareDevel-
opments
System
Software
Application
Software
E-commerce
System
FirmwireCommunication
System
AnalysisFinance
Statistics History
Linguistics
(Simu/Emu)lation
Multiagent
System
Software
Testing
Mathematical
Problem
Artificial
Biological
Elements
Chemistry
Mahmudul Faisal Al Ameen — Formal Program Verification 4/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Catastrophic Software Bug: Cluster (Ariane 5)
Loss: US$1 billion
Cause: Overflow bug
Mahmudul Faisal Al Ameen — Formal Program Verification 5/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Catastrophic Software Bug: Therac 25
Casualty: At least 6 reported death
When occured: A particular nonstandard sequence ofkeystrokes was entered as – an ”X” to (erroneously) select 25MeV photon mode followed by ”cursor up”
The engineer had reused software from older models.
Mahmudul Faisal Al Ameen — Formal Program Verification 6/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Catastrophic Software Bug: North AmericaBlackout
Loss: 28,700 MW dropped to 5,716 MW (80% loss)
Cause: Race condition
Mahmudul Faisal Al Ameen — Formal Program Verification 7/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Catastrophic Software Bug: Smartship USSYorktown
Dead duration: 3 hours
Cause: Divide by Zero
Mahmudul Faisal Al Ameen — Formal Program Verification 8/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Software Verification
SoftwareVerification
StaticVerifi-cation
Softwaremetricscalcu-lation
Codeconven-
tionsverifi-cation
Anti-patterndetec-tion
Formalverifi-cation
DynamicVerifi-cation
Unittest
Testin thelarge
Moduletest
Integrationtest
Systemtest
Acceptancetest
Functionaltest
Stresstest
Mahmudul Faisal Al Ameen — Formal Program Verification 9/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification
DynamicVerifi-cation
Unittest
Testin thelarge
Moduletest
Integrationtest
Systemtest
Acceptancetest
Functionaltest
Stresstest
Mahmudul Faisal Al Ameen — Formal Program Verification 10/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (α-Testing): Prime Tester
.
.
.
1
2
3
0 (no)
1 (yes)
1 (yes)
Prime Tester
Mahmudul Faisal Al Ameen — Formal Program Verification 11/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (α-Testing): Prime Tester
.
.
.
7
8
91
1 (yes)
0 (no)
1 (yes)
Prime Tester
Mahmudul Faisal Al Ameen — Formal Program Verification 12/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (α-Testing): Prime Tester
.
.
.
100000007
10000008
100000000003
1 (yes)
0 (no)
1 (yes)
Prime Tester
Mahmudul Faisal Al Ameen — Formal Program Verification 13/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (status): Prime Tester
Correct.Hence released as β-version.
Mahmudul Faisal Al Ameen — Formal Program Verification 14/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (β-Testing): Prime Tester
.
.
.
9
15
93
1 (yes)
1 (yes)
1 (yes)
Prime Tester
Mahmudul Faisal Al Ameen — Formal Program Verification 15/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (comments): Prime Tester
Totally incorrect.Bad program.
Mahmudul Faisal Al Ameen — Formal Program Verification 16/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (review): Prime Tester
.
.
.
9
15
93
1 (yes)
1 (yes)
1 (yes)
int isPrime(int x){if(x==1) return 0;
if(x==2) return 1;
if(x % 2 == 0)
return 0;
return 1;
}
Mahmudul Faisal Al Ameen — Formal Program Verification 17/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (fixation): Prime Tester
.
.
.
9
15
93
0 (no)
0 (no)
0 (no)
int isPrime(int x){if(x==1) return 0;
if(x==2) return 1;
if(x % 2 == 0)
return 0;
if(x % 3 == 0)
return 0;
return 1;
}
Mahmudul Faisal Al Ameen — Formal Program Verification 18/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (happiness): Prime Tester
Programmer is happy. Finalversion is released.
Mahmudul Faisal Al Ameen — Formal Program Verification 19/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (at user): Prime Tester
.
.
.
49
25
35
1 (yes)
1 (yes)
1 (yes)
int isPrime(int x){if(x==1) return 0;
if(x==2) return 1;
if(x % 2 == 0)
return 0;
if(x % 3 == 0)
return 0;
return 1;
}
Mahmudul Faisal Al Ameen — Formal Program Verification 20/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (impact): Prime Tester
User may in dangeroussituation.
Mahmudul Faisal Al Ameen — Formal Program Verification 21/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (conclusion): Prime Tester
Dynamic verification is notenough always.
Mahmudul Faisal Al Ameen — Formal Program Verification 22/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Dynamic Verification (correct): Prime Tester
.
.
.
49
25
35
1 (yes)
1 (yes)
1 (yes)
int isPrime(int x){if(x==1) return 0;
int i = 2;
while(i < x){if(x % i == 0)
return 0;
i = i + 1;
}return 1;
}
Mahmudul Faisal Al Ameen — Formal Program Verification 23/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Software Verification
StaticVerification
Softwaremetricscalcu-lation
Codeconven-
tionsverifi-cation
Anti-patterndetec-
tion
Formalverifi-cation
Mahmudul Faisal Al Ameen — Formal Program Verification 24/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Formal Verification
FormalVerification
Mahmudul Faisal Al Ameen — Formal Program Verification 25/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Notation
P is a program
A is an assertion, a formula of first order logic
b is a boolean expression, that evaluates always to true orfalse
e is an arithmatic expression
x is a variable
+, ×, =, <, ∧, ∨, ¬, → are operators.
Mahmudul Faisal Al Ameen — Formal Program Verification 26/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Expression
e is x
0 1
e + e e × e
e − e e/e
Mahmudul Faisal Al Ameen — Formal Program Verification 27/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Boolean Expression
b is e = e e < e
b ∧ b b ∨ b
¬b b → b
Mahmudul Faisal Al Ameen — Formal Program Verification 28/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Programming Language
P is skip; x := e;
if(b){P
}else{P
}
while(b){P
}
P
P
Mahmudul Faisal Al Ameen — Formal Program Verification 29/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Assertion Language
A is e = e e < e
¬A A ∧ A
A ∨ A A→ A
∀x(A) ∃x(A)
Mahmudul Faisal Al Ameen — Formal Program Verification 30/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Hoare’s Logic: An Asserted Program
An asserted program -
ProgramPrecondition Postcondition
means -
Preconditionis true
∧ Program
finished execution
→ Postconditionis true
‘The Asserted Program is true’ means‘if Precondition is true and the Program finished execution thenPostcondition is also true’Note: Precondition and postcondition are assertions.
Mahmudul Faisal Al Ameen — Formal Program Verification 31/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Axiom: Skip
skipA A
Example:
skipx = 0 x = 0
Mahmudul Faisal Al Ameen — Formal Program Verification 32/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Axiom: Assignment
x := e;A[x ← e] A
Example (all three are equivalent):
x := x + 1;(x = 1)[x ← x + 1] x = 1
x := x + 1;(x + 1 = 1) x = 1
x := x + 1;x = 0 x = 1
Mahmudul Faisal Al Ameen — Formal Program Verification 33/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: If
P1A ∧ b B
P2A ∧ ¬b B
if (b){P1
}else{P2
}
A B
Mahmudul Faisal Al Ameen — Formal Program Verification 34/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: If (Example)
x := 10;(x = 1) ∧ (x > 0) x = 10
x := 100;(x = 1) ∧ ¬(x > 0) x = 10
if (x > 0){x := 10;
}else{x := 100;
}
x = 1 x = 10
Mahmudul Faisal Al Ameen — Formal Program Verification 35/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: While
PA ∧ b A
while (b){P
}A A ∧ ¬b
Mahmudul Faisal Al Ameen — Formal Program Verification 36/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: While (Example)
y := y + 1;x := x + 1;
(x = y) ∧ x < 10 x = y
while (x < 10){y := y + 1;x := x + 1;
}
x = y x = y ∧ ¬(x < 10)
Mahmudul Faisal Al Ameen — Formal Program Verification 37/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Composition
P1A B
P2B C
P1
P2A C
Mahmudul Faisal Al Ameen — Formal Program Verification 38/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Composition (Example)
x:=1;x = 0 ∧ y = 0 x = 1 ∧ y = 0
y:=1;x = 1 ∧ y = 0 x = 1 ∧ y = 1
x:=1;
y:=1;x = 0 ∧ y = 0 x = 1 ∧ y = 1
Mahmudul Faisal Al Ameen — Formal Program Verification 39/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Consequence - 1
PA B
skip;A1 A
PA1 B
Mahmudul Faisal Al Ameen — Formal Program Verification 40/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Consequence - 1 (Example)
x := x + 1x > 0 x = 2
skip;x = 1 x > 0
x := x + 1x = 1 x = 2
Mahmudul Faisal Al Ameen — Formal Program Verification 41/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Consequence - 2
PA B
skip;B B1
PA B1
Mahmudul Faisal Al Ameen — Formal Program Verification 42/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Inference Rule: Consequence - 2 (Example)
x := x + 1x > 0 x = 2
skip;x = 2 x > 1
x := x + 1x > 0 x > 1
Mahmudul Faisal Al Ameen — Formal Program Verification 43/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Verification Process: A Bad Program (step 1)
z = a ∧ b = 0
if( z=1 ) { b:=0; }else{
if( z=2 ) { b:=1; }else{
w := z / 2;
if( w × 2 = z ){ b := 0; }else{
w := z / 3;
if(w × 3 = z){ b := 0; }else { b := 1; }
}}
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 44/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘ if’ (step 2)
z = a ∧ b = 0 ∧ z = 1
b:=0;
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Figure: True by assignment andconsequence
z = a ∧ b = 0 ∧ ¬(z = 1)
if( z=2 ) { b:=1; }else{
w := z / 2;
if( w × 2 = z ){ b := 0; }else{
w := z / 3;
if(w × 3 = z){ b := 0; }else { b := 1; }
}}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 45/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘if’ (step 3)
z = a ∧ b = 0 ∧ ¬(z = 1) ∧ (z = 2)
b := 1;
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Figure: True by assignment andconsequence
z = a ∧ b = 0 ∧ ¬(z = 1) ∧ ¬(z = 2)
w := z / 2;
if( w × 2 = z ){ b := 0; }else{
w := z / 3;
if(w × 3 = z){ b := 0; }else { b := 1; }
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 46/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘composition’ (step 4)
z = a ∧ b = 0 ∧ ¬(z = 1) ∧ ¬(z = 2)
w := z / 2;
z = a ∧ b = 0 ∧ ¬(z = 1) ∧ ¬(z =2) ∧ (w = z/2)
Figure: True by assignment andconsequence
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ (w = z/2)
if( w × 2 = z ){ b := 0; }else{
w := z / 3;
if(w × 3 = z){ b := 0; }else { b := 1; }
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 47/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘if’ (step 5)
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧
(w = z/2) ∧ (w × 2 = z)
b := 0;
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Figure: True by assignment andconsequence
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ (w =
z/2) ∧ ¬(w × 2 = z)
w := z / 3;
if(w × 3 = z){b := 0;
}else {b := 1;
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 48/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘composition’ (step 6)
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ (w =
z/2) ∧ ¬(w × 2 = z)
w := z / 3;
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ w = z/3
Figure: True by assignment andconsequence
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ w = z/3
if(w × 3 = z){b := 0;
}else {b := 1;
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 49/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘if’ (step 7)
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧w = z/3 ∧ (w × 3 = z)
b := 0;
A→ (b = 1) ∧ ¬A→ (b = 0)
Figure: True by assignment andconsequence
(z = a) ∧ (b = 0)∧¬(z = 1) ∧ ¬(z = 2) ∧ (w =
z/3) ∧ ¬(w × 3 = z)
b := 1;
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Figure: This part is false justwhen a = 25
Hence it is proved that the program is incorrect.
Mahmudul Faisal Al Ameen — Formal Program Verification 50/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Verification Process: A Good Program (step 1)
z = a ∧ b = 0
b := 1;
if(z=1) { b := 0; }else {
i = 2;
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 51/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘composition’ (step 2)
z = a ∧ b = 0
b := 1;
z = a ∧ b = 1
Figure: True by assignment andconsequence
z = a ∧ b = 1
if(z=1) { b := 0; }else {
i = 2;
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 52/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘if’ (step 3)
(z = a ∧ b = 0) ∧ (z = 1)
b := 0;
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Figure: True by assignment andconsequence
(z = a ∧ b = 0) ∧ ¬(z = 1)
i = 2;
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 53/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘composition’ (step 4)
(z = a ∧ b = 0) ∧ ¬(z = 1)
i := 2;
(z = a ∧ b = 0) ∧ ¬(z = 1) ∧ i = 2
Figure: True by assignment andconsequence
(z = a ∧ b = 0) ∧ ¬(z = 1) ∧ i = 2
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
A → (b = 1) ∧ ¬A → (b = 0) where
A = ¬(a = 1 ∨ ∃xy((1 < x, y < a) ∧ (x × y = a)))
Mahmudul Faisal Al Ameen — Formal Program Verification 54/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘consequence - 2’ (step 5)
A → (b = 1) ∧ ¬A → (b = 0)∧¬(i < z ∧ b = 1)
skip;
A→ (b = 1) ∧ ¬A→ (b = 0)
Figure: True by skip andconsequence
(z = a ∧ b = 0) ∧ ¬(z = 1) ∧ i = 2
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
A→ (b = 1) ∧ ¬A→ (b = 0)∧¬(i < z ∧ b = 1)
Mahmudul Faisal Al Ameen — Formal Program Verification 55/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘consequence - 1’ (step 6)
(z = a ∧ b = 0) ∧ ¬(z = 1) ∧ i = 2
skip;
Loop Invariant
Figure: True by skip andconsequence
Loop Invariant
while(i < z ∧ b = 1){w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}}
Loop Invariant and ¬(i < z ∧ b = 1)
Mahmudul Faisal Al Ameen — Formal Program Verification 56/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Using the rule ‘while’ (step 7)
Loop Invariant and i < z ∧ b = 1
w := z / i;
if(w × i = z) {b := 0;
} else {i = i + 1;
}
Loop Invariant
Mahmudul Faisal Al Ameen — Formal Program Verification 57/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Hoare’s Logic is sound
A provedcorrect
programis
indeedcorrect
Mahmudul Faisal Al Ameen — Formal Program Verification 58/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Hoare’s Logic is complete
All correctprogram
isprovablein thissystem
Mahmudul Faisal Al Ameen — Formal Program Verification 59/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Extensions
Hoare’sLogic
+ Re-cursiveProce-dure
SeparationLogic
+ Re-cursiveProce-dure
+InductiveTypes
Mahmudul Faisal Al Ameen — Formal Program Verification 60/62
Programming Bug Verification Formal Verification Language Hoare’s Logic Example Correctness Conclusion
Renowned People
Sir Tony Hoare Stephen A. Cook Krzysztof R. Apt
John C. Reynolds Makoto Tatsuta
Mahmudul Faisal Al Ameen — Formal Program Verification 61/62