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 a:= a+r; r:=r+r+r; s:= (s – 1)/3; end else a:= a+r+r; r:=r+r+r; s:= (s – 2)/3; end end return a Algorithm 1: Multiply We can model Algorithm ]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 8 that for s > 0: (3r,s/3,a) if 3|s 8(r,s,a) = {(3r, (s –1)/3,a+r) 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

This is a discerete maths assignment 

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).)
Transcribed Image 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).)
Expert Solution
steps

Step by step

Solved in 2 steps with 42 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education