(* ::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:: *)
B[0,_]=0; B[_,0]=0;
B[c_*x:(c|e|f|h),y_]:=Expand[c B[x,y]];
B[y_,c_*x:(c|e|f|h)]:=Expand[c B[y,x]];
B[x_Plus,y_] := B[#,y]& /@ x;
B[x_,y_Plus] := B[x,#]& /@ y;
B[x_,x_] =0;
B[y_,x_] := Expand[-B[x,y]];


(* ::Input::Initialization:: *)
B[h,e]=2e; B[h,f]=-2f; B[e,f]=h;  B[c,_]=0;
Basis[] :={c,e,f,h};


(* ::Input::Initialization:: *)
PBWRule={};
x_\[PrecedesEqual]y_:=OrderedQ[{x,y}/.PBWRule]; x_\[Precedes]y_:=!OrderedQ[{y,x}/.PBWRule];
Subscript[UU, i_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. (x:c|e|f|h):>Subscript[U, i][x];
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;
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[{},0]={1}; UProducts[{},d_Integer] /; d>0 = {};
UProducts[{i_,is___}, d_Integer] := Sort@Flatten@Table[(Subscript[U, i]@@@Subsets[Basis[],{j}])u, {j,0,d},{u,UProducts[{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];
UB[x_,y_] := Simp[x**y-y**x];



