1. Correctness
A program is correct if it produces correct output for every valid input.
- Partial correctness: if the program terminates ⇒ output is correct
- Termination: program always terminates
2. Hoare Triple
Notation:
: initial assertion : final assertion : program
Meaning:
If
3. Partial Correctness
Note: does NOT guarantee termination.
4. Composition Rule
If:
Then:
5. Conditional Statements
5.1 If (no else)
text
if condition then SRule:
Therefore:
5.2 If-Else
text
if condition then S1 else S2Rule:
Therefore:
5.3 Rule of Inference: If – Else If – ... – Else
text
if condition1 then S1
else if condition2 then S2
...
else SnRule
Để chứng minh:
Ta cần chứng minh các điều sau:
Kết luận
6. Loop Invariant (While)
text
while condition do SDefinition
While Rule
If:
Then:
7. Intuition
- Invariant = something always true during the loop
- When loop ends:
- condition = false
- invariant still true
⇒ derive final result
8. Proof Checklist for While
- Initialization:
- Maintenance:
- Termination: