Building Truthful Half-Adders
As we continue our logic lessons on Brilliant.org, we are now on to building digital circuits. Today, we learn how to make a half adder, but I will also go on to show how to create one with Netica (a Bayesian Network).
We are given three choices between OR, XOR, and AND so as to produce (0, 1, 1, 0) from the two binary inputs A and B.
We need some equations:
input (A, B) = 2 * A + B // maps the boolean node to digits
gate (A, B, select) =
select0 ( select , or (A, B) , xor (A, B), and (A, B) ) // map index to gates
S1 (gate) = gate // the output for 1S(Note that “S1 (gate) = gate” is just a pass-through to S1)
We can already see that XOR is the desired logic gate for the desired output (0, 1, 1, 0).
Let’s watch the network in action as we test each logic gate with the inputs (0, 1, 2, 3) and watch the output S1 on the other side.
We verified that XOR produces the desired output given the inputs.
We do the same thing for output 2S:
We can reuse the same network, and indeed, we have already seen the solution. Since the desired output for 2S is (0, 0, 0, 1), we can see that the AND gate will work.
What Brilliant.org does is good as far as it goes, but it simply does not go far enough in my view. In spite of that, I have still been a paying subscriber since 2022 and, on the whole, I have generally been satisfied. But it does not seem to me that these animations they give are nearly as satisfying (and instructive) as what can easily be accomplished by building a digital circuit with a Bayesian network like Netica (or GeNIe, as I show below).
Get Pascal Bercker’s stories in your inbox
Join Medium for free to get updates from this writer.
We can combine the gates to complete the adder:
Our corresponding network is as follows:
Let’s check to see that as we cycle through the inputs (0, 1, 2, 3) that, with the selected gates, we really produce the desired outputs (0, 1, 1, 0) for S1 and (0, 0, 0, 1) for S2 (note that variable names cannot start with a number, hence S1 and S2 instead of 1S and 2S). We will activate the AND gate and the XOR gate (in green) and verify that each input produces the correct output.
At the risk of cluttering things too much, let’s be more explicit about what we have done. We input two binary bits, choose the right set of gates for a half-adder, carry out the logic to add them, and convert the result to a decimal sum.
The Brilliant.org lesson concludes:
We have indeed, but I would add this: Once we leave that page on Brilliant.org, the half-adder we have built just disappears along with the page, and there is nothing to take home, as it were. But if instead we really build one with a Bayesian Network like Netica, then, at the end of the day, we have our little half-adder tucked away somewhere on our computer, saved in a file in whatever format we like. (I’m happy to share the file with anyone who asks!)
Just for the sake of interest, I converted the Netica model to a GeNie file format. Here is what it looks like. It has the same basic structure with some minor differences in how it handles equational nodes (but we will ignore that for now).
What’s next? A full adder, of course!
SOURCES & REFERENCES









