This is a discerete maths assignment 0:[(3r,s/3,a)8(r, s,a) = {(3r, (s - 1)/3,a+r)if 3 | sif 3 | (s– 1)(3r, (s – 2)/3,a+ 2r) otherwise.1. List the sequence of steps that appears in the execution...


This is a discerete maths assignment


Writing Prompt<br>Consider the following algorithmic procedure:<br>Input :Non-negative integers x, y<br>Output : Non-negative integer a<br>r:= x;<br>s:= y;<br>a := 0;<br>while s + 0 do<br>if 3 | s then<br>r:=r+r+r;<br>s:= s/3;<br>end<br>else if 3 | (s-1) then<br>а:3а+r;<br>r:=r+r+r;<br>s:= (s – 1)/3;<br>end<br>else<br>а:3а+r+r;<br>r:=r+r+r;<br>s:= (s – 2)/3;<br>end<br>end<br>return a<br>Algorithm 1: Multiply<br>We can model Algorithm I as a state machine whose states are triples of non-negative integers<br>(r, s, a). The initial state is (x, y, 0). The transitions are given by the rule & that for s > 0:<br>[(3r,s/3,a)<br>8(r, s,a) = {(3r, (s - 1)/3,a+r)<br>if 3 | s<br>if 3 | (s– 1)<br>(3r, (s – 2)/3,a+ 2r) otherwise.<br>1. List the sequence of steps that appears in the execution of the algorithm for inputs x = 20 and<br>y = 21. In other words, walk us through the algorithm starting from the initial state, showing<br>the values of r, s, a after each transition, and ending with the final state. Note that for the rest<br>of the prompt, you are considering arbitrary inputs x, y. The above example inputs are just to<br>help you familiarize yourself with the algorithm.<br>2. Verify the partial correctness of Algorithm [I<br>(a) Define a predicate P on the states that you believe is a preserved invariant. (Suggestion:<br>Think about why the loop condition is s # 0 and look at your sequence of steps from<br>Part 1.)<br>(b) Prove that P is a preserved invariant.<br>(c) Apply the Invariant Principle to prove that if s = 0, then a = xy.<br>3. Verify that Algorithm [] terminates.<br>(a) Define a strictly decreasing derived variable on the states.<br>(b) Prove that the algorithm terminates after at most 1 + logą y executions of the body of the<br>do statement. (Suggestion: Review the Fast Exponentiation program in [1).)<br>

Extracted text: Writing Prompt Consider the following algorithmic procedure: Input :Non-negative integers x, y Output : Non-negative integer a r:= x; s:= y; a := 0; while s + 0 do if 3 | s then r:=r+r+r; s:= s/3; end else if 3 | (s-1) then а:3а+r; r:=r+r+r; s:= (s – 1)/3; end else а:3а+r+r; r:=r+r+r; s:= (s – 2)/3; end end return a Algorithm 1: Multiply We can model Algorithm I as a state machine whose states are triples of non-negative integers (r, s, a). The initial state is (x, y, 0). The transitions are given by the rule & that for s > 0: [(3r,s/3,a) 8(r, s,a) = {(3r, (s - 1)/3,a+r) if 3 | s if 3 | (s– 1) (3r, (s – 2)/3,a+ 2r) otherwise. 1. List the sequence of steps that appears in the execution of the algorithm for inputs x = 20 and y = 21. In other words, walk us through the algorithm starting from the initial state, showing the values of r, s, a after each transition, and ending with the final state. Note that for the rest of the prompt, you are considering arbitrary inputs x, y. The above example inputs are just to help you familiarize yourself with the algorithm. 2. Verify the partial correctness of Algorithm [I (a) Define a predicate P on the states that you believe is a preserved invariant. (Suggestion: Think about why the loop condition is s # 0 and look at your sequence of steps from Part 1.) (b) Prove that P is a preserved invariant. (c) Apply the Invariant Principle to prove that if s = 0, then a = xy. 3. Verify that Algorithm [] terminates. (a) Define a strictly decreasing derived variable on the states. (b) Prove that the algorithm terminates after at most 1 + logą y executions of the body of the do statement. (Suggestion: Review the Fast Exponentiation program in [1).)
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here