(* ::Package:: *)

BeginPackage["ThadStuff`"]

conj::usage="Replaces I by -I in an expression"
CG::usage="fast ClebschGordan routine"
C::usage="Clebsch-Gordan \!\(\*SubsuperscriptBox[\(C\), \(l1, m1, l2, m2\), \(l3, m3\)]\)  "
ThadForm::usage="Better Display of Matrices"
ThadPlot::usage="Plot[a,b,Style options,{xlabel,ylabel}] or Show[oldplot,{xlabel,ylabel}]"
ThadListPlot::usage="ListPlot[a,Style options,{xlabel,ylabel}]"
\[DoubleStruckCapitalI]::usage="Identity Matrix \!\(\*SubscriptBox[\"II\", \"g\"]\)"
\[Sigma]::usage="Pauli matrices"
Begin["`Private`"]
<<Notation`
Notation[ParsedBoxWrapper[SubsuperscriptBox["C", RowBox[{"j1_", ",", "m1_", ",", "j2_", ",", "m2_"}], RowBox[{"j3_", ",", "m3_"}]]] \[DoubleLongLeftRightArrow] ParsedBoxWrapper[RowBox[{"CG", "[", RowBox[{RowBox[{"{", RowBox[{"j1_", ",", "m1_"}], "}"}], ",", RowBox[{"{", RowBox[{"j2_", ",", "m2_"}], "}"}], ",", RowBox[{"{", RowBox[{"j3_", ",", "m3_"}], "}"}]}], "]"}]]]
CG[{a_,\[Alpha]_},{b_,\[Beta]_},{c_,\[Gamma]_}]:=If[c>a+b||c<Abs[a-b]||\[Gamma]!= \[Alpha]+\[Beta]||Abs[\[Alpha]]>a||Abs[\[Beta]]>b||Abs[\[Gamma]]>c,0,Sqrt[(a+b-c)!(a-b+c)!(-a+b+c)!/(a+b+c+1)!]Sqrt[(a+\[Alpha])!(a-\[Alpha])!(b+\[Beta])!(b-\[Beta])!(c+\[Gamma])!(c-\[Gamma])!(2c+1)]\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(z = Max[0, b - c - \[Alpha], a + \[Beta] - c]\), \(Min[a + b - c, a - \[Alpha], b + \[Beta]]\)]
\*FractionBox[
SuperscriptBox[\((\(-1\))\), \(z\)], \(\(z!\) \(\((a + b - c - z)\)!\) \(\((a - \[Alpha] - z)\)!\) \(\((b + \[Beta] - z)\)!\) \(\((c - b + \[Alpha] + z)\)!\) \(\((c - a - \[Beta] + z)\)!\)\)]\)]
conj[x_]:=x/.Complex[a_,b_]->Complex[a,-b]
ThadForm[q_]:=Quiet[NumberForm[MatrixForm[Chop[q]],3]]
ThadPlot[a_,b_,c_,d_]:=Plot[a,b,{c,AxesStyle->Directive[Black,18],GridLines->Automatic,GridLinesStyle->LightGray,Frame->True,Axes->False,
	FrameLabel->{Text[Style[d[[1]],FontSize->14]],Text[Style[d[[2]],FontSize->14]]},FrameStyle->{{Directive[GrayLevel[0],14],GrayLevel[1]},{Directive[GrayLevel[0],14],GrayLevel[1]}}}]
ThadPlot[a_,b_]:=Show[a,{AxesStyle->Directive[Black,18],GridLines->Automatic,GridLinesStyle->Directive[Thin,LightGray],Axes->False,Frame->True,FrameLabel->b,FrameStyle->{{Directive[GrayLevel[0],14],GrayLevel[1]},{Directive[GrayLevel[0],14],GrayLevel[1]}}}]
ThadListPlot[a_,c_,d_]:=ListPlot[a,{c,AxesStyle->Directive[Black,18],GridLines->Automatic,GridLinesStyle->LightGray,Frame->True,
	FrameLabel->{Text[Style[d[[1]],FontSize->14]],Text[Style[d[[2]],FontSize->14]]},FrameStyle->{{Directive[GrayLevel[0],14],GrayLevel[1]},{Directive[GrayLevel[0],14],GrayLevel[1]}}}]
a_\[CircleTimes]b_:=If[Length[Dimensions[a]]==Length[Dimensions[b]]==1,Flatten[KroneckerProduct[{a},{b}]],KroneckerProduct[a,b]]
SuperStar[a_]:=a/.Complex[x_,y_]->Complex[x,-y]
SuperDagger[b_]:=ConjugateTranspose[b]/.Conjugate[x_]->(x/.Complex[a_,c_]->Complex[a,-c])
Subscript[\[DoubleStruckCapitalI], g_]:=IdentityMatrix[g]
\[Sigma]:={{
 {0, 1},
 {1, 0}
},{
 {0, -I},
 {I, 0}
},{
 {1, 0},
 {0, -1}
}}
End[]
EndPackage[]





