CSC236H1 Lecture Notes - Lecture 15: Postcondition, Precondition, Loop Invariant

66 views11 pages
26 Feb 2019
School
Course
Professor

Document Summary

Correctness of iterative programs: termination: p re t erm, partial correctness p re t erm p ost, precondition: p re_cond, postcondition: p ost_cond. def iter_prog(r_1,,r_n): Li induction steps while loop_cond: { pre and steps. #post_cond pre atermination and termination is post and. Example proving the loop invariant so o six c tenca since by pre and. In i a i i so since another iteration of the whitehoop exists we have ie e cenca. So in i e cenca so 0 e i ke e cenca ice elen a ca suma. E acj i o a cia by line a. Example proving partial correctness: precondition: a is a non-empty list of numbers, postcondition: returns the average of the numbers in a. def avg(a): Li(k): if the loop is executed at least k times, then: (a) sk = qik 1 j=0 a[j]; (b) 0 ik len(a). Also lz ct it e cenca ik clenck holds ik uncas iterations.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents