(Solved) : 4 Proving Function Correct 4 Points 52 Necessary Introduce New Local N Second Version Comp Q44029129 . . .
4 Proving a Function Correct (4 points) 5.2 Why was it necessary to introduce the new local n in the second version of compute.sc above? In this question, we’ll do part of the proof of correctness for a function compute_square relative to a specification function SQUARE. We won’t prove that the loop invariants are true initially, and we won’t prove that they’re preserved by an arbitrary iteration of the loop int compute_square(int n) { int total = 0; while in > ) { total += 2-n – 1; Give a suitable extra invariant that would allow us to prove the function correct. //@loop_invariant when the loop ter- Which line numbers would we point to to justify that n == minates? return total; 5.1 Complete the specification function below with the simple mathematical formula that gives the square of the numbers 13. int SQUARE(int n) 2//@requires Ocn && n < 10000; Substitute in 0 for n in your loop invariant on line 17 and then simplify. return Give a postcondition for compute square using this specification function. int compute_square(int num) //@requires Ocnum && num < 10000; 10 //@ensures When you substitute result for total in the simplified version, you should have exactly the postcondition on line 10. This proves that the loop invariant and the negation of the loop guard imply the postcondition. 5.3 Termination arguments for loops (in this class, at least) must have the following form: During an arbitrary iteration of the loop, the quantity gets strictly larger, but from the loop in variants, we know this quantity can’t ever get bigger than … or During an arbitrary iteration of the loop, the quantity … gets strictly smaller, lut from the loop innriants, we know this quantity can’t ever get smaller than …. Assuming that your loop invariants are true initially preserved by every iteration of the loop (which we didn’t prove), why does the loop in compute_square terminate? int n – num; int total = 0; while (n > 0) //@loop invariant 0 <= n; //@loop invariant n <= 10000; // Additional loop invariant will go here total + 2+n – 1; During an arbitrary iteration of the loop, the quantity – gets return total; strictly but from the loop invariants, we know that this quantity can’t ever get than Show transcribed image text 4 Proving a Function Correct (4 points) 5.2 Why was it necessary to introduce the new local n in the second version of compute.sc above? In this question, we’ll do part of the proof of correctness for a function compute_square relative to a specification function SQUARE. We won’t prove that the loop invariants are true initially, and we won’t prove that they’re preserved by an arbitrary iteration of the loop int compute_square(int n) { int total = 0; while in > ) { total += 2-n – 1; Give a suitable extra invariant that would allow us to prove the function correct. //@loop_invariant when the loop ter- Which line numbers would we point to to justify that n == minates? return total; 5.1 Complete the specification function below with the simple mathematical formula that gives the square of the numbers 13. int SQUARE(int n) 2//@requires Ocn && n
Expert Answer
Answer to 4 Proving a Function Correct (4 points) 5.2 Why was it necessary to introduce the new local n in the second version of c…
OR