(* ::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`Utilities`DataPackage`",{"QuantumGroups`","QuantumGroups`Utilities`Debugging`","QuantumGroups`MatrixPresentations`","QuantumGroups`RepresentationTensors`","QuantumGroups`Representations`","QuantumGroups`Algebra`","QuantumGroups`QuantumRoots`"}];


ValuesAsString;PackageData;MatchingValues;DefiniteValues;


{PackageMatrixPresentations,PackageDecompositionMaps,PackageQuantumRoots,PackageRMatrix,PackagePartialRMatrixPresentation,PackageDirectSumDecompositions,PackageHighWeightVectors,PackageSubIrrepWeightBases,PackageBraidingMatrices,PackageBRPresentations,PackageBraidingMaps};


Begin["`Private`"];


DefiniteValues[s_Symbol]:=Cases[DownValues[s]~Join~SubValues[s],rule:(pattern_/;FreeQ[pattern,Blank]:>_):>rule]


MatchingValues[s_Symbol,p_]:=Cases[DownValues[s]~Join~SubValues[s],rule:(pattern_/;MatchQ[pattern/.HoldPattern->Hold,Hold[p]]:>_):>rule]


ConvertRuleToAssignmentString[a_HoldPattern:>b_]:=StringTake[ToString[a,InputForm,CharacterEncoding->"PrintableASCII"],{13,-2}]<>":="<>ToString[b,InputForm,CharacterEncoding->"PrintableASCII"]<>"\n"


ValuesAsString[s_Symbol,p_]:=StringJoin@@(ConvertRuleToAssignmentString/@MatchingValues[s,p])


WriteRule[filename_,a_HoldPattern:>b_]:=
(WriteString[filename,StringTake[ToString[a,InputForm,CharacterEncoding->"PrintableASCII"],{13,-2}]<>":="];
CautiousWriteString[filename,b,InputForm,CharacterEncoding->"PrintableASCII"];
WriteString[filename,"\n"];)


CautiousWriteString[filename_,s_Symbol,options___]:=WriteString[filename,ToString[s,options]]
CautiousWriteString[filename_,s_String,options___]:=WriteString[filename,s]
CautiousWriteString[filename_,s_Integer,options___]:=WriteString[filename,ToString[s,options]]
CautiousWriteString[filename_,s_Real,options___]:=WriteString[filename,ToString[s,options]]
CautiousWriteString[filename_,x_Plus,options___]:=WriteString[filename,ToString[x,options]]
CautiousWriteString[filename_,x_Times,options___]:=WriteString[filename,ToString[x,options]]
CautiousWriteString[filename_,x_TensorProduct,options___]:=WriteString[filename,ToString[x,options]]
CautiousWriteString[filename_,x_CircleTimes,options___]:=WriteString[filename,ToString[x,options]]
CautiousWriteString[filename_,{},options___]:=WriteString[filename,"{}"]
CautiousWriteString[filename_,{x__},options___]:=
(WriteString[filename,"{"];
(CautiousWriteString[filename,#,options];WriteString[filename,", "])&/@Most[{x}];
CautiousWriteString[filename,Last[{x}],options];
WriteString[filename,"}"];)
CautiousWriteString[filename_,f_[x___],options___]:=
(WriteString[filename,ToString[f,options]];WriteString[filename,"["];
(CautiousWriteString[filename,#,options];WriteString[filename,", "])&/@Most[{x}];
CautiousWriteString[filename,Last[{x}],options];
WriteString[filename,"]"];)


Options[PackageData]={"Needs"->{},"ExtraPackageCode"->"","ExtraPrivateCode"->"","LoadPreexistingPackage"->True,"Message"->"QuantumGroups::loading","UseGzip"->False,"ByteCountLimit"->\[Infinity]};
PackageData[s_Symbol,p_,packagePath:{__String},opts___]:=PackageData[{{s,p}},QuantumGroupsDataDirectory[],packagePath,opts]
PackageData[s_Symbol,p_,baseDirectory_String,packagePath:{__String},opts___]:=PackageData[{{s,p}},baseDirectory,packagePath,opts]
PackageData[patterns:{{_Symbol,_}..},packagePath:{__String},opts___]:=PackageData[patterns,QuantumGroupsDataDirectory[],packagePath,opts]
PackageData[patterns:{{_Symbol,_}..},baseDirectory_String,packagePath:{__String},opts___]:=Module[{fullPackagePath,package,directory,filename,contentsTop, contentsBottom,needs,extraPackageCode,extraPrivateCode,loadPreexistingPackage,message,useGzip,byteCountLimit},
needs="Needs"/.{opts}/.Options[PackageData];
extraPackageCode="ExtraPackageCode"/.{opts}/.Options[PackageData];
extraPrivateCode="ExtraPrivateCode"/.{opts}/.Options[PackageData];
loadPreexistingPackage="LoadPreexistingPackage"/.{opts}/.Options[PackageData];
message="Message"/.{opts}/.Options[PackageData];
useGzip="UseGzip"/.{opts}/.Options[PackageData];
byteCountLimit="ByteCountLimit"/.{opts}/.Options[PackageData];
SetDirectory[baseDirectory];
fullPackagePath={"QuantumGroups","Data"}~Join~packagePath;
directory=ToFileName[Most[fullPackagePath]];
If[Length[FileNames[fullPackagePath[[-2]],ToFileName[Drop[fullPackagePath,-2]]]]==0,CreateDirectory[directory]];
package=StringJoin@@(Flatten[Transpose[{fullPackagePath,Table["`",{Length[fullPackagePath]}]}],1]);
filename=ToFileName[Most[fullPackagePath],Last[fullPackagePath]<>".m"];
If[loadPreexistingPackage\[And]!MemberQ[$ContextPath,package],
If[useGzip\[And]Length[FileNames[filename]]==0\[And]Length[FileNames[filename<>".gz"]]!=0,
SetDirectory[directory];
Run["gzip -d "<>Last[fullPackagePath]<>".m.gz"];
ResetDirectory[]
];
If[Length[FileNames[filename]]!=0,Get[package]]
];
contentsTop="BeginPackage[\""<>package<>"\""<>If[MatchQ[needs,{__String}],", "<>ToString[needs,InputForm],""]<>"]"<>"\n"
<>"Message["<>message<>",\""<>package<>"\"]"<>"\n"
<>extraPackageCode<>"\n"
<>"Begin[\"`Private`\"]"<>"\n"
<>extraPrivateCode<>"\n";
contentsBottom="End[]\n"<>"EndPackage[]";
If[Length[FileNames[filename]]!=0,DeleteFile[filename]];
If[useGzip\[And]Length[FileNames[filename<>".gz"]]!=0,DeleteFile[filename<>".gz"]];
WriteString[filename,contentsTop];
(Function[{rule},WriteRule[filename,rule]]/@Cases[MatchingValues@@#,((p_:>v_)/;ByteCount[v]<=byteCountLimit)])&/@patterns;
WriteString[filename,contentsBottom];
Close[filename];
If[useGzip,SetDirectory[directory];Run["gzip --rsync "<>Last[fullPackagePath]<>".m"];ResetDirectory[]];
ResetDirectory[];]


PackageqDimensions[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
{{QuantumGroups`Representations`Private`fastQDimension,HoldPattern[QuantumGroups`Representations`Private`fastQDimension[Subscript[\[CapitalGamma], n]][Irrep[Subscript[\[CapitalGamma], n]][_]]]},{QuantumGroups`Representations`Private`recursiveQDimension,HoldPattern[QuantumGroups`Representations`Private`recursiveQDimension[Subscript[\[CapitalGamma], n]][Irrep[Subscript[\[CapitalGamma], n]][_]]]}},
{ToString[\[CapitalGamma]]<>ToString[n],"qDimensions"},
"Needs"->{"QuantumGroups`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False
]


PackageMatrixPresentations[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
MatrixPresentation,MatrixPresentation[Subscript[\[CapitalGamma], n]][_][Irrep[Subscript[\[CapitalGamma], n]][_],FundamentalBasis,_],
{ToString[\[CapitalGamma]]<>ToString[n],"MatrixPresentations"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Algebra`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False
]


PackageDecompositionMaps[Subscript[\[CapitalGamma]_, n_]]:=(PackageData[
{{DecompositionMap,DecompositionMap[Subscript[\[CapitalGamma], n],_,_]},{InverseDecompositionMap,HoldPattern[InverseDecompositionMap[Subscript[\[CapitalGamma], n],_,_]]}},
{ToString[\[CapitalGamma]]<>ToString[n],"DecompositionMaps"},
"Needs"->{"QuantumGroups`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`","QuantumGroups`RepresentationTensors`","QuantumGroups`MatrixPresentations`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False,"ByteCountLimit"->6000000
];
PackageLargeDecompositionMaps[Subscript[\[CapitalGamma], n],6000000];
)


weightToString[\[Lambda]:{__Integer}]:=StringDrop[StringJoin@@((ToString[#]<>"$")&/@\[Lambda]),-1]


PackageLargeDecompositionMaps[Subscript[\[CapitalGamma]_, n_],limit_Integer]:=Module[{tensorPowerQ,tensorPowerPattern,largeValues,largeTensorPowers,largeTensorPowerData,otherLargeValues},
(*tensorPowerQ checks if W looks like a tensor power of V*)
tensorPowerQ[V_][W_]:=MatchQ[W,V]||MatchQ[W,U_\[CircleTimes]V/;tensorPowerQ[V][U]];
tensorPowerPattern=U_\[CircleTimes](V:(Irrep[Subscript[\[CapitalGamma], n]][\[Lambda]_]))/;tensorPowerQ[V][U];
largeValues=Cases[MatchingValues[DecompositionMap,DecompositionMap[Subscript[\[CapitalGamma], n],_,_]],((p_:>v_)/;(ByteCount[v]>limit)):>p];
largeTensorPowers=Cases[largeValues/.HoldPattern->Hold,Hold[DecompositionMap[Subscript[\[CapitalGamma], n],V_,_]]/;MatchQ[V,tensorPowerPattern]]/.Hold->HoldPattern;
(* oops, watch out in the next line, V means two different things! *)
largeTensorPowerData=largeTensorPowers/.HoldPattern->Hold/.Hold[DecompositionMap[_,V_,_]]:>V/.U:(_\[CircleTimes]V:Irrep[_][\[Lambda]_]):>{\[Lambda],Count[U,Irrep[_][\[Lambda]],\[Infinity]],U};
otherLargeValues=Complement[largeValues,largeTensorPowers];
If[Length[otherLargeValues]>0,
PackageData[{DecompositionMap,#}&/@otherLargeValues,{ToString[\[CapitalGamma]]<>ToString[n],"DecompositionMaps","Large"},"Needs"->{"QuantumGroups`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`","QuantumGroups`RepresentationTensors`","QuantumGroups`MatrixPresentations`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False]];
If[Length[largeTensorPowers]>0,Function[{d},PackageData[DecompositionMap,HoldPattern[DecompositionMap[##]]&@@{Subscript[\[CapitalGamma], n],d[[3]],_},{ToString[\[CapitalGamma]]<>ToString[n],"DecompositionMaps","w"<>weightToString[d[[1]]],"k"<>ToString[d[[2]]]},"Needs"->{"QuantumGroups`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`","QuantumGroups`RepresentationTensors`","QuantumGroups`MatrixPresentations`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False]]/@largeTensorPowerData];
]


PackageQuantumRoots[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
ExpandQuantumRoot,ExpandQuantumRoot[Subscript[\[CapitalGamma], n]][_],
{ToString[\[CapitalGamma]]<>ToString[n],"QuantumRoots"},
"Needs"->{"QuantumGroups`","QuantumGroups`QuantumRoots`","QuantumGroups`Algebra`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageRMatrix[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
RMatrix,RMatrix[Subscript[\[CapitalGamma], n],_,_,_,_],
{ToString[\[CapitalGamma]]<>ToString[n],"RMatrix"},
"Needs"->{"QuantumGroups`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;","UseGzip"->False
]


PackagePartialRMatrixPresentation[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
QuantumGroups`RMatrix`Private`PartialRMatrixPresentation,QuantumGroups`RMatrix`Private`PartialRMatrixPresentation[Subscript[\[CapitalGamma], n],__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"PartialRMatrixPresentation"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`RMatrix`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageDirectSumDecompositions[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
QuantumGroups`MatrixPresentations`Private`DirectSumDecomposition,QuantumGroups`MatrixPresentations`Private`DirectSumDecomposition[Subscript[\[CapitalGamma], n]][__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"DirectSumDecompositions"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageSubIrrepWeightBases[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
QuantumGroups`MatrixPresentations`Private`SubIrrepWeightBasis,QuantumGroups`MatrixPresentations`Private`SubIrrepWeightBasis[Subscript[\[CapitalGamma], n]][__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"SubIrrepWeightBases"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageBraidingMaps[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
{{BraidingMap,BraidingMap[Subscript[\[CapitalGamma], n],_,_]},{InverseBraidingMap,InverseBraidingMap[Subscript[\[CapitalGamma], n],_,_]}},
{ToString[\[CapitalGamma]]<>ToString[n],"BraidingMaps"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`RepresentationTensors`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageBRPresentations[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
KnotTheory`BR,KnotTheory`BR[_,_][Subscript[\[CapitalGamma], n],__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"BRPresentations"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`RepresentationTensors`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageHighWeightVectors[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
HighWeightVectors,HighWeightVectors[Subscript[\[CapitalGamma], n]][__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"HighWeightVectors"},
"Needs"->{"QuantumGroups`","QuantumGroups`MatrixPresentations`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


PackageBraidingMatrices[Subscript[\[CapitalGamma]_, n_]]:=PackageData[
QuantumGroups`Braiding`Private`BraidingMatrices,QuantumGroups`Braiding`Private`BraidingMatrices[Subscript[\[CapitalGamma], n]][__],
{"tmp",ToString[\[CapitalGamma]]<>ToString[n],"BraidingMatrices"},
"Needs"->{"QuantumGroups`","QuantumGroups`Braiding`","QuantumGroups`MatrixPresentations`","QuantumGroups`Utilities`MatrixWrapper`","QuantumGroups`Representations`"},
"ExtraPrivateCode"->"q=Global`q;"
]


End[];


EndPackage[];
