Michael Jablonski

July 23, 2021

Truth Tables

In the past weeks I have done some reading about formal software design methods, which I understand are used in safety-critical systems. 
 
The IEEE Computer Society’s guide to the “Software Engineering Body of Knowledge” says, “Formal design analysis uses mathematical models that allow designers to predicate the behavior and validate the performance of the software instead of having to rely entirely on testing.” These mathematical models often use Boolean logic.
 
I have never consciously used formal software design methods, but many times I have used Boolean truth tables to help write code, finding that when I use truth tables, and when the truth tables are finished, the programming and testing is easier than usual.
 
To write a program predicated on truth tables, I tackled this classic problem: 
 
“You are given 12 rings and one of these rings is different from the others, but you don't know if it is lighter or heavier than the others. Identify the special ring in three weighings and determine whether it is lighter or heavier than the others.”
 
I could not solve this problem on my own, but I found a solution here:
 
 
Nor could I easily write code based on the text that describes the solution, even though the steps to solve the problem are explained very well.
 
So, I expressed the steps to solve the 12 rings problem in a set of truth tables. Based on those tables I was able to quickly write and test the code, with a high measure of certainty that I got it right. The code executes a step by step, brute force, algorithm using the truth tables.
 
Is this design partially using formal methods of software design? 
 
I am not sure. Further study of formal methods is needed. Using the truth tables, however, made it easy to translate the text from the written instruction into a working program.
 
 You can see my truth tables and the Python source code that solves the 12 rings program on GitHub: