I was reading the TECS book (The Elements of Computing Systems), in the book, we start to build the other logical gates with a single primitive logical gate, the $NAND$ gate. With it, we could easily make the $NOT$ gate, then the $AND$ gate and then the $OR$ gate.

With the $NOT$, $AND$ and $OR$ gates, we could express any truth table through cannonical representation.

The book has the table given below, I was wondering if we could do the same by taking any other boolean function as primitive, I'm quite sure that it's not possible to do with both constant $0$ nor constant $1$. What about the others?

enter image description here


Your question concerned arbitrary ($n$-ary) boolean functions, yet you seemed to have restricted your search to $0$-ary, $1$-ary and $2$-ary functions. A collection $C$ of boolean functions that can generate all the others by composition is called functionally complete, and when $C$ is a singleton $\{f\}$ we call such $f$ a Sheffer function. Now, a full characterization of functionally complete collections of boolean functions was given in "The Two-Valued Iterative Systems of Mathematical Logic" (Post 1941). As this book is hardly legible, though, I would heartily recommend the explanation of the main theorem in "Post's functional completeness theorem" instead. In "Composition and clones of Boolean functions", by Pöschel and Rosenberg (first chapter of Boolean Models and Methods in Mathematics, Computer Science, and Engineering), the exact number of $n$-ary Sheffer functions is determined: $2^{2^n - 2} - 2^{2^{n - 1} - 1}$. So, if you go beyond the $2$ binary functions NAND and NOR you should find $56$ functionally complete ternary functions, $16\,256$ functionally complete quaternary functions, and so on.


As you noted, it's impossible for the constants to generate all of the boolean functions; the gates which are functions of a single input also can't do it, for equally-obvious reasons (it's impossible to generate the boolean function $f(x,y)=y$ from either $f_1(x,y)=x$ or $f_2(x,y)=\bar{x}$).

OR and AND can't do it either, for a slightly more complicated reason — it's impossible to generate nothing from something! (More specifically, neither one of them is able to represent negation, and in particular neither one can represent a constant function — this is because any function composed of only ORs and ANDs will always return 0 when its inputs are all-0s and will return 1 when its inputs are all-1s.

XOR is a bit more complicated: it's obviously possible to generate 0 and 1 via XORs, and thus NOT; but the 'parity preserving' nature of XOR makes it impossible to represent $x\wedge y$ with XOR alone.

In fact, it can be shown that NOR and NAND are the only two-input boolean functions which suffice in and of themselves; for more details, have a look at the Wikipedia page on functional completeness.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.