Skip to content

Instantly share code, notes, and snippets.

@darius
Created December 10, 2023 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darius/cb11ae80c6d1e624d6e5746e669c1a98 to your computer and use it in GitHub Desktop.
Save darius/cb11ae80c6d1e624d6e5746e669c1a98 to your computer and use it in GitHub Desktop.
uh... thinking about balanced ternary again.
Earlier I thought a bit about written notation for balanced trits.
Some maybe fun follow-on topics:
-------
What would a 4-trit character encoding look like? It'd be less
cramped than the historical 6 bits of many earlier systems, but
more cramped than ASCII. Find a cute system starting with: the
alphabet has 26 letters, and 3 trits encode 27 values.
(Call a 4-trit chunk a 'tryte'?)
Most obvious start: 0 for space, 1-26 for letters. What's an
"uppercase space" then? Newline?
(However, treating trits as signed means that 0 is in the middle,
making the alphabet nonconsecutive. How bad is it to think of trits as
subject to either signed or unsigned interpretations? OTOH with the
first half of the alphabet positive and the second half negative, it
can be considered "consecutive mod overflow".)
Do you spend the second page on uppercase letters and newline? Assume
so for now; though if you kept only one case of letters, there'd be
room for plenty of punctuation and control/escape in the one-tryte
code (albeit not so many control codes as ASCII's).
I guess decimal digits would go in codes 0..9 of the third "zero
page". Then there are 17 codes left for punctuation, control, and
escapes.
ASCII has 31 punctuation codes, and don't forget NUL. Say we
reserve NUL and 2 different escape codes (at the top of the
space?). This leaves 14 for punctuation.
ASCII's: !"#$%&'()*+,-.:;<=>?@[\]^_`{|}~
, . ? ! : ; - + / ' " ( ) =
- - - - - - - - - - - - - -
leaving: <>*#$%&@[\]^_`{|}~
I guess one escape code would be for the extended char-set (with our
leftover punct), and the other for control codes. Control codes should
include an application-defined reserved subspace along with a subspace
with a standard interpretation (like tabs etc.). You should be able to
chunk the reserved codes in ignorance of their interpretation.
(Do we want this ad-hoc/standard subspace split for both the
"control-code" sequences and the "extended-charset" sequences? Or do
we demark ad-hoc/standard by the choice of initial escape code?)
This is not as nice encoding-wise as UTF8, is it? What if we restarted
this design exercise with a goal of multi-tryte UTF8-style encoding?
I suspect we'd want 5-trit trytes. If those then reserve one value of
the top trit to denote that this character extends into the next
tryte, that gives a radix per (5-trit) tryte of 81 codes available
(162 in the unmarked, non-extended trytes). For 4-trit trytes: 27, 54.
Encoding arbitrary trinary data in the ad-hoc subspace should be
reasonably efficient, to ensure that the way that's done is standard.
It'd be extra nice if that encoding were *trivially* mappable to the
design equivalent of base58 (i.e. nonconfusable printable encoding of
data) with a simple mask operation or some such.
This was English-centric. Any local changes worth making to marginally
reduce that objection? I guess my main idea there is, allocate
uppercase to the extended char sequences, so even ordinary English
can't get away with assuming all chars are one tryte.
-------
We have BCD binary coded decimal. How cute can you make TCD (ternary)
and does it in some sense make arithmetic/comparisons/etc. actually
easier for us than arabic numerals do?
(As I was thinking before, the 9 symbols for a balanced ternary
trit-pair could presumably be chosen to be competitive with our
standard digits in convenience of reading/writing, while remaining
a systematic 'picture' notation unlike ours.)
- E.g. a trit pair for the decimal digits 1-9 (as 5+-4) and a special
numeral for decimal 0; or maybe as "balanced decimal" (-5..5) where
+/-5 are the digits getting a special symbol?
- In terms of encoding in actual trits rather than a human notation,
one idea is a variable-length code where most decimal digits are
two trits and a few are three.
- Or else is there a scheme in 3 trits per decimal which goes
nicely with a carry-save addition algorithm?
The last of those suggests an abacus where the wires have a kind of
indentation/slot in the middle so it's quick/reliable to slide a bead
to any of 3 positions, top/middle/bottom.
TODO make a web touch UI for that abacus to experiment?
-------
Mental algorithms for conversions <-> legacy notation and the above?
-------
Any particular tricks TDDs (ternary decision diagrams) would be
particularly good for? (Yes they're just a special case of multiway
decision diagrams.)
Design balanced-ternary add and multiply circuits using 3-way logic
gates.
Find a universal set of elegant 3-way logic devices. Merkle's buckling
springs are 2-state -- can you figure out mechanical switches with 3
states?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment