(* ::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:: *)
SetDirectory["C:\\drorbn\\AcademicPensieve\\2017-06"];


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


(* ::Input::Initialization:: *)
q:=Sum[(\[HBar] \[Alpha] \[Beta])^k/k!, {k,0,Min[$T\[Beta]D]}];
AlgebraAtom = y|a|x;
PBWRule={y->1,a->2,x->3};
B[U@a,U@y]=-\[Alpha] U@y; B[U@x,U@a]=-\[Alpha] U@x;
(*B[U@x,U@y]=(q-1)UU[y,x]+UU@Sum[-(((t-2 a \[Beta])^(k+1)\[HBar]^k)/(k+1)!) ,{k,0,$TD}];*)
B[U@x,U@y]:=(q-1)UU[y,x]+UU[\[HBar]^-1 (1-Sum[T (-2 a \[Beta] \[HBar])^k/k! ,{k,0,$T\[Beta]D}])];


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


(* ::Input::Initialization:: *)
Subscript[U, i_][\[ScriptCapitalE]_] := \[ScriptCapitalE] /. {t->Subscript[t, i],T->Subscript[T, i],u_U :> Replace[u, x_ :> Subscript[x, i],1]};
B[U[Subscript[(x_), i_]],U[Subscript[(y_), i_]]]:=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_,x_]=0;
B[U[y_],U[x_]]=Simp[-B[U[x],U[y]]];
B[x_,y_] := x**y-y**x;


(* ::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;


(* ::Input::Initialization:: *)
U[xx___,x_] ** U[y_,yy___] := If[x\[PrecedesEqual]y,U[xx,x,y,yy], U@xx**(U@y**U@x+B[U@x,U@y])**U@yy];


(* ::Input::Initialization:: *)
UU[c_.*(l:AlgebraAtom)^n_,r___]/;FreeQ[c, AlgebraAtom]:= Expand[c UU[Sequence@@Table[l,{n}],r]];
UU[c_.*l:AlgebraAtom,r___] := Expand[c U[l]**UU[r]];
UU[c_,r___]/;FreeQ[c, AlgebraAtom]:= Expand[c UU[r]];
UU[]=U[];
UU[l_Plus, r___] := UU[#,r]& /@ l;
UU[l_,r___] := UU[Expand[l],r];


(* ::Input::Initialization:: *)
\[DoubleStruckCapitalO][poly_, specs___] := Module[{vs,us,z},
vs=Join@@(First /@ {specs});
us=Join@@({specs} /. (l_->s_) :> (l/.Subscript[x_, i_]:>Subscript[x, s]));
Simp@Total[CoefficientRules[Normal@Series[poly, {\[HBar],0,$TD}], vs] /. (p_->c_) :> c UU@@(us^p)]
]



