(* 09_05 3次数ベクトルの1次関係式 *)

(* 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="3次数ベクトルの1次関係式";
SELNUM=4;NUM=200;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤300,ct++,
Vb1={{Rnz[4]},{Rnz[4]},{Rnz[4]}};
Vb2={{Rnz[4]},{Rnz[4]},{Rnz[4]}};
While[MatrixRank[ColCat[{Vb1,Vb2}]]==1,Vb2={{Rnz[4]},{Rnz[4]},{Rnz[4]}}];
p1=RandomChoice[{-2,-1,2,2,2,3,3,4}];
p2=RandomChoice[{-3,-2,3,3,3,3,4}];
QtList=Append[QtList,{RandomInteger[1]+1,{Vb1,Vb2},{p1,p2}}];
QtList=DeleteDuplicates[QtList]];QtList=RandomSample[QtList,NUM];Length[QtList]

QtextF[mm_]:=Module[{Cn,Vbs,Vb1,Vb2,Vb3,p1,p2},{Cn,{Vb1,Vb2},{p1,p2}}=QtList[[mm]];
Vb3=p1*Vb1+p2*Vb2;Vbs="{\\mathbf b}";
Return["次の\\("<>Vbs<>"_1="<>TOT[Vb1]<>","<>Vbs<>"_2="<>TOT[Vb2]
<>","<>Vbs<>"_3="<>TOT[Vb3]<>"\\)の1次結合のうち\\("<>TOTT[{{0,0,0}}]<>"\\)"
<>"となるものをすべて選びなさい."]];

QtextF[5]

Clear[x,y,z];

CListF[mm_]:=Module[{Cn,Vbs,Vb1,Vb2,Vb3,Lbs2,Rbs2,Lbs3,Rbs3,a1,a2,a3,p1,p2,fs,ret={}},
{Cn,{Vb1,Vb2},{p1,p2}}=QtList[[mm]];fs="正解です.";
(* normal case *)
{a1,a2,a3}={p1,p2,-1};
Vbs="{\\mathbf b}";
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
If[a3<0,Lbs3="(";Rbs3=")",Lbs3="";Rbs3=""];
ret=Append[ret,{"\\("<>StringReplace[ToString[TeXForm[a1*b1+a2*b2+a3*b3]],
{"\\text{b1}"->Vbs<>"_1","\\text{b2}"->Vbs<>"_2","\\text{b3}"->Vbs<>"_3"}]<>"\\)",fs}];
(* scalar multiple *)
{a1,a2,a3}=RandomChoice[{-2,-2,-1,2,3}]*{p1,p2,-1};
Vbs="{\\mathbf b}";
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
If[a3<0,Lbs3="(";Rbs3=")",Lbs3="";Rbs3=""];
ret=Append[ret,{"\\("<>StringReplace[ToString[TeXForm[a1*b1+a2*b2+a3*b3]],
{"\\text{b1}"->Vbs<>"_1","\\text{b2}"->Vbs<>"_2","\\text{b3}"->Vbs<>"_3"}]<>"\\)",fs}];
Return[RandomSample[ret,Cn]]];

CListF[3]

ICListF[mm_]:=Module[{Cn,Vbs,Vb1,Vb2,Vb3,Lbs2,Rbs2,Lbs3,Rbs3,a1,a2,a3,p1,p2,fs1,ret={}},
{Cn,{Vb1,Vb2},{p1,p2}}=QtList[[mm]];
fs1="計算を確認してみよう.";
(* case 1 *)
{a1,a2,a3}={p1,p2,1};
Vbs="{\\mathbf b}";
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
If[a3<0,Lbs3="(";Rbs3=")",Lbs3="";Rbs3=""];
ret=Append[ret,{"\\("<>StringReplace[ToString[TeXForm[a1*b1+a2*b2+a3*b3]],
{"\\text{b1}"->Vbs<>"_1","\\text{b2}"->Vbs<>"_2","\\text{b3}"->Vbs<>"_3"}]<>"\\)",fs1}];
(* case 2 *)
{a1,a2,a3}=RandomChoice[{-2,-2,1,1,1,2,3}]*{p1,p2-1,-1};
Vbs="{\\mathbf b}";
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
If[a3<0,Lbs3="(";Rbs3=")",Lbs3="";Rbs3=""];
ret=Append[ret,{"\\("<>StringReplace[ToString[TeXForm[a1*b1+a2*b2+a3*b3]],
{"\\text{b1}"->Vbs<>"_1","\\text{b2}"->Vbs<>"_2","\\text{b3}"->Vbs<>"_3"}]<>"\\)",fs1}];
(* case 2' *)
{a1,a2,a3}=RandomChoice[{-2,1,2,1,1,3}]*{p1-1,p2,-1};
Vbs="{\\mathbf b}";
If[a2<0,Lbs2="(";Rbs2=")",Lbs2="";Rbs2=""];
If[a3<0,Lbs3="(";Rbs3=")",Lbs3="";Rbs3=""];
ret=Append[ret,{"\\("<>StringReplace[ToString[TeXForm[a1*b1+a2*b2+a3*b3]],
{"\\text{b1}"->Vbs<>"_1","\\text{b2}"->Vbs<>"_2","\\text{b3}"->Vbs<>"_3"}]<>"\\)",fs1}];
Return[RandomSample[ret,SELNUM-Cn]]];

QtextF[3]

ICListF[6]

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