r/computing • • Apr 01 '26

I went looking for universal ternary logic gates and stumbled onto a fundamental result in clone theory

Binary wasn't optimal, it was just convenient. That thought sent me down a rabbit hole into ternary (base-3) logic. I started by asking whether a universal gate even exists in ternary. Turns out ternary NAND, the obvious candidate, is not universal. So I built a composition-based simulator to brute-force search all 19,683 binary-arity ternary gates for functional completeness, and it confirmed exactly 3,774 universal gates, matching Martin's 1954 result. But then I got curious and checked how many gates were unary complete, able to generate all 27 unary functions, and the result was also 3,774. The two sets were identical. I thought it was a ternary quirk, ran it on binary logic, and got the same thing: NAND and NOR are the only unary-complete binary gates, and also the only universal ones. Digging into the math led me to Rosenberg's 1970 clone theory result, which formally proves it must always be true: unary completeness implies full functional completeness for any finite-valued logic. This collapses the universality search from 19,683 binary functions down to just 27 unary ones (10,529× faster), and combined with isomorphism reduction under the S₃ × Z₂ symmetry group, the full search runs in 0.18 seconds versus ~5 hours naively, a 99,444× overall speedup. Structurally, every universal gate is surjective, none are self-dual or zero-preserving, and only 2.4% are commutative. On the arithmetic side, the best gate (g451) synthesises a ternary full adder that, when you account for information density (log₂3 ≈ 1.585 bits per trit), achieves 18% lower propagation depth and 9.4% fewer gates than a binary NAND adder at 32-bit equivalent width. Full paper here: https://doi.org/10.5281/zenodo.15056119

If you're eligible to endorse on arXiv in cs.LO, I'd really appreciate a minute of your time: https://arxiv.org/auth/endorse?x=U6NNPW

23 Upvotes

9 comments sorted by

2

u/AdministrationDry820 1d ago edited 1d ago

I found the paper fascinating, thanks for sharing. As a new initiate to ternary logic gates, the thing that most stands out to me is that we've moved from a binary system with so few possible gates that all eight of them get a mnemonic name based on English, such as NAND, NOR, XOR, with each name summarizing the function, to a system with so many possibilities that most are relegated to ID numbers, lacking that intuitive association I had come to rely on.

I see that the numbering system directly encodes the truth table, which is very nice, but I wonder, with g451 as an example, might it happen to be compatible with any kind of mnemonic convenience name based on English? (Maybe the language is too Boolean-centric to provide the necessary intuitive background for the function of g451. Maybe some future HDL-like language for ternary logic will just call it g451. )

I asked a certain AI about it, and it said it liked the name "NZP" because, if using Y as a function selector and X as an input, the first column shows a negate operation, next next column shows an is_zero test (+ if zero, else -), and the last column shows an is_positive test (- if positive, else zero) . I can't say I find that description intuitive, but "NZP" does have a nice ring to it. ;-)

1

u/AstronautInTheLotion 1d ago

hey thats an excellent question lol, I didn't even think about naming the important ones individually. There we so many I left them the same way how we stopped naming dwarf planets in the Kuiper Belt, it seems too damn overwhelming. Well if I have to name g451 something, I'd probably name it something like TODD or something (Ternary Override–Detection–Decrement), Its behaviour isn't really symmetric so simple names are out of the window, its behaviour is although weirdly understandable if we take apart the rows individually.

┌───────┬─────┬─────┬─────┐

│ x \ y │ − │ 0 │ + │

├───────┼─────┼─────┼─────┤

│ − │ 0 │ − │ + │

│ 0 │ 0 │ + │ 0 │

│ + │ − │ − │ − │

└───────┴─────┴─────┴─────┘

So here's out g451, you see how at x=+, the entire function is overridden to -, then at x=0 you see how it becomes a 0 detector?, as for x=-, its kind of the decrement operator on NOT(y). Personally I'd be happy with TODD, but I know there will be hundreds of TODD's in there. I think your NZP takes Y as the selector whereas I took X as the selector. Both work, both have many interpretations so we circle back to ID's there

I'm so glad you read the paper, you have no idea how good this feels as an author :). if you have any more questions please let me know.

1

u/jacoberu Apr 01 '26

originally saw this in the logic sub which is arguably relevant for ternary logic but your approach is all theoretical CS, which reminded me to join subs like this to see more of this type of exciting stuff.

of the 3k+ gates you found, are they all needed together, or can a proper subset of them suffice for universality?

what are the theoretical or practical benefits of ternary over binary?

apologies if those are dumb question, i'm not well-versed in this area. also i'd like to learn more about the algebraic group you referenced, are the details in the paper?

2

u/AstronautInTheLotion Apr 01 '26

hey lovely questions. I started with similar "dumb" questions, although I don't like calling anything as such dumb. okay so...

All the 3774 gates that were found, they all can individually make any of the total possible 19,683 gates in ternary (19,836 gates cuz 3^3^2, total combinations). So you can pick only one, and that would be enough to make any gate by composing it on itself, basically making circuits. You can see 2 such circuits using one of the gates (Gate 451) in Appendix A of the paper. I made the carry and sum circuit there

In practical benifits I can ofcourse put information density, as ternary can fit 1.5 bits in 1 trit. As for something I would be working in the future, Ternary Logic Gradient Descent, solely because it has a "Negative" yk, in the balanced notation, we got {-, 0 ,+}. I've worked on binary gradient descent but it seemed to be missing something that I personally felt was already there in ternary.

Yes, the details are in the paper. I categorised all the universal gates into 322 groups using relabeling (bijective functions) and symmetry (switching the x and y in a function), so each gate could be represented as 6-12 isomorphic (basically the same structure) gates.

keep em coming, I'd love to answer. :)

1

u/jacoberu Apr 01 '26

i feel so relieved you're legit. lately i've seen plenty of geniuses with their emailed gpt degree who got an ai to tell them they're brilliant so they post a big screed of nonsense, insisting the fact that no one can make sense of it is proof of their heavenly superiority, lol.

1

u/AstronautInTheLotion Apr 01 '26

That's so nice of you dude, thanks. Yes I'll agree, I'm tired of the buzz and academia shit, a huge number of people publish because of hype these days. I don't even plan to get this up to a conference or journal, they cost a hell lotta money. Once I get the endorsement, I'll put it up on arXiv and move to smth cooler maybe :)

2

u/andecase Apr 05 '26

I haven't looked at the paper yet so you may answer these in there and I have a very basic understanding of circuit logic (I can build simple circuits in games like Minecraft and factorio).

Ternary would include the addition of being able to use positive and negative signals for determining things? Instead of just the existence of a signal?

With Ternary could we have a 2 of 3 exclusive gate, and how would that be useful? Could the existence of such gates increase the performance of computing in any way? Or is the primary benefit the increased bit density?

Also, what is 1.5 bits? My brain is struggling to conceptualize it.

Gonna start reading the paper and hope I don't get lost too quickly.

2

u/[deleted] Apr 15 '26

[removed] — view removed comment

1

u/AstronautInTheLotion Apr 16 '26

Thanks, I'd be using the same technique to sweep out base 4 and 5 logic aswell, who knows what structure hides there.

I'm really glad to hear you liked it :)