0
$\begingroup$

I have the boolean expression (a && !b). I want to add variables c, d into the expression and then have Mathematica transform the expression into conjunctive normal form. I would like it to go something like this:

a&&!b
  = (a && !b && c) || (a && !b && !c)
  = (a && !b && c && d) || (a && !b && c && !d) || (a && !b && !c && d) || 
    (a && !b && !c && !d)

Although a human can do this easily, how can can I get Mathematica to do it? What are the commands?

$\endgroup$
  • 1
    $\begingroup$ Take a look at BooleanConvert and forms it has available. But I don't know how to use it for your purpose :) $\endgroup$ – Kuba Aug 29 '13 at 8:40
4
$\begingroup$

I don't now that I really understand your question, but from a pure expression manipulation perspective this might be useful:

Or @@ And @@@ Tuples[{{a && ! b}, {c, ! c}, {d, ! d}}]

(a && ! b && c && d) || (a && ! b && c && ! d) || (a && ! b && ! c && d) || (a && ! b && ! c && ! d)

The same operation a bit more concisely:

Or @@ Tuples[{a && ! b} && {c, ! c} && {d, ! d}]
$\endgroup$
  • $\begingroup$ I still don't believe that this is not automatic :P Are you really going to put && {sym, ! sym} each time? But +1 for Tuples I don't know why I decided to use Outer.:) $\endgroup$ – Kuba Aug 29 '13 at 10:57
  • $\begingroup$ @Kuba Frankly I don't understand the question so I wasn't sure what operation was to be done. I voted for your answer by the way. I think my code is open ended in that you could have any number of variations in each sublist. $\endgroup$ – Mr.Wizard Aug 29 '13 at 10:59
  • $\begingroup$ I have a CNF and BooleanMinimize can simplify it to a&&!b. Now I want to perform the revert process. $\endgroup$ – Gqqnbig Aug 29 '13 at 11:19
2
$\begingroup$

Since I don't know how to incorporate BooleanConvert here is a walkaround for this case:

conv = Or @@ Flatten[Outer[
                           And,
                           {#1},
                           Sequence @@ Transpose[{Not /@ #2, #2}]]
                    , 2] &

.

conv @@ {a && ! b, {c}}
(a && ! b && ! c) || (a && ! b && c)
conv @@ {a && ! b, {c, d}}
(a && ! b && ! c && ! d) || (a && ! b && ! c && d) || (a && ! b && c && ! d) || 
(a && ! b && c && d)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.