Click here to Skip to main content
15,914,014 members
Articles / Mathematics

“Trits” Instead of “bits” – A Short Introduction to Balanced Ternary

Rate me:
Please Sign up or sign in to vote.
3.91/5 (6 votes)
19 Dec 2014BSD4 min read 21.6K   9
“Trits” instead of “bits” – A short introduction to balanced ternary

It’s usually said that students who would like to study computer science should familiarize themselves with binary representation of numbers and thus get used to very common powers of 2, i.e. 2¹=2, 2²=4, 2³=8, etc. That’s definitely true; the digital world we live in uses bits and almost all programming languages are based on Boolean algebra. But, just because something is popular does not mean it’s good. In this short article, my aim is to give the reader a general understanding of the concept of balanced ternary, the benefits of using it, and finally some history of earlier attempts to create ternary computers.

Introduction

The concept Balanced ternary has many underlying ideas, so let’s try to break it down into things we can relate to. The word ternary, in this context, refers to ternary numeral system. A numeral system is a way in which different people express numbers: the Great Greeks used a superscript on letters to identify numbers, i.e. α’, β’, γ’. In the Roman Empire, they used I, II, III, IV (we still use these numbers in names, i.e. Charles XII). Many people nowadays use numbers like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (origin from Hindu-Arabic numbers). This way of writing numbers can be referred to as base 10 or simply decimal. A ternary numeral base is similar to decimal, but allows only 0, 1, 2. In binary (base 2), we only allow 0, 1.

Decimal (Base 10) 0 1 2 3 4 5 6 7 8 9 10
Ternary (Base 3) 0 1 2 10 11 12 20 21 22 100 101

A clear observation from this table is that once digits end (i.e. going from 9 to 10), we put a zero and carry a 1 forward (in the number). This is similar to base 3, however, since we only have 0, 1, 2, our digits end faster than in base 10.

There exists an algorithm to convert between different bases, but that would probably be better suited for another article. Therefore, it’s not going to be discussed here (convert numbers). However, it’s quite simple to convert from base 3 to base 10 by an interesting observation. For example, 123 is equivalent to saying that 123= 1*10²+2*10¹+3*10° = 1*100+2*10+3. In base 3, we have a similar approach, but instead of 10, we use 3. Say we want to convert 22 (in base 3) to base 10. Therefore, 2*3¹+2*3°=2*3+2=8 (in base 10). This conclusion goes hand in hand with the one in the table.

Now, we should have some grasp of ternary numeral systems. Let’s move on to the term balanced. A intuitive way of thinking about it that something should be balanced, like masses on opposite sides of a weight should cancel out. So, how would such system look like? I turns out that instead of saying that we can use digits 0, 1, 2 we instead introduce -1 so that the digits in the balanced ternary system are -1, 0, 1 (looks to be balanced?). Let’s refer to the -1 as n and 1 as p. The table below links the numbers in base 10 with the ones in balanced ternary.

Decimal (Base 10) 0 1 2 3 4 5 6 7 8 9 10
Balanced Ternary (Base 3) 0 p pn p0 pp pnn pn0 pnp p0n p00 p0p

There is a similar pattern here as for unbalanced ternary. The interested reader should consider to experiment with this concept by implementing it in the favourite programming language (see all implementations).

Benefits

Here are some of the benefits of the balanced ternary:

  • The sign (+/-) is stored in the number, and can be deduced by the leading trit (similar to bit). So, if a number starts with -1, or using our notation, n, we know it’s negative.
  • In order to get the number with the opposite sign, simply replace all n‘s with p‘s and all p‘s with n‘s. Eg. Since 7 is pnp, -7 is npn.
  • In order to round to the nearest integer, the fractional part should be removed.
  • Things don’t have to be either true or false. There exists an unknown case also.

History

It might seem that this idea works in theory but not in real computers. However, this is not true. At Moscow State University, a series of Setun computers was developed. The first Setun was built in 1958. An interesting thing that can be noted is that it used ternary logic.

Further Reading

For those who are interested, please take a look at the links below:

