(* ::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:: *)
\[Epsilon] /: \[Epsilon]^n_/;n>1 :=0;
PBWBasis={a,c,w};

B[U@c,U@u]=-(B[U@u,U@c]=-U@u);
B[U@u,U@w]=-(B[U@w,U@u]=(1-t)U[]+\[Epsilon]  U[u,w]-2\[Epsilon] t  U[c]);

B[U@c,U@w]=-(B[U@w,U@c]=U@w);
B[U@c,U@a]=-(B[U@a,U@c]=-U@a);
B[U@a,U@w]=-(B[U@w,U@a]=(1-t)U[]-\[Epsilon](1+t) U[c]);
(*
B[U@a,U@w]=-(B[U@w,U@a]= (1-t)U[]+\[Eta](1-t) U[c]);   
*)


(* ::Input::Initialization:: *)
UU[l___,x_^n_,r___]:= UU[l,Sequence@@Table[x,{n}],r];
UU[l___,1,r___]:= UU[l,r];
UU[]=U[]; UU[l_,r___]:=U[l]**UU[r];
Subscript[U, i_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. {t->Subscript[t, i], u_U :> UU@@Replace[u, x_ :> Subscript[x, i],1]};


(* ::Input::Initialization:: *)
B[x_,x_]=0;
B[U[Subscript[(x_), i_]],U[Subscript[(y_), i_]]]:=Subscript[U, i][B[U@x,U@y]];
B[U[Subscript[(x_), i_]],U[Subscript[(y_), j_]]] /; i=!=j := 0;
B[x_,y_] := x**y-y**x;


(* ::Input::Initialization:: *)
x_\[PrecedesEqual]y_:=OrderedQ[{x,y}]; x_\[Precedes]y_:=!OrderedQ[{y,x}];
Simp[\[ScriptCapitalE]_]:= Collect[\[ScriptCapitalE], _U,Together];


(* ::Input::Initialization:: *)
Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[x_] := x;
0**_=_**0=0;
x_**U[]:=x; U[]**x_:=x;
(a_*x_U)**(b_*y_U) := If[a b === 0, 0, Simp[a b (x**y)]];
(a_*x_U)**y_ := Simp[a(x**y)]; x_**(a_*y_U) := Simp[a(x**y)];
(x_Plus)**y_ := (#**y)& /@ x; x_**(y_Plus) := (x**#)& /@ y;
U[x_]**U[y_] := (*U[x]**U[y] =*) If[x\[Precedes]y, U[x,y], U[y,x]+B[U@x,U@y]];
U[x_] ** U[y1_,yy__] := (*U[x] ** U[y1,yy] =*)If[x\[PrecedesEqual]y1,U[x,y1,yy],(U@x**U@y1)**U@yy];
U[xx__,xn_]**U[yy__] := (*U[xx,xn]**U[yy] =*) U@xx**(U@xn**U@yy);


(* ::Input::Initialization:: *)
\[Sigma][i_,j_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. {Subscript[b, i]->Subscript[b, j],Subscript[t, i]->Subscript[t, j],Subscript[a, i]->Subscript[a, j],Subscript[c, i]->Subscript[c, j],Subscript[u, i]->Subscript[u, j],Subscript[w, i]->Subscript[w, j]};


(* ::Input::Initialization:: *)
mul[i_,j_][\[ScriptCapitalE]_] := Simp[\[ScriptCapitalE] /. x_U :> DeleteCases[x,Subscript[_, j]]**U@@Cases[x,Subscript[y_, j]:>Subscript[y, i]] /. {Subscript[b, j]->Subscript[b, i], Subscript[t, j]->Subscript[t, i]}];
mul[i_,j_,k_][\[ScriptCapitalE]_] := \[ScriptCapitalE] // mul[i,j] // \[Sigma][i,k];


(* ::Input::Initialization:: *)
\[CapitalDelta][i_,j_,k_][\[ScriptCapitalE]_] := Simp[\[ScriptCapitalE]/. {
z_. U[]:>(z /. {Subscript[b, i]->Subscript[b, j]+Subscript[b, k],Subscript[t, i]->Subscript[t, j] Subscript[t, k]})U[],
z_. x_U :> (z /. {Subscript[b, i]->Subscript[b, j]+Subscript[b, k],Subscript[t, i]->Subscript[t, j] Subscript[t, k]})NonCommutativeMultiply@@(x /. {
Subscript[c, i]->U@Subscript[c, j]+U@Subscript[c, k],
 Subscript[u, i]->Subscript[t, k] U@Subscript[u, j]+\[Epsilon] Subscript[t, k] UU[Subscript[c, k],Subscript[u, j]]+U@Subscript[u, k],
 Subscript[w, i]->U@Subscript[w, j]+\[Epsilon] UU[Subscript[c, k],Subscript[w, j]]+U@Subscript[w, k],
Subscript[a, i]->Subscript[t, k] U[Subscript[a, j]]+U[Subscript[a, k]]-\[Epsilon] U[Subscript[a, k],Subscript[c, j]],
 Subscript[y_, l_]:>U@Subscript[y, l]
})
}]


(* ::Input::Initialization:: *)
S[i_][\[ScriptCapitalE]_] := Simp[\[ScriptCapitalE] /. {z_. x_U:>(z /. {Subscript[b, i]->-Subscript[b, i],Subscript[t, i]->Subscript[t, i]^-1})S[i][x]}];
S[i_][U[]]=U[];
S[i_][U[Subscript[y_, j_],more___]] /; i!=j := U[Subscript[y, j]]**S[i][U[more]];   (*Careful! if mathematica cannot decide i\[Equal]j or not then we get an error*)
S[i_][U[Subscript[c, i_],more___]] := S[i][U[more]]**(-U@Subscript[c, i]);
S[i_][U[Subscript[u, i_],more___]] := S[i][U[more]]**(-Subscript[t, i]^-1U@Subscript[u, i]+Expand[\[Epsilon] Subscript[t, i]^-1 UU[Subscript[u, i],Subscript[c, i]]]);
S[i_][U[Subscript[w, i_],more___]] := S[i][U[more]]**(-U@Subscript[w, i]+Expand[\[Epsilon] UU[Subscript[w, i],Subscript[c, i]]]);S[i_][U[Subscript[a, i_],more___]] := S[i][U[more]]**(Expand[-Subscript[t, i]^-1((1+\[Epsilon]) U[Subscript[a, i]]+\[Epsilon] U[Subscript[a, i],Subscript[c, i]])]);


(* ::Input::Initialization:: *)
Sinv[i_][\[ScriptCapitalE]_] := Simp[\[ScriptCapitalE] /. {z_. x_U:>(z /. {Subscript[b, i]->-Subscript[b, i],Subscript[t, i]->Subscript[t, i]^-1})Sinv[i][x]}];
Sinv[i_][U[]]=U[];
Sinv[i_][U[Subscript[y_, j_],more___]] /; i!=j := U[Subscript[y, j]]**Sinv[i][U[more]];   (*Careful! if mathematica cannot decide i\[Equal]j or not then we get an error*)
Sinv[i_][U[Subscript[c, i_],more___]] := Sinv[i][U[more]]**(-U@Subscript[c, i]);
Sinv[i_][U[Subscript[u, i_],more___]] := Sinv[i][U[more]]**(-Subscript[t, i]^-1U@Subscript[u, i]+Expand[\[Epsilon] Subscript[t, i]^-1 UU[Subscript[c, i],Subscript[u, i]]]);
Sinv[i_][U[Subscript[w, i_],more___]] := Sinv[i][U[more]]**(-U@Subscript[w, i]+Expand[\[Epsilon] UU[Subscript[c, i],Subscript[w, i]]]);Sinv[i_][U[Subscript[a, i_],more___]] := Sinv[i][U[more]]**(Expand[-Subscript[t, i]^-1( U[Subscript[a, i]]+\[Epsilon] U[Subscript[a, i],Subscript[c, i]])]);


(* ::Input::Initialization:: *)
CoUnit[i_][\[ScriptCapitalE]_] :=Simp[\[ScriptCapitalE]/. {z_. x_U:>(z/. {t->1,b->0,Subscript[b, i]->0,Subscript[t, i]->1})CoUnit[i][x]}] ;
CoUnit[i_][U[]]=U[];
CoUnit[i_][U[Subscript[y_, j_],more___]] /; i!=j := U[Subscript[y, j]]**CoUnit[i][U[more]];
CoUnit[i_][U[Subscript[y_, i_],more___]] /;y!=a:=0;
CoUnit[i_][U[Subscript[a, i_],more___]]:= CoUnit[i][U[more]];


(* ::Input::Initialization:: *)
LBasis[n_Integer] := LBasis[Range[n]];
LBasis[S_] := DeleteCases[0]@Module[{i,j,k,l}, SortBy[(# /. {\[Epsilon]->2,Subscript[c, _]->2,Subscript[u, _]->2,Subscript[w, _]->2, U->Times})&][
Union@Flatten[{{U[],\[Epsilon] U[]},
Table[{U@Subscript[c, i],U@Subscript[u, i],U@Subscript[w, i],\[Epsilon] U@Subscript[c, i],\[Epsilon] U@Subscript[u, i],\[Epsilon] U@Subscript[w, i]}, {i,S}],
Table[{U[Subscript[u, i],Subscript[w, j]],\[Epsilon] U[Subscript[u, i],Subscript[w, j]],\[Epsilon] U@@Sort@{Subscript[c, i],Subscript[c, j]},\[Epsilon] U[Subscript[c, i],Subscript[u, j]],\[Epsilon] U[Subscript[c, i],Subscript[w, j]]}, {i,S}, {j,S}],
Table[{\[Epsilon] U[Subscript[c, i],Subscript[u, j],Subscript[w, k]],\[Epsilon] U@@Sort@{Subscript[u, i],Subscript[u, j],Subscript[w, k]},\[Epsilon] U@@Sort@{Subscript[u, i],Subscript[w, j],Subscript[w, k]}}, {i,S}, {j,S},{k,S}],
Table[\[Epsilon] U@@Sort@{Subscript[u, i],Subscript[u, j],Subscript[w, k],Subscript[w, l]}, {i,S}, {j,S},{k,S},{l,S}] }]
]]


(* ::Input::Initialization:: *)
BLBasis[n_Integer] := BLBasis[Range[n]];
BLBasis[S_] := DeleteCases[0]@Module[{i,j,k,l}, SortBy[(# /. {\[Epsilon]->2,Subscript[c, _]->2,Subscript[u, _]->2,Subscript[w, _]->2, U->Times})&][
Union@Flatten[{{U[],\[Epsilon] U[]},
Table[{U@Subscript[c, i],\[Epsilon] U@Subscript[c, i]}, {i,S}],
Table[{U[Subscript[u, i],Subscript[w, j]],\[Epsilon] U[Subscript[u, i],Subscript[w, j]],\[Epsilon] U@@Sort@{Subscript[c, i],Subscript[c, j]}}, {i,S}, {j,S}],
Table[{\[Epsilon] U[Subscript[c, i],Subscript[u, j],Subscript[w, k]]}, {i,S}, {j,S},{k,S}],
Table[\[Epsilon] U@@Sort@{Subscript[u, i],Subscript[u, j],Subscript[w, k],Subscript[w, l]}, {i,S}, {j,S},{k,S},{l,S}] }]
]]


(* ::Input::Initialization:: *)
UExp[\[ScriptCapitalE]_,n_]:=Module[{t=U[],k}, U[]+Sum[(t=t**\[ScriptCapitalE])/k!, {k,n}]]//Simp


(* ::Input::Initialization:: *)
ToDegree[n_][\[ScriptCapitalE]_] := (Simp[\[ScriptCapitalE]] /. {\[Epsilon]->\[HBar] \[Epsilon],\[Eta]->\[HBar] \[Eta], Subscript[b, i_]:>\[HBar] Subscript[b, i], Subscript[t, i_]:>E^(\[HBar] Subscript[b, i]),b->\[HBar] b,  t:>E^(\[HBar] b),x_U:>\[HBar]^(Count[x,u|Subscript[u, _]]+Count[x,a|Subscript[a, _]]) x} /. a_. x_U :>Normal[Series[a,{\[HBar],0,n}]]*x)/.\[HBar]->1


(* ::Input::Initialization:: *)
R[i_,j_,d_]:= Sum[UU[Subscript[a, i]^n]**(U[]+\[Epsilon] n U[Subscript[c, i]])**(Subscript[b, i]^m U[]+\[Epsilon] m Subscript[b, i]^(m-1) U[Subscript[c, i]])**UU[Subscript[c, j]^m,Subscript[w, j]^n]/(m!n!) (1+\[Epsilon] 1/4 (n-1)n),{m,0,d},{n,0,d-m}]//ToDegree[d]



(* ::Input::Initialization:: *)
Rinv[i_,j_,d_]:=S[i][R[i,j,d]]//Expand


(* ::Input::Initialization:: *)
(*\[Eta] /: \[Eta]^n_/;n>1 :=0; *) 
\[Eta]=(t+1)/(t-1) \[Epsilon];
q = 1+\[Eta];
qI[k_]:=k(1+\[Eta] (k-1)/2)//Expand
qFac[n_]:=n!(1+\[Eta] (n-1)n/4)//Expand
InvqFac[n_]:=(1-\[Eta] (n-1)n/4)/n!//Expand
qBin[n_,k_]:= Binomial[n,k](1+\[Eta] k (n-k) /2)//Expand




