Back in school I had a few courses in digital electronics, so Karnaugh maps were not something alien to me. Unfortunately, my life experience never took me down a path where I had to simplify Boolean equations.
A current software development project required a screen with various UI options to allow the user to configure the application. Among the usual validations that I had to perform on the entered selections was one that was somewhat unusual.
The application provides logging functionality and also calls an external process that also performs logging functions. In both cases the folder location of the log file can be specified by the user. The UI elements to handle this were the following:
- A checkbox that allows the user to either enable or disable logging for the application.
- Another checkbox to specify that the external application should use the same log folder as the calling app.
- A text field where the user types in a valid folder specification where the log file will be created.
The validation is a success when either of these checkboxes are ticked and the folder specification is valid or when neither checkbox is ticked. Of course, I could have just put together an interesting IF statement that would accomplish the required tests, but I wondered if I could put together one Boolean formula (function) that would return the status of the validation given the rules above.
That’s when I remembered the Karnaugh maps. I also came to the realization that I did not remember how to use these maps. I already had the truth table:
a = Log enable/disable check box
b = External app uses same log folder as main app check box
c = Valid folder specification text field
a b c Valid
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
I just needed to remember the technique for setting up the map, inserting the result values and deriving the resultant Boolean formula. After doing some research and reading I managed to perform the first two steps (left side of image):
I should note that I had completely forgotten that little rule that indicates that the rows (or columns) should be numbered such that only one bit changes. I had initially numbered the rows 00, 01, 10 and 11, but when I read that I changed it as shown above.
After a bit more research I understood how to get the formula’s terms which are also shown above. The translation of this formula to code was easy from here:
Function fLoggingUIIsValid() as Boolean
Return (Not chkboxEnLog.Checked and Not chkboxXAppLog.Checked) or
fFolderExists(txtboxLogFolder.Text)
End Function
And there it is. This worked nicely for my purposes. Regards.
Top Comments