(* 11_07 *)

(* 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);
PtString[M_]:=StringReplace[ToString[M],{"{"->"(","}"->")"}];
ai2tex[s_]:=StringReplace[TOT[s],Table["\\text{a"<>TOT[i]<>"}"->"{\\mathbf a}_"<>TOT[i],{i,1,5}]];
Title="行列の積の定義と型";
SELNUM=6;NUM=200;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤1000,ct++,
QtList=Append[QtList,RandomChoice[{1,2,2,2,3,3,3,3,4,4,4,5,5}]]];
QtList=RandomSample[QtList,NUM];Length[QtList]

(* This question is canceled *)

QtextF="行列の積が定義される場合をすべて選べ";

CListF[mm_]:=Module[{Cn,ct,r1,c1,r2,c2,MA,MB,PatL={},fs,ret={}},Cn=QtList[[mm]];
fs="正解です.";
For[ct=1,Length[PatL]≤Cn,ct++,
r1=RandomChoice[{2,2,2,3,3,3,3,4,4,4,5}];
c1=RandomChoice[{2,2,3,3,3,4,4,5,5,5,6}];
r2=c1;
c2=RandomChoice[{2,2,2,2,3,3,3,4,4,5}];
PatL=Append[PatL,{r1,c1,r2,c2}];
PatL=DeleteDuplicates[PatL]];
For[ct=1,ct≤Cn,ct++,
{r1,c1,r2,c2}=PatL[[ct]];
MA=Table[Table[Rnz[2],c1],r1];
MB=Table[Table[Rnz[2],c2],r2];
ret=Append[ret,{"\\("<>TOT[MA]<>TOT[MB]<>"\\)",fs}]];
Return[ret]];

ICListF[mm_]:=Module[{Cn,ct,r1,c1,r2,c2,MA,MB,PatL={},fs,ret={}},Cn=QtList[[mm]];
fs="積が定義されるためには左側の行列と右側の行列の何と何が一致していないといけないのでしょうか?";
For[ct=1,Length[PatL]≤3,ct++,
r1=RandomChoice[{2,2,2,3,3,3,3,4,4,4,5}];
c1=RandomChoice[{2,2,3,3,3,4,4,5,5}];
While[c1==r1,c1=RandomChoice[{2,2,3,3,3,4,4,5,5,5,6}]];r2=r1;
c2=RandomChoice[{2,2,2,2,3,3,3,4,4,5}];
PatL=Append[PatL,{r1,c1,r2,c2}];
PatL=DeleteDuplicates[PatL]];
For[ct=1,Length[PatL]≤6,ct++,
r1=RandomChoice[{2,3,3,4,4,4,4,5,5,5,5}];
c1=RandomChoice[{2,2,2,2,2,3,3,4,5}];
r2=RandomChoice[{2,2,2,2,3,3,3,4,4,5}];
While[r2==c1,r2=RandomChoice[{2,2,2,2,3,3,3,4,4,5}]];c2=c1;
PatL=Append[PatL,{r1,c1,r2,c2}];
PatL=DeleteDuplicates[PatL]];
For[ct=1,ct≤Length[PatL],ct++,
{r1,c1,r2,c2}=PatL[[ct]];
MA=Table[Table[Rnz[2],c1],r1];
MB=Table[Table[Rnz[2],c2],r2];
ret=Append[ret,{"\\("<>TOT[MA]<>TOT[MB]<>"\\)",fs}]];
Return[RandomSample[ret,SELNUM-Cn]]];

GenerateMCxml[DFname[],"LA/11-07."<>Title<>"(MC1)",Title,NUM,"false",QtextF,CListF,ICListF]

CListF[45]

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

Nr=3;Nc=4;

Table[Table[Rnz[3],Nc+Rpos[1]],Nr]

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