(* 10-05p1 *)

(* Require XMLgen_MC.nb ver >=0.20 *)
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],{"{"->"(","}"->")"}];
Rv[m_]:={Rnz[m],Rnz[m]};
Category="LA/10-05p1.";
Title="2次正方行列同士の積の性質(改)";
SELNUM=8;NUM=300;
DebugMode=True;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤300,ct++,
Cn=RandomInteger[3]+2;
MA={{Rnz[4],Rnz[4]},{Rnz[4],Rnz[4]}};
RC=RandomChoice[{"R1","R2","C1","C2"}];
QtList=Append[QtList,{Cn,MA,RC}];
QtList=DeleteDuplicates[QtList]];QtList=RandomSample[QtList,NUM];Length[QtList]

RCconv[RC_,M_]:=Module[{R12={{0,1},{1,0}}},
Which[RC=="R1",M,RC=="R2",R12.M,RC=="C1",Transpose[M],RC=="C2",Transpose[R12.M]]];

RCconvS[RC_,M1_,M2_]:=Module[{R12={{0,1},{1,0}}},
Which[RC=="R1","\\("<>TOT[M1]<>TOT[M2]<>"\\)",
RC=="R2","\\("<>TOT[R12.M1]<>TOT[R12.M2]<>"\\)",
RC=="C1","\\("<>TOTT[M2]<>TOTT[M1]<>"\\)",
RC=="C2","\\("<>TOTT[M2]<>TOTT[R12.M1]<>"\\)"]];

QtextF[mm_]:=Module[{Cn,MA,RC,R12},{Cn,MA,RC}=QtList[[mm]];
MA[[2]]={"*","*"};R12={{0,1},{1,0}};MA=RCconv[RC,MA];
Return["次の行列の積のうち, 計算するとベクトルの積の結果が必ず\\("<>TOT[MA]<>"\\)となるものをすべて選べ"]];

AListF[mm_]:=Module[{Cn,MA,RC,LR,RV,R12,CI,MA1,MM,RR,Tmp,a,b,fs,retC,retI},
{Cn,MA,RC}=QtList[[mm]];RR=Range[2];R12={{0,1},{1,0}};
fs={"正解です.","必ず指定の形になるものを選んで下さい."};retC={};retI={};
MM={{1,0},{"*","*"}};Tmp=MA;Tmp[[2]]=Rv[3];
retC=Append[retC,{"C",RCconvS[RC,MM,Tmp],fs[[1]]}];
MM={{1,0},{"*","*"}};Tmp=MA;Tmp[[2]]=Rv[3];
retI=Append[retI,{"I",RCconvS[RC,Tmp,MM],fs[[2]]}];
MM={{0,1},{"*","*"}};Tmp=R12.MA;Tmp[[1]]=Rv[3];
retC=Append[retC,{"C",RCconvS[RC,MM,Tmp],fs[[1]]}];
MM={{0,1},{"*","*"}};Tmp=R12.MA;Tmp[[1]]=Rv[3];
retI=Append[retI,{"I",RCconvS[RC,Tmp,MM],fs[[2]]}];
MM={{1,1},{"*","*"}};Tmp=MA;Tmp[[1]]=Rv[3];Tmp[[2]]=MA[[1]]-Tmp[[1]];
retC=Append[retC,{"C",RCconvS[RC,MM,Tmp],fs[[1]]}];
retI=Append[retI,{"I",RCconvS[RC,Tmp,MM],fs[[2]]}];
a=RandomChoice[{-4,-3,-2,-1,2,3,4,5}];MM={{1,a},{"*","*"}};
Tmp=MA;Tmp[[2]]=Rv[3];Tmp[[1]]=MA[[1]]-a*Tmp[[2]];
retC=Append[retC,{"C",RCconvS[RC,MM,Tmp],fs[[1]]}];
retI=Append[retI,{"I",RCconvS[RC,Tmp,MM],fs[[2]]}];
Tmp=MA;Tmp[[2]]=Rv[3];Tmp[[1]]=MA[[1]]+a*Tmp[[2]];
retI=Append[retI,{"I",RCconvS[RC,MM,Tmp],fs[[2]]}];
a=RandomChoice[{-4,-3,-2,-1,2,3,4,5}];MM={{a,1},{"*","*"}};
Tmp=MA;Tmp[[1]]=Rv[3];Tmp[[2]]=MA[[1]]-a*Tmp[[1]];
retC=Append[retC,{"C",RCconvS[RC,MM,Tmp],fs[[1]]}];
retI=Append[retI,{"I",RCconvS[RC,Tmp,MM],fs[[2]]}];
Tmp=MA;Tmp[[1]]=Rv[3];Tmp[[2]]=MA[[1]]+a*Tmp[[2]];
retI=Append[retI,{"I",RCconvS[RC,MM,Tmp],fs[[2]]}];
Return[Join[{{Cn,SELNUM-Cn}},RandomSample[retC,Cn],RandomSample[retI,SELNUM-Cn]]]];

DebugMode=False

For[ct=1,ct≤NUM,ct++,AListF[ct]]

GenMCxmlV2[DFname[],Category<>Title<>"(MC2)",Title,NUM,"false",QtextF,AListF]

Col[{{1,2},{3,4}},1]

Join[{a,b},{c,d}]

Range[2]

MA[[{1,2},2]]={Rnz[3],Rnz[3]}

MA