(* Require XMLgen_MC.nb ver >=0.24 *)
SetDirectory[NotebookDirectory[]];
<<XMLgenMC.mx;
DebugMode=False;
ThisNo=StringReplace[StringSplit[ NotebookFileName[],"/"][[-1]],{"LA_"->"",".nb"->"","_"->"-"}];
Category="LA/"<>ThisNo<>".";

(* Global Options *)
Numbering="abc";Title="2次行列式の線形性と退化性による計算";
(* Numbers of select options and questions *)
Shuffle="false";Single="true";SELNUM=8;NUM=300;

TOT[mt_]:=ToString[OneLineTeXForm[mt]];
TOTT[mt_]:=ToString[OneLineTeXForm[Transpose[mt]]];
TTSt[eq_]:=ToString[TeXForm[StandardForm[eq]]];
TOC[mt_,c_]:=TOTT[{Transpose[mt][[c]]}];
TTD[r_]:=StringReplace[TT[r],"\\frac"->"\\dfrac"];
MFT[m_]:=MatrixForm[Transpose[m]];
MF[m_]:=MatrixForm[m];
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]]}];
PtString[M_]:=StringReplace[ToString[M],{"{"->"(","}"->")"}];
ai2tex[s_]:=StringReplace[TOT[s],Table["\\text{a"<>TOT[i]<>"}"->"{\\mathbf a}_"<>TOT[i],{i,1,8}]];
ci2tex[c_,s_]:=StringReplace[s,Table["\\text{"<>c<>TOT[i]<>"}"->"{\\mathbf "<>c<>"}_"<>TOT[i],{i,1,5}]];
ci2tex[c_,s_,tx_]:=StringReplace[s,Table["\\text{"<>c<>TOT[i]<>"}"->"{"<>tx<>c<>"}_"<>TOT[i],{i,1,8}]];
TOTci2tex[c_,s_]:=StringReplace[TOT[s],Table["\\text{"<>c<>TOT[i]<>"}"->"{\\mathbf "<>c<>"}_"<>TOT[i],{i,1,8}]];
TeXArray2Matrix[s_,mtx_]:=StringReplace[s,Join[{"array"->mtx,"\\left("->"","\\right)"->""},#->"" &/@ ("{"<>StringRepeat["c",#]<>"}" &/@ Reverse[Range[20]])]];
TAM[s_,mtx_]:=TeXArray2Matrix[TOT[s],mtx];
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]]];
GCDL[L_]:=Module[{ct,ret=0},For[ct=1,ct≤Length[L],ct++,ret=GCD[ret,L[[ct]]]];Return[ret]];

Clear[p,q,r,s,t,u,v,x,y,z]

(* select pairs of matrices *)
MAlist={-4,-3,-2,-1,2,2,3,3,4,5};
QtList={}; For[ct=1,ct≤NUM*1.02,ct++,
Cn=RandomChoice[{0,0,1,1,1,1,1,1,1}];
DvL=Table[Rnz[3],3];
While[MatrixRank[MA=ArrayReshape[RandomSample[MAlist,6],{2,3}]]==1];
QtList=Append[QtList,{Cn,MA,DvL}]];
(* QtList=DeleteDuplicates[QtList]; *)
QtList=RandomSample[QtList,NUM];Length[QtList]

Clear[a,b,c,QtextF];QtextF[mm_]:=Module[{Cn,MA,DvL,Va,Vb,Vc,Mabc,ret,ct,Tmp},
{Cn,MA,DvL}=QtList[[mm]];Tmp="";Mabc=MA.{a,b,c};
Va="{\\mathbf a}";Vb="{\\mathbf b}";Vc="{\\mathbf c}";
ret="2次数ベクトル\\("<>Va<>","<>Vb<>","<>Vc<>"\\)について,"
<>"\\(\\left|"<>Va<>"\\ "<>Vb<>"\\right|="<>TOT[DvL[[3]]]<>"\\),"
<>"\\(\\left|"<>Vb<>"\\ "<>Vc<>"\\right|="<>TOT[DvL[[1]]]<>"\\),"
<>"\\(\\left|"<>Va<>"\\ "<>Vc<>"\\right|="<>TOT[-DvL[[2]]]<>"\\),"
<>"であるとき, \\(\\left|"<>StringReplace[TOT[Mabc[[1]]]<>"\\ \\ "<>TOT[Mabc[[2]]],
#->"{\\mathbf "<>#<>"}" &/@ {"a","b","c"}]<>"\\right|\\)を求めよ.";
Return[IfDeb[{DvL,MF[MA]},ret]]];

MemberQ[{1,2,3},3]

AListF[mm_]:=Module[{Cn,DvL,MA,MAv,ct,MAv1,Tmp,ValL,Cans,Ians,IL={},aret,fsL={},ret={}},
{Cn,MA,DvL}=QtList[[mm]];MAv=Cross[MA[[1]],MA[[2]]];
fsL=Append[fsL,"正解です."];fsL=Append[fsL,"正解はあります."];
fsL=Append[fsL,"2次行列式の交代性を理解しよう?"];
fsL=Append[fsL,"\\(\\left|{\\mathbf a}\\ {\\mathbf a}\\right|=0\\)に注意"];
fsL=Append[fsL,"符号に注意して計算を確認しよう."];
Cans=DvL.MAv;
If[Cn==1,ret=Append[ret,{"C","\\("<>TOT[Cans]<>"\\)",fsL[[1]]}]];
aret[ia_,fn_]:=If[ia≠Cans&&!MemberQ[IL,ia],IL=Append[IL,ia];
ret=Append[ret,{"I","\\("<>TOT[ia]<>"\\)",fsL[[fn]]}];ret=DeleteDuplicates[ret]];
MAv1={MA[[1,2]]*MA[[2,3]]+MA[[1,3]]*MA[[2,2]],
MA[[1,3]]*MA[[2,1]]+MA[[1,1]]*MA[[2,3]],
MA[[1,1]]*MA[[2,2]]+MA[[1,2]]*MA[[2,1]]};
aret[DvL.MAv1,3];
aret[DvL.MAv+MA[[1]].MA[[2]],4];ct=0;
While[Length[ret]<SELNUM-1,ct++;If[ct>15,Ians=Cans+Rnz[10];aret[Ians,5],
Ians=(Table[Rnz[0],Length[DvL]]*DvL).(Table[Rnz[0],Length[MAv]]*MAv);
aret[Ians,5]]];
ret=RandomSample[ret];
If[Cn==1,ret=Append[ret,{"I","この中に正解はない.", fsL[[2]]}],
ret=Append[ret,{"C","この中に正解はない.",fsL[[1]]}]];
Return[Join[{{1,SELNUM-1}},ret]]];

DebOn[];QtextF[2]

AListF[6]

DebOn[];For[ct=1,ct≤NUM,ct++,QtextF[ct];AListF[ct]]

(* For[ct=1,ct≤NUM,ct++,Print[ct];QtextF[ct];AListF[ct]]; (* Error Check *) *)

DebOff[];GenMCxmlV2[DFname[1],Category<>Title<>"(MC1)",Title,NUM,Single,QtextF,AListF]