Message Boards Message Boards

GROUPS:

Boolean algebra, engineering format

Posted 8 months ago
610 Views
|
0 Replies
|
1 Total Likes
|

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. enter image description here

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:

enter image description here

There are options:

enter image description here

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

enter image description here Expressions can be checked for truth:

enter image description here

Here are the boolean axioms applied to the above expression:

enter image description here

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.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract