32
Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August 31, 2015

Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Embed Size (px)

Citation preview

Page 2: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Abstract: There is base 10 and base 2 and base 16 (hexadecimal) notation but why not base 3 (ternary) and in particular balanced ternary notation? We’ll examine what balanced ternary notation is and how to add, subtract, multiply, divide and take square roots. There is some evidence that balanced ternary notation is the most efficient of numbering systems, the so called “Goldilocks” of numbering systems in that “base 2 is too small”, “base 10 is too big”, and “base 3 is just right”. “Perhaps the prettiest number system of all … is the balanced ternary notation” –

Donald Knuth, The Art of Programming

Page 3: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

A brief historical overview of numbering systems

The standard positional notations: decimal and binary

Why not ternary and balanced ternary?

Arithmetic operations in balanced ternary

Square roots? (with time)

Why ternary is the Goldilocks of positional notation – a proof?

Page 4: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Type A – Additive Systems (3 subtypes) “simple transcriptions of even more concrete systems of counting”

A.1 Egyptian Hieroglyphic systemA.2 Roman NumeralsA.3 Greek Alphabetic

Type B – Hybrid Systems (5 subtypes) “written transcriptions of more or less organized verbal expressions of number” – additive and multiplicative principle

B.1. Common Assyro-Babylonian B.5. Common Chinese

Type C – Positional Systems (2 subtype)

C.1. Learned Babylonian; Learned Chinese Mayan (base 20 – modified)

C.2. Indian -> Modern

Georges Ifrah “The Universal History of Numbers”

An Overview of Numbering

Systems

Page 5: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Egyptian Numerals

Page 7: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Common Assyro-Babylonian

Page 8: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Common Chinese

Page 10: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Positional Notations: Decimal Base and Binary Notation

2413 = 2×103 + 4×102 + 1×101 + 3×100

1011101 = 1×26 + 0×25 +1×24 + 1×23 + 1×22 + 0×21 + 1×0 = 64 + 16 + 8 + 4 + 1 = 91

Also Octal (0135) and Hexadecimal (0x5D) Notation

Binary to Decimal Conversion: Expand by Powers of 2

Decimal to Binary Conversion: Subtract out Powers of 2

Page 11: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Example: Convert 413 to Binary

256 128 64 32 16 8 4 2 1 1 1 0 0 1 1 0 1 1

413 157 29 11 3 1 -256 -128 -16 - 8 -2 -1 157 29 11 3 1 0

Example: Convert 2413 to binary

2048 1024 256 128 64 32 16 8 4 2 1

Why Binary Notation: Pros and Cons?

Page 12: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Ternary (base 3) Notation

In Ternary natation we use three digits (0, 1, 2) and powers of 3

Example 12013 = 1×33 + 2×32 + 0×31 + 1×30 = 27 + 2×9 + 0 + 1 = 46

To convert Ternary to Decimal expand by powers of 3

To convert Decimal to Ternary subtract out (multiple) powers of 3

729 243 81 27 9 3 1

Page 13: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Example: Convert 413 to Ternary

243 81 27 9 3 1486 162 54 18 6 2

1 2 0 0 2 2

413 170 8 2 -243 -162 - 6 - 2 170 8 2 0

Example: Convert 2413 to Ternary

Page 14: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Balanced (Signed) Ternary Notation

Instead the digits 0, 1, and 2 use (-1), 0, 1 so that negative digits are used

Example:1(-1)0(-1) = 1×33 + (-1)×32 + 0×31 + (-1)×30 = 27 – 9 – 1 = 17

To make things easier, use T, 0 ,1 for digits instead of (-1), 0, and 1

Example: 1T0T = 17

Aside: A capital Theta Θ which looks like a minus sign inside a circle can be used for -1 so “T” stands for capital Theta.

Page 15: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Counting from -1 to 10

Decimal Binary Ternary BalancedTernary

-1 -1 -1 T 00T

0 0 0 0 000

1 1 1 1 001

2 10 2 1T 01T

3 11 10 10 010

4 100 11 11 011

5 101 12 1TT 1TT

6 110 20 1T0 1T0

7 111 21 1T1 1T1

8 1000 22 10T 10T

9 1001 100 100 100

10 1010 101 101 101

Page 16: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Decimal - Balanced Ternary Conversions

Balanced Ternary to Decimal: Expand by Powers of 3

1T0T = 33 – 32 -30 = 27 – 9 – 1 = 17

Decimal to Balanced Ternary (2 steps) Decimal to Ternary then Ternary to Balanced Ternary.

From right to left convert 2 to 1T Add the 1 to the next digit

17 = 1223 = 1(1T)(1T) = (1+1)(T+1)T = 1T0T

Convert 52 to balanced ternary

Page 17: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Addition and Subtraction

9 rules for addition:

1 + T cancel

0 + anything = anything

Only 2 rules have carries

To negate swap 1’s and T’s

To subtract, negate and add

T T T T 0 1--- --- --- T1 T 0

0 0 0 T 0 1--- --- --- T 0 1

1 1 1 T 0 1--- --- --- 0 1 1T

Page 18: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Advantages to Balanced Ternary Notation

Leading digit indicates sign of the number

Easy to “compare” numbers: 11T> 10T > 1TT To negate any integer swap T’s and 1’s

if 17 = 1T0T then -17 = T101

Examples

1T0T = 17+10TT = 23----- -- 1111 = 40

1T0T = 17+T011 = -23----- -- 0T10 = -6

T101 = -17+T011 = -23----- -- TTTT = -40

-17+23--- ??

Page 19: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Multiplication

3 rules for multiplication: 1 × anything is anything - copy0 × anything = 0 T × anything = swap T & 1: invert

