fexpr41[s0_]:=DynamicModule[{s=s0},
g=WolframAlpha[s,"PodCells"];
Column[{
Row[{"a) Truth table","                        ","b) Boolean Expression","                   ","c) Logic network"}],
Row[{g[[3]],"     ",g[[2]],"       ",g[[6]]}]
}]
];


fexpr[s0_,n0_]:=DynamicModule[{s=s0,n=n0},
g=WolframAlpha[s,"PodCells"];
g[[n]]
];


(*module1[]:=DynamicModule[{},
Dynamic[Column[{Button["Again",
expr=RandomChoice@{"P AND NOT Q","P AND NOT Q AND R","P AND NOT Q AND R OR P ","(P AND Q) OR (NOT (P AND T))","P OR (Q AND T)","((Q AND T) AND (Q OR T))","(P AND Q) OR T"};
g=WolframAlpha[expr,"PodCells"];],
Row[{Column[{g[[2]],
g[[6]]},Alignment->Center],
"        ",
Column[{Row[{"Vienn diagram for: ",g[[2]]}],
g[[7]]
},Alignment->Center]
}]
}],SynchronousUpdating->False]
,

Initialization:>(expr=RandomChoice@{"P AND NOT Q","P AND NOT Q AND R","P AND NOT Q AND R OR P ","(P AND Q) OR T"};g=WolframAlpha[expr,"PodCells"];)
];*)




makeTextTable[data0_]:=Module[{data},
(* FIXME data=Table[ToString[#,TraditionalForm]&/@(data0[[i]]),{i,1,Length[data0]}];*)

Text@Grid[data0,Background->{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}},Dividers->{{Darker[Gray,.6],{Lighter[Gray,.5]},Darker[Gray,.6]},{Darker[Gray,.6],Darker[Gray,.6],{False},Darker[Gray,.6]}},ItemSize->Automatic]

];

t1=makeTextTable[{{"\"∨\" \"or\" \"+\"","0","1"},{"0","0","1"},{"1","1","1"}}];
t2=makeTextTable[{{"\"∧\" \"and\" \".\"","0","1"},{"0","0","0"},{"1","0","1"}}];
t3=makeTextTable[{{"x","x'"},{"0","1"},{"1","0"}}];

g1=Grid[{{"x + 0 = 0","","x + 1 = 1","","x + x = x","","x + x' = 1"},
{""},
{"x.0 = 0","","x.1 = x","","x.x = x","","x.x' = 0"}},Frame->{False,All},Background->{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}}];

g2=Grid[{{"x.[x.y + y'(x + y)']"},
{""},
{"(x.y.z') + (x'.y.z) + (x.y'.z)'"}},Frame->{False,All},Background->{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}}];

t4=makeTextTable[{{"1. a)","x.y = y.x"," Commutative law ","x + y = y + x"},
{"2. a)","x.(y.z) = (x.y).z"," Associative law ","x + (y + z) = (x + y) + z"},
{"3. a)","x.(y + z) = x.y + x.z"," Distributive law ","x + (y.z) = (x + y).(x + z)"}
}];

t5=makeTextTable[{{"x.(y + z)' + (x.y) = x.(y + z')"},
{"x.y + x.z' + x.y = x.y + x.y + x.z'"},
{"                 = x.y + x.z' "},
{"                 = x.(y + z')"}
}];

t6=makeTextTable[{{"x","(Subscript[f, 0])","(Subscript[f, 1])","(Subscript[f, 2])","(Subscript[f, 3])"},{"0","0","0","1","1"},{"1","0","1","0","1"}}];

t7 = makeTextTable[{{"(Subscript[x, 1])","(Subscript[x, 2])","(Subscript[f, 0])","(Subscript[f, 1])","(Subscript[f, 2])","(Subscript[f, 3])","(Subscript[f, 4])","...","(Subscript[f, 14])","(Subscript[f, 15])"},{"0","0","0","0","0","0","0","...","1","1"},{"0","1","0","0","0","0","1","...","1","1"},
{"1","0","0","0","1","1","0","...","1","1"},{"1","1","0","1","0","1","0","...","0","1"}}];

