libLIST=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/libLIST.m"]<>"\n";
libSYMLOGIC=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/METCS248.m"]<>"\n";
libIO=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/libIO.m"]<>"\n";
libERR=ReadString["/Users/darashayda1xfer/Desktop/MODULES/Ryerson/libERR.m"]<>"\n";

libLIST=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/2016/libLIST.m"]<>"\n";
libSYMLOGIC=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/2016/METCS248.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/2016/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/2016/libERR.m"]<>"\n";

data1=ToString[{{"Connective","Symbol", "Formal Name"},
{"not","¬","negation"},
{"and","∧","conjunction"},
{"or","∨","disconjunction"},
{"if ... then","→","conditional"},
{"...if and only if...","↔","bicconditional"}
},InputForm]<>"\n";
variation1=data1<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data1]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

(* make each one of these variations and solutions as a fixed level of difficulty into a list of lists to build the LEVEL OF DIFFICULTY. For now all level of difficulty should share the same GUI *)
data2="\n"<>"textfghjkl:="<>ToString[{

(* top question*)
{""}, 

(*a*)
{""},

(*b*)
{""},

(*c*)
{""},

(*d*)
{""}

},InputForm]<>";\n ";


(* ANNA add a lot more here *)
data3="listfghjkl:="<>ToString[{
{{¬p,¬q,p∨q,p∧q,p\[Implies]q,p⧦q,p⊼q,p⊽q,p⊻q,p\[Xnor]q},
{ ¬p,¬q,p∨q,p∧q,¬p∨q,p∧(¬q)},
{¬p,¬q,p\[Implies](¬q),(¬p)⧦q},
{p⊽q,p⊻q,p\[Xnor]q},
{p,q,p∧q,(p∧q)\[Implies]q}
},

{{¬r,¬p,¬q,p∨r,r\[Implies]q ,p⊼r},{p\[Implies]q,q\[Implies]r,p\[Implies]q\[Implies]r,p∧q,p∧q\[Implies]r,(p\[Implies]q\[Implies]r)\[Implies](p∧q\[Implies]r)},
{p,q,r,!r\[Implies]p,p\[Implies]!q,q\[Implies]r,(!r\[Implies]p)&&(p\[Implies]!q),(!r\[Implies]p)&&(p\[Implies]!q)\[Implies](q\[Implies]r)},
{p,q,r,q\[Implies]r,p\[Implies](q\[Implies]r)}}
}]<>";\n ";

data4=ToString[{data2, data3}, InputForm];

(* add another data here for the variation of the boolean expressions in header *)
variation2=ToExpression[data4][[1]]<>ToExpression[data4][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol, parta, partb, partc, partd,question,b2,variables,sols,table,index,expr,header,nn},


nn=RandomInteger[{1,2}]; (* n could be used as variable name for logic *)
expr=qRandList[listfghjkl[[nn]]];



Clear[p,q,r]; (*FIXME:p and q need to be global and reserved for this boolean table*)
variables=If[ nn==1,nLetters[{"a","o"},2],nLetters[{"a","o"},3]] ; 
header=(variables~Join~expr)/.If[nn==1, {p->variables[[1]],q->variables[[2]]},{p->variables[[1]],q->variables[[2]],r->variables[[3]]}] ; 

index=noRepeats2[cartProd[Range[1,2^Length[variables]],Range[Length[variables]+1,Length[header]-Length[variables]]],4];


table=BooleanTable[header,variables]/.{True->"T", False->"F"};
sols=table[[#[[1]],#[[2]]]]&/@index;


vars={ToString[header],ToString[variables],ToString[index]};
parta={"",vars,ToString[sols[[1]]]} ;


(* part b*)


vars={ToString[header],ToString[variables],ToString[index]};


partb={"",vars,sols[[2]]} ;


(* part c*)

vars={ToString[header],ToString[variables],ToString[index]};


partc={"",vars,sols[[3]]} ;


(* part d*)


vars={ToString[header],ToString[variables],ToString[index]};


partd={"",vars,sols[[4]]} ;

{{question,parta[[1]], partb[[1]],partc[[1]],partd[[1]]},{parta[[2]], partb[[2]],partc[[2]],partd[[2]]}, {parta[[3]], partb[[3]],partc[[3]],partd[[3]]}}



(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution2=ToExpression[data4][[1]]<>ToExpression[data4][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd},



varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];
varsd=vars[[4]];



body={
{"",
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint2=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={
{"",
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

(* try with context for A vars *)
qpanelMultiLOGICTABLE=ToString[Hold[DynamicModule[{pn,proc,level0,max,mult,diag0,answer,myEnabled,A1,answerStudent,A2,a1,a2,level1,stateH=False,state=False,xxx,yyy,text,sol,prev,again, variation,hint, solution, procs,first=True,options,io,answers,locs,vars,i,ii,A22,A12,a22,myEnabled2,A21,A11,a21,myEnabled1},


Deploy@Panel[Column[{

If[diag00==0 ||diag00==2,Panel[Row[{OpenerView[{Button["Again",
(*AppendTo[level1[[3]],prev];*)

first=ConstantArray[True,mult0];
level1=again;
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];Table[A2[[j]]=ToString[bigNumber];A1[[j]]=Null;myEnabled[[j]]=True,{j,1,mult0}];], ""}],
OpenerView[{Button["Hint",Which[stateH==True,stateH=False,stateH==False, stateH=True],Method->"Queued"],Dynamic[If[stateH==True,hint]]},Dynamic[stateH]],
OpenerView[{Button["Solution",Which[state==True,state=False,state==False, state=True],Method->"Queued"],Dynamic[If[state==True,ReleaseHold[ToExpression[StringReplace[solution,{"ertyuiop"->ToString[vars,InputForm]}]]]]]},Dynamic[state]]}]],""],



answers=Table[With[{i=i},

(* what the student sees all together for the question and answer and verification *)
Column[{

Dynamic[A2[[i]]=If[TrueQ[A1[[i]]==Null], ToString[bigNumber],A1[[i]]];
If[Length[StringSplit[A2[[i]]]]==1, a2=StringSplit[A2[[i]]][[1]],a2=StringSplit[A2[[i]]]];If[ToExpression[a2]===bigNumber,"", myEnabled[[i]]=False;""<>Which[ToExpression[sol[[i]]]===ToExpression[a2]&&ToExpression[a2]=!=bigNumber, prev=True;

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[i]]==True,"Correct",
diag00==1,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"Correct",True, ""],

ToExpression[sol[[i]]]=!=ToExpression[a2]&&ToExpression[a2]=!=bigNumber,prev=False;
Which[diag00==0&&first[[i]]==True,"Incorrect",
diag00==1,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"",
diag00==2,If[first[[i]]==True,io[pn,i,True,a2, diag00]];first[[i]]=False;"Incorrect",True, ""],True,""]]],

If[i==1,Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->5(*,BoxID->"AA2"*)],Deploy@InputField[Dynamic[A1[[i]]],String,Enabled->Dynamic[myEnabled[[i]]],FieldSize->5]]}]


],{i, 1,mult0}];
,

(*answers={
Column[{

Dynamic[my`A21=If[TrueQ[my`A11==Null], ToString[bigNumber],my`A11];
If[Length[StringSplit[my`A21]]==1, my`a21=StringSplit[my`A21][[1]],my`a21=StringSplit[my`A21]];If[ToExpression[ my`a21]===bigNumber,"",my`myEnabled1=False;""<>Which[ToExpression[sol[[1]]]===ToExpression[ my`a21]&&ToExpression[my`a21]=!=bigNumber, 

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[1]]==True,"Correct",
diag00==1,If[first[[1]]==True,io[pn,2,True, my`a21, diag00]];first[[1]]=False;"",
diag00==2,If[first[[1]]==True,io[pn,2,True, my`a21, diag00]];first[[1]]=False;"Correct",True, ""],

ToExpression[sol[[1]]]=!=ToExpression[my`a21]&&ToExpression[ my`a21]=!=bigNumber,
Which[diag00==0&&first[[1]]==True,"Incorrect",
diag00==1,If[first[[1]]==True,io[pn,2,True, my`a21, diag00]];first[[1]]=False;"",
diag00==2,If[first[[1]]==True,io[pn,2,True,my`a21, diag00]];first[[1]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[my`A11],String,Enabled->Dynamic[my`myEnabled1],FieldSize->5]}],



Column[{

Dynamic[my`A22=If[TrueQ[my`A12==Null], ToString[bigNumber],my`A12];
If[Length[StringSplit[my`A22]]==1, my`a22=StringSplit[my`A22][[1]], my`a22=StringSplit[my`A22]];If[ToExpression[ my`a22]===bigNumber,"", my`myEnabled2=False;""<>Which[ToExpression[sol[[2]]]===ToExpression[my`a22]&&ToExpression[my`a22]=!=bigNumber, 

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[2]]==True,"Correct",
diag00==1,If[first[[2]]==True,io[pn,2,True, my`a22, diag00]];first[[2]]=False;"",
diag00==2,If[first[[2]]==True,io[pn,2,True, my`a22, diag00]];first[[2]]=False;"Correct",True, ""],

ToExpression[sol[[2]]]=!=ToExpression[ my`a22]&&ToExpression[ my`a22]=!=bigNumber,
Which[diag00==0&&first[[2]]==True,"Incorrect",
diag00==1,If[first[[2]]==True,io[pn,2,True, my`a22, diag00]];first[[2]]=False;"",
diag00==2,If[first[[2]]==True,io[pn,2,True, my`a22, diag00]];first[[2]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[my`A12],String,Enabled->Dynamic[my`myEnabled2],FieldSize->5]}]};*)


(*for different tables this is the only line to change *)Dynamic@makeTruthTable2[ToExpression[vars[[1]][[1]]],ToExpression[vars[[1]][[2]]],answers,ToExpression[vars[[1]][[3]]]]

(*{
Column[{

Dynamic[A21=If[TrueQ[A11==Null], ToString[bigNumber],A11];
If[Length[StringSplit[A21]]==1, a21=StringSplit[A21][[1]],a21=StringSplit[A21]];If[ToExpression[ a21]===bigNumber,"",myEnabled1=False;""<>Which[ToExpression[sol[[1]]]===ToExpression[ a21]&&ToExpression[a21]=!=bigNumber, 

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[1]]==True,"Correct",
diag00==1,If[first[[1]]==True,io[pn,2,True, a21, diag00]];first[[1]]=False;"",
diag00==2,If[first[[1]]==True,io[pn,2,True, a21, diag00]];first[[1]]=False;"Correct",True, ""],

ToExpression[sol[[1]]]=!=ToExpression[a21]&&ToExpression[ a21]=!=bigNumber,
Which[diag00==0&&first[[1]]==True,"Incorrect",
diag00==1,If[first[[1]]==True,io[pn,2,True, a21, diag00]];first[[1]]=False;"",
diag00==2,If[first[[1]]==True,io[pn,2,True,a21, diag00]];first[[1]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A11],String,Enabled->Dynamic[myEnabled1],FieldSize->5]}],



Column[{

Dynamic[A22=If[TrueQ[A12==Null], ToString[bigNumber],A12];
If[Length[StringSplit[A22]]==1, a22=StringSplit[A22][[1]],a22=StringSplit[A22]];If[ToExpression[ a22]===bigNumber,"", myEnabled2=False;""<>Which[ToExpression[sol[[2]]]===ToExpression[a22]&&ToExpression[a22]=!=bigNumber, 

(* 0 practice Module no record, 1 test Module record, 2 practice module record*)
Which[diag00==0&&first[[2]]==True,"Correct",
diag00==1,If[first[[2]]==True,io[pn,2,True,a22, diag00]];first[[2]]=False;"",
diag00==2,If[first[[2]]==True,io[pn,2,True, a22, diag00]];first[[2]]=False;"Correct",True, ""],

ToExpression[sol[[2]]]=!=ToExpression[ a22]&&ToExpression[ a22]=!=bigNumber,
Which[diag00==0&&first[[2]]==True,"Incorrect",
diag00==1,If[first[[2]]==True,io[pn,2,True, a22, diag00]];first[[2]]=False;"",
diag00==2,If[first[[2]]==True,io[pn,2,True, a22, diag00]];first[[2]]=False;"Incorrect",True, ""],True,""]]],

Deploy@InputField[Dynamic[A12],String,Enabled->Dynamic[myEnabled2],FieldSize->5]}]}


,*)






}]],

Initialization:>(stateH=False;state=False;

libs; (* add the needed functions and constants *)


(* these are the parameters that used to be passed as argument list *)
(* FIXME: mult0 has to be written over by replacement and cannot be initialized here *)
pn=pn0;proc=proc0;level0=level00;max=max0;mult=mult0;diag0=diag00;
io=ToExpression[IO00];

(* the rest here sets up the math for the question *)
answer=ConstantArray[" ",mult];
A1=ConstantArray["",mult];
a2=ConstantArray["",mult];
A2=ConstantArray[ToString[bigNumber],mult];
A22=ToString[bigNumber];
A21=ToString[bigNumber];
a22="";
a21="";
A12=Null;
A11=Null;
answerStudent=ConstantArray[" ",mult];
myEnabled=ConstantArray[True,mult];
myEnabled2=True;
myEnabled1=True;
first=ConstantArray[True,mult];

Table[A2[[i]]=ToString[bigNumber];A1[[i]]=Null;myEnabled[[i]]=True,{i,1,mult}];

{again, variation, hint, solution}=proc;
again=ToExpression[again];
{text,vars,sol}=ReleaseHold[ToExpression[StringReplace[variation,{"fghjkl"->ToString[pn]}]]];
xxxx=vars;
hint=ReleaseHold[ToExpression[hint]];

level1=again;


SetOptions[EvaluationNotebook[],PrivateNotebookOptions->{"PluginToolbarEnabled"->False},DockedCells->Cell[BoxData[ToBoxes[Row[{Column[{Image[,ImageSize->125],"Prof. Madani\nJan 2016"},ItemSize->{20,Automatic}],PopupMenu[Dynamic[CurrentValue[EvaluationNotebook[],"Magnification"]],Range[0.5,3,0.5]]},Spacer[5]]]],"DockedCell"]];

)

]],InputForm]<>"\n";

proc1=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation2,hint2,solution2},InputForm]<>";\n";

data5=ToString[{{"Symbolic Form","English Equivalent"},
{"p→q",Column[{"If p then q", "p only if q", "q, if p","p is a sufficient condition for q","q is a necessary condition for p","All p are q"}]},
{"p↔q",Column[{"p if and only if q","p is a necessary and sufficient condition for q"}]},
{"(p ∨ q) ∧ ¬(p ∧ q)","Either p or q"}
},InputForm]<>"\n";
variation3=data5<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data5]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n ";

panelsLOGIC={StringReplace[qpanelMultiLOGICTABLE,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libIO<>"\n"<>libERR),"level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"2","IO00"->"qClick"}]};

(*FIXME: even with the fix below, the ToExpression[ nLetters[] ] grabs the global first

foo=10;

DynamicModule[{foo=20},{foo,ToExpression["foo"]}]


output is

{20,10}



*)

againTable=ToString[Hold[DynamicModule[{expr,variables,poiuy},

Panel[Column[{Button["Again",
(*Reuse Variation for logic table*)
{expr,variables}=ReleaseHold[variation20][[2]][[1]][[1;;2]]; (* No ToExpression necessary *)
againTable`g=makeTruthTable[ToExpression[expr],ToExpression[variables]];],

Dynamic[againTable`g],
Dynamic[TreeForm[Last@ToExpression[expr],DirectedEdges-> True,ImageSize->200]/.{Implies->"\[Implies]",Not->"¬",And->"∧",Nand->"⊼",Equivalent->"⧦",Or->"∨",Xor->"⊻",Xnor->"\[Xnor]",Nor->"⊽"}]}]],
Initialization:>(
libs;
{expr,variables}=ReleaseHold[variation20][[2]][[1]][[1;;2]];
againTable`g=makeTruthTable[ToExpression[expr],ToExpression[variables]];)
]],InputForm]; (* solution for global variable occlusion and large local variable inclusion*)

againTable2=ToString[Hold[DynamicModule[{expr,variables,sentence,poiuy},

Panel[Column[{Button["Again",
(*Reuse Variation for logic table*)
{expr,variables,sentence}=ReleaseHold[variation20][[2]][[1]][[1;;3]]; (* No ToExpression necessary *)
againTable2`g=makeTruthTable[ToExpression[expr],ToExpression[variables]];],
Dynamic[ToExpression[sentence]],
Dynamic[againTable2`g],
Dynamic[TreeForm[Last@ToExpression[expr],DirectedEdges-> True,ImageSize->200]/.{Implies->"\[Implies]",Not->"¬",And->"∧",Nand->"⊼",Equivalent->"⧦",Or->"∨",Xor->"⊻",Xnor->"\[Xnor]",Nor->"⊽"}]}]],
Initialization:>(
libs;
{expr,variables,sentence}=ReleaseHold[variation20][[2]][[1]][[1;;3]]; (* No ToExpression necessary *)
againTable2`g=makeTruthTable[ToExpression[expr],ToExpression[variables]];)
]],InputForm];

(* make each one of these variations and solutions as a fixed level of difficulty into a list of lists to build the LEVEL OF DIFFICULTY. For now all level of difficulty should share the same GUI *)
data6="\n"<>"textfghjkl:="<>ToString[{

(* top question*)
{""}, 

(*a*)
{""},

(*b*)
{""},

(*c*)
{""},

(*d*)
{""}

},InputForm]<>";\n ";


(* ANNA add a lot more here *)
data7="listfghjkl:="<>ToString[{

{<|"¬s"->{"fails to submit a project in course ","cannot do a project in course "},"s"->{"must have submitted a project ","must have done a project "},"f"->{"fails the course ","flunks the course "},
"g"->{"graduates"},"¬g"->{"cannot graduate"},"info"->{"1"}|>},

{<|"s"->"@p is an integer ","f"->"@p is odd","g"->"@p is even","info"->{"2"}|>,
<|"s"->"@p is prime ","f"->"@p = 2","g"->"@p is odd","info"->{"2"}|>,
<|"s"->"@p@r=0 ","f"->"@p = 0","g"->"@r = 0","info"->{"2"}|>,
<|"s"->ToString[Abs["@p"],TraditionalForm]<>"=#q","f"->ToString["@p=+#q",TraditionalForm],"g"->ToString["@p=-#q",TraditionalForm],"info"->{"2"}|>
},

{<|"f"->{"I take all exams","I complete all exams","I take every exam"},"g"->{"I get an A", "A is my grade","my grade will be A","I will be A student"},"¬f"->{"I do not take all exams","I miss some exams","I do not attend some exams"},"¬g"->{"I will no get an A", "I get less than A", "my grade will not be A"},"info"->{"3"}|>},

{<|"f"->{"it rains ","it is raining ","it showers "},"g"->{"I get wet ", "I will be drenched","I will be soaked","truely wet I will be "},"¬f"->{"it does not rain ","it is sunny skies ","it is clear skies","there is no cloud in sight "},"¬g"->{"I will not be wet" , "I will be dry ", "no way I will get wet "},"info"->{"4"}|>},

{<|"f"->{"I do not eat a lot ","I eat little ","I deit","I go on deit "},"g"->{"I get slim ","I slim up ", "I lose weight " },"¬f"->{"I do eat a lot","I have no control on my eating","I pig out"},"¬g"->{"I will not lose weight ", "I will not be slim " , "I will not be fit ","I get fat ", "I gain weight ","I will be overweight "},"info"->{"5"}|>}

},InputForm]<>";\n ";

data8="\n"<>"textfghjkl:="<>ToString[{

<|"or"->{"or"},"then"->{", then ",", consequently ",", ",", thus ",", therefore ", ", as a result ", ", as a consequence "},"if"->{"If","Let's say ", "On condition that ","In the event that ","In the case that ","On the assumption that ","Supposing"},"h"->{"Hence, ", "Therefore, ","In other words, "},"¬"->{"it is not true that "},"¬2"->{"nor it is true that "}|>,

{<|"name"->"Joe","pronoun"->{"he","him", "his"}|>,<|"name"->"Jack","pronoun"->{"he","him", "his"}|>,
<|"name"->"Deidre","pronoun"->{"she","her", "hers"}|>,<|"name"->"Lucia","pronoun"->{"she","her", "hers"}|>}

},InputForm]<>";\n ";


data9=ToString[{data7, data8}, InputForm];

(* add another data here for the variation of the boolean expressions in header *)
variation4=ToExpression[data9][[1]]<>ToExpression[data9][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, vars,text,list,sol, parta, partb, partc, partd,question,b2,variables,sols,table,index,expr,header,name,assoc,info,ss,s,p,r,tmp,assoc2,varLogicGeneral,varLogic,course},



varLogic=qRandList[listfghjkl];
(*varLogic=listfghjkl[[3]];*)
varLogicGeneral=textfghjkl[[1]];

vars=Which[


varLogic[[1]]["info"][[1]]=== "1",
{ss,ff,gg}=nLetters[{"a","z"},3];
assoc2:=qRandList/@varLogicGeneral;
assoc:=qRandList/@(varLogic[[1]]);
name=qRandList@textfghjkl[[2]];
course=qRandList[{"METCS248","METCS556","METCS662"}];
{
{ToString/@({f,g,s,¬s\[Implies]f,f\[Implies]¬g,g\[Implies]s,(¬s\[Implies]f)∧(f\[Implies]¬g),((¬s\[Implies]f)∧(f\[Implies]¬g))\[Implies]g\[Implies]s}/.{f->ff,g->gg,s->ss}),
ToString/@({f,g,s}/.{f->ff,g->gg,s->ss}),

ToString[
Row[{
Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],
name["name"]<>" ",
Labeled[Framed[assoc["¬s"],Background->LightGreen], Style["¬"<>ss,Bold, Green]],
course<>" ",
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],
Labeled[Framed[assoc["f"],Background->LightRed], Style[ff,Bold, Red]],
Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],
name["name"]<>" ",
Labeled[Framed[StringReplace[assoc["f"],{"the course"-> course}],Background->LightRed], Style[ff,Bold, Red]],
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],
name["pronoun"][[1]]<>" ",
Labeled[Framed[assoc["¬g"],Background->LightGreen], Style["¬"<>gg,Bold, Green]],assoc2["h"],
Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],
name["name"]<>" ",
Labeled[Framed[assoc["g"],Background->LightBlue], Style[gg,Bold, Blue]],
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],
name["pronoun"][[1]]<>" ",
Labeled[Framed[assoc["s"],Background->LightGreen], Style[ss,Bold, Green]]}]

,InputForm],

((¬s\[Implies]f)∧(f\[Implies]¬g))\[Implies]g\[Implies]s/.{f->ff,g->gg,s->ss}
}
}
,

varLogic[[1]]["info"][[1]]=== "2", 
{ss,ff,gg}=nLetters[{"a","z"},3]; (* caps to avoid confusion with p and q and r *)
{p,r}=nLetters[{"a","z"},2];
assoc2:=qRandList/@varLogicGeneral;
tmp=ToString[RandomReal[]];
assoc=StringReplace[#,{"@p"->p,"@r"->r,"#q"->tmp}]&/@((qRandList@varLogic));

{{ToString/@({f,g,s,f ∨ g,s\[Implies](f∨g)}/.{f->ff,g->gg,s->ss}),
ToString/@({f,g,s}/.{f->ff,g->gg,s->ss}),
ToString[Row[{

Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],

Labeled[Framed[assoc["s"],Background->LightGreen], Style[ss,Bold, Green]],
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],

Labeled[Framed[assoc["f"],Background->LightRed], Style[ff,Bold, Red]],
Labeled[Framed[assoc2["or"],Background->LightGray], Style["∨",Bold, Black]],
Labeled[Framed[assoc["g"],Background->LightBlue], Style[gg,Bold, Blue]]
}],InputForm],


(s\[Implies](f∨g))/.{f->ff,g->gg,s->ss}

}
}

,

varLogic[[1]]["info"][[1]]=== "3", 
{ff,gg}=nLetters[{"a","z"},2]; (* caps to avoid confusion with p and q and r *)
assoc2:=qRandList/@varLogicGeneral;
assoc:=qRandList/@varLogic[[1]];

{{ToString/@({f,g,f \[Implies] g,¬f\[Implies]¬g,(¬f\[Implies]¬g)∧¬(f\[Implies]g)}/.{f->ff,g->gg}),
ToString/@({f,g}/.{f->ff,g->gg}),

ToString[Row[{
Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],
Labeled[Framed[assoc["¬f"],Background->LightGreen], Style["¬"<>ff,Bold, Green]],
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],
Labeled[Framed[assoc["¬g"],Background->LightGreen], Style["¬"<>gg,Bold, Green]],
Labeled[Framed[assoc2["¬"],Background->LightRed], Style["¬",Bold, Red]],
Labeled[Framed[assoc2["if"],Background->LightGray], Style["",Bold, Black]],

Labeled[Framed[assoc["f"],Background->LightRed], Style[ff,Bold, Red]],
Labeled[Framed[assoc2["then"],Background->LightGray], Style["\[Implies]",Bold, Black]],
Labeled[Framed[assoc["g"],Background->LightBlue], Style[gg,Bold, Blue]]
}],InputForm],

((¬f\[Implies]¬g)∧¬(f\[Implies]g))/.{f->ff,g->gg}

}
}

];

sol=vars;
parta={" " ,vars[[1]],sol};



(* part b*)





sol=vars;
partb={" " ,vars[[1]],sol};




(* part c*)




sol=vars;
partc={{" "," "},vars[[1]], {sol}};



(* part d*)





sol=vars;
partd={{" "," "},vars[[1]], {sol}};


{{question,parta[[1]], partb[[1]],partc[[1]],partd[[1]]},{parta[[2]], partb[[2]],partc[[2]],partd[[2]]}, {parta[[3]], partb[[3]],partc[[3]],partd[[3]]}}



(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution4=ToExpression[data9][[1]]<>ToExpression[data9][[2]]<>ToString[Hold[Module[{a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,kk, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd},



varsa=vars[[1]];
varsb=vars[[2]];
varsc=vars[[3]];
varsd=vars[[4]];



body={
{"",
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint4=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={
{"",
"",
""},
{Null ,Null, Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data10=ToString[{{p,¬p},{p}
},InputForm]<>"\n";
variation5=data10<>ToString[Hold[Module[{},

Pane@makeTruthTable[ToExpression[data10][[1]],ToExpression[data10][[2]]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data11=ToString[{{p,q,p∨q,p∧q,p\[Implies]q,p⧦q},{p,q}
},InputForm]<>"\n";
variation6=data11<>ToString[Hold[Module[{},

Pane@makeTruthTable[ToExpression[data11][[1]],ToExpression[data11][[2]]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data12=ToString[{{"p","q" ,"p ∧ ¬q"},
{"T","T","t F f"},
{"T","F","t T t"},
{"F","T","f F f"},
{"F","F","f F t"}
},InputForm]<>"\n";
variation7=data12<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data12]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data13=ToString[{{"p","q" ,"r","(p \[Implies] q) \[Implies] (q ∨ r)"},
{"T","T","T",""},
{"T","T","F",""},
{"T","F","T",""},
{"T","F","F",""},
{"F","T","T",""},
{"F","T","F",""},
{"F","F","T",""},
{"F","F","F",""}
},InputForm]<>"\n";
variation8=data13<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data13]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data14=ToString[{{"p","q" ,"r","(p → q) → (q ∨ r)"},
{"T","T","T","T                "},
{"T","T","F","T                "},
{"T","F","T","F                "},
{"T","F","F","F                "},
{"F","T","T","T                "},
{"F","T","F","T                "},
{"F","F","T","T                "},
{"F","F","F","T                "}
},InputForm]<>"\n";
variation9=data14<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data14]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data15=ToString[{{"p","q" ,"r","(p → q) → (q ∨ r)"},
{"T","T","T","T               T"},
{"T","T","F","T               T"},
{"T","F","T","F               T"},
{"T","F","F","F               F"},
{"F","T","T","T               T"},
{"F","T","F","T               T"},
{"F","F","T","T               T"},
{"F","F","F","T               F"}
},InputForm]<>"\n";
variation10=data15<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data15]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data16=ToString[{{"p","q" ,"r","(p → q) → (q ∨ r)"},
{"T","T","T","T       T        T"},
{"T","T","F","T       T        T"},
{"T","F","T","F       T        T"},
{"T","F","F","F       T        F"},
{"F","T","T","T       T        T"},
{"F","T","F","T       T        T"},
{"F","F","T","T       T        T"},
{"F","F","F","T       F        F"}
},InputForm]<>"\n";
variation11=data16<>ToString[Hold[Module[{},

Pane@makeTextTable[ToExpression[data16]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

data17=ToString[{{p,q,p∨¬p,p∨q,q\[Implies]p,p\[Implies]q,¬(p∧q),p,q,¬(p⧦q),p⧦q,¬q,¬p,p∧q,¬(p\[Implies]q),¬(q\[Implies]p),¬(p∨q),p ∧ ¬p},{p,q}},InputForm]<>"\n";
variation12=data17<>ToString[Hold[Module[{},

Pane@makeTruthTable[ToExpression[data17][[1]],ToExpression[data17][[2]]] (* ToExpression has to be here to make the string back to list/matrix *)
]],InputForm]<>"\n";

ToExpression[libSYMLOGIC];
ToExpression[s0]
ToExpression[s1]
ToExpression[s2]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation1]]
ToExpression[s3]
ToExpression[s4]
ToExpression[s5]
ToExpression[s6]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation3]]
ToExpression[s8]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation5]]
ToExpression[s9]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation6]]
ToExpression[s10]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation7]]
ToExpression[s11]
ToExpression[s12]
ToExpression[s13]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation8]]
ToExpression[s14]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation9]]
ToExpression[s15]
ToExpression[s16]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation10]]
ToExpression[s17]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation11]]
ToExpression[s18]
ReleaseHold[ToExpression[StringReplace[againTable<>"\n ",{"libs"->libLIST,"variation20"->variation2,"poiuy"->StringReplace[ToString[CharacterRange["a","z"],InputForm],{"{"->" ","}"->" ","\""->" "}]}]]]
ToExpression[s19]
ToExpression[s20]
ToExpression[s21]
ToExpression[s22]
ReleaseHold[ToExpression[libLIST<>"\n "<>variation12]]
ToExpression[s23]
ReleaseHold[ToExpression[panelsLOGIC[[1]]]]
ToExpression[s24]
ReleaseHold[ToExpression[StringReplace[againTable2<>"\n ",{"libs"->libLIST,"variation20"->variation4,"poiuy"->StringReplace[ToString[CharacterRange["a","z"],InputForm],{"{"->" ","}"->" ","\""->" "}]}]]]

SetOptions[EvaluationNotebook[],PrivateNotebookOptions->{"PluginToolbarEnabled"->False}];
CDFDeploy[ToFileName[{$UserDocumentsDirectory},"logic_statements_connectives_tables2_2016.cdf"],Column[{ToExpression[libSYMLOGIC];
Pane@ToExpression[s0],
Pane@ToExpression[s1],
Pane@ToExpression[s2],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation1]],
ToExpression[s3],
Pane@ToExpression[s4],
Pane@ToExpression[s5],
Pane@ToExpression[s6],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation3]],
Pane@ToExpression[s8],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation5]],
Pane@ToExpression[s9],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation6]],
Pane@ToExpression[s10],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation7]],
Pane@ToExpression[s11],
Pane@ToExpression[s12],
Pane@ToExpression[s13],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation8]],
Pane@ToExpression[s14],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation9]],
Pane@ToExpression[s15],
Pane@ToExpression[s16],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation10]],
Pane@ToExpression[s17],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation11]],
Pane@ToExpression[s18],
ReleaseHold[ToExpression[StringReplace[againTable<>"\n ",{"libs"->libLIST,"variation20"->variation2,"poiuy"->StringReplace[ToString[CharacterRange["a","z"],InputForm],{"{"->" ","}"->" ","\""->" "}]}]]],
Pane@ToExpression[s19],
Pane@ToExpression[s20],
Pane@ToExpression[s21],
Pane@ToExpression[s22],
ReleaseHold[ToExpression[libLIST<>"\n "<>variation12]],
Pane@ToExpression[s23],
Pane@ReleaseHold[ToExpression[panelsLOGIC[[1]]]],
ToExpression[s24],
ReleaseHold[ToExpression[StringReplace[againTable2<>"\n ",{"libs"->libLIST,"variation20"->variation4,"poiuy"->StringReplace[ToString[CharacterRange["a","z"],InputForm],{"{"->" ","}"->" ","\""->" "}]}]]]


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