(* 13_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);
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]]];
Category="LA/13-07.";
Title="1次変換を表す行列の計算";
SELNUM=6;
Single="true";
NUM=200;

PtString[{2,3}]

(* select pairs of matrices *)
We1={{1},{0}};We2={{0},{1}};
QtList={}; For[ct=1,ct≤300,ct++,
Cn=1;
MA=Table[Table[Rnz[4],2],2];
MP=Table[Table[Rnz[2],2],2];
While[Abs[Det[MP]]≠1,MP=Table[Table[Rnz[1],2],2]];
QtList=Append[QtList,{Cn,MA,MP}]];
(* QtList=DeleteDuplicates[QtList]; *)
QtList=RandomSample[QtList,NUM];Length[QtList]

Clear[QtextF];QtextF[mm_]:=Module[{Cn,MA,MP,MQ,p1,p2,q1,q2},
{Cn,MA,MP}=QtList[[mm]];MQ=MA.MP;
p1=Transpose[Col[MP,1]][[1]];p2=Transpose[Col[MP,2]][[1]];
q1=Transpose[Col[MQ,1]][[1]];q2=Transpose[Col[MQ,2]][[1]];
Return["平面の1次変換で"<>PtString[p1]<>"を"<>PtString[q1]<>"に"
<>PtString[p2]<>"を"<>PtString[q2]<>"に写す平面の1次変換表す行列を選べ."]];
QtextF[5]

CListF[mm_]:=Module[{Cn,MA,MP,MQ,ct,fs,ret={}},
{Cn,MA,MP}=QtList[[mm]];fs="正解です.";
ret=Append[ret,{"\\("<>TOT[MA]<>"\\)",fs}];
Return[RandomSample[ret,Cn]]];

CListF[15]

ICListF[mm_]:=Module[{Cn,MA,MA1,MP,ct,fs,ret={}},
{Cn,MA,MP}=QtList[[mm]];
fs="検算して確かめよう. 定義も確かめよう.";
MA1=Transpose[MA];
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
MA1=MA;MA1[[{1,2},1]]=MP[[{1,2},1]];
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
MA1=MA;MA1[[{1,2},2]]=MP[[{1,2},2]];
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
MA1=MA+Table[Table[Rnz[0],2],2];
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
MA1=MA+Table[Table[Rnz[0],2],2];;
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
MA1=MA+Table[Table[Rnz[0],2],2];;
ret=Append[ret,{"\\("<>TOT[MA1]<>"\\)",fs}];
ret=DeleteDuplicates[ret];
Return[RandomSample[ret,SELNUM-Cn]]];

MA={{a,b},{c,d}}

MA[[{1,2},1]]

ICListF[10]

For[ct=1,ct≤NUM,ct++,QtextF[ct];ICListF[ct]] (* Error check *)

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

ICListF[3]

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

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

MA={{3,5},{7,9}}

MA1=MA;MA1[[{1,2},1]]={{1},{0}};

MA1

RowCat[{IdentityMatrix[2],MA}]