6

I want to simplify this expression:

BooleanMinimize[(A ∧ ¬ B ∧ C ∧ ¬ D) ∨ (A ∧ B ∧ ¬ C ∧ ¬ D) ∨ (A ∧ B ∧ C ∧ ¬ D)]

And I get this:

(A ∧ B ∧ ¬ D) ∨ (A ∧ C ∧ ¬ D)

But using a Karnaugh Map and "don't cares" I get ¬ D. Is there anyway that I can get similar answer in Mathematica?

andre314
  • 18,474
  • 1
  • 36
  • 69
Bardulf
  • 63
  • 4
  • can you complete your question with the "don't care cases" ? otherwise we can't guess what you wish. – andre314 Nov 04 '17 at 18:18
  • I Consider hexadecimal and my "don't cares" are 0-9 – Bardulf Nov 04 '17 at 18:30
  • So you mean that A,B,C,D are 10,11,12,13(decimal) in your code ? , that is to say constants ? Apparently, you use them as is they where some variables (like x,y,z) – andre314 Nov 04 '17 at 18:45
  • I mean from (A ∧ ¬ B ∧ C ∧ ¬ D) this "1010" that represent "A" in hexadecimal and some thing like (A ∧ ¬B ∧ ¬C ∧ ¬ D) consider as "don't cares" – Bardulf Nov 04 '17 at 18:55
  • OK, I understand now – andre314 Nov 04 '17 at 19:13

2 Answers2

5

An arbitrary function with "don't cares" can be defined using either BooleanFunction or BooleanConvert, but in those cases, Mathematica makes no effort to find the minimal representation of such a function.

Instead, use BooleanMinimize with the optional third argument: an assumed condition on the variables. In your case, you can specify that your "don't cares" are 0-9 by making the condition be A ∧ (B ∨ C).

Then the calculation

BooleanMinimize[
  (A ∧ ¬ B ∧ C ∧ ¬ D) ∨ (A ∧ B ∧ ¬ C ∧ ¬ D) ∨ (A ∧ B ∧ C ∧ ¬ D),
  "DNF", 
  A ∧ (B ∨ C)] 

will produce the desired output of !D.

Misha Lavrov
  • 291
  • 1
  • 6
4

Thank's to @Misha Lavrov (a great thanks !), here is how you can solve the problem :

BooleanMinimize[  
    BooleanFunction[{
        {1,0,1,0}-> 1,
        {1,0,1,1}-> 0,
        {1,1,0,0}-> 1,
        {1,1,0,1}-> 0,
        {1,1,1,0}-> 1,
        {1,1,1,1}-> 0
      },{a,b,c,d}],  
    "SOP" (* = "DNF" *),
    BooleanFunction[{
        {1,1,_,_}-> 1, (* all cases above ... *)
        {1,_,1,_}-> 1, (* ... are "do care" *)
        {_,_,_,_}-> 0 (* other cases are "don't care" *)
      },{a,b,c,d}]]  
! d

Note :

@Misha Lavrov's comment (just below) was written before I added the third argument to BooleanMinimize. At this time there were some "don't care" states in the first BooleanFunction[...]

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
andre314
  • 18,474
  • 1
  • 36
  • 69