There are 16 binary functions over 2 variables. This is a simple consequence of there being 4 input possibilities and only 2 output possibilities for each. In computer programming we frequently use ‘and’ and ‘or’, less often ‘xor’, but that still leaves 13 more.
Lets take a closer look at all 16. For brevity I will label each by their outputs for the inputs F,F T,F F,T T,T – so ‘and’ is FFFT.
- TTTT – ‘always true’. Not very interesting, but it exists.
- FFFF – ‘always false’. Again not very interesting.
- FFFT – ‘and’. Well known and used in programming frequently.
- TTTF – ‘not and’. Simple combination of the negation function with the and.
- FTTT – ‘or’. Well known and used in programming frequently.
- TFFF – ‘not or’. Simple combination of negation and ‘or’.
- FTTF – ‘xor’. Not quite as well known as ‘or’, but simply ‘or’ where it can’t be both.
- TFFT – ‘not xor’. Again a simple combination of negation and ‘xor’. But it is also the A == B scenario and thus xor can also be described as A != B.
- FFTT – ‘B is true’. First parameter is ignored, and second is just passed through.
- TTFF – ‘B is not true’. Again just the negation of the one before.
- FTFT – ‘A is true’. This time the second parameter is ignored.
- TFTF – ‘A is not true’. Yet another simple negation.
- TFTT – ‘A implies B’. If A is true, B must be true, but otherwise anything goes.
- FTFF – ‘A and (not B)’. This is also the negation of ‘A implies B’ but programming sees combinations of ‘and’ and ‘not’ far more frequently.
- TTFT – ‘B implies A’. If B is true, A must be true.
- FFTF – ‘(not A) and B’. As for 14, but reversed.
So, why did I list all these? So I could categorize them.
- Really, really boring: TTTT, FFFF – No interest in the inputs.
- Boring: FFTT, TTFF, FTFT, TFTF – Only one input is used.
- ‘And’ variants: FFFT, TFFF, FFTF, FTFF – Only one scenario is true.
- ‘Or’ variants: FTTT, TTTF, TFTT, TTFT – Three scenarios are true.
- Strongly linked: TFFT, FTTF – Two scenarios are true, and both inputs are used.
I am now going to state that I think ‘and’ variants are actually boring as well. Since there is only one possible true state, they all result in you being able to say something about A or something about B, in isolation. The problem is separable. Which is just the nature of ‘and’, but it makes it less interesting to me.
This leaves 6 ‘interesting’ functions. A is the same as B. A is the opposite of B (xor). A implies B. B implies A. Not both false (or). Not both true (nand).
Of these, ‘or’ is obviously the most commonly used in programming. Interestingly, despite being a fundamental element of predicate logic, I have not yet worked with a programming language where A implies B has its own operator, you have to do B or not A, which is a bit clumsy.
Where does this thought train lead me… well maybe I will have more to say on this topic another time.