162 points · by Tomte · 2y ago · 160 comments
>Ternary circuits: why R=3 is not the Optimal Radix for Computation
https://arxiv.org/abs/1908.06841
Previous HN discussion:
Also ternary gets a bit weird in some other ways. The practical ternary systems that the Soviets invented used balanced ternary, digits {–, o, +} so that 25 for example is +o–+,
25 = 27 + 0*9 – 3 + 1.
If you think about what is most complicated about addition for humans, it is that you have these carries that combine adjacent numbers: and in the binary system you can prove that you relax to a 50/50 state, the carry bit is 50% likely to be set, and this relaxation happens in average by the 3rd bit or so, I think? Whereas ternary full adders only have the carry trit set ¼ of the time (so ⅛ +, ⅛ –) and it takes a few more trits for it to get there. (One of those nice scattered uses for Markov chains in the back of my head, the relaxation goes as the inverse of the second eigenvalue because the first eigenvalue is 1 and it creates the steady state. I got my first summer research job by knowing that factoid!) So you start to wonder if there's something like speculative execution possible then—half-adder-+ is definitely too simple for this but full adder + chains all these bits together and for larger numbers maybe it's not!Similarly I think that binary proliferated in part because the multiplication story for binary is so simple, it's just a few bitshifts away. But for balanced ternary it's just inversions and tritshifts too, so it has always felt like maybe it has some real “teeth” there.
Yes... but nobody uses binary systems. We use 64 bit systems (and a number of other systems, but all larger than one bit), which has abundantly more than enough space to represent "greater than/less than/equal".
The main software issue with ternary computing is that with this, the entire advantage goes up in smoke. It is quite hard to articulate an actual advantage a multi-bit system would see since we do not use 1-bit or 1-trit systems in real life. (If you've got some particular small hardware thingy that could use it, by all means go for it; it's no problem to use it in just one little place and have a conventional binary interface.)
Taylodl's hardware issue with ternary circuits sounds like a reasonable one as well. If you've already minimized the voltage difference for your binary circuits to as small as it can reasonably be, the addition of ternary hardware necessarily entails doubling it the maximum voltage in the system.
Is this Quanta Magazine's "Brash And Stupid Claims About Computing Week" or something? https://news.ycombinator.com/item?id=41155021 The last paragraph is outright crockery, that "trit-based security system" is well known to be from a crackpot who appears to simply not comprehend that our binary systems do not in fact explode the moment they have to represent a "3", despite repeated attempts for people to explain it to the guy.
Programmers and hardware designers are not in fact just total idiots stuck in the mud about digital (vs analog) and binary (vs ternary) representations. They are the way they are for good and solid engineering reasons that aren't going anywhere, and there is basically no space here for someone to displace these things. It isn't just path dependence, these really are the best choices based on current systems.
Another big thing was TRIZ: a theory that you can codify invention by making a rulebook and arranging the rules in different permutations. There were plenty of smaller things too, especially in academia. It would typically start with one researcher sticking to some bizarre idea, then growing his own gang of grad students and adjuncts who all feed on that. Except the theory would be borderline batshit and all the publications are in-group, referring each other, and naturally a semester or two worth of this sectarian stuff is getting dropped into the undergrad curriculum.
It was just at the late 80s that this changed.
You can. It's just slow that's all.
Superoptimizers 'invent' new compiler optimizations by exactly this technique.
and https://en.m.wikipedia.org/wiki/Systematic_inventive_thinkin...
then https://arxiv.org/abs/2403.13002 (AutoTRIZ: Artificial Ideation with TRIZ and Large Language Models)
This line really struck me and it's a failure in technical writing. This is an article published on "quantamagazine", about niche computing techniques. You have a technical audience... you shouldn't still be explaining what binary is at the halfway point in your article.
That's not the way I've heard the story. Ternary isn't just on/off, voltage yes/no like binary - you need to know the charge of the voltage: is it positive or negative? Essentially then your circuits are -/0/+ instead of (0/+) like it is for binary. Such ternary circuits resisted miniaturization. At a certain point the - and + circuits cross and arc and create a fire. The binary circuits kept getting miniaturized.
The story I've heard that goes along with this is that's how the US ultimately won the space race: the US bet on binary computing and the Soviets bet on ternary computing. The Soviets lost.
- harder to discriminate values as you pack more in the same dynamic range
- more susceptible to noise
- requires lower clock rates for (wired) transmission
- requires more complex protocols for (wireless) transmission
- representing 0 or 1 as switched states uses "no" power, but getting a switch to be "halfway on" uses a lot of power
50 years ago this may not have been such a problem, but now that we care a lot, lot more about the power consumption of our computing, and a lot of that power consumption is based on voltage (and IIRC often super-linearly), so a tech that requires us to introduce additional voltage levels pervasively to our chips is basically disqualified from the very start. You're not sticking one of these in your server farm, phone, or laptop anytime soon.
Wait, what?! I did not know this. Is there a link where I can learn more?
Op didn’t specify any particular voltage but you should get the example. You need more voltage between the highest and lower states to differentiate the signals compared to binary. It can work well but only in circuits where there’s already very low leakage (flash mentioned as another reply is a great example).
note: I am aware that strictly speaking a CPU isn't transistors, but it is a lot of variously doped silicon still.
I wonder if this is why they suggested a negative voltage. Even though voltages are secretly relative under the hood, it seems like it could simplify things to have two directionally different voltages.
That's not unique to ternary circuits. That's just how voltage differential of any kind works.
The trick is figuring out how many states you can reliably support below the maximum voltage differential the material supports. As we reach the physical limits of miniaturization, "two states" is almost certainly not going to remain the optimal choice.
> The conclusion of Apollo 11 is regarded by many Americans as ending the Space Race with an American victory.
To do binary logic we do CMOS. The reason CMOS gets hot is because the complementary transistors don't switch at the same time. So, at a certain point, the Vss and Vdd circuits connect and create a massive current drain.
> The binary circuits kept getting miniaturized.
Sure.. but they're not getting much faster.
Pretty sure c) dominates for high frequency/low power applications like CPUs, as it's quadratic.
In support of your point, of the Soviet computers surveyed in the cited article, six were pure binary, two used binary-coded decimal numerics, and only SETUN was ternary[2].
[1] [Willis p. 149]https://dl.acm.org/doi/pdf/10.1145/367149.1047530#page=19
[2] [Willis p. 144]https://dl.acm.org/doi/pdf/10.1145/367149.1047530#page=14
[Willis] Willis H. Ware. 1960. Soviet Computer Technology–1959. Commun. ACM 3, 3 (March 1960), 131–166. DOI:https://doi.org/10.1145/367149.1047530
Many modern CPUs use different voltage levels for certain components, and everything works fine.
But none of them use more than 2 states. If you've got a circuit at 0.9V or one at 2.5V they both have a single threshold (determined by device physics) that determines the binary 1 or 0 state and voltages tend toward 0 or that upper supply voltage. There is no analog or level-based behavior. A transistor is either on or off - anything in the middle has resistance and leads to extra power dissipation.
- Single-level cell (SLC) flash: One bit per cell, two possible voltage states
- Multi-level cell (MLC) flash: Two bits per cell, four possible voltage states
- Triple-level cell (TLC) flash: Three bits per cell, eight possible voltage states
- Quad-level cell (QLC) flash: Four bits per cell, 16 possible voltage statesWait until the hear about base Googol
Maybe I'm missing something, but this sounds like a silly argument for ternary. A ternary system seems like it would be decidedly harder to build a computer on top of. Control flow, bit masking, and a mountain of other useful things are all predicated on boolean logic. At best it would be a waste of an extra bit (or trit), and would also introduce ambiguity and complexity at the lowest levels of the machine, where simplicity is paramount.
But again, maybe I'm missing something. I'd be super interested to read about those soviet-era ternary systems the author mentioned.
One thing we were trying way back then was standard cells that integrated one flip flop or latch and some logic function into one cell. To trade a slightly larger cell (and many more different cells) for less wiring in the routing channel.
There is an even bigger mountain of useful things predicated on ternary logic waiting to be discovered. "Tritmasks" would be able to do so much more than bitmasks we are used to as there would be one more state to assign a meaning to. I'm not sure if the implementation complexity is something we can ever overcome, but if we did I'm sure there would eventually be a Hacker's Delight type of book filled with useful algorithms that take advantage of ternary logic.
If ternary logic has not been widely studied I assume there is a lot to be discovered still.
> At best it would be a waste of an extra bit (or trit), and would also introduce ambiguity and complexity at the lowest levels of the machine, where simplicity is paramount.
This seems backwards to me. It isn’t a “waste” of a bit, because it doesn’t use bits, it is the addition of a third state. It isn’t ambiguous, it is just a new convention. If you look at it through the lens of binary computing it seems more confusing than if you start from scratch, I think.
It might be more complex, hardware-wise though.
Doesn't this have more to do with the fact that it's not part of the standard math curriculum taught at the high school level? I'm no math wiz and discrete math was basically a free A when I took it in college. The most difficult part for me was memorizing the Latin (modus ponens, modus tollens - both of which I still had to lookup because I forgot them beyond mp, mt).
Being a college course doesn't imply that it's hard, just that it's requisite knowledge that a student is not expected to have upon entering university.
I think you mean 41, not 31 (3^31 is about a factor of 30000 away from 2^64).
The difference in the number of trits/bits is not exponential, it's linear with a factor of log(2)/log(3) (so about 0.63 trits for every bit, or conversely 1.58 bits for every trit).
> ternary computers have more states and the voltage differences between highest and lowest has to be higher to allow differentiation and then this causes more leakage which is terrible
Yes -- everything else being equal, with 3 states you'd need double the voltage between the lowest and highest states when compared to 2 states.
Also, we spent the last 50 years or so optimizing building MOSFETs (and their derivatives) for 2 states. Adding a new constraint of having a separate stable state *between* two voltage levels is another ball game entirely, especially at GHz frequencies.
Absolutely not, look e.g. at all the SIMD programming where bit manipulation is paramount.
Now I'm left with an even more interesting question. Why e? The wikipedia page has some further discussion, hinting that the relative efficiency of different bases is a function of the ratio of their natural logarithms.
A = d * b
d is roughly equal to the log of the number represented, N, base b. d ~= ln(N)/ln(b)
Substituting, A ~= b * ln(N) / ln(b)
Take the derivative of the area with respect to b and find where the derivative is zero to find the minimum. Using the quotient rule, dA/db = ln(N) * (ln(b)*1 - b/b) / ln(b)^2
0 = ln(N) * (ln(b) - 1) / ln(b)^2
0 = ln(b) - 1
ln(b) = 1
b = e
I hope I got that right. Doing math on the internet is always dangerous.Only if you see correctness as a thing to be avoided. In my experience, being Wrong On The Internet is the fastest way to get something proofread.
It can be easily shown that the "radix economy" described in the article is identical to this formulation by simply taking the logarithm of both expressions (base 10 as described in the article, but it doesn't really matter, as it's just a scaling factor; this doesn't change the inequality since log x is monotonically increasing for x > 0): y log x vs x log y. Or, if you want to rearrange the terms slightly to group the variables, y / log y vs x / log x. (This doesn't change the direction of the inequality, as when restricted to x > 1, log x is always positive.) If you minimize x / log x for x > 1, then you find that this minimum value (i.e. best value per digit) is achieved at x=e.
(Choosing the base = e for calculation purposes: take a derivative and set to zero -- you get (ln x - 1) / (ln x)^2 = 0 => ln x - 1 = 0 => ln x = 1 => x = e.)
For some intuition:
For small x and y, you have that x^y > y^x (consider, for instance, x=1.1 and y=2 -- 1.1^2 = 1.21, vs 2^1.1 is about 2.14). But when x and y get large enough, you find the exact opposite (3^4 = 81 is larger than 4^3 = 64).
You might notice that this gets really close for x=2 and y=3 -- 2^3 = 8, which is just barely smaller than 3^2 = 9. And you get equality in some weird cases (x=2, y=4 -- 2^4 = 4^2 = 16 is the only one that looks nice; if you consider 3, its pairing is roughly 2.47805).
It turns out that what really matters is proximity to e (in a weird sense that's related to the Lambert W function). You can try comparing e^x to x^e, or if you want, just graph e^x - x^e and observe that's greater than 0 for x != e.
I thought that was interesting so I made (well, Claude 3.5 Sonnet made) a little visualization, plotting the radix efficiency of different bases against a range of numbers:
https://paulsmith.github.io/radix-efficiency/radix_effciency...
Ternary system has very limited Energy efficiency benefit compared to binary - roughly 1.5 more efficient and a lot more difficult to trasmit over differential lines. Today the latter is a big concern.
I suspect this is widespread.
So what does the answer to that query look like? I get a trit which is -1 for x < y, 0 for x == y, and 1 for x > y? It would make more sense for the query to be "Is x less than or equal to y?" so that I can get back a true/false value and jump to the next instruction as appropriate.
This of course raises a lot of questions as to how to program a ternary computer.
My guess is that most hot conditional jumps are loop returns. That's certainly binary.
Being able to store 0-8 numbers in 2 trits instead of 0-7 numbers in 3 bits is not a value added.
The comparison (</=/>) is the only real advantage they mentioned, but the way that might provide an advantage is if it's a single trit register within a primarily binary system. I.e. your (binary) comparison instruction (comparing two binary numbers) drops the result in the single-trit register, and then your (binary) jump instructions jump to a (binary) location based on that trit register. Point is, there's no benefit to having the entire system be ternary just for one ternary value. This is a semantic benefit, because the operation really does have 3 possible outcomes, but there are potential energy efficiency downsides to this.
A bigger benefit might be representing unknowns or don't-cares--notably numbers in this system are still binary, but some bits are unknown or don't matter. In this case, you can actually make some energy efficiency gains, especially in the context of don't cares, because you can simply jam whatever voltage is most convenient into that "bit"--it doesn't even have to match a voltage range. But I'm not entirely sure that it's accurate to call those systems "ternary".
Binary computing if anything has a massive advantage in the accumulation of technology underlying it. Hard to beat. But still worth considering it now and then as it might be bringing you an advantage in one function or another. Currently within a chip, obviously storage density and transmission density - which doesn't mean you shouldn't keep it in mind for other functions.
A waiter walks up to a table of two and asks “is everybody ready to order?”. One of them responds, “I’m not sure”. Then the other says, “Now we are”.
(Edit: I didn’t really ask a question, so it may not seem like a riddle. To some people, when they imagine it, this scene makes perfect sense, so it’s not much of a riddle to them. To others, it’s sort of bizarre, and so the “question” - how is this possible, or what happened - is obvious. Then you can consider the answer. In any case, this is a very simple demonstration of ternary logic, and much more complicated riddles exist that all more or less build off of the same mechanism.)
In practice this answer is hardly different from saying Yes, since it's understood that the person saying Yes is just speaking for themselves and the waiter will wait for the other person to confirm.
https://en.m.wikipedia.org/wiki/Non-integer_base_of_numerati...
Cheeky math aside, getting signalling logic to work with ternary, especially when clock rates go so high the signal starts to look less like square wave pulses and almost more like a modulated sine (due to slew), you now need much more sophisticated decoders.
https://blog.samtec.com/post/understanding-nrz-and-pam4-sign...
Tristate logic is how computer busses have been made for about the last half century.
I'd hardly call USB unpopular ...
Claim: Three-state logic can be advantageous in a digital system with a shared bus. The third state, Hi-Z, effectively disconnects a device from the bus. It allows multiple devices to share a single line efficiently.
Does the above claim overlook anything fundamental about where tristate logic shines?
There are alternative ways to design buses, but my EE-fu is not particularly current (pun intended). If others want to weigh in, please go ahead... e.g. open drain, multiplexing, TDMA, etc.
The issue is that open collector is slow. It's hard to make a bus function above 1MHz and it won't go much beyond that. Sufficient for your typical temperature/ADC/whatever peripheral even today but 1Mhz is not very fast.
10kOhm pull-up will pull the bus back up to 3.3V or whatever your I2C operates at.
Let's say each device on the bus adds 15pF of capacitance.
At 6 devices, we are at 10kOhm * 6 * 15pF * 2.2 rise time == 2,000,000 ps rise time, aka 2us rise time aka 500kHz or somewhere in that neighborhood. (2.2 * RC constant gives the 80% rise time of a resistor-capacitor system. Capacitances in parallel add together. One 10kOhm pull-up resistor).
-------
TriState buffers fix that by allowing a far greater drive of current into the bus.
Current is the easiest way to fight back against fan-out * capacitance. Every chip will add parasitic capacitance and it actually adds up to real issues in practice.
Logic /levels/ are what matters, not bus state.
You can even see this in how it's implemented. You typically have an OUT line, and an OUT_ENABLE line. This is really just 2 bits.
If DeviceA tries to set a line to 5V while DeviceB tries to set the same line to 0V, it doesn't matter what you think is going on in abstract computer land. There is likely some magic smoke getting let out somewhere.
------
EEs paper over these details by defining lines to be OpenCollector (ex: 8051 chips) where high voltage 5V is driven high by a 10kOhm pull-up resistor but otherwise no one trying to push currents (8051 has only uA of current push supported).
But pull-down is strong. 8051 had IIRC 2mA of pulldown, sufficient to 'Beat' the 10kOhm resistor (which is pushing maybe 20uA).
--------
TriState logic allows for greater currents to push onto the line. You can now push 2mA or 10mA of current to drive the line to 5V which leads to faster communication.
Just with TriState, because of the greater currents involved, you must be aware of the fire hazard and try not to have a 5V drive at the same time as someone else's 0V.
------
EEs will pretend that these voltages and currents are 0 or 1 for the computer programmers. But there is actually a lot going on here.
This is why TTL vs CMOS vs RTL vs Diode Logic vs whatever is a thing. EEs are calculation the currents and voltages necessary to build up the 0 vs 1 abstraction. But it only works within the specs of electricity / logic chosen. TTL has different specs than RTL has different specs than CMOS.
Yes, but transceivers do.
> This is why TTL vs CMOS vs RTL vs Diode Logic vs whatever is a thing.
Yes, and they all have /different/ logic levels.
> the specs of electricity / logic chosen
Yes, what one might call the "logic levels."
Edit: layer8 below has a much better link
This article is honestly worthless, it doesn't address the actual challenges & strengths of moving to ternary or a different base system. Binary is superior mostly because the components are way more reliable and therefor can be made much much smaller for the same price.
Trust me if Nvidia or Snapdragon could make a chip or even a whole prebuild computer working in base 3 that was 5% more efficient for the same price they ABSOLUTLY would and would get rich doing it.
E.g.
Tonal languages allows individuals to express way more than Latin based languages.
Sumerians used a Base-60 numbering system, and were exceedingly advanced in mathematics.
EDIT:
Why the downvotes?
Not true. There was a study that showed that information density is pretty consistent across all languages, regardless of the average number of phonemes used in that language or the strategies that are employed to encode structural information like syntax. I can only assume you are refering to the density with your statement based on the subject matter in that article as well as the fact that, given enough time and words, any language can represent anything any other language can represent.
I apologise if my terms are not exact, it's been years since I've studied linguistics. In addition, since I'm not going to dig up a reference to that paper, my claim here is just heresay. However the finding lines up with a pretty much all linguistic theory I learned regarding language acquisition and production as well as theory on how language production and cognition are linked so I was confident in the paper's findings even though a lot of the theory went over my head.
How achievable is literacy?
Do you have any evidence of this? I've never heard this claim before.
Vietnamese is one example. Having tones attached to syllables means that words and sentences are shorter. In fact, the grammar is very logical and efficient compared to baroque European ones, especially of the slavic/baltic flavour.
But. The same mechanism in Indo-European languages is used for intonation. we express sarcasm, irony, etc this way be essentially using a single sentence tone.
I have some good Vietnamese friends explaining how hard it is for them to use (and hear) a sentence-wide tone. So, say, some of the fluently speaking Russian Vietnamese always sound like they are sarcastic.
Otoh, I always had problems ordering rice with pork in hanoi...
This does not entail that more can be expressed than other languages. Please see my other reply which goes into (admittedly only slightly) more detail.
Otoh, there should br some connection between grammar complexity and written culture. It is my hypothesis but, say, culture with a rich novel writing tradition leads to a complication of the language grammar. A 3 page long sentence, anyone? One can see how Middle Egyptian literature made the underlying language more complex.
I've sort of thought 60 might be a nice base to work in. Some mathematicians prefer base-12 because it works with a wide number of factors and base-60 is just adding a factor of 5 to base-12. The result would be a base with an even wider variety of factors and, ideally, fewer instances of fractional amounts.
Downvotes happen no reason needed.
I bet that could be expressive if not legible.
(CTG)
The familiar 74181 has control inputs to let the circuit summon any of the 16 operations on two bits. (A two bit operation has four possible inputs, and two possible outputs for each input so 2 ^ 4 = 16 possible operations). A similar ALU part for ternary would have two trits as input so nine possible inputs. Each would have three possible values, so 3 ^ 9 = 19683. It would need nine control inputs, each a trit. But 19683 is so much more than 16. How many gates do you need to be able to combine them to produce all possible (trit,trit)->trit gates?
Here are three gates that get you a long way mathematically. First a swap gate
-1 -> 0
0 -> -1
1 -> 1
Then a permute gate
-1 -> 0
0 -> 1
1 -> -1
This lets your generate all permutations
Then you need a "spot" gate that spots one input, say (0 0) and output 1, and 0 otherwise. Since you have all permutations you have all spot gates. And inverse spot gates. Does that solve the problem? It is late and I'm tired. And I can see that the mathematically minimal set is impractical.
https://commons.wikimedia.org/wiki/File:Balanced_ternary_ope...
has six operations. There are three for doing arithmetic, the units from multiplication, the units from addition, and the carry from addition (it is part of the attraction of balanced ternary that there is no carry out from multiplying digits). There are also three for doing logic, based on -1 is false, +1 is true, and basically degenerating into binary logic.
Is that how this is done? The Instruction Set Architecture (ISA) has two kinds of words, numbers in balanced ternary, and bit-rows in degenerate binary. The hardware is built with a pragmatic mixture of binary and ternary logic gates, with the ternary gates heavily used in the Arithmetic Unit, barely at all in the Logic unit, and only opportunistically in the rest of the hardware, that is mostly binary gates as usual?
I have a bizarre mad science interest in this because I see how to build AND gates with mechanical linkages, http://alan.sdf-eu.org/linkage-logic/now-with-labels.html and wonder if the same technique works for ternary gates. But what are the operation tables for ternary gates? I should attempt the specialized ones for arithmetic first.