This preview shows page 1-2-3-4-5-6-7-52-53-54-55-56-57-58-59-104-105-106-107-108-109-110 out of 110 pages.
Unary, Binary, and BeyondPowerPoint PresentationA Frequently Arising CalculationThe Geometric SeriesSlide 5nth Triangular Numbernth Square NumberSlide 8Slide 9Slide 10Slide 11Strings Of Symbols.Strings over the alphabet .Slide 14*Slide 16The Natural Numbers“God Made The Natural Numbers. Everything Else Is The Work Of Man.”Last Time: Unary NotationSlide 20Peano Unary (PU)Each number is a sequence of symbols in {S, 0}+Peano Unary Representation of Natural NumberInductive Definition of +S0 + S0 = SS0 (i.e., “1+1=2”)Inductive Definition of *Inductive Definition of ^ = { 0, S0, SS0, SSS0, . . .} = { 0, 1, 2, 3, . . .}a = [a DIV b]*b + [a MOD b]45 = [45 DIV 10]*10 + [ 45 MOD 10] = 4*10 + 5Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Initial Cases, length(X)=1Suppose n=length(X)>S0Example X= 238Slide 45Slide 46Slide 47Slide 48One digit cases.Suppose X > 9Slide 51Slide 52Clear when X is a single digit.Slide 54Slide 55X2 NLZ, n=length(Z) > 1Slide 57Slide 58Base X NotationS = an-1, an-2, …, a0 represents the number: an-1 Xn-1 + an-2 Xn-2 + . . . + a0 X0Slide 61Bases In Different CulturesBiggest n “digit” number in base X would be: (X-1)Xn-1 + (X-1)Xn-2 +…+ (X-1)X0Slide 64Biggest n “digit” number in base X would be: S= (X-1)Xn-1 + (X-1)Xn-2 +…+ (X-1)X0 Add 1 to get: Xn + 0 Xn-1 + … + 0 X0 Thus, S = Xn - 1Slide 66(X-1)Xn-1 + (X-1)Xn-2 +…+ (X-1)X0 = Xn - 1The highest n digit number in base X.Slide 69Slide 70Plus/Minus Base XSlide 72Slide 73Slide 74Slide 750 has a unique n-digit plus/minus base X representation as all 0’s.Each of the numbers from 0 to Xn-1 is uniquely represented by an n-digit number in base X.Slide 78Fundamental Theorem For Base X: Each of the numbers from 0 to Xn-1 is uniquely represented by an n-digit number in base X.Slide 80Egyptian MultiplicationEgyptian Multiplication a times b by repeated doublingEgyptian Multiplication 15 times 5 by repeated doublingWhy does that work?Slide 85Slide 86Egyptian Base ConversionSlide 88Start the algorithmSlide 90Slide 91Slide 92Slide 93Slide 94And Keep Going until 0Slide 96Rhind Papyrus (1650 BC) 70*13Slide 98Rhind Papyrus (1650 BC)Slide 100Slide 101Slide 102Standard Binary Multiplication = Egyptian MultiplicationEgyptian Base 3Unique Representation Theorem for Egyptian Base 3 No integer has 2 distinct, n-digit, Egyptian base-3 representations. We can represent all integers from -(3n-1)/2 to (3n-1)/2Slide 106Slide 107Slide 108Slide 109ReferencesUnary, Binary, and BeyondGreat Theoretical Ideas In Computer ScienceSteven RudichCS 15-251 Spring 2004Lecture 3 Jan 20, 2004 Carnegie Mellon UniversityWe are going to need this fundamental sum:The Geometric Series 1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xn-2n-2 + X + Xn-1n-1 == XXn n – 1 – 1 XX - - 11A Frequently Arising Calculation(X-1) ( 1 + X1 + X2 + X 3 + … + Xn-2 + Xn-1 )= X1 + X2 + X 3 + … + Xn-1 + Xn - 1 - X1 - X2 - X 3 - … - Xn-2 – Xn-1= - 1 + Xn= Xn - 1The Geometric Series(X-1) ( 1 + X1 + X2 + X 3 + … + Xn-1 ) = Xn - 1 1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xn-2n-2 + X + Xn-1n-1 == XXn n – 1 – 1 XX - - 11 when X1Last time we talked about unary notation.nth Triangular Numbern = 1 + 2 + 3 + . . . + n-1 + n = n(n+1)/2nth Square Numbern = 1 + 3 + … + 2n-1 = Sum of first n odd numbersnth Square Numbern = n + n-1 = n2(( nn))2 =2 = (( n-1n-1))2 2 ++nn (( nn))2 2 = + + . . . = + + . . . + + nnWe will define sequences of symbols that give us a unary representation of the Natural number.First we define the general language we use to talk about strings.Strings Of Symbols.We take the idea of symbol and sequence of symbols as primitive.Let be any fixed finite set of symbols. is called an alphabet, or a set of symbols. Examples: = {0,1,2,3,4}= {a,b,c,d, …, z}= all typewriter symbols.Strings over the alphabet A string is a sequence of symbols from . Let s and t be strings. Let st denote the concatenation of s and t, i.e., the string obtained by the string s followed by the string t. Define + by the following inductive rules: x2 ) x2 +s,t 2 + ) st 2 +Intuitively, + is the set of all finite strings that we can make using (at least one) letters from .Define be the empty string. I.e.,XY= XY for all strings X and Y. is also called the string of length 0.Define 0 = { }Define * = + [ {}Intuitively, * is the set of all finite strings that we can make using letters from including the empty string.The Natural Numbers = { 0, 1, 2, 3, . . .}Notice that we include 0 as a Natural number.“God Made The Natural Numbers. Everything Else Is The Work Of Man.” = { 0, 1, 2, 3, . . .}KroneckerLast Time: Unary Notation1234To handle the notation for zero, we introduce a small variation on unary.Peano Unary (PU)0 01 S02 SS03 SSS04 SSSS05 SSSSS06 SSSSSS0Giuseppe Peano [1889]Each number is a sequence of symbols in {S, 0}+0 01 S02 SS03 SSS04 SSSS05 SSSSS06 SSSSSS0Peano Unary Representation of Natural Number = { 0, S0, SS0, SSS0, . . .}0 is a natural number called zero.Set notation: 0 2 If X is a natural number, then SX is a natural number called successor of X.Set notation: X 2 ) SX 2 Inductive Definition of + = { 0, S0, SS0, SSS0, . . .}Inductive definition of addition (+):X, Y 2 )X “+” 0 = XX “+” SY = S(X”+”Y)S0 + S0 = SS0 (i.e., “1+1=2”)Proof:S0 + S0 = S(S0 + 0) = S(S0) = SS0 X, Y 2 )X “+” 0 = XX “+” SY = S(X”+”Y)Inductive Definition of * = { 0, S0, SS0, SSS0, . . .}Inductive definition of times (*):X, Y 2 )X “*” 0 = 0X “*” SY = (X”*”Y) + XInductive Definition of ^ = { 0, S0, SS0, SSS0, . . .}Inductive definition of raised to the (^):X, Y 2 )X “^” 0 = 1 [or X0 = 1 ]X “^” SY = (X”^”Y) * X [or XSY = XY * X] = { 0, S0, SS0, SSS0, . . .}Defining < for :8 x,y 2 “x > y” is TRUE “y < x” is FALSE“x > y” is TRUE “y > x” is FALSE“x+1 > 0” is TRUE“x+1 > y+1” is TRUE ) “x > y” is TRUE = { 0, 1, 2, 3, . . .}Defining partial minus for :8 x,y 2 x-0 = x x>y ) (x+1) – (y+1) = x-ya = [a DIV b]*b + [a MOD b]Defining DIV and MOD for :8 a,b 2 a<b ) a DIV b = 0 a¸b>0 ) a DIV b = 1 + (a-b) DIV ba MOD b = a – …
View Full Document