
Universal Logic Gates (2015) - joycian
https://www.allaboutcircuits.com/technical-articles/universal-logic-gates/
======
cperciva
Of the 16 possible 2-input/1-output gates:

* 8 of them are linear, in that the output is A xor (B and X) xor (C and Y). Any combination of these can only ever generate linear combinations of their inputs, thus they cannot be universal.

* 6 of them are monotonic, in that X op Y <= X' op Y' if X <= X' and Y <= Y'. Any combination of these can only ever generate monotonic functions of their inputs, thus they cannot be universal.

* 4 gates (0, X, Y, 1) are both linear and monotonic.

* The 6 gates which are neither linear nor monotonic are universal.

------
dreamcompiler
Slightly off-topic but it's clear from the table that you can simulate any
2-in, 1-out gate with four bits of memory and two address lines. Which is
exactly how "gates" are implemented in FPGAs (albeit with more inputs and
outputs).

------
fallingfrog
You can almost make a continuous variable version of all the logic gates, for
variables A and B which are between 0 and 1, but I couldn't quite get it to
work. I tried: (I'm using => to mean "maps to")

!A => 1 - A

A && B => AB

A || B => A + B - AB

If you do this, some of the rules of logic work fine:

!(!A && !B) => 1 - ((1 - A)(1 - B)) = A + B - AB, which is the same as the
expression for A || B.

But A && A obviously doesn't work, you get A^2 instead of just A.

And to relate this to the article, the rule to convert NAND into OR doesn't
work either, you get

(A NAND A) NAND (B NAND B) => 1 - ((1 - A^2) * (1 - B^2)) = A^2 + B^2 - (AB)^2

Now all of these do evaluate to the right answer when A and B are either 0 or
1 but not when they are some value in between.

You can also try letting A && B => sqrt(AB) but you get similar issues.

~~~
abdullahkhalids
The generalization of continuous variable version of boolean logic can be
achieved in various ways as far as I know. One way is Cox's theorem [1], which
forms the basis of Bayesian probability theory, and will give you consistent
logic and reduces to the standard rules of boolean logic in the limit of 0/1.

[1]
[https://en.wikipedia.org/wiki/Cox%27s_theorem](https://en.wikipedia.org/wiki/Cox%27s_theorem)

~~~
fallingfrog
The way I came up with my attempt was just to notice that when you are looking
at the probability of two independent events happening together, you multiply
them; and if you want the probability of A or B or both, you add them and then
subtract the probability of (A and B). I guess the reason the multiplication
rule doesn’t work for (A && A) is that those two variables are clearly not
independent, since they’re the same variable.

------
joycian
This article shows more universal gates than the NAND and NOR that are usually
discussed. Are any Hacker News users knowledgeable about the topic? Because I
was wondering why I never heard about these universal gates before. Almost
always, only NAND and NOR are discussed.

~~~
_0ffh
I would guess that NAND and NOR might better lend themselves to practical
physical implementation.

Also: If you don't limit yourself to 2-input/1-output gates, there's loads
more universal gates. Many 3-in/3-out reversible gates are universal [1]. I
really have a soft spot for the Fredkin, it just seems so elegant.

[1] [http://www.thefullwiki.org/Three-
input_universal_logic_gate](http://www.thefullwiki.org/Three-
input_universal_logic_gate)

~~~
noajshu
The monotone, linear, etc. functions are called clones and the clones form a
lattice called Post's Lattice

[https://en.wikipedia.org/wiki/Post%27s_lattice](https://en.wikipedia.org/wiki/Post%27s_lattice)

Given several logic gates, if their most recent common ancestor in the lattice
is the clone of all boolean functions, then that set is universal. This
provides a convenient prescription for deciding universality for a new k-input
gate.

