Boolean algebra, engineering format

Mathematica doesn’t use the usual boolean notation with which circuit designers are familiar.

The plan is to enter boolean expression as

a c d + b d not a + a not b  not c (a not c not d + b not c not d)

and produce overbars on the complemented variables. I can’t get the overbars to show as code, so I’ll use images. A notebook is attached with all the code.

5151boole131.png

The not is implemented as:

$PreRead =.
$PreRead = (ReplaceAll[#, "not" :> "OverBar@"] &)

Boolean minimization is a Mathematica function, but it uses boolean expressions in the usual logical form. That is foreign to circuit designers.

Here is the minimization converted to engineering format:

boolmin[m_, opts_: "DNF"] := 
 Module[{ans}, 
  ans = BooleanMinimize[
    m /. {Plus -> Or, Times -> And, OverBar -> Not}, opts]; 
  ans = ans /. {Or -> Plus, And -> Times, Not -> OverBar};
  ans /. {a_^_ -> a, _Integer a_ -> a}
  ]

The engineering format is converted to logical format, minimized, and then converted back to engineering. {a_^_ → a, Integer a → a} is necessary because the expression is arithmetic.

Here it is applied to the expression above:

boole132.png

There are options:

Here is a truth table in engineering format:

 variables[
  m_] := (Variables[m] /. OverBar -> Variables // Flatten // 
     DeleteDuplicates // Sort) /. List -> Sequence

truthTable[m_] := 
 Module[{mm}, mm := variables[m]; 
  TableForm[
   Boole@BooleanTable[{variables[m], 
      m /. Plus -> Or /. Times -> And /. OverBar -> Not}, {variables[
       m]}], TableHeadings -> {None, {mm}}]]

tt = truthTable

Expressions can be checked for truth:

boole135.png

Here are the boolean axioms applied to the above expression:

This particular expression minimizes to the same expression as the default Mathematica minimization but that is an unfortunate choice. In general that is not so.

DANGER!! The opening line in the first attached notebook removes all current work in your notebook. I can’t replace the downloaded file with a new file.

Use the corrected version, please. One error found and fixed.

With some tweaking, the boole.nb notebook below resulted. It’s pretty robust.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=5151boole131.png&userId=455211
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=boole132.png&userId=455211
[3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=boole133.png&userId=455211
[4]: http://community.wolfram.com//c/portal/getImageAttachment?filename=boole134.png&userId=455211
[5]: http://community.wolfram.com//c/portal/getImageAttachment?filename=boole135.png&userId=455211
[6]: http://community.wolfram.com//c/portal/getImageAttachment?filename=boole136.png&userId=455211

1 Like