Edits

  • 24.12.2014 - Corrected the description (formating)
  • 23.12.2014 - Corrected the base10-base3 table
  • 20.12.2014 - First published

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Student
Sweden Sweden
My name is Artem, and I am a student at the School of Electrical Engineering and Computer Science at KTH Royal Institute of Technology.

Currently working on https://cryptolens.io.

Comments and Discussions

 
AnswerNot an article Pin
Akhil Mittal23-Dec-14 17:37
professionalAkhil Mittal23-Dec-14 17:37 
AnswerRe: Not an article Pin
Artem Los23-Dec-14 23:28
Artem Los23-Dec-14 23:28 
GeneralMy vote of 1 Pin
Member 1022280123-Dec-14 3:18
Member 1022280123-Dec-14 3:18 
AnswerRe: My vote of 1 Pin
Artem Los24-Dec-14 0:33
Artem Los24-Dec-14 0:33 
GeneralMy vote of 1 Pin
Petr Kirjat Valasek23-Dec-14 0:44
Petr Kirjat Valasek23-Dec-14 0:44 
AnswerRe: My vote of 1 Pin
Artem Los24-Dec-14 0:28
Artem Los24-Dec-14 0:28 
Thank you for the feedback! Correct, there was a tiny error in the first table, however, it's now fixed in the post!

We shouldn't put a lower/upper bound for the knowledge required to be a CodeProject user. I am quite convinced that there are many users with different kinds of interests and backgrounds (some are students, hobby-programmers, professionals, etc). Some readers will find the concept of balanced ternary obvious, while some might not have heard about it before. My goal is to target the latter group, and therefore I put much emphasis on describing the concept of a numeral system (unbalanced numeral system).

Since this isn't an article, it does not cover the entire subject. The idea is to give the reader an introduction so that it’s possible to find out more about balanced ternary if desired. I believe that the interested reader will find the way to convert from these different forms.

The paragraph where conversion from base 3 to base 10 is described should serve as a hint for how numbers in the balanced base 3 should be converted back to decimal. I mean, we haven’t really changed anything dramatically; we've just introduced different values i.e. base 3 {0,1,2} and balanced base 3 {-1,0,1}, so the conversion follows the same principle. So, if you want to convert eg. ppn to decimal, simply replace the p’s and n’s with 1 and -1 respectively, and follow the same recipe as for unbalanced ternary.

In your comment, you make some claims that are not backed up. I've listed them below (including the list in the end of the comment).

  • You mentioned that balanced ternary always starts with “p”. I don’t agree with this statement, but maybe I’ve misunderstood it. Could you please elaborate it!
  • “the leading digit encodes the sign /../ so what?” – In binary representations of numbers, in fact in all unbalanced bases with positive base the number only tells you the value, so you need to introduce another bit (or anything similar) that will keep track of the sign. In balanced bases (and bases where the base is negative), the leading digit gets two birds in one shot: it stores the sign as well as information about the value.
  • “/../here do you describe how fractions are represented” – I’m not going to argue, since the point of this blog article is a bit different (see the earlier discussion on that point). However, since you asked, here’s how it’s done: To convert a base 10 number to balanced ternary, one way is to convert from base 10 to unbalanced base 3, and then add an infinitely long number of 1’s, i.e. 11111.11111 and later subtract it. This will work for fractions also. The addition should be performed in unbalanced base 3.
  • “/../exactly, and there exists "maybe", /../ How exactly balanced ternaries help in that?” – The advantage of having the third case is for example because it’s more natural, that is, there exist situations where it’s not possible to say that something is true/false. It doesn't have to tackle problems black-and-white, and allows a case where it’s uncertain what the answer is.

Thank you for your feedback! Smile | :) Please let me know if you have other questions.
GeneralRe: My vote of 1 Pin
Petr Kirjat Valasek26-Dec-14 21:55
Petr Kirjat Valasek26-Dec-14 21:55 
GeneralThanks Pin
SteveHit20-Dec-14 23:05
SteveHit20-Dec-14 23:05 
AnswerRe: Thanks Pin
Artem Los25-Dec-14 3:18
Artem Los25-Dec-14 3:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.