(* ::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.                                                         *)
(************************************************************************)



(* ::Input::Initialization:: *)
Subscript[\[Chi], cond_] := If[TrueQ@cond, 1, 0];
B[0,_]=0; B[_,0]=0;
B[c_*x:Subscript[(e|f|g|h), __],y_]:=Expand[c B[x,y]];
B[y_,c_*x:Subscript[(e|f|g|h), __]]:=Expand[c B[y,x]];
B[x_Plus,y_] := B[#,y]& /@ x;
B[x_,y_Plus] := B[x,#]& /@ y;
P[0,_]=0; P[_,0]=0;
P[c_*x:Subscript[(e|f|g|h), __],y_]:=Expand[c P[x,y]];
P[y_,c_*x:Subscript[(e|f|g|h), __]]:=Expand[c P[y,x]];
P[x_Plus,y_] := P[#,y]& /@ x;
P[x_,y_Plus] := P[x,#]& /@ y;


(* ::Input::Initialization:: *)
P[Subscript[e, i_,j_], Subscript[f, k_,l_]] := Subscript[\[Chi], j==k\[And]i==l]; P[Subscript[f, k_,l_], Subscript[e, i_,j_]] := Subscript[\[Chi], j==k\[And]i==l];
P[Subscript[(e|f), __],Subscript[h, _]]=0; P[Subscript[h, _],Subscript[(e|f), __]]=0;
P[Subscript[g, i_],Subscript[h, j_]]:=2Subscript[\[Chi], i==j]; P[Subscript[h, j_],Subscript[g, i_]]:=2Subscript[\[Chi], i==j]; P[Subscript[h, i_],Subscript[h, j_]]:=-4\[Epsilon] Subscript[\[Chi], i==j];
P[Subscript[(e|g), __],Subscript[(e|g), __]]=0;
P[Subscript[(f|g), __],Subscript[(f|g), __]]=0;


(* ::Input::Initialization:: *)
B[Subscript[h, _],_] = 0; B[Subscript[g, _],Subscript[g, _]]= 0; 

B[Subscript[e, i_,j_],Subscript[e, k_,l_]] := Subscript[\[Chi], j==k] Subscript[e, i,l]-Subscript[\[Chi], l==i] Subscript[e, k,j];
B[Subscript[f, i_,j_],Subscript[f, k_,l_]] := \[Epsilon] Subscript[\[Chi], j==k] Subscript[f, i,l]-\[Epsilon] Subscript[\[Chi], l==i] Subscript[f, k,j];
B[Subscript[e, i_,j_],Subscript[f, k_,l_]] := Expand[Subscript[\[Chi], j==k](\[Epsilon] Subscript[\[Chi], i<l] Subscript[e, i,l]+Subscript[\[Chi], i>l] Subscript[f, i,l]) - Subscript[\[Chi], l==i](\[Epsilon] Subscript[\[Chi], k<j] Subscript[e, k,j]+Subscript[\[Chi], k>j] Subscript[f, k,j])+Subscript[\[Chi], j==k\[And]i==l](1/2 (Subscript[h, i]-Subscript[h, j])+\[Epsilon] (Subscript[g, i]-Subscript[g, j]))];

B[Subscript[g, i_],Subscript[e, j_,k_]] := (Subscript[\[Chi], i==j]-Subscript[\[Chi], i==k])Subscript[e, j,k];
B[Subscript[g, i_],Subscript[f, j_,k_]] := (Subscript[\[Chi], i==j]-Subscript[\[Chi], i==k])Subscript[f, j,k];


(* ::Input::Initialization:: *)
B[y_,x_] := Expand[-B[x,y]];


(* ::Input::Initialization:: *)
SuperPlus[Basis][n_] := Union@Flatten@{Table[Subscript[e, i,j], {i,n-1}, {j,i+1,n}],Table[Subscript[g, i], {i,n}]};
SuperMinus[Basis][n_] := Union@Flatten@{Table[Subscript[f, i,j], {i,2,n}, {j,i-1}],Table[Subscript[h, i], {i,n}]};
Basis[n_] := Union[SuperPlus[Basis][n], SuperMinus[Basis][n]];


(* ::Input::Initialization:: *)
$TD=\[Infinity]; \[HBar] /: \[HBar]^d_. /;d>$TD :=0;


(* ::Input::Initialization:: *)
PBWRule={};
x_\[PrecedesEqual]y_:=OrderedQ[{x,y}/.PBWRule]; x_\[Precedes]y_:=!OrderedQ[{y,x}/.PBWRule];
Subscript[UU, i_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. Subscript[(x:e|f|g|h), s__]:>Subscript[U, i][Subscript[x, s]];
Simp[\[ScriptCapitalE]_]:= Collect[\[ScriptCapitalE], Times[Subscript[U, _][__]..], Expand];
Simp[\[ScriptCapitalE]_]:=Expand[\[ScriptCapitalE]];


(* ::Input::Initialization:: *)
Subscript[m, s__][0]=0;
Subscript[m, s__][x_Plus] := Subscript[m, s]/@x;


(* ::Input::Initialization:: *)
Subscript[m, i_->j_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. Subscript[U, i]->Subscript[U, j];


(* ::Input::Initialization:: *)
Subscript[m, i_,j_->k_][c_. Subscript[U, i_][x___]Subscript[U, j_][]]:=c Subscript[U, k][x];
Subscript[m, i_,j_->k_][c_. Subscript[U, i_][]Subscript[U, j_][y___]]:=c Subscript[U, k][y];
Subscript[m, i_,j_->k_][c_. Subscript[U, i_][xx___,x_]Subscript[U, j_][y_,yy___]]:=If[x\[PrecedesEqual]y,
c Subscript[U, k][xx,x,y,yy],
((Subscript[U, i][xx](Subscript[U, j][y,x]+Subscript[UU, j][B[x,y]]) // Expand // Subscript[m, i,j->i])Subscript[U, j][yy] // Expand // Subscript[m, i,j->k])c // Simp
];


(* ::Input::Initialization:: *)
UProducts[n_,{},0]={1}; UProducts[n_,{},d_Integer] /; d>0 = {};
UProducts[n_,{i_,is___}, d_Integer] := Sort@Flatten@Table[(Subscript[U, i]@@@Subsets[Basis[n],{j}])u, {j,0,d},{u,UProducts[n,{is},d-j]}];


(* ::Input::Initialization:: *)
S[\[ScriptCapitalE]_]:= Union@Cases[{\[ScriptCapitalE]}, Subscript[U, i_][___]:>i, \[Infinity]];


(* ::Input::Initialization:: *)
Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[x_] := x;
x_**y_ := Module[{is=S[x]\[Intersection]S[y],\[Sigma],z},
z=x; Do[z=Subscript[m, i->\[Sigma]@i][z], {i,is}];
z=Expand[y z]; Do[z=Subscript[m, \[Sigma]@i,i->i][z], {i,is}]; z]