g3 = Grid[{{makeTextTable[{{"x","y","z","m(x,y,z)"},
{"0","0","0","0"},
{"0","0","1","0"},
{"0","1","0","0"},
{"0","1","1","1"},
{"1","0","0","0"},
{"1","0","1","0"},
{"1","1","0","0"},
{"1","1","1","0"}
}],
 " ⟹  m(x,y,z) = 1  only if x=0, y=1, z=1 ⟹  m(x,y,z) = x'.y.z"
}}];

g4 = Grid[{{makeTextTable[{{"x","y","z","f(x,y,z)"},
{"0","0","0","1"},
{"0","0","1","0"},
{"0","1","0","0"},
{"0","1","1","1"},
{"1","0","0","1"},
{"1","0","1","0"},
{"1","1","0","0"},
{"1","1","1","1"}
}],
 " ⟹ f(x,y,z) = x'.y'.z' + x'.y.z + x.y'.z' + x.y.z "
}}];

t8 = makeTextTable[{{"","xy","xy'","x'y'","x'y"},{"z"," "," "," "," "},{"z'"," "," "," "," "}}];

t9 = makeTextTable[{{"","xy","xy'","x'y'","x'y"},
{"zw"," "," "," "," "},
{"z'w"," "," "," "," "},
{"z'w'"," "," "," "," "},
{"zw'"," "," "," "," "}
}];

r1=Row[{makeTextTable[{{"","xy","xy'","x'y'","x'y"},{"z","1"," "," ","1"},{"z'"," ","1","1"," "}}],"   f(x,y,z) = yz + y'z'"}];

r2 = Row[{makeTextTable[{{"","xy","xy'","x'y'","x'y"},{"z","1"," "," ","1"},{"z'","1"," "," ","1"}}],"   f(x,y,z) = x"}];

r3 = Row[{makeTextTable[{{"","xy","xy'","x'y'","x'y"},
{"zw","1"," "," ","1"},
{"z'w"," ","1","1"," "},
{"z'w'"," ","1","1"," "},
{"zw'","1"," "," ","1"}
}],"  f(x,y,z,w) = z'y' + yz"
}];

p1=;
p2=;
p3 =;
p4=;

g5 = Grid[{{"OR gate","NOT gate/inverter","AND gate","NAND gate"},{p1,p2,p3,p4}}];


r4=fexpr41["(X AND (NOT Y)) OR ((NOT X) AND Y) "];


r5=Row[{makeTextTable[{
{"X","Y","Z","P","f(X,Y,Z,P)"},
{"0","0","0","0","0"},
{"0","0","0","1","0"},
{"0","0","1","0","0"},
{"0","0","1","1","0"},
{"0","1","0","0","1"},
{"0","1","0","1","1"},
{"0","1","1","0","1"},
{"0","1","1","1","1"},
{"1","0","0","0","0"},
{"1","0","0","1","0"},
{"1","0","1","0","0"},
{"1","0","1","1","1"},
{"1","1","0","0","1"},
{"1","1","0","1","1"},
{"1","1","1","0","1"},
{"1","1","1","1","1"}
}],
"                  ",
Column[{fexpr["(X AND Z AND P) OR Y",2],fexpr["(X AND Z AND P) OR Y",5]},Alignment->Center]
}
];

CDFDeploy[ToFileName[{$UserDocumentsDirectory},"functions.cdf"],CreateDocument[{


Pane@Text[
Style["Boolean Algebra",Bold,Darker[Orange],30]],
Spacer[100],
Pane@Text[Style["Boolean Algebra is a powerful mathematical tool from logical circuits design. It takes its name from its founder Geirge Bool in the (19^th)-century.", 16]
],
Spacer[100],
Pane@Text[
Style["1. Boolean Expressions",Bold,Lighter[Darker[Orange]],23]],
Spacer[100],
Pane@Text[Style["A Boolean Expression in n variables (Subscript[x, 1]), (Subscript[x, 2]), (Subscript[x, 3]), ..., (Subscript[x, n]) is any finite string of symbols formed by applying the following rules:", 16]
],
Spacer[20],
Pane@Text[Style["1)  (Subscript[x, 1]), (Subscript[x, 2]), (Subscript[x, 3]), ..., (Subscript[x, n])  are Boolean expressions.", 16]],
Pane@Text[Style["2) If x and y are Boolean expressions, so are (x+y), (x.y) and x'.", 16]],
Spacer[20],
Pane@Text[Style["In our context we build a Boolean Algebra on a set B={0,1}. All together with the operations of disjunction, conjunction, and negation.", 16]
],
Spacer[100],
Pane@Row[{t1,"    ",t2,"   ",t3}],
Spacer[100],
Pane@Text[Style["Also remember that always:", 16]
],
Spacer[100],
Pane@g1,
Spacer[100],
Pane@Text[Style["Some complex Boolean expressions:", 16]
],
Spacer[100],
Pane@g2,
Spacer[100],
Pane@Text[Style["can apply truth table, and 2 expressions are said to be equivalent if they have the same truth table.", 16]
],
Spacer[100],
Pane@Text[Style["Theorem 1.1.",Bold, 16]],
Pane@Text[Style["Let x,y, and z be Boolean Variables, the following identities always hold:", 16]
],
Spacer[100],
Pane@t4,
Spacer[100],
Pane@Text[Style["Now use theorem 1.1. to show that:", 16]
],

Pane@t5,
Spacer[100],
Pane@Text[
Style["1.1. De Morgan's Law",Bold,Lighter[Darker[Red]],20]],
Spacer[100],
Pane@Text[Style["Theorem 1.1.1.",Bold, 16]],
Pane@Text[Style["For all Boolean Expressions x and y:", 16]],
Pane@Text[Style["1) (x + y)' = x'.y'", 16]],
Pane@Text[Style["2) (x.y)' = x' + y'", 16]],
Spacer[100],
Pane@Text[Style["Theorem 1.1.2.",Bold, 16]],
Pane@Text[Style["If   x+y = 1  and   x.y = 0   ⟹    x = y'", 16]],
Pane@Text[Style["proof:", 16]],
Pane@Text[Style["x = x.1 = x.(y + y')    ⟹      x = x.y + x.y' = 0 + x.y' = y.y' + x.y' = y'(x + y) = y'     ⟹  x = y'", 16]],
Spacer[100],
Pane@Text[Style["Example 1.1.1.",Bold, 16]],
Pane@Text[Style["Prove that:", 16]],
Spacer[10],
Pane@Text[Style["a) (p + q')'.r' = p'.q.r'", 16]],
Pane@Text[Style["use De Morgan's Law:  p'.q.r'", 16]],
Spacer[10],
Pane@Text[Style["b) ((p + q').(r.(p + q')))' = p'.q", 16]],
Pane@Text[Style["use De Morgan's Law: ", 16]],
Pane@Text[Style[" ((p + q').(r.(p + q')))' = (p + q')' + (r.(p + q'))' = p'.q + r' + (p + q')' = p'.q + r' + p'.q = r' + p'.q ", 16]],
Spacer[10],
Pane@Text[Style[" c) x.y.x'.y + x'.y' + x.y' = y'", 16]],
Pane@Text[Style["x.x'.y.y + x'.y' + x.y' = 0.y + x'.y' + x.y' = y'.(x + x') = y'.1 = y'", 16]],
Spacer[10],
Pane@Text[Style["d) x.y + x'.y + x'.y' + x.y' = 1", 16]],
Pane@Text[Style["x.y + x'.y + x'.y' + x.y' = (x + x').y + (x + x').y' = 1.y + 1.y' = y + y' = 1", 16]],
Spacer[100],
Pane@Text[
Style["2. Representation of Expressions",Bold,Lighter[Darker[Orange]],23]],
Spacer[100],
Pane@Text[Style["What is the best way to write a boolean Expression. We consider first by considering the different functions of Boolean functions.", 16]],
Spacer[100],
Pane@Text[Style["\!\(TraditionalForm\`\*SubscriptBox[\(∀\), \(n ⩾ 1\)]\\ \\ \\ let\\ \\ \\ \\ \\ \*SuperscriptBox[\(F\), \(n\)]\\  = \\ {\\ f\\  | \\ \(f\\  : \\ \*SuperscriptBox[\(ℬ\), \(\(n\)\(\\ \)\)]⟶\\ ℬ\)\\ }\\ \\ , \\ where\\ \\ \\ ℬ\\  = \\ {0, 1}\)", 16]],
Spacer[100],
Pane@Text[Style["Example 2.1.",Bold, 16]],
Pane@Text[Style["List all the elements of (F^1) and (F^2), \!\(TraditionalForm\`\*SuperscriptBox[\(F\), \(1\)] : \\ \\ x\\  ∈ \\ ℬ\\ '\\  = \\ \(ℬ\\  = \\ \(\({0, 1}\)\(.\)\)\)\) ", 16]],
Pane@t6,
Pane@Text[Style["for (F^2): ", 16]],
Pane@t7,
Pane@Text[Style["\!\(\*SubscriptBox[\(f\), \(\(1\)\(\\ \)\)]\)+ (Subscript[f, 2]) = (Subscript[f, 3]),", 16]],
Pane@Text[Style["\!\(\*SubscriptBox[\(f\), \(\(1\)\(\\ \)\)]\)+ (Subscript[f, 14]) = (Subscript[f, 15]),", 16]],
Pane@Text[Style["\!\(\*SubscriptBox[\(f\), \(\(3\)\(\\ \)\)]\). (Subscript[f, 4]) = (Subscript[f, 0]),", 16]],
Pane@Text[Style["\!\(TraditionalForm\`\*SubscriptBox[\(f\), \(3\)]'\\  = \\ \*SubscriptBox[\(f\), \(12\)]\) ", 16]],

Pane@Text[Style["The # of functions in (F^n) is (2^(2^n)).", 16]],
Spacer[100],
Pane@Text[
Style["2.1. Minterms",Bold,Lighter[Darker[Red]],20]],
Spacer[100],
Pane@Text[Style["Since a large number of possible functions for few Boolean Variables, we look for a method of representing them in a canonical form, called set of minters. ", 16]],

Spacer[100],
Pane@Text[Style["Definition 2.1.1.",Bold, 16]],
Pane@Text[Style["A minterm is a Boolean function that has exactly one 1 in its truth table. ", 16]],
Spacer[100],
Pane@Text[Style["Example 2.1.1. ",Bold, 16]],
Pane@g3,
Pane@Text[Style["This is the product representation of the minterm, only conjunction and negation.", 16]],
Spacer[100],
Pane@Text[
Style["2.2 Normal form",Bold,Lighter[Darker[Red]],20]],
Pane@Text[Style["Any minterm can be written or expressed only in terms of \"and\" and \"negation\". The next step is to show that any Boolean function can be written as a disjunction of minterms, \"sum of Products\".", 16]],
Spacer[100],
Pane@Text[Style["Theorem 2.2.1. ",Bold, 16]],
Pane@Text[Style["Every Boolean function can be expressed as a disjunction of minterms.", 16]],
Spacer[100],
Pane@Text[Style["Example 2.2.1.",Bold, 16]],
Pane@g4,
Pane@Text[
Style["2.3. Complete set of operators",Bold,Lighter[Darker[Red]],20]],
Pane@Text[Style["Any Boolean Algebra can be represented in terms of \"+\", \".\" , \" ' \". All sets of operators that are sufficient to represent all Boolean expressions is called Complete Set of Operators. ", 16]],
Spacer[100],
Pane@Text[Style["{+, . , ' } is complete set of operators", 16]],
Pane@Text[Style["{. , ' } is also complete set of operators. ", 16]],
Spacer[100],
Pane@Text[Style["NAND defined as not and is also a Complete Set of operation.", 16]],
Spacer[100],
Pane@Text[
Style["3. Minimization of Boolean Expressions",Bold,Lighter[Darker[Orange]],23]],
Pane@Text[Style["Now, not only we are interested in finding a form of a set of product, but we want a simpler expression that is equivalent to the original one. This can be done with the use of Karnaugh map.", 16]],
Spacer[100],
Pane@Text[Style["Karnaugh map with 3 variables", 16]],
Pane@t8,
Pane@Text[Style["Karnaugh map with 4 variables", 16]],
Pane@t9,
Spacer[100],
Pane@Text[Style["Example 3.1.",Bold, 16]],
Pane@Text[Style["f(x,y,z) = x'y'z' + x'yz + xy'z' + xyz' + xyz", 16]],
Pane@r1,
Spacer[100],
Pane@Text[Style["Example 3.2.",Bold, 16]],
Pane@r2,
Spacer[100],
Pane@Text[Style["Example 3.3.",Bold, 16]],
Pane@r3,
Spacer[100],
Pane@Text[
Style["4. Switching Theory",Bold,Lighter[Darker[Orange]],23]],

Spacer[100],
Pane@Text[Style["Application to binary devices. Combinational devices or network.", 16]],
Pane@Text[Style["Basic combinational circuit - Gates;", 16]],

Pane@g5,
Pane@Text[Style["Composed circuits - logical network", 16]],
(*Pane@module1[],*)
Pane@DynamicModule[{},
Dynamic[Column[{Button["Again",
expr=RandomChoice@{"P AND NOT Q","P AND NOT Q AND R","P AND NOT Q AND R OR P ","(P AND Q) OR (NOT (P AND T))","P OR (Q AND T)","((Q AND T) AND (Q OR T))","(P AND Q) OR T"};
g=WolframAlpha[expr,"PodCells"];],
Row[{Column[{g[[2]],
g[[6]]},Alignment->Center],
"        ",
Column[{Row[{"Vienn diagram for: ",g[[2]]}],
g[[7]]
},Alignment->Center]
}]
}],SynchronousUpdating->False]
,

Initialization:>(expr=RandomChoice@{"P AND NOT Q","P AND NOT Q AND R","P AND NOT Q AND R OR P ","(P AND Q) OR T"};g=WolframAlpha[expr,"PodCells"];)
]
(**),
Pane@Text[Style["Example 4.1.",Bold, 16]],
Pane@Text[Style["A hall light is controlled by two light swiches one at each eand. Find (a) a truth function (b) a Boolean Expression (c) a logic network that allows the light to be swiched on or off by either side.", 16]],
Pane@r4,
Spacer[100],
Pane@Text[Style["Example 4.2.",Bold, 16]],
Pane@Text[Style["A mail order cosmetic firm, an automatic control device is used to supervise the package of orders. The firm sells lipstick, perfume, makeup and nail polish. As a bonus item, shampoo is included with any order that includes perfume or any order that includes lipstick, makeup, and nail polish. How can we design the logic network that control wheter shampoo is packaged with an order ?", 16]],
Spacer[100],
Pane@Text[Style["Input to the network : 4 items ", 16]],
Pane@Text[Style["\!\(TraditionalForm\`X : \\ lipstick\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`Y : \\ perfume\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`Z : \\ makeup\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`P : \\ nail\\ polish\) ", 16]],
Spacer[100],
Pane@Text[Style["\!\(TraditionalForm\`X\\  = \\ 1\\ \\ \\ ⟹\\ \\ \\ \\ \\ lipstick\\ is\\ \(\(ordered\)\(.\)\)\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`Y\\  = \\ 1\\ \\ \\ ⟹\\ \\ \\ \\ \\ perfume\\ is\\ \(\(ordered\)\(.\)\)\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`Z\\  = \\ 1\\ \\ \\ ⟹\\ \\ \\ \\ \\ makeup\\ \\ is\\ \(\(ordered\)\(.\)\)\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`P = \\ 1\\ \\ \\ ⟹\\ \\ \\ \\ \\ nail\\ polish\\ is\\ \(\(ordered\)\(.\)\)\)", 16]],
Pane@Text[Style["\!\(TraditionalForm\`f(\(TraditionalForm\`X\), \(TraditionalForm\`Y\), \(TraditionalForm\`Z\), \(TraditionalForm\`P\))\\  = \\ 1\\ \\ \\ \\ ⟹\\ \\ \\ \\ shampoo\\ to\\ be\\ \(\(included\)\(.\)\)\)", 16]],
Pane@r5

}],
"Method"->"Standalone"];