On Raising A Number To A PowerSo Far We Have Seen:Slide 3Let’s Articulate A New One:Slide 5Compiler Translationb:=a8General VersionPowering By Repeated MultiplicationExampleDefinition of M(n)What is M(n)? Can we calculate it exactly? Can we approximate it?Some Very Small ExamplesM(8) = ?Slide 15Slide 16Slide 17Slide 18Applying Two IdeasWhat is the more essential representation of M(n)?The a is a red herring.Addition ChainsExamplesAddition Chains Are A Simpler To Represent The Original ProblemSlide 25Some Addition Chains For 30Slide 27Binary RepresentationBinary Method Repeated Squaring Method Repeated Doubling MethodBinary Method Applied To 30Rhind Papyrus (1650 BC) What is 30 times 5?Rhind Papyrus (1650 BC) Actually used faster chain for 30*5.The Egyptian ConnectionSlide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40GENERALIZATIONSlide 42A Lower Bound IdeaInduction ProofLet Sk be the statement that no k stage addition chain will contain a number greater than 2kProof By Invariant (Induction)Change Of VariableTheorem: 2i is the largest number that can be made in i stages, and can only be made by repeated doublingSlide 495 < M(30)Suppose M(15) = 4Slide 52Slide 53Rhind Papyrus (1650 BC)Factoring BoundSlide 56Slide 57Corollary (Using Induction)More CorollariesM(33) < M(3) + M(11)Conjecture: M(2n) = M(n) +1 (A. Goulard)Open ProblemConjectureSlide 64High Level PointStudy BeeSlide 67Slide 68REFERENCESOn Raising A Number To A PowerGreat Theoretical Ideas In Computer ScienceSteven RudichCS 15-251 Spring 2004Lecture 5 Jan 27, 2004 Carnegie Mellon University1515aaSo Far We Have Seen:Don’t let the representation choose you. CHOOSE THE REPRESENTATION!Representation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123So Far We Have Seen:Induction is how we define and manipulate mathematical ideas.Let’s Articulate A New One:AbstractionAbstraction: : Abstract away the inessential Abstract away the inessential features of a problem or solutionfeatures of a problem or solution=Even very simple computational problems can be surprisingly subtle.Compiler TranslationA compiler must translate a high level language (e.g., C) with complex operations (e.g., exponentiation) into a lower level language (e.g., assembly) that can only support simpler operations (e.g., multiplication).b:=a8b:=a*ab:=b*ab:=b*ab:=b*ab:=b*ab:=b*ab:=b*ab:=a*ab:=b*bb:=b*bThis method costs only 3 multiplications. The savings are significant if b:=a8 is executed often.General VersionGiven a constant k, how do we implement b:=ak with the fewest number of multiplications?Powering By Repeated MultiplicationInput: a,nOutput:A sequence starting A sequence starting with a, ending with awith a, ending with ann, , and such that each and such that each entry other than the entry other than the first is the product of first is the product of previous entries.previous entries.ExampleInput: a,5Output: a, a2, a3, a4, a5orOutput: a, a2, a3, a5 orOutput: a, a2, a4, a5Definition of M(n)M(n) = The minimum number of multiplications required to produce an by repeated multiplicationWhat is M(n)? Can we calculate it exactly? Can we approximate it?Exemplification:Exemplification:Try out a problem orTry out a problem or solution on small examples. solution on small examples.Some Very Small ExamplesWhat is M(1)?–M(1) = 0 [a]•What is M(0)?–M(0) is not clear how to define•What is M(2)?–M(2) = 1 [a, a2]M(8) = ?a, a2, a4, a8 is a way to make a8 in 3 multiplications. What does this tell us about the value of M(8)?M(8) = ?a, a2, a4, a8 is a way to make a8 in 3 multiplications. What does this tell us about the value of M(8)?M( )8 3Upper Bound? ( ) M 8 3Lower Bound? ( ) M 8 3Lower Bound3 8 M( )Exhaustive Search. There are only two sequences with 2 multiplications. Neither of them make 8: a, a2, a3 & a, a2, a43 8 3 M( )Upper BoundLower BoundM(8) = 3Applying Two IdeasAbstractionAbstraction: : Abstract away the inessential Abstract away the inessential features of a problem or solutionfeatures of a problem or solution=Representation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123What is the more essential representation of M(n)?AbstractionAbstraction: : Abstract away the inessential Abstract away the inessential features of a problem or solutionfeatures of a problem or solution=Representation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123 ((( )))The a is a red herring.ax times ay is ax+yEverything besides the exponent is inessential. This should be viewed as a problem of repeated addition, rather than repeated multiplication.Addition ChainsM(n) = Number of stages required to make n, where we start at 1 and in each subsequent stage we add two previously constructed numbers.ExamplesAddition Chain for 8:1 2 3 5 8Minimal Addition Chain for 8:1 2 4 8Addition Chains Are A Simpler To Represent The Original ProblemAbstractionAbstraction: : Abstract away the inessential Abstract away the inessential features of a problem or solutionfeatures of a problem or solution=Representation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123M(30) = ?1515aaSome Addition Chains For 301 2 4 8 16 24 28 301 2 4 5 10 20 301 2 3 5 10 15 301 2 4 8 10 20 30? ( )? ( ? MM n30 6)Binary RepresentationLet Bn be the number of 1s in the binary representation of n. Ex: B5 = 2 since 101 is the binary representation of 5Proposition: Bn 6 b log2 (n) c + 1 The length of the binary representation of n is bounded by this quantity.Binary MethodRepeated Squaring MethodRepeated Doubling MethodPhase I (Repeated Doubling)For Add largest so far to itself(1, 2, 4, 8, 16, . . . )Phase II (Make n from bits and pieces)Expand n in binary to see how n is the sum of Bn powers of 2. Use Bn-1 stages to make n from the powers of 2 created in phase Ilog2n stages:Total Cost: log21n Bn Binary Method Applied To 30Binary30 11110Phase I1 12 104
View Full Document