(* 09_01 2次数ベクトル *)

(* 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],{"{"->"(","}"->")"}];
Title="2次数ベクトルの1次結合";
SELNUM=4;NUM=100;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤300,ct++,
V2={{Rnz[4]},{Rnz[4]}};
QtList=Append[QtList,{RandomInteger[1]+2,V2}];
QtList=DeleteDuplicates[QtList]];QtList=RandomSample[QtList,NUM];Length[QtList]

QtextF[mm_]:=Module[{Cn,V2},{Cn,V2}=QtList[[mm]];
Return["次の1次結合のうち\\("<>TOT[V2]<>"\\)と一致するものをすべて選びなさい."]];

Clear[x,y,z];

CListF[mm_]:=Module[{Cn,GM2,V2,Va,a1,a2,Lbs1,Lbs2,Rbs1,Rbs2,Va1,Va2,fs,ret={}},
{Cn,V2}=QtList[[mm]];fs="正解です.";
Va1={{1},{0}};Va2={{0},{1}};
a1=V2[[1,1]];a2=V2[[2,1]];
If[a1<0,Lbs1="(";Rbs1=")",Lbs1="";Rbs1=""];
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
ret=Append[ret,{"\\("<>Lbs1<>TOT[a1]<>Rbs1<>TOT[Va1]<>"+"<>Lbs2<>TOT[a2]<>Rbs2<>TOT[Va2]<>"\\)",fs}];
(* GM2 *)
GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}};
While[Det[GM2]!=1,GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}}];
Va1=Col[GM2,1];Va2=Col[GM2,2];
{{a1},{a2}}=Inverse[GM2].V2;
If[a1<0,Lbs1="(";Rbs1=")",Lbs1="";Rbs1=""];
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
ret=Append[ret,{"\\("<>Lbs1<>TOT[a1]<>Rbs1<>TOT[Va1]<>"+"<>Lbs2<>TOT[a2]<>Rbs2<>TOT[Va2]<>"\\)",fs}];
(* GM2 *)
GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}};
While[Det[GM2]!=1,GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}}];
Va1=Col[GM2,1];Va2=Col[GM2,2];
{{a1},{a2}}=Inverse[GM2].V2;
If[a1<0,Lbs1="(";Rbs1=")",Lbs1="";Rbs1=""];
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
ret=Append[ret,{"\\("<>Lbs1<>TOT[a1]<>Rbs1<>TOT[Va1]<>"+"<>Lbs2<>TOT[a2]<>Rbs2<>TOT[Va2]<>"\\)",fs}];
Return[RandomSample[ret,Cn]]];

QtextF[3]

CListF[10]

ICListF[mm_]:=Module[{Cn,GM2,V2,Va,a1,a2,Lbs1,Lbs2,Rbs1,Rbs2,Va1,Va2,fs1,fs2,ret={}},
{Cn,V2}=QtList[[mm]];
fs1="計算が合っていないようです.";
fs2="成分が1次結合の係数になるというわけではありません.";
(* GM2 fake *)
GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}};
While[Det[GM2]!=1||GM2=={{1,0},{0,1}},GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}}];
Va1=Col[GM2,1];Va2=Col[GM2,2];
(* {{a1},{a2}}=Inverse[GM2].V2; *)
a1=V2[[1,1]];a2=V2[[2,1]];
If[a1<0,Lbs1="(";Rbs1=")",Lbs1="";Rbs1=""];
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
ret=Append[ret,{"\\("<>Lbs1<>TOT[a1]<>Rbs1<>TOT[Va1]<>"+"<>Lbs2<>TOT[a2]<>Rbs2<>TOT[Va2]<>"\\)",fs2}];
(* Random *)
GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}};
While[Det[GM2]!=1||GM2=={{1,0},{0,1}},GM2={{Rnz[3],Rnz[3]},{Rnz[3],Rnz[3]}}];
Va1=Col[GM2,1];Va2=Col[GM2,2];a1=2;a2=2;
While[a1*Va1+a2*Va2==V2,a1=Rnz[3];a2=Rnz[3]];
ret=Append[ret,{"\\("<>Lbs1<>TOT[a1]<>Rbs1<>TOT[Va1]<>"+"<>Lbs2<>TOT[a2]<>Rbs2<>TOT[Va2]<>"\\)",fs1}];
Return[RandomSample[ret,SELNUM-Cn]]];

QtextF[3]

ICListF[3]

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

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