(* 11_06 *)

(* 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="行列の列ベクトルの1次結合と積";
SELNUM=4;NUM=200;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤1000,ct++,
sz=RandomInteger[2]+3;(* 3,4,5 *)
vt=Table[Rnz[6],sz];
rc=RandomChoice[{"R","C"}];
QtList=Append[QtList,{1,sz,vt,rc}]
(* QtList=DeleteDuplicates[QtList]; *)
];QtList=RandomSample[QtList,NUM];Length[QtList]

(* This question is canceled *)

QtextF[mm_]:=Module[{Cn,sz,vt,rc,rs,lc},{Cn,sz,vt,rc}=QtList[[mm]];
rs=If[rc=="R","行","列"];
lc=vt.ToExpression[Table["a"<>TOT[j],{j,1,sz}]];
Return["\\("<>TOT[sz]<>rs<>"の行列\\(A\\)の第\\(j\\)"<>rs<>"ベクトルを\\(a_j\\)とする."
<>"\\(A\\)がどのような場合でも,\\("<>ai2tex[lc]<>"\\)と一致するものを選べ"]];

QtextF[49]

CListF[mm_]:=Module[{Cn,sz,vt,rc,Av,fs,ret={}},
{Cn,sz,vt,rc}=QtList[[mm]];fs="正解です.";
If[rc=="R",Av=TOT[{vt}]<>"A",Av="A"<>TOT[{vt}]];
ret=Append[ret,{"\\("<>Av<>"\\)",fs}];
Return[RandomSample[ret,Cn]]];

ICListF[mm_]:=Module[{Cn,sz,vt,vt1,vt2,rc,Av,fs,ret={}},
{Cn,sz,vt,rc}=QtList[[mm]];fs="行列の積の定義をよく考察しよう.";
vt1=RandomSample[vt,Length[vt]];
While[vt1==vt,vt1=RandomSample[vt,Length[vt]]];
If[rc=="R",Av=TOT[{vt1}]<>"A",Av="A"<>TOT[{vt}]];
ret=Append[ret,{"\\("<>Av<>"\\)",fs}];


 Return[RandomSample[ret,SELNUM-Cn]]];

GenerateMCxml[DFname[],"LA/11-06."<>Title<>"(MC2)",Title,NUM,"true",QtextF,CListF,ICListF]

ICListF[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}]]