10T = 8 × 10T = 8 ------- T01 invert 000 nothing+ 10T copy--------- 1T101 = 81 – 27 + 9 + 1 = 64

17 = 1T0T×23 = 10TT--- ----391

Page 20: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Aside: Doubling a Number (multiplication by 1T)

Example: 47 × 2

1TT1T = 47 1T = 2 T11T1 1TT1T 10111 = 94

Left shift multiplicand and add invertedmultiplicand

Page 21: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Division is done the normal way but makes effective use of positive and negative divisors (make copies of both)

110T 10T | 101101 T01 T01 1T1 T01 T0 T01 10T 0

If the current dividend is positive (leadingdigit is 1) add the negative divisor, setQuotient digit to 1 and bring down thenext digit

If the current dividend is negative (leadingdigit is T) add the positive divisor, setThe quotient digit to T and break down thenext digit.

Otherwise bring down next digit and set quotient digit to 0280 / 8 = 35

Page 22: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

More Division Examples

81 / 13 = 6 r 3

111 r 11 100 | 11111 T00 T00 111 T00 111

T00 11

121/9 = 13 r 4

1T0 r 10 111 | 10000 TTT TTT TT0 111 10 00 10

Page 23: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Note: The remainder in division might not be positive

1T0 r T10 | 1T0TT0 T0 T0 10 0T 00 0T

17 ÷ 3 = 6 r -1

The solution is toadd the divisor tothe remainder andsubtract 1 from thedividend (add T)

1TT r 1T10 | 1T0T

17 ÷ 3 = 5 r 2

Page 24: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

1 6 . 5 2 | 2 73 . 00 00 1 1 ------- 2 b 1 73 2 6 1 56

---------- 32 b 17 00 32 5 16 25 ----------- 330 b 75 00 330 2 66 04

---------- 8 98 etc.

Square RootsCompute

Starting from decimal pointpartition digits into pairs

Call leading paired or unpaireddigits the “current dividend”

273

Page 25: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

1 6 . 5 2 | 2 73 . 00 00 1 1 ------- 2 b 1 73 2 6 1 56

---------- 32 b 17 00 32 5 16 25 ----------- 330 b 75 00 330 2 66 04

---------- 8 98 etc.

Square Roots

Starting with the current dividendestimate the largest digit “currentquotient” whose square is lessthan or equal to the currentdividend

Subtract the “quotient squared”from the current dividend and bring down the next two digits.

Call the current quotient a

Page 26: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

1 6 . 5 2 | 2 73 . 00 00 1 1 ------- 2 b 1 73 2 6 1 56

---------- 32 b 17 00 32 5 16 25 ----------- 330 b 75 00 330 2 66 04

---------- 8 98 etc.

Square Roots

Double the “current quotient” aand left shift it (multiply by 10). Find the largest digit b such that10×a+b times b is less than thecurrent dividend. Subtract andbring down the next two digits.

Repeat

Page 27: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

1 0 T 1 | 1 T1 01 T T 0 T1 bring down next 2 digits 1T b 2 x current quotient + b 1T T current dividend negative; try b = T T1 1 1 TT (2 x current quotient + b) × T 0 10 & subtract 1T0 b T1 01 T10 T 1T0 1 T10 T T1 0T 00 00

Square Roots

Page 28: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

1 0 T 1 | 1 T1 01 T T 0 T1 1T b 1T T T1 1 1 TT 0 10 Problem: |10| > |T1|; Therefore b = 0 T1 01 Bring down next two digits 1T0 b 2 × current quotient + b 1T0 T current dividend negative; try b = T T10 1 (2 x current quotient + b) × T 1T0 T 1T 0T & subtract 00 00

Square Roots

Page 29: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Balanced Ternary in Retrospect

1. Ternary Numbers systems have been called the “Goldilocks” numbering systems – binary is too small, decimal is too big but ternary is just right

2. Balanced Ternary has less carry propagation; negating numbers is easy; the mechanics of calculation are simplified

3. In the 1840’s Thomas Fowler an English self-taught mathematician and inventor invented a calculating machine that used balanced ternary to perform its calculations. Fowler observed that the mechanics of calculation were simplified using balanced ternary.

4. There have been a few attempts to construct ternary computers. In the 1950’s Nikolai Brousentsov at Moscow State University designed a ternary computer called the Setun with a word length of 18 “trits” (same range as a 28 bit computer) in stead of “bits”. 50 were build between 1958 and 1965. In 1973 G. Frieder at SUNY Buffalo designed a base 3 machine called the “Ternac” along with a software emulator for it.

5. In ternary a Flip-Flop is a Flip-Flap-Flop

Page 31: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

If r is the radix (base) and w is the width of an integer (number of digits) you want to minimize the product y = r∙w for some fixed value C = rw (constraint).

Thus w = ln(C) / ln(r) so if you minimize y = r (ln C /ln r)∙

Note that 3 is closer to e than 2.

2 2

1ln ln ln ln

ln 1 0ln ln

r C r C Cdy r rdr r r

ln 1r

r e

If C = 1000w10 = 3w2 = log2(1000)≈9.97w3 = log3(1000)≈6.26 y10 = 10×3=30y2 = 2×9.97=19.94y3 = 3×6.26=18.78

Page 32: Balanced Ternary Notation The Goldilocks of Numbering Systems Brian Shelburne Department of Mathematics and Computer Science Wittenberg University August

Any Questions?

Thank You

Brian ShelburneDepartment of Mathematics

and Computer ScienceWittenberg University

10T/1011/1TT0

“Perhaps the prettiest number system of all … is the balanced ternary notation” –Donald Knuth, The Art of Programming