You are on page 1of 10

PRACTICAL - 6

basic operators && (AND), || (OR), ! (NOT)

In[1]:= True || false


Out[1]= True

In[2]:= True || True


Out[2]= True

In[4]:= False || True


Out[4]= True

In[5]:= False || False


Out[5]= False

In[6]:= True && True


Out[6]= True

In[7]:= True && False


Out[7]= False

In[8]:= False && True


Out[8]= False

In[9]:= False && False


Out[9]= False

In[10]:= ! True
Out[10]=
False

In[11]:= ! False
Out[11]=
True

In[12]:= ! True && False


Out[12]=

False

In[13]:= ! True || False


Out[13]=

False
2

In[14]:= True && ! True


Out[14]=

False

In[15]:= True ∧ False


Out[15]=

False

In[16]:= True ∨ False


Out[16]=

True

In[17]:= ¬ True
Out[17]=

False

REPRESENTING BOOLEAN FUNCTIONS

1. f (x, y, z) = xy + yz + zx

In[18]:= f[x_ , y _, z_] := (x ∧ y) ∨ (y ∧ z) ∨ (z ∧ x);

In[19]:= f[p, q, r]
Out[19]=

(p && q) || (q && r) || (r && p)

In[20]:= f[True, False, True]


Out[20]=

True

In[21]:= f[True, q, r]
Out[21]=

q || (q && r) || r

In[22]:= f[True, q, r] // Simplify


Out[22]=

q || r

2. g (x, y) = ! (! x + y) x + ! ! ! y + xy + x ! y

In[23]:= g[x_ , y _] := ! ((! (x ∨ y) ∧ x) ∨ ! ! ! y) ∨ (x ∧ y) ∨ (x ∧ ! y)


3

In[24]:= g[False, False]


Out[24]=

False

In[25]:= g[False, True]


Out[25]=

True

In[26]:= gTrue, False


Out[26]=
True

In[27]:= g[True, True]


Out[27]=
True

3. h (x, y, z) = x (! (y + z)) + (xy + ! z) x

In[28]:= h[x_ , y _, z_] := (x ∧ (! (y ∨ z))) ∨ ((x ∧ y) ∨ ! z) ∧ x;

In[29]:= h[0, 0, 0] // Simplify


Out[29]=

False

In[30]:= h[1, 0, 0] // Simplify


Out[30]=
True

In[31]:= h[0, 1, 0] // Simplify


Out[31]=
False

In[32]:= h[0, 0, 1] // Simplify


Out[32]=
False

In[33]:= h[1, 1, 0] // Simplify


Out[33]=

True

In[34]:= h[1, 0, 1] // Simplify


Out[34]=

False
4

In[35]:= h[1, 1, 1] // Simplify


Out[35]=

True

TABLE FORM
1. FOR BOOLEAN POLYNOMIAL FUNCTION f :

In[37]:= BooleanTable[{p, q, r, f[p, q, r]}, {p, q, r}] // TableForm


Out[37]//TableForm=
True True True True
True True False True
True False True True
True False False False
False True True True
False True False False
False False True False
False False False False

In[38]:= Boole[BooleanTable[{p, q, r, f[p, q, r]}, {p, q, r}]] // TableForm


Out[38]//TableForm=
1 1 1 1
1 1 0 1
1 0 1 1
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
0 0 0 0

In[39]:= TableForm[Boole[BooleanTable[{p, q, r, f[p, q, r]}, {p, q, r}]],


TableHeadings → {None, {p, q, r, f}}]
Out[39]//TableForm=
p q r f
1 1 1 1
1 1 0 1
1 0 1 1
1 0 0 0
0 1 1 1
0 1 0 0
0 0 1 0
0 0 0 0

2. FOR BOOLEAN POLYNOMIAL FUNCTION g :


5

In[40]:= TableForm[Boole[BooleanTable[{p, q, g[p, q]}, {p, q}]],


TableHeadings → {None, {p, q, g}}]
Out[40]//TableForm=
p q g
1 1 1
1 0 1
0 1 1
0 0 0

3. FOR BOOLEAN POLYNOMIAL FUNCTION h :


In[41]:= TableForm[Boole[BooleanTable[{p, q, r, h[p, q, r]}, {p, q, r}]],
TableHeadings → {None, {p, q, r, h}}]
Out[41]//TableForm=
p q r h
1 1 1 1
1 1 0 1
1 0 1 0
1 0 0 1
0 1 1 0
0 1 0 0
0 0 1 0
0 0 0 0

PRACTICAL - 7
1. DUAL OF A GIVEN BOOLEAN POLYNOMIAL / EXPRESSION.
In[1]:= dual[expr_] := expr /. {And → Or, Or → And, False → True, True → False}

In[2]:= dual1 = dual[(x && ! y) || (y && ! z) || (! x && z)]


Out[2]= (x || ! y) && (y || ! z) && (! x || z)

In[3]:= dual2 = dual[(! x && y) || (! y && z) || (x && ! z)]


Out[3]= (! x || y) && (! y || z) && (x || ! z)

2. WHETHER OR NOT TWO BOOLEAN


POLYNOMIALS ARE EQUIVALENT.
In[4]:= distributiveL = x && (y || z);
distributiveR = (x && y) || (x && z);
6

In[6]:= TautologyQ[Equivalent[distributiveL, distributiveL, distributiveR], x, y, z]


Out[6]= True

In[7]:= TautologyQ[Equivalent[x || (x && y), y], {x, y}]


Out[7]= False

In[8]:= f1[x_ , y _] := ! (x && y);

f2[x_ , y _] := ! x || ! y;

In[10]:= TautologyQ[Equivalent[f1[x, y], f2[x, y]], {x, y}]


Out[10]=

True

3. DISJUNCTIVE NORMAL
FORM CONJUNCTIVE NORMAL FORM
FROM A GIVEN BOOLEAN EXPRESSION.
In[11]:= example3 = (x || y) && ! z
Out[11]=

(x || y) && ! z

In[12]:= BooleanConvert[example3, "DNF"]


Out[12]=

(x && ! z) || (y && ! z)

In[13]:= BooleanConvert[example3]
Out[13]=

(x && ! z) || (y && ! z)

In[14]:= BooleanConvert[example3, "CNF"]


Out[14]=

(x || y) && ! z

4. DISJUNCTIVE NORMAL FORM


CONJUNCTIVE NORMAL FORM WHEN THE GIVEN BOOLEAN

FUNCTION IS EXPRESSED BY A TABLE OF VALUES.


7

In[15]:= BFexample = BooleanFunction[{{1, 1, 1} → 0, {1, 1, 0} → 1, {1, 0, 1} → 0,


{1, 0, 0} → 1, {0, 1, 1} → 0, {0, 1, 0} → 0, {0, 0, 1} → 1, {0, 0, 0} → 0}]
Out[15]=

Number of variables: 3
BooleanFunction 
Function index: 82

In[16]:= BFexample[True, False, True]


Out[16]=
False

In[29]:= BooleanFunction[{{1, 1, 1} → 0, {1, 1, 0} → 1, {1, 0, 1} → 0,


{1, 0, 0} → 1, {0, 1, 1} → 0, {0, 1, 0} → 1, {0, 0, 1} → 1, {0, 0, 0} → 0}, {x, y, z}]
Out[29]=

(x && ! z) || (! x && ! y && z) || (y && ! z)

In[30]:= BooleanFunction[{{1, 1, 1} → 0, {1, 1, 0} → 1, {1, 0, 1} → 0, {1, 0, 0} → 1,


{0, 1, 1} → 0, {0, 1, 0} → 1, {0, 0, 1} → 1, {0, 0, 0} → 0}, {x, y, z}, "CNF"]
Out[30]=

(! x || ! z) && (x || y || z) && (! y || ! z)

In[19]:= BooleanTable[{x, y}, {x, y}] // TableForm


Out[19]//TableForm=
True True
True False
False True
False False

In[28]:= BooleanFunction[{0, 1, 0, 1, 0, 1, 1, 0}, {x, y, z}]


Out[28]=
(x && ! z) || (! x && ! y && z) || (y && ! z)

PRACTICAL - 8
8

Representing a given circuit diagram


expressed using gates in the form of boolean expression :

1.

In[1]:= G4 = ¬ a;

In[2]:= G5 = ¬ c;

In[3]:= G3 = G4 ∧ G5 ∧ c;

In[4]:= G2 = a ∧ b;

In[5]:= G1 = G2 ∨ G3;

In[6]:= G1
Out[6]= (a && b) || (! a && ! c && c)

In[8]:= G2 = A ∧ B ∧ C;

In[9]:= G4 = ¬ C;

In[10]:= G3 = A ∧ B ∧ G4;

In[11]:= G5 = ¬ A;
9

In[12]:= G6 = ¬ C;

In[13]:= G7 = G5 ∧ B ∧ G6;

In[14]:= G1 = G2 ∨ G3 ∨ G7;

In[15]:= G1
Out[15]=

(A && B && C) || (A && B && ! C) || (! A && B && ! C)

In[27]:= G1 = ¬ x;

In[28]:= G2 = G1 ∧ x;

In[29]:= G3 = ¬ G2;

In[50]:= G4 = G3 ∨ G3;

In[40]:= G5 = ¬ w;

In[41]:= G6 = y ∧ G5;

In[42]:= G7 = y ∧ w;

In[43]:= G8 = ¬ z;

G9 = G7 ∨ G8;

In[35]:= G10 = G6 ∨ G9;

In[45]:= G11 = G4 ∨ G10;

In[46]:= G11
Out[46]=

! (! x && x) || ! (! x && x) || (y && ! w) || (y && w) || ! z


10

PRACTICAL - 9

In[47]:= BooleanMinimize[(a ∧ b) ∨ (! a ∧ b ∧ ! c)]


Out[47]=

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

In[48]:= BooleanMinimize[(a ∧ b) ∨ (! a ∧ b ∧ ! c), "CNF"]


Out[48]=

(a || ! c) && b

In[49]:= Simplify[(a ∧ b) ∨ (! a ∧ b ∧ ! c)]


Out[49]=

(a || ! c) && b

You might also like