{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture12

# lecture12 - COMPSCI 102 Discrete Mathematics for Computer...

This preview shows pages 1–18. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMPSCI 102 Discrete Mathematics for Computer Science Ancient Wisdom: On Raising A Number To A Power Lecture 12 a 1 5 1 5 The Egyptians used decimal numbers but multiplied and divided in binary Egyptian Multiplication a x b By Repeated Doubling b has n-bit representation: b n-1 b n-2 …b 1 b Starting with a, repeatedly double largest number so far to obtain: a, 2a, 4a, …., 2 n-1 a Sum together all the 2 k a where b k = 1 a b = b 2 a + b 1 2 1 a + b 2 2 2 a + … + b n-1 2 n-1 a 2 k a is in the sum if and only if b k = 1 b = b 2 + b 1 2 1 + b 2 2 2 + … + b n-1 2 n-1 Wait! How did the Egyptians do the part where they converted b to binary? They used repeated halving to do base conversion! Egyptian Base Conversion Output 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 Egyptians combined the base conversion by halving and multiplication by doubling into a single algorithm Binary for 13 is 1101 = 2 3 + 2 2 + 2 70*13 = 70*2 3 + 70*2 2 + 70*2 70 x 13 Rhind Papyrus [1650 BC] 70 140 280 560 13 6 3 1 * 70 350 910 Doubling Halving Odd? Running Total * * 5 x 30 5 10 20 40 30 15 7 3 * 30 70 Doubling Halving Odd? Running Total * * 80 1 150 * 10 184 / 17 Rhind Papyrus [1650 BC] Doubling Powers of 2 Check 17 34 68 136 1 2 4 8 * * 184 = 17*8 + 17*2 + 14 184/17 = 10 with remainder 14 This method is called “Egyptian Multiplication / Division” or “Russian Peasant Multiplication / Division” × 1101 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Standard Binary Multiplication = Egyptian Multiplication We can view numbers in many different, but corresponding ways Representation: Representation: Understand the relationship between Understand the relationship between different representations of the same different representations of the same information or idea information or idea 1 2 3 Our story so far… Induction is how we define and manipulate mathematical ideas Induction has many guises Master their interrelationship • Formal Arguments • Loop Invariants • Recursion • Algorithm Design • Recurrences Our story so far… Abstraction Abstraction : : Abstract away the inessential Abstract away the inessential features of a problem or solution features of a problem or solution = Let’s Articulate a New One: b:=a 8 b:=a*a b:=b*a b:=b*a b:=b*a b:=b*a b:=b*a b:=b*a b:=a*a b:=b*b...
View Full Document

{[ snackBarMessage ]}

### Page1 / 62

lecture12 - COMPSCI 102 Discrete Mathematics for Computer...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online