Loop Invariants: Part 2
7 January 2019 OSU CSE 1
Loop Invariants: Part 2 7 January 2019 OSU CSE 1 Maintaining the - - PowerPoint PPT Presentation
Loop Invariants: Part 2 7 January 2019 OSU CSE 1 Maintaining the Loop Invariant A claimed loop invariant is valid only if the loop body actually maintains the property, i.e., the loop invariant remains true at the end of each execution of
7 January 2019 OSU CSE 1
7 January 2019 OSU CSE 2
7 January 2019 OSU CSE 3
7 January 2019 OSU CSE 4
7 January 2019 OSU CSE 5
7 January 2019 OSU CSE 6
7 January 2019 OSU CSE 7
7 January 2019 OSU CSE 8
7 January 2019 OSU CSE 9
double result = 1.0; double factor = x; int pLeft = p; /** * @updates result, factor, pLeft * @maintains * pLeft >= 0 and * result * factor^(pLeft) = x^(p) * @decreases * pLeft */ while (pLeft > 0) { ... } return result;
7 January 2019 OSU CSE 10
7 January 2019 OSU CSE 11
x = 3.0 p = 5 result = 1.0 factor = 3.0 pLeft = 5 /** * @maintains * pLeft >= 0 and * result * factor^(pLeft) = x^(p) */ while (pLeft > 0) { ... } x = 3.0 p = 5 result = factor = pLeft =
7 January 2019 OSU CSE 12
7 January 2019 OSU CSE 13
7 January 2019 OSU CSE 14
7 January 2019 OSU CSE 15
7 January 2019 OSU CSE 16
7 January 2019 OSU CSE 17
7 January 2019 OSU CSE 18
7 January 2019 OSU CSE 19
7 January 2019 OSU CSE 20