(* 11_10 *)

(* Require XMLgen_MC.nb ver >=0.04 *)
SetDirectory[NotebookDirectory[]];
<<XMLgenMC.mx;
TTS[mt_]:=ToString[TeXForm[StandardForm[mt]]];
TOT[mt_]:=ToString[OneLineTeXForm[mt]];
TOTT[mt_]:=ToString[OneLineTeXForm[Transpose[mt]]];
TOC[mt_,c_]:=TOTT[{Transpose[mt][[c]]}];
TTD[r_]:=StringReplace[TT[r],"\\frac"->"\\dfrac"];
Rnz[m_]:=(RandomInteger[m]+1)*(2*RandomInteger[1]-1); (* \\pm 1,\pm2,...,\pm(m+1) *)
Rpos[m_]:=RandomInteger[m]+1; (* 1,2,...,m+1 *)
Rbtw[m_]:=RandomInteger[2m]-m;
TTC[A_,n_]:=TOTT[{(Transpose[A])[[n]]}];
Col[A_,n_]:=Transpose[{A[[Range[Length[A]],n]]}];
ColCat[CL_]:=Join@@@(Transpose@CL);
RowCat[CL_]:=Join@@(CL);
PtString[M_]:=StringReplace[ToString[M],{"{"->"(","}"->")"}];
ai2tex[s_]:=StringReplace[TOT[s],Table["\\text{a"<>TOT[i]<>"}"->"{\\mathbf a}_"<>TOT[i],{i,1,5}]];
Category="LA/11-10.";
Title="転置行列の定義と性質";
SELNUM=6;NUM=200;

(* select pairs of matrices *)
QtList={}; For[ct=1,ct≤300,ct++,
Cn=RandomChoice[{2,2,3,3,3,3,3,4,4}];
{r1,r2,r3}=RandomSample[{2,3,4,5,6,7,8},3];
TA=RandomChoice[{{r1,r2},{r2,r1}}];
TB=RandomChoice[{{r2,r3},{r3,r2}}];
TC=RandomChoice[{{r1,r3},{r3,r1}}];
TQ=RandomChoice[{{r1,r3},{r3,r1}}];
QtList=Append[QtList,{Cn,{TA,TB,TC,TQ}}]];
(* QtList=DeleteDuplicates[QtList]; *)
QtList=RandomSample[QtList,NUM];Length[QtList]

TpStr[L_]:="\\("<>TOT[L[[1]]]<>"\\times"<>TOT[L[[2]]]<>"\\)";
TpTpse[L_]:=If[L=={},{},{L[[2]],L[[1]]}];
PType[A_,B_]:=If[A=={}||B=={},Return[{}],
If[A[[2]]===B[[1]],Return[{A[[1]],B[[2]]}],Return[{}]]];
PTypeL[L_]:=Module[{ct,len,tmp},len=Length[L];
Which[len==0,Return[{}],len==1,Return[L[[1]]],
len==2,Return[PType[L[[1]],L[[2]]]],
True,tmp=L[[1]];For[ct=2,ct≤len,ct++,tmp=PType[tmp,L[[ct]]]];Return[tmp]]];

PTypeL[{{2,3},{3,4}}]

Rest[{1,2,3}]

(* This question is canceled *)

PType[PType[TA,TB],TC]

Clear[QtextF];QtextF[mm_]:=Module[{Cn,TA,TB,TC,TQ},
{Cn,{TA,TB,TC,TQ}}=QtList[[mm]];Return["行列\\(A\\)は"<>TpStr[TA]<>", \\(B\\)は"<>TpStr[TB]
<>", \\(C\\)は"<>TpStr[TC]<>"である. 次の式のうち積が定義されて, かつ"
<>TpStr[TQ]<>"となるものをすべて選べ."]];

For[ct=1,ct≤200,ct++,QtextF[ct]]

CListF[mm_]:=Module[{Cn,TA,TB,TC,TQ,TTA,TTB,TTC,TTQ,TL,SL,Pmt,len,pm,CL={},ct,fs,ret={}},
{Cn,{TA,TB,TC,TQ}}=QtList[[mm]];fs="正解です.";
TTA=TpTpse[TA];TTB=TpTpse[TB];TTC=TpTpse[TC];TTQ=TpTpse[TQ];
TL={TA,TB,TC,TTA,TTB,TTC};
SL={"A\\,","B\\,","C\\,","{}^t\\!A\\,","{}^t\\!B\\,","{}^t\\!C\\,"};
(* At(B) and t(At(B)) type *)
For[len=2,len≤3,len++,
Pmt=Permutations[{1,2,3,4,5,6},{len}]/. Append[#->Nothing &/@ Permutations[{1,2,3},{2}],{1,2,3}->Nothing];
For[ct=1,ct≤Length[Pmt],ct++,pm=Pmt[[ct]];
If[PTypeL[TL[[pm]]]==TQ,CL=Append[CL,StringJoin[SL[[pm]]]]];
If[PTypeL[TL[[pm]]]==TTQ,
CL=Append[CL,"{}^t\\!\\left("<>StringJoin[SL[[pm]]]<>"\\right)"]]]];
For[ct=1,ct≤Length[CL],ct++,
ret=Append[ret,{"\\("<>CL[[ct]]<>"\\)",fs}]];
Return[RandomSample[ret,Cn]]];

QtextF[10]
CListF[10]

ICListF[mm_]:=Module[{Cn,TA,TB,TC,TQ,TTA,TTB,TTC,TTQ,TL,SL,Pmt,len,pm,tp,CL={},ct,fs1,fs2,ret={}},{Cn,{TA,TB,TC,TQ}}=QtList[[mm]];
fs1="積が定義されません.";
fs2="積は定義されますが, 型が違うようです.";
TTA=TpTpse[TA];TTB=TpTpse[TB];TTC=TpTpse[TC];TTQ=TpTpse[TQ];
TL={TA,TB,TC,TTA,TTB,TTC};
SL={"A\\,","B\\,","C\\,","{}^t\\!A\\,","{}^t\\!B\\,","{}^t\\!C\\,"};
(* At(B) and t(At(B)) type *)
For[len=2,len≤3,len++,
Pmt=Permutations[{1,2,3,4,5,6},{len}] /. Append[#->Nothing &/@ Permutations[{1,2,3},{2}],{1,2,3}->Nothing];
For[ct=1,ct≤Length[Pmt],ct++,pm=Pmt[[ct]];
tp=PTypeL[TL[[pm]]];
Which[tp=={},
ret=Append[ret,{"\\("<>StringJoin[SL[[pm]]]<>"\\)",fs1}],
tp≠TQ,
ret=Append[ret,{"\\("<>StringJoin[SL[[pm]]]<>"\\)",fs2}],
tp≠TTQ,
ret=Append[ret,{"\\({}^t\\!\\left("<>StringJoin[SL[[pm]]]<>"\\right)\\)",fs2}]]]];
Return[RandomSample[ret,SELNUM-Cn]]];

GenerateMCxml[DFname[],Category<>Title<>"(MC2)",Title,NUM,"false",QtextF,CListF,ICListF]

ICListF[4]

{1,2,3} /. 5->Nothing

Permutations[{1,2,3,4},{2}] /. Permutations[{1,2,3},{2}]Nothing

Nothing @@Permutations[{1,2,3},{2}]

? Apply

#->Nothing &/@ Permutations[{1,2,3},{2}]

sz=3;ToExpression[Table["a"<>TOT[j],{j,1,sz}]]

ColCat[{{{1,2},{2,3}},{{5},{7}}}]

RowCat[{{{1,2,3},{3,3,5}},{{4,4,4}}}]

Permutations[{1,2,3},{2}]

{1,2}@@{1,2,3,4,5}

? Apply

{a,b,c,d,e}[[{3,5}]]

?

StringJoin[{"a","c"}]

? Nothing