Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 5. Invariants: Integer Multiplication from Bit Shifts We'll show that the following simple algorithm (state machine efficiently computes the product of two nonnegative integers,

image text in transcribed

Problem 5. Invariants: Integer Multiplication from Bit Shifts We'll show that the following simple algorithm (state machine efficiently computes the product of two nonnegative integers, I and y. (It takes advantage of the fact that multiplying or dividing an integer by 2 is especially fast on most computers, requiring just a single bit- shift operation. The set of states is N = {(r, s, a) r, s, a EN}, i.e., the set of triples of nonnegative integers. The start state is (r, y,0). Finally, the state transitions are as follows: (r, s, a) + (2r, s/2, a) 2r, (s - 1)/2, a +r) nothing for even s > 0 for odd s > 0, for s=0 We'll show that this state machine eventually reaches a final state with no transitions re- maining the algorithm doesn't run forever!), and that this final state (ry, Spa) will have a = r.y the algorithm computes the desired answer!). (a) Compute the full sequence of transitions from starting state (5,22,0). Does it correctly compute 5. 22 = 110? (b) Prove by strong induction on s that from any state r, s, a), this algorithm terminates after at most 1 + log, s steps (if s > 0). So the algorithm finishes, and it does so quickly. Hint: Recall that log (/2) = log2 s) - 1. (c) Prove that rs + a=ry is an invariant of this procedure (d) Use the previous two parts to conclude that this algorithm must terminate in some final state rf, Sf. a) that has a = ry. Problem 5. Invariants: Integer Multiplication from Bit Shifts We'll show that the following simple algorithm (state machine efficiently computes the product of two nonnegative integers, I and y. (It takes advantage of the fact that multiplying or dividing an integer by 2 is especially fast on most computers, requiring just a single bit- shift operation. The set of states is N = {(r, s, a) r, s, a EN}, i.e., the set of triples of nonnegative integers. The start state is (r, y,0). Finally, the state transitions are as follows: (r, s, a) + (2r, s/2, a) 2r, (s - 1)/2, a +r) nothing for even s > 0 for odd s > 0, for s=0 We'll show that this state machine eventually reaches a final state with no transitions re- maining the algorithm doesn't run forever!), and that this final state (ry, Spa) will have a = r.y the algorithm computes the desired answer!). (a) Compute the full sequence of transitions from starting state (5,22,0). Does it correctly compute 5. 22 = 110? (b) Prove by strong induction on s that from any state r, s, a), this algorithm terminates after at most 1 + log, s steps (if s > 0). So the algorithm finishes, and it does so quickly. Hint: Recall that log (/2) = log2 s) - 1. (c) Prove that rs + a=ry is an invariant of this procedure (d) Use the previous two parts to conclude that this algorithm must terminate in some final state rf, Sf. a) that has a = ry

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions

Question

Why are value-added activities defined from a customer viewpoint?

Answered: 1 week ago

Question

Using Language That Works

Answered: 1 week ago

Question

4. Are my sources relevant?

Answered: 1 week ago