Tuesday, July 3, 2018

tutorials: balanced ternary basics

If you happened across SBTCVM and/or Balanced Ternary someplace, and you are wondering what the heck a trit or tryte is, you are at the right place.

Lets start with the very basics:

balanced ternary, like regular ternary (base 3), has 3 digits.

Several notations exist for balanced ternary. the one you use often is best chosen for the circumstance. For example: +0- is supported by all versions of SBTCVM, while p0n is only supported by the newer SBTCVM Gen 2-9 VM, thats still in development. 
Here is the number '8' in a few forms of balanced ternary notation:
+0-
p0n

  • Positive: (+,p) your familiar positive digit.
  • Ground: (0) ground, or zero, is in the middle. but that's not even the most confusing bit.
  • Negative: (-,n) this is the curve ball, and why 2 in balanced ternary is '+-'

still dont get it? lets count from -4 to +4

-- (nn) -4
-0 (n0) -3
-+ (np) -2
0- (0n) -1
00 (00)  0
0+ (0p)  1
+- (pn)  2
+0 (p0)  3
++ (pp)  4

here are some key terms:
  • trit: a balanced ternary digit
  • tryte: 6 balanced ternary digits
 Special note: 1093 is based on the MPI of 7 trits.
  • KiloTryte (KT): 1093 trytes.
  • Kilotrit (Kt): 1093 trits.
 Helpful equations. (SBTCVM's libbaltcalc has functions for these)
  • MPI: Max positive integer: maximum positive value a length of trits can represent. ((3^n)-1)/2=MPI where n=length of trits
  • MNI: Max negative integer: lowest value a length of trits can represent. is the opposite of MPI. 
  • MCV: Max combinations value: number of combinations in a length of trits. 3^n=MCV where n=length of trits
why is MPI, MNI, and MCV, relevant now?

 Well. thats a good question! this brings me to another point:

Balanced ternary, like other balanced base numbers, have many subtle differences form bases like binary and decimal. for example: lets compare 8 trits & 8 bits
    8 trits | 8 bits
MPI: 3280   | 255
MCV: 6561   | 256

Aside from balanced ternary knocking binary out of the park numerically, notice how with binary, the MPI and MCV equivalents are only 1 off, while in balanced ternary its 3281 off. why is this? 

ok but why are MPI and MCV so different?

well. balanced ternary, like other balanced base numbers, is inherently signed. lets look at the combinations of 1 trit:

- (n) accounts for one MPI
0 (0) zero accounts for 1
+ (p) accounts for one MPI

this can be summed up into this formula:

n=length of trits
x=MPI(n)
y=MCV(n)

and then:
x+1+x=y

i.e.

x=MPI(3)=13
y=MCV(3)=27
x+1+x=y
13+1+13=y=27
 

No comments:

Post a Comment