(* 09_04 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次結合";
Numbering="abc";
SELNUM=5;NUM=200;

(* Select matrices satisfying some mapping conditions *)
QtList={}; For[ct=1,ct≤400,ct++,
b1={Rpos[1],Rnz[1],Rnz[1]};
b2={Rnz[1],Rnz[1],Rnz[2]};
While[MatrixRank[{b1,b2}]==1,b2={Rnz[1],Rnz[1],Rnz[2]}];
c1=Rnz[1];c2=Rnz[2];
a1=Rnz[2];a2=Rnz[2];
QtList=Append[QtList,{RandomChoice[{1,2,2,2,3,3,3,3,3,4}],{b1,b2,c1,c2,a1,a2}}];
QtList=DeleteDuplicates[QtList]];QtList=RandomSample[QtList,NUM];Length[QtList]

QtextF[mm_]:=Module[{Cn,b1,b2,c1,c2,a1,a2,b3,a},{Cn,{b1,b2,c1,c2,a1,a2}}=QtList[[mm]];
b3=c1*b1+c2*b2;a=a1*b1+a2*b2;
Return["3次数ベクトル\\({\\mathbf b}_1="<>TOTT[{b1}]
<>",{\\mathbf b}_2="<>TOTT[{b2}]
<>",{\\mathbf b}_3="<>TOTT[{b3}]
<>"\\)の次の1次結合のうち, \\("<>TOTT[{a}]<>"\\)となるものをすべて選びなさい."]];

Clear[x,y,z]; 
(* b3=c1*b1+c2*b2; a=a1*b1+a2*b2+k(c1*b1+c2*b2-b3); *)

CListF[mm_]:=Module[{Cn,b1,b2,c1,c2,a1,a2,b3,a,kL,k,ct,bs,fs,ret={}},
{Cn,{b1,b2,c1,c2,a1,a2}}=QtList[[mm]];fs="正解です.";
kL=RandomSample[{-3,-2,-1,0,1,2,3,4,5},Cn];
bs[k1_,k2_,k3_]:="\\("<>StringReplace[TOT[k1*"b1"+k2*"b2"+k3*"b3"],Table["\\text{b"<>TOT[i]<>"}"->"{\\mathbf b}_"<>TOT[i],{i,1,3}]]<>"\\)";
For[ct=1,ct≤Cn,ct++,
k=kL[[ct]];
ret=Append[ret,{bs[a1+k*c1,a2+k*c2,-k],fs}]];
Return[ret]];

ICListF[mm_]:=Module[{Cn,b1,b2,c1,c2,a1,a2,b3,a,kL,k,ct,bs,fs,e1,e2,e3,ret={}},
{Cn,{b1,b2,c1,c2,a1,a2}}=QtList[[mm]];
fs="計算をよく確認してみよう. ";
fs=fs<>"\\({\\mathbf b}_3="<>TOT[c1]<>"{\\mathbf b}_1"<>If[c2>0,"+",""]<>TOT[c2]<>"{\\mathbf b}_2\\)";
fs=fs<>"となることを使うと確認は簡単かもしれません.";
kL=RandomSample[{-3,-2,-1,0,1,2,3,4,5},SELNUM-Cn];
bs[k1_,k2_,k3_]:="\\("<>StringReplace[TOT[k1*"b1"+k2*"b2"+k3*"b3"],Table["\\text{b"<>TOT[i]<>"}"->"{\\mathbf b}_"<>TOT[i],{i,1,3}]]<>"\\)";
For[ct=1,ct≤SELNUM-Cn,ct++,
k=kL[[ct]];e1=RandomInteger[2]-1;e2=RandomInteger[2]-1;e3=Rnz[2]-e1-e2;
ret=Append[ret,{bs[a1+k*c1+e1,a2+k*c2+e2,-k+e3],fs}]];
Return[ret]];

CListF[3]

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

TeXForm[(Rpos[3]^3+1)^(1/3)]

? Numbering

b1={1,2,3};b2={2,5,1};b3={3,1,1};

StringReplace[TOT[-1*"b1"+2*"b2"+3*"b3"],{"\\text{b.}"->"{\\mathbf b}_\1"}]

Clear[b1,b2,b3]

? RegularExpression