(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



BeginPackage["QuantumGroups`MatrixPresentations`",{"QuantumGroups`","QuantumGroups`Utilities`IntersectSubspaces`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Utilities`Debugging`","QuantumGroups`Utilities`DataPackage`","QuantumGroups`RootSystems`","QuantumGroups`Algebra`","QuantumGroups`Representations`"}];


MatrixPresentation::usage="";


HighWeightVectors::usage="";


HighWeightVectorQ;


HighWeights::usage="";


AllHighWeightVectors::usage="";


TensorProductWeightSpaceInclusion;


ChangeOfBasisMatrix;


ShortRootBasis;


Begin["`Private`"];


q=Global`q;


(*MatrixPresentation[\[CapitalGamma]_][A_][CircleTimes[V_],\[Beta]_,\[Lambda]_]:=MatrixPresentation[\[CapitalGamma]][A][V,\[Beta],\[Lambda]]*)


MatrixPresentation[\[CapitalGamma]_][A_**B_][V_,\[Beta]_,\[Lambda]_]/;!MemberQ[Weights[\[CapitalGamma],V],\[Lambda]+OperatorWeight[\[CapitalGamma]][A**B]]:=Matrix[0,WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A_**B_][V_,\[Beta]_,\[Lambda]_]:=MatrixPresentation[\[CapitalGamma]][A][V,\[Beta],\[Lambda]+OperatorWeight[\[CapitalGamma]][B]].MatrixPresentation[\[CapitalGamma]][B][V,\[Beta],\[Lambda]]


MatrixPresentation[\[CapitalGamma]_][\[ScriptZero]][V_,_,\[Lambda]_]:=With[{m=WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]},ZeroesMatrix[m,m]]


MatrixPresentation[\[CapitalGamma]_][\[ScriptOne]][V_,_,\[Lambda]_]:=identityMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][\[Alpha]_?qNumberQ A_][V_,\[Beta]_,\[Lambda]_]:=\[Alpha] MatrixPresentation[\[CapitalGamma]][A][V,\[Beta],\[Lambda]]


MatrixPresentation[\[CapitalGamma]_][A_Plus][V_,\[Beta]_,\[Lambda]_]/;(Length[Union[OperatorWeight[\[CapitalGamma]][#]&/@(List@@A)]]==1):=MatrixPresentation[\[CapitalGamma]][#][V,\[Beta],\[Lambda]]&/@A


MatrixPresentation[\[CapitalGamma]_][Subscript[K, i_]][V_,_,\[Lambda]_]:=q^(CartanFactors[\[CapitalGamma]][[i]]\[Lambda][[i]]) identityMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]
MatrixPresentation[\[CapitalGamma]_][Subscript[K, i_]^-1][V_,_,\[Lambda]_]:=q^(-CartanFactors[\[CapitalGamma]][[i]]\[Lambda][[i]]) identityMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A:(SuperPlus[Subscript[X, _]]|SuperMinus[Subscript[X, _]])][Irrep[\[CapitalGamma]_][\[Mu]_],\[Beta]_,\[Lambda]_]/;(ZeroVectorQ[\[Mu]]\[And]Length[\[Mu]]==Rank[\[CapitalGamma]]\[And]Length[\[Lambda]]==Rank[\[CapitalGamma]]):=If[ZeroVectorQ[\[Lambda]],ZeroesMatrix[0,1],ZeroesMatrix[WeightMultiplicity[\[CapitalGamma],Irrep[\[CapitalGamma]][\[Mu]],\[Lambda]+OperatorWeight[\[CapitalGamma]][A]],0]]


MatrixPresentation[\[CapitalGamma]_][A:(SuperPlus[Subscript[X, _]]|SuperMinus[Subscript[X, _]])][V_,\[Beta]_,\[Lambda]_]/;MinusculeRepresentationQ[\[CapitalGamma],V]:=OnesMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]+OperatorWeight[\[CapitalGamma]][A]],WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A_\[CircleTimes]B_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]/;!MemberQ[Weights[\[CapitalGamma],V\[CircleTimes]W],\[Lambda]+OperatorWeight[\[CapitalGamma]][A\[CircleTimes]B]]:=Matrix[0,WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A_\[CircleTimes]B_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]/;OperatorLength[\[CapitalGamma],A]>WeightDiameter[\[CapitalGamma],V]:=ZeroesMatrix[WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]+OperatorWeight[\[CapitalGamma]][A\[CircleTimes]B]],WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]]]
MatrixPresentation[\[CapitalGamma]_][A_\[CircleTimes]B_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]/;OperatorLength[\[CapitalGamma],B]>WeightDiameter[\[CapitalGamma],W]:=ZeroesMatrix[WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]+OperatorWeight[\[CapitalGamma]][A\[CircleTimes]B]],WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A_\[CircleTimes]B_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]:=
AppendRows@@Table[
TensorProductWeightSpaceInclusion[\[CapitalGamma],{V,W},{\[Lambda]+OperatorWeight[\[CapitalGamma]][A]-Weights[\[CapitalGamma],W][[i]],Weights[\[CapitalGamma],W][[i]]+OperatorWeight[\[CapitalGamma]][B]}].Together[MatrixKroneckerProduct[MatrixPresentation[\[CapitalGamma]][A][V,\[Beta],\[Lambda]-Weights[\[CapitalGamma],W][[i]]],MatrixPresentation[\[CapitalGamma]][B][W,\[Beta],Weights[\[CapitalGamma],W][[i]]]]],
{i,1,Length[Weights[\[CapitalGamma],W]]}]


MatrixPresentation[\[CapitalGamma]_][A_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]/;!MemberQ[Weights[\[CapitalGamma],V\[CircleTimes]W],\[Lambda]+OperatorWeight[\[CapitalGamma]][\[CapitalDelta][A]]]:=Matrix[0,WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A_][V_\[CircleTimes]W_,\[Beta]_,\[Lambda]_]:=MatrixPresentation[\[CapitalGamma]][\[CapitalDelta][A]][V\[CircleTimes]W,\[Beta],\[Lambda]]


MatrixPresentation[\[CapitalGamma]_][A_][V_DirectSum,\[Beta]_,\[Lambda]_]:=BlockDiagonalMatrix@@(MatrixPresentation[\[CapitalGamma]][A][#,\[Beta],\[Lambda]]&/@(List@@V))


PadWithZeroRows[m_Matrix,initial_?NaturalQ,total_?NaturalQ]:=With[{rows = Dimensions[m][[1]],cols=Dimensions[m][[2]]},Matrix[total,cols,Join[ConstantArray[0,{initial,cols}],MatrixData[m],ConstantArray[0,{total-initial-rows,cols}]]]]


WeightMultiplicityComponents[\[CapitalGamma]_,V1_,V2_,\[Lambda]_]:=Table[WeightMultiplicity[\[CapitalGamma],V1,\[Lambda]-Weights[\[CapitalGamma],V2][[i]]]WeightMultiplicity[\[CapitalGamma],V2,Weights[\[CapitalGamma],V2][[i]]],{i,1,Length[Weights[\[CapitalGamma],V2]]}]


WeightMultiplicityPartialSums[\[CapitalGamma]_,V1_,V2_,\[Lambda]_]:=WeightMultiplicityPartialSums[\[CapitalGamma],V1,V2,\[Lambda]]=Drop[FoldList[Plus,0,WeightMultiplicityComponents[\[CapitalGamma],V1,V2,\[Lambda]]],-1]


TensorProductWeightSpaceInclusion[\[CapitalGamma]_,{V_,W_},{\[Lambda]_,\[Mu]_}]:=With[{m0=WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]WeightMultiplicity[\[CapitalGamma],W,\[Mu]],m1=WeightMultiplicity[\[CapitalGamma],V\[CircleTimes]W,\[Lambda]+\[Mu]],pos=Position[Weights[\[CapitalGamma],W],\[Mu]]},
If[pos=={}\[Or]m0==0,
Matrix[m1,m0],
PadWithZeroRows[identityMatrix[m0],WeightMultiplicityPartialSums[\[CapitalGamma],V,W,\[Lambda]+\[Mu]][[pos[[1,1]]]],m1]
]
]


HighWeightVectorQ[\[CapitalGamma]_,V_,b_,\[Lambda]_]:=(And@@Table[ZeroVectorQ[Together[MatrixPresentation[\[CapitalGamma]][SuperPlus[Subscript[X, i]]][V,b,\[Lambda]].#]],{i,1,Rank[\[CapitalGamma]]}])&


HighWeightVectors[\[CapitalGamma]_][Irrep[\[CapitalGamma]_][\[Lambda]_],_,\[Lambda]_]:={{1}}
HighWeightVectors[\[CapitalGamma]_][Irrep[\[CapitalGamma]_][\[Lambda]_],_,_]:={}


HighWeightVectors[\[CapitalGamma]_][V_,b_,\[Lambda]_]:=HighWeightVectors[\[CapitalGamma]][V,b,\[Lambda]]=Module[{T,r},
T=AppendColumns@@Table[MatrixPresentation[\[CapitalGamma]][SuperPlus[Subscript[X, i]]][V,b,\[Lambda]],{i,1,Rank[\[CapitalGamma]]}];
If[Dimensions[T][[1]]==0,Return[IdentityMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]]];
DebugPrint["About to find the null space of a ",Dimensions[T][[2]]," by ",Dimensions[T][[2]]," matrix."];
r=Together[NullSpace[T,Method->"OneStepRowReduction"]];
DebugPrint["Finished finding null space."];
r
]


AllHighWeightVectors[\[CapitalGamma]_][V_,\[Beta]_]:=Flatten[Function[{\[Lambda]},{\[Lambda],#}&/@HighWeightVectors[\[CapitalGamma]][V,\[Beta],\[Lambda]]]/@PositiveWeights[\[CapitalGamma],V],1]


HighWeights[\[CapitalGamma]_,V_]:=SortWeights[\[CapitalGamma]][Union[DecomposeRepresentation[\[CapitalGamma]][V]/.{DirectSum[v__]:>{v},i:Irrep[_][_]:>{i}}/.Irrep[\[CapitalGamma]][\[Lambda]_]:>\[Lambda]]]


AddOneVectorToSpanningSet[{},v_?VectorQ]:=If[ZeroVectorQ[v],{},{v}]


AddOneVectorToSpanningSet[m_?MatrixQ,v_?VectorQ]:=If[MatrixRank[m~Join~{v}]==Length[m],m,m~Join~{v}]


SpanningSet[{}]:={};


SpanningSet[m_?MatrixQ]:=(Global`spanningSetArgument=m;Fold[AddOneVectorToSpanningSet,{},m])


SpanningSet[Matrix[_,_,data_]]:=SpanningSet[data]


LazyAddOneVectorToSpanningSet[{},v_?VectorQ]:=If[ZeroVectorQ[v],{},{v}]


LazyAddOneVectorToSpanningSet[m_?MatrixQ,v_?VectorQ]:=If[MatrixRank[m~Join~{v}/.q->1]==Length[m],m,m~Join~{v}]


LazySpanningSet[{}]:={};


LazySpanningSet[m_?MatrixQ]:=(Global`spanningSetArgument=m;Fold[LazyAddOneVectorToSpanningSet,{},m])


LazySpanningSet[Matrix[_,_,data_]]:=LazySpanningSet[data]


CarefulSpanningSetNewTime=CarefulSpanningSetOldTime=0;


CarefulSpanningSet[m_]:=Module[{tnew,rnew,told,rold},
{tnew,rnew}=AbsoluteTiming[LazySpanningSet[m]];
{told,rold}=AbsoluteTiming[SpanningSet[m]];
If[rnew=!=rold,Print["LazySpanningSet failed!"]];
CarefulSpanningSetNewTime+=tnew;
CarefulSpanningSetOldTime+=told;
rnew
]


SubIrrepWeightBasis[\[CapitalGamma]_][V_,\[Beta]_,\[Lambda]_,v_,\[Lambda]_]:={v}


SubIrrepWeightBasis[\[CapitalGamma]_][V_,\[Beta]_,\[Lambda]_,v_,\[Mu]_]/;InWeylPolytopeQ[\[CapitalGamma],\[Lambda],\[Mu]]:=SubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],\[Lambda],v,\[Mu]]=Module[{c,r},
DebugPrintHeld["Calculating ",SubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],\[Lambda],v,\[Mu]]];
c=Join@@Table[MatrixPresentation[\[CapitalGamma]][SuperMinus[Subscript[X, i]]][V,\[Beta],\[Mu]-OperatorWeight[\[CapitalGamma]][SuperMinus[Subscript[X, i]]]].#&/@SubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],\[Lambda],v,\[Mu]-OperatorWeight[\[CapitalGamma]][SuperMinus[Subscript[X, i]]]],{i,1,Rank[\[CapitalGamma]]}];
DebugPrint[" ... prepared spanning set."];
r=LazySpanningSet[Together[c]];
DebugPrintHeld["Finished calculating ",SubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],\[Lambda],v,\[Mu]]];
r
]


SubIrrepWeightBasis[\[CapitalGamma]_][V_,\[Beta]_,\[Lambda]_,v_,\[Mu]_]:={}


FullSubIrrepWeightBasis[\[CapitalGamma]_][V_,\[Beta]_,\[Mu]_]:=Flatten[SubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],#[[1]],#[[2]],\[Mu]]&/@AllHighWeightVectors[\[CapitalGamma]][V,\[Beta]],1]


DirectSumDecomposition[\[CapitalGamma]_][V_,\[Beta]_,\[Lambda]_]:=DirectSumDecomposition[\[CapitalGamma]][V,\[Beta],\[Lambda]]=
With[{data=FullSubIrrepWeightBasis[\[CapitalGamma]][V,\[Beta],\[Lambda]],d=WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]},
If[Length[data]!=d,Print["Direct sum decomposition failed, in weight space ",\[Lambda]," of ", V];Return[$Failed]];
Transpose[Matrix[Length[data],d,data]]
]


InverseDirectSumDecomposition[\[CapitalGamma]_][V_,\[Beta]_,\[Lambda]_]:=InverseDirectSumDecomposition[\[CapitalGamma]][V,\[Beta],\[Lambda]]=Inverse[DirectSumDecomposition[\[CapitalGamma]][V,\[Beta],\[Lambda]]]


DirectSumProjection[\[CapitalGamma]_][V_DirectSum,index_Integer,\[Lambda]_]:=With[{a=WeightMultiplicity[\[CapitalGamma],Take[V,index-1],\[Lambda]],b=WeightMultiplicity[\[CapitalGamma],V[[index]],\[Lambda]],c=WeightMultiplicity[\[CapitalGamma],Drop[V,index],\[Lambda]]},
AppendRows[ZeroesMatrix[b,a],identityMatrix[b],ZeroesMatrix[b,c]]
]


DirectSumProjection[\[CapitalGamma]_][V_DirectSum,indexes:{___Integer},\[Lambda]_]:=AppendColumns@@(DirectSumProjection[\[CapitalGamma]][V,#,\[Lambda]]&/@indexes)


DirectSumInclusion[\[CapitalGamma]_][V_DirectSum,index_,\[Lambda]_]:=Transpose[DirectSumProjection[\[CapitalGamma]][V,index,\[Lambda]]]


ChangeOfBasisMatrix[\[CapitalGamma]_][V:Irrep[\[CapitalGamma]_][_],\[Beta]_,FundamentalBasis,\[Lambda]_]:=DirectSumDecomposition[\[CapitalGamma]][V,\[Beta],\[Lambda]]
ChangeOfBasisMatrix[\[CapitalGamma]_][V:Irrep[\[CapitalGamma]_][_],FundamentalBasis,\[Beta]_,\[Lambda]_]:=Inverse[ChangeOfBasisMatrix[\[CapitalGamma]][V,\[Beta],FundamentalBasis,\[Lambda]]]
ChangeOfBasisMatrix[\[CapitalGamma]_][V_,\[Beta]_,\[Beta]_,\[Lambda]_]:=identityMatrix[WeightMultiplicity[\[CapitalGamma],V,\[Lambda]]]


MatrixPresentation[\[CapitalGamma]_][A:(SuperPlus[Subscript[X, _]]|SuperMinus[Subscript[X, _]])][Irrep[\[CapitalGamma]_][\[Lambda]_],ShortRootBasis,\[Kappa]_]/;UnitVectorQ[\[Lambda]]\[And]ShortDominantRootQ[\[CapitalGamma],\[Lambda]]:=MatrixPresentation[\[CapitalGamma]][A][Irrep[\[CapitalGamma]][\[Lambda]],ShortRootBasis,\[Mu]]=Module[{x,h,s,d,kf,action,basis},
Subscript[s, i_]:=SimpleRoots[\[CapitalGamma]][[i]];
Subscript[d, i_]:=CartanFactors[\[CapitalGamma]][[i]];
kf=KillingForm[\[CapitalGamma]];
action[SuperPlus[Subscript[X, i_]]][Subscript[x, \[Mu]_]]:=Switch[2 kf[\[Mu],Subscript[s, i]]/kf[Subscript[s, i],Subscript[s, i]],2|0|1,0,-1,Subscript[x, \[Mu]+Subscript[s, i]],-2,Subscript[h, Subscript[s, i]]];
action[SuperMinus[Subscript[X, i_]]][Subscript[x, \[Mu]_]]:=Switch[2 kf[\[Mu],Subscript[s, i]]/kf[Subscript[s, i],Subscript[s, i]],-2|0|-1,0,1,Subscript[x, \[Mu]-Subscript[s, i]],2,Subscript[h, Subscript[s, i]]];
action[SuperPlus[Subscript[X, i_]]][Subscript[h, \[Mu]_]]:=Switch[2 kf[\[Mu],Subscript[s, i]]/kf[Subscript[s, i],Subscript[s, i]],2,qInteger[2][q^Subscript[d, i]],-1,1,_,0]Subscript[x, Subscript[s, i]];
action[SuperMinus[Subscript[X, i_]]][Subscript[h, \[Mu]_]]:=Switch[2 kf[\[Mu],Subscript[s, i]]/kf[Subscript[s, i],Subscript[s, i]],2,qInteger[2][q^Subscript[d, i]],-1,1,_,0]Subscript[x, -Subscript[s, i]];
basis[\[Mu]_]:=If[MemberQ[ShortRoots[\[CapitalGamma]],\[Mu]],{Subscript[x, \[Mu]]},
If[ZeroVectorQ[\[Mu]],Subscript[h, #]&/@ShortSimpleRoots[\[CapitalGamma]],{}]];
With[{\[Beta]1=basis[\[Kappa]],\[Beta]2=basis[\[Kappa]+OperatorWeight[\[CapitalGamma]][A]]},
Matrix[Length[\[Beta]2],Length[\[Beta]1],Coefficient[action[A]/@\[Beta]1,#]&/@\[Beta]2]
]
]


MatrixPresentation[\[CapitalGamma]_][A:(SuperPlus[Subscript[X, _]]|SuperMinus[Subscript[X, _]])][V:Irrep[\[CapitalGamma]_][\[Lambda]_],FundamentalBasis,\[Kappa]_]/;UnitVectorQ[\[Lambda]]\[And]ShortDominantRootQ[\[CapitalGamma],\[Lambda]]:=MatrixPresentation[\[CapitalGamma]][A][V,FundamentalBasis,\[Kappa]]=ChangeOfBasisMatrix[\[CapitalGamma]][V,FundamentalBasis,ShortRootBasis,\[Kappa]+OperatorWeight[\[CapitalGamma]][A]].MatrixPresentation[\[CapitalGamma]][A][V,ShortRootBasis,\[Kappa]].ChangeOfBasisMatrix[\[CapitalGamma]][V,ShortRootBasis,FundamentalBasis,\[Kappa]]


IrrepContainmentRules={
Irrep[Subscript[B, n_]][\[Lambda]_]/;MemberQ[Take[IdentityMatrix[n],{2,-2}],\[Lambda]]:>Irrep[Subscript[B, n]][RotateLeft[\[Lambda]]]\[CircleTimes]Irrep[Subscript[B, n]][UnitVector[n,1]],
Irrep[Subscript[C, n_]][\[Lambda]_]/;MemberQ[Drop[IdentityMatrix[n],2],\[Lambda]]:>Irrep[Subscript[C, n]][RotateLeft[\[Lambda]]]\[CircleTimes]Irrep[Subscript[C, n]][UnitVector[n,1]],
Irrep[Subscript[D, n_]][\[Lambda]_]/;MemberQ[Take[IdentityMatrix[n],{3,-3}],\[Lambda]]:>If[EvenQ[n-Position[IdentityMatrix[n],\[Lambda]][[1,1]]],Irrep[Subscript[D, n]][UnitVector[n,n]]\[CircleTimes]Irrep[Subscript[D, n]][UnitVector[n,n]],Irrep[Subscript[D, n]][UnitVector[n,n-1]]\[CircleTimes]Irrep[Subscript[D, n]][UnitVector[n,n]]],
Irrep[Subscript[G, 2]][{0,1}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(G\), \(2\)]]\)[{1, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[F, 4]][{1,0,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(F\), \(4\)]]\)[{0, 0, 0, 1}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[F, 4]][{0,0,1,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(F\), \(4\)]]\)[{0, 0, 0, 1}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[F, 4]][{0,1,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(F\), \(4\)]]\)[{1, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 6]][{0,0,1,0,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(6\)]]\)[{1, 0, 0, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 6]][{0,1,0,0,0,0}]->Irrep[Subscript[E, 6]][{1,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 6]][{0,0,0,0,0,1}],
Irrep[Subscript[E, 6]][{0,0,0,0,1,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(6\)]]\)[{0, 0, 0, 0, 0, 1}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 6]][{0,0,0,1,0,0}]->Irrep[Subscript[E, 6]][{1,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 6]][{0,0,1,0,0,0}],
Irrep[Subscript[E, 7]][{0,0,1,0,0,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(7\)]]\)[{1, 0, 0, 0, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 7]][{0,1,0,0,0,0,0}]->Irrep[Subscript[E, 7]][{1,0,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 7]][{0,0,0,0,0,0,1}],
Irrep[Subscript[E, 7]][{0,0,0,0,0,1,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(7\)]]\)[{1, 0, 0, 0, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 7]][{0,0,0,0,1,0,0}]->Irrep[Subscript[E, 7]][{1,0,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 7]][{0,1,0,0,0,0,0}],
Irrep[Subscript[E, 7]][{0,0,0,1,0,0,0}]->Irrep[Subscript[E, 7]][{0,0,1,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 7]][{1,0,0,0,0,0,0}],
Irrep[Subscript[E, 8]][{0,0,0,0,0,0,1,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(8\)]]\)[{0, 0, 0, 0, 0, 0, 0, 1}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 8]][{1,0,0,0,0,0,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(8\)]]\)[{0, 0, 0, 0, 0, 0, 0, 1}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 8]][{0,1,0,0,0,0,0,0}]->Irrep[Subscript[E, 8]][{1,0,0,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 8]][{0,0,0,0,0,0,0,1}],
Irrep[Subscript[E, 8]][{0,0,0,0,0,1,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(8\)]]\)[{1, 0, 0, 0, 0, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 8]][{0,0,1,0,0,0,0,0}]->
\!\(\*SuperscriptBox[\(\(Irrep[
\*SubscriptBox[\(E\), \(8\)]]\)[{1, 0, 0, 0, 0, 0, 0, 0}]\), \(\[CircleTimes]2\)]\),
Irrep[Subscript[E, 8]][{0,0,0,0,1,0,0,0}]->Irrep[Subscript[E, 8]][{0,1,0,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 8]][{1,0,0,0,0,0,0,0}],
Irrep[Subscript[E, 8]][{0,0,0,1,0,0,0,0}]->Irrep[Subscript[E, 8]][{0,0,1,0,0,0,0,0}]\[CircleTimes]Irrep[Subscript[E, 8]][{1,0,0,0,0,0,0,0}],
Irrep[\[CapitalGamma]_][\[Lambda]_]/;(!UnitVectorQ[\[Lambda]]\[And]!ZeroVectorQ[\[Lambda]]):>Module[{n=Rank[\[CapitalGamma]],pos,\[Mu]},pos=Position[\[Lambda],_?(#!=0&)][[1,1]];\[Mu]=UnitVector[n,pos];
Irrep[\[CapitalGamma]][\[Lambda]-\[Mu]]\[CircleTimes]Irrep[\[CapitalGamma]][\[Mu]]]
};


MatrixPresentation[\[CapitalGamma]_][A:(SuperPlus[Subscript[X, _]]|SuperMinus[Subscript[X, _]])][V:Irrep[\[CapitalGamma]_][\[Mu]_],FundamentalBasis,\[Lambda]_]/;\[Not]ZeroVectorQ[\[Mu]]\[And]\[Not]UnitVectorQ[\[Mu]]\[Or](\[Not]ShortDominantRootQ[\[CapitalGamma],\[Mu]]\[And]\[Not]MinusculeRepresentationQ[\[CapitalGamma],V]):=Module[{W=V/.IrrepContainmentRules,p,result},MatrixPresentation[\[CapitalGamma]][A][V,FundamentalBasis,\[Lambda]]=
(DebugPrintHeld["Calculating ",MatrixPresentation[\[CapitalGamma]][A][V,FundamentalBasis,\[Lambda]], " by looking at ",V," as a subrep of ",Evaluate[W]];
If[W==V,Print["Warning, couldn't work out how to find matrix presentations for ",V];Return[$Failed]];
p=Position[DecomposeRepresentation[\[CapitalGamma]][W],V][[1,1]];
result=Simplify[Together[DirectSumProjection[\[CapitalGamma]][DecomposeRepresentation[\[CapitalGamma]][W],p,\[Lambda]+OperatorWeight[\[CapitalGamma]][A]].InverseDirectSumDecomposition[\[CapitalGamma]][W,FundamentalBasis,\[Lambda]+OperatorWeight[\[CapitalGamma]][A]].MatrixPresentation[\[CapitalGamma]][A][W,FundamentalBasis,\[Lambda]].DirectSumDecomposition[\[CapitalGamma]][W,FundamentalBasis,\[Lambda]].DirectSumInclusion[\[CapitalGamma]][DecomposeRepresentation[\[CapitalGamma]][W],p,\[Lambda]]]];
DebugPrintHeld["Finished calculating ",MatrixPresentation[\[CapitalGamma]][A][V,FundamentalBasis,\[Lambda]]];
result);
ReportSavedMatrixPresentation[\[CapitalGamma]][A][V,FundamentalBasis,\[Lambda]];
result
]


numberOfSavedMatrixPresentations[_]:=0


autopackagingMatrixPresentations=True;


ReportSavedMatrixPresentation[\[CapitalGamma]_][A_][V_,\[Beta]_,\[Lambda]_]:=Module[{},
++numberOfSavedMatrixPresentations[\[CapitalGamma]];
If[autopackagingMatrixPresentations\[And]Mod[numberOfSavedMatrixPresentations[\[CapitalGamma]],10]==0,
PackageMatrixPresentations[\[CapitalGamma]]
];
]


End[];


EndPackage[];
