Ancient Wisdom: On Raising A Number To A PowerEgyptian MultiplicationEgyptian Multiplication a times b by repeated doublingWhy does that work?Slide 5Slide 6Egyptian Base ConversionSlide 8Rhind Papyrus (1650 BC) 70*13Slide 10Rhind Papyrus (1650 BC) Division: 184/17Slide 12Slide 13Slide 14Standard Binary Multiplication = Egyptian MultiplicationOur story so far…Slide 17Let’s Articulate A New One:Slide 19Compiler 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 29Slide 30Slide 31Applying Two IdeasWhat is the more essential representation of M(n)?The “a” is a red herring.Addition ChainsExamplesAddition Chains Are A Simpler Way To Represent The Original ProblemSlide 38Some Addition Chains For 30Slide 40Binary 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 47Slide 48Slide 49Slide 50Slide 51Slide 52GeneralizationSlide 54A Lower Bound IdeaLet Sk be the statement that no k stage addition chain will contain a number greater than 2kProof By Invariant (Induction)Change Of VariableSlide 59Theorem: 2i is the largest number that can be made in i stages, and can only be made by repeated doubling5 < M(30)Suppose M(15) = 4Slide 63Slide 64Rhind Papyrus (1650 BC)Factoring BoundSlide 67Corollary (Using Induction)More CorollariesM(33) < M(3) + M(11)Conjecture: M(2n) = M(n) +1 (A. Goulard)Open ProblemConjectureSlide 74High Level PointStudy BeeSlide 77Slide 78REFERENCESAncient Wisdom:On Raising A Number To A PowerGreat Theoretical Ideas In Computer ScienceAnupam GuptaCS 15-251 Fall 2005Lecture 5 Sept 13, 2005 Carnegie Mellon University1515aaEgyptian MultiplicationThe Egyptians used decimal numbers but multiplied and divided in binaryEgyptian Multiplication a times bby repeated doublingb has some n-bit representation: bn-1bn-2…b1b0Starting with a, repeatedly double largest number so far to obtain: a, 2a, 4a, …., 2n-1aSum together all the 2ka where bk = 1Why does that work? b = b020 + b121 + b222 + … + bn-12n-1ab = b020a + b121a + b222a + … + bn-12n-1aIf bk is 1 then 2ka is in the sum.Otherwise that term will be 0.Wait! How did the Egyptians do the part where they converted b to binary?They used repeated halving to do base conversion. Consider …Egyptian Base ConversionOutput stream will print right to left.Input X;repeat { if (X is even)then print 0; else {X := X-1; print 1;} X := X/2 ;} until X=0;Sometimes the Egyptian combined the base conversion by halving and multiplication by doubling into a single algorithmRhind Papyrus (1650 BC)70*137014028056013 * 7063 * 3501 * 910Rhind Papyrus (1650 BC)70*137014028056013 * 7063 * 3501 * 910Binary for 13 is 1101 = 23 + 22 + 2070*13 = 70*23 + 70*22 + 70*2017346813612 *48 *184 48 14Rhind Papyrus (1650 BC)Division: 184/1717346813612 *48 *184 48 14Rhind Papyrus (1650 BC)Division: 184/17184 = 17*8 + 17*2 + 14184/17 = 10 with remainder 14This method is called “Egyptian Multiplication/Division” or “Russian Peasant Multiplication/Division”.Wow. Those Russian peasants were pretty smart.Standard Binary Multiplication= Egyptian Multiplication×1101 * * * * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * *We can view numbers in many different, but corresponding ways.Our story so far…Representation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123Induction is how we define and manipulate mathematical ideas.Inductionhas many guises.Master their interrelationship.•Formal Arguments•Loop Invariants•Recursion•Algorithm Design•Recurrences Our story so far…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 n, how do we implement b:=an with the fewest number of multiplications?Powering By Repeated MultiplicationInput: a, nOutput:A sequence starting with a, A sequence starting with a, ending with aending with ann, such that , such that each entry other than the each entry other than the first is the product of two first is the product of two 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 ofmultiplications required to produce an from a 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 Examples•What 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 one 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 one way to make a8 in 3 multiplications. What does this tell us about the value of M(8)?M( )8 3Upper BoundExhaustive Search. There are only two sequences with 2 multiplications. Neither of them make 8: a, a2, a3 & a, a2, a4 ? ≤ M(8) ≤ 33 ≤ M(8)Upper BoundLower BoundM(8) = 33 ≤ M(8) ≤ 3Applying Two IdeasRepresentation:Representation:Understand the relationship betweenUnderstand the relationship betweendifferent representations of the samedifferent representations of the sameinformation or ideainformation or idea123AbstractionAbstraction: : Abstract away the inessential Abstract away the inessential features of a problem or solutionfeatures of a problem or solution=What is the more essential representation
View Full Document