CS 201 Lecture 18 - Program Correctness
CS 201 Lecture 18 - Program Correctness
Kholoud Nairoukh
Department of Computer Science
German-Jordanian University
Lecture 18
• We want to be able to prove that a given
program meets the intended specifications.
– This can often be done manually, or even by
automated program verification tools.
– Example: PVS (People’s Verification
System).
• A program is correct if it produces the
correct output for every possible input.
– A program has partial correctness if it
produces the correct output for every input
for which the program eventually halts.
Dr. Kholoud Nairoukh
• A program’s I/O specification can be given using initial and final
assertions.
– The initial assertion p is the condition that the program’s
input (its initial state) is guaranteed (by its user) to satisfy.
– The final assertion q is the condition that the output
produced by the program (its final state) is required to
satisfy.
• Hoare triple notation:
– The notation p{S}q means that, for all inputs I such that p(I)
is true, if program S (given input I) halts and produces
output O = S(I), then q(O) is true.
• That is, S is partially correct with respect to
specification p,q.
p{S1}q
q{S2}r
∴ p{S1; S2}r