- Learning how to (systematically) reason about simple, sequential programs.
- Learning how to prove that a method is correct.
一,Program State
The state at a program point is a valuation of the variables in scope at that program point.
// 状态就是在某个点时,在范围内的变量的值
二,Floyd Logic
{P} S {Q} #霍尔三元组
P--precondition // requires
S--program
Q--postcondition // ensures
当 P 满足,执行 S 后,Q 就会被满足(holds)
三,Strongest Postconditions and Weakest Preconditions
Forward Reasoning --> Strongest Postconditions
Backward reasoning --> Weakest Preconditions
//Weaker predicates describe fewer constraints on the state (only relevant variables constrained).
// 因为简单所以weakest
四,Method Correctness
The method is correct when its precondition implies the calculated weakest precondition.
(P == > WP) // Pstronger,范围更小