(* Require XMLgen_MC.nb ver >=0.20 *)
SetDirectory[NotebookDirectory[]];
<<XMLgenMC.mx;
DebugMode=False;
ThisNo=StringReplace[StringSplit[ NotebookFileName[],"/"][[-1]],{"LA_"->"",".nb"->"","_"->"-"}];
Category="LA/"<>ThisNo<>".";

(* Global Options *)
Numbering="abc";Single="false";Shuffle="true";
(* Numbers of select options and questions *)
SELNUM=6;NUM=200;Title="行列と平面の1次変換";

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}]];
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]]];

(* select pairs of matrices *)
We1={{1},{0}};We2={{0},{1}};
QtList={}; For[ct=1,ct≤NUM*1.2,ct++,
Cn=RandomChoice[{2,3}];
Sv=RandomChoice[{We1,We2,We1+We2,We1-We2,We2-We1}];
Tv=Transpose[{Table[Rnz[4],2]}];
QtList=Append[QtList,{Cn,{Sv,Tv}}]];
(* QtList=DeleteDuplicates[QtList]; *)
QtList=RandomSample[QtList,NUM];Length[QtList]

Clear[QtextF];QtextF[mm_]:=Module[{Cn,Sv,Tv},
{Cn,{Sv,Tv}}=QtList[[mm]];
Return["次の行列のうち, 平面の1次変換を定め, かつ\\("<>TOT[Sv]<>"\\)が\\("<>TOT[Tv]<>"\\)に写されるものをすべて選べ."]];

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

CListF[mm_]:=Module[{Cn,Sv,Su,Tv,Tu,MS,MT,MA,ct,fs,tmpL={},ret={}},
{Cn,{Sv,Tv}}=QtList[[mm]];fs="正解です.";
While[Length[tmpL]≤Cn,
While[Abs[Det[MS=ColCat[{Sv,Transpose[{Table[Rnz[3],2]}]}]]]≠1];
MT=ColCat[{Tv,Transpose[{Table[Rnz[3],2]}]}];
MA=MT.Inverse[MS];
tmpL=Append[tmpL,MA];tmpL=DeleteDuplicates[tmpL]];
For[ct=1,ct≤Length[tmpL],ct++,ret=Append[ret,{"\\("<>TOT[tmpL[[ct]]]<>"\\)",fs}]];
Return[RandomSample[ret,Cn]]];

ICListF[mm_]:=Module[{Cn,Sv,Su,Tv,Tu,MS,MT,MA,ct,fs1,fs2,ret={}},
{Cn,{Sv,Tv}}=QtList[[mm]];
fs1="平面の1次変換を定めません.";
fs2="平面の1次変換は定まりますが, 条件を満たしません.";
MA=Table[Table[Rnz[2],3],2];ret=Append[ret,{"\\("<>TOT[MA]<>"\\)",fs1}];
MA=Table[Table[Rnz[2],2],3];ret=Append[ret,{"\\("<>TOT[MA]<>"\\)",fs1}];
(* case 2-1 *)
While[Length[ret]<SELNUM-Cn,
While[Abs[Det[MS=ColCat[{Transpose[{Table[Rnz[3],2]}],Sv}]]]≠1];
Tu=Transpose[{Table[Rnz[3],2]}];MT=ColCat[{Tv,Tu}];
MA=MT.Inverse[MS];
If[MA.Sv≠Tv,ret=Append[ret,{"\\("<>TOT[MA]<>"\\)",fs2}]];
(* case 2-2 *)
While[Abs[Det[MS=ColCat[{Sv,Transpose[{Table[Rnz[3],2]}]}]]]≠1];
Tu=Transpose[{Table[Rnz[2],2]}];MT=ColCat[{Tu,Tv}]; (* exchanged *)
MA=MT.Inverse[MS];
If[MA.Sv≠Tv,ret=Append[ret,{"\\("<>TOT[MA]<>"\\)",fs2}]]];
Return[RandomSample[ret,SELNUM-Cn]]];

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

ICListF[9]

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

#->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