Ternary base representation

Balanced Ternary Numeral System - forum was moved from http://ternary.info

Moderator: haqreu

eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Ternary base representation

Post by eudoxie »

I'm playing around with a virtual ternary machine I've made, and modeled roughly after the (binary) 6502 processor, but with ternary features.

It is in a fairly working state, so now I'm writing an assembler for it. I am looking for an analogue to hexadecimal notation in binary, to represent addresses and that sort of thing.

My machine uses 6 trit wide balanced trytes. The natural choice is to use balanced base-27, but this is very difficult hard to represent in letters and numbers, since there are no negative digits.

I tried using a-m to represent positive 1-13, 0 to represent 0, and A-M to represent negative 1-13. But that was very counter-intuitive, and caused much headache. It would be very elegant to somehow work the 26 English letters into a representation (because then you could represent text very effectively, all possible bigrams could be represented in one tryte.)

Is there any ideas or conventions on how to represent trinary numbers in a non-decimal base?
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

It's great!

What do you think about using "overlined" characters for negative digits representation?

Example:

Code: Select all

_____________
DCBA9876543210123456789ABCD
_
1A = -1*27+10 = -17
  _
10D = 1*729+0*27-13 = 716
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

It's an interesting thought, but then the problem becomes representing those overlined characters on binary architectures (with ASCII characters).

They're probably supported in UNICODE, so that could be a way, but then the problem is that there is no obvious way of entering them on a standard keyboard.

-- edit --

I've come up with a way that works pretty well now: Representing a tryte with triplets of balanced base 9. So I get DCBA01234.
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

eudoxie wrote: It's an interesting thought, but then the problem becomes representing those overlined characters on binary architectures (with ASCII characters).

They're probably supported in UNICODE, so that could be a way, but then the problem is that there is no obvious way of entering them on a standard keyboard.
Actually you can write it in ASCII the same way like I just did it here - using previous line to put "underline" character in needed places to simulate "overline" for the next line of characters. Disadvantage of this approach is to use 2 lines instead of 1 line to represent separate line of ternary numbers.
eudoxie wrote: I've come up with a way that works pretty well now: Representing a tryte with triplets of balanced base 9. So I get DCBA01234.
So 1 tryte with 6 trits in your system should look like 3-character word (A01 or 0DD), right? Unusual :)
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

So 1 tryte with 6 trits in your system should look like 3-character word (A01 or 0DD), right? Unusual :)
Exactly. It's a bit exotic in the beginning, but you get used to it quickly, and then it's pretty intuitive and a lot easier to "think" in than base 27. Besides, there's some sort of elegant symmetry in a ternary system having three symbols to represent a tryte, where binary systems usually have two.

It goes very well with what I'm trying to do with my system. I'm trying to make a ternary virtual computer people without a degree in computer science can associate to. That's why I modeled it after the 6502 (because it's very simple and well-known, yet very easy to do meaningful and relatively powerful stuff in.)
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

It's very interesting to see results of your work. Do you have specification or some kind of detailed description of proposed ternary command set?

P.S. In Russia most common and well-known microprocessor from XX century is Intel 8080 (there are a few Soviet/Russian clones and extensions of it) and almost nobody knows 6502 for some unknown reasons...

P.P.S. On our forum we have link to Java simulator of ternary processor based on PDP command set:
viewtopic.php?t=75
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

I don't have any specs yet, but it's got almost all 6502 operations (here is a good overview of that architecture) -- or operations with similar ternary behavior, with a few extensions.

I can only speculate that the reason for the 6502's limited use in Russia has something to do with Soviet/Western relations.

The 8080 (and sequels) is probably the biggest one here as well (especially with the advent of the PC), but the 6502 (and sequels) was also widely used in the 1980's, machines such as the Commodore 64, early Apple computers, the BBC Micro, the NES and so forth used it.
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

Thanks for the link to 6502 overview!

Do you plan to use one of the coolest features of ternary command set as "ternary" conditional branch in one "atomic" command?

if a<b goto A1
if a==b goto A2
if a>b goto A3
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

Unfortunately, I don't think that's going to be possible (it would be possible, but it would be an eyesore in the specs).

All my operations take zero to two trytes as arguments. That operation would take six trytes as argument. It's a bit too abstract for machine code. It would be really easy and elegant to implement in a higher level language based on my machine though.
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

eudoxie wrote: Unfortunately, I don't think that's going to be possible (it would be possible, but it would be an eyesore in the specs).

All my operations take zero to two trytes as arguments. That operation would take six trytes as argument. It's a bit too abstract for machine code. It would be really easy and elegant to implement in a higher level language based on my machine though.
Probably it could be done by using 3 special address registers - not directly
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

Hm, my machine doesn't have that many address registers. Though, it could be doable using the stack instead.


Anyways, I made a rough draft of my machine's specifications http://nedopc.org/ternary/tunguska/specsdraft.pdf

It's probably a bit esoteric at the moment, but it should give you an idea of how it works.
User avatar
Shaos
Admin
Posts: 23989
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Ternary base representation

Post by Shaos »

Thanks! It's interesting to read
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

Yeah. I'm in the process of cleaning it up and fixing the worst bugs, making a usable memory image to start with (at least an image that does -something-), and then I'm going to release it for a public alpha version.
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Ternary base representation

Post by Mac Buster »

Don't you have plans to add a parity flag to program status register ? It is very usefull thing in ternary :) I'll be glad to see working emulator or something and to help you in your work.
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Ternary base representation

Post by eudoxie »

I'm not sure if a parity flag is going to be necessary. There is an operation that allows you to set the status flags as though a tritwise AND operation with the accumulator has been performed. With an and-mask that masks out all trits except one arbitrary trit, you will transfer that trit to the sign flag, and from there -- for all intents and purposes, it can be a parity flag.

I've got a few things to fix before I release a public alpha version of it. It shouldn't be -that- far away, things are in fairly working order, -- maybe a month? (optimistically) But when that's done, I'll be sure to post a notification here, and you're welcome to tinker in the code (it's going to be open source).