(* ::Package:: *)

(************************************************************************)\012(* This file was generated automatically by the Mathematica front end.  *)\012(* It contains Initialization cells from a Notebook file, which         *)\012(* typically will have the same name as this file except ending in      *)\012(* ".nb" instead of ".m".                                               *)\012(*                                                                      *)\012(* This file is intended to be loaded into the Mathematica kernel using *)\012(* the package loading commands Get or Needs.  Doing so is equivalent   *)\012(* to using the Evaluate Initialization Cells menu command in the front *)\012(* end.                                                                 *)\012(*                                                                      *)\012(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)\012(* automatically each time the parent Notebook file is saved in the     *)\012(* Mathematica front end.  Any changes you make to this file will be    *)\012(* overwritten.                                                         *)\012(************************************************************************)\012\012

(* ::Input::Initialization:: *)
$k=1; $U=QU; $E:={$k};
$trim:={\[Epsilon]^k_./;k>$k->0};
SetAttributes[{SS,SST},HoldAll];
Subscript[q, \[HBar]]=E^(\[Gamma] \[Epsilon] \[HBar]);
(* Upper to lower and lower to Upper: *)
U2l={\!\(
\*SubsuperscriptBox[\(B\), \(i_\), \(p_.\)] -> 
\*SuperscriptBox[\(E\), \(\(-p\)\ \[HBar]\ \[Gamma]\ 
\*SubscriptBox[\(b\), \(i\)]\)]\),B^p_.->E^(-p \[HBar] \[Gamma] b), \!\(
\*SubsuperscriptBox[\(T\), \(i_\), \(p_.\)] -> 
\*SuperscriptBox[\(E\), \(p\ \[HBar]\ 
\*SubscriptBox[\(t\), \(i\)]\)]\),T^p_.->E^(p \[HBar] t),\!\(
\*SubsuperscriptBox[\(\[ScriptCapitalA]\), \(i_\), \(p_.\)] -> 
\*SuperscriptBox[\(E\), \(p\ \[Gamma]\ 
\*SubscriptBox[\(\[Alpha]\), \(i\)]\)]\),\[ScriptCapitalA]^p_.->E^(p \[Gamma] \[Alpha])}; 
l2U={E^(c_. Subscript[b, i_]+d_.):>\!\(
\*SubsuperscriptBox[\(B\), \(i\), \(\(-c\)/\((\[HBar]\ \[Gamma])\)\)] 
\*SuperscriptBox[\(E\), \(d\)]\),E^(c_. b+d_.):>B^(-c/(\[HBar] \[Gamma])) E^d,
E^(c_. Subscript[t, i_]+d_.):>\!\(
\*SubsuperscriptBox[\(T\), \(i\), \(c/\[HBar]\)] 
\*SuperscriptBox[\(E\), \(d\)]\),E^(c_. t+d_.):>T^(c/\[HBar]) E^d,
E^(c_. Subscript[\[Alpha], i_]+d_.):>\!\(
\*SubsuperscriptBox[\(\[ScriptCapitalA]\), \(i\), \(c/\[Gamma]\)] 
\*SuperscriptBox[\(E\), \(d\)]\),E^(c_. \[Alpha]+d_.):>\[ScriptCapitalA]^(c/\[Gamma]) E^d,
E^\[ScriptCapitalE]_:>E^Expand@\[ScriptCapitalE]}; 
SS[\[ScriptCapitalE]_,op_]:=Collect[Normal@Series[\[ScriptCapitalE],{\[Epsilon],0,$k}],\[Epsilon],op];
SS[\[ScriptCapitalE]_]:=SS[\[ScriptCapitalE],Together];
SST[\[ScriptCapitalE]_,op___]:=SS[\[ScriptCapitalE]/.U2l,op];
Simp[\[ScriptCapitalE]_,op_]:=Collect[\[ScriptCapitalE],_CU|_QU,op];
Simp[\[ScriptCapitalE]_]:=Simp[\[ScriptCapitalE],SS[#,Expand]&];
SimpT[\[ScriptCapitalE]_]:=Collect[\[ScriptCapitalE],_CU|_QU,SST[#,Expand]&];
K\[Delta]/:Subscript[K\[Delta], i_,j_]:=If[i===j,1,0];
Subscript[c_Integer, k_Integer] := c+O[\[Epsilon]]^(k+1);


(* ::Input::Initialization:: *)
CF[\[ScriptCapitalE]_] := ExpandDenominator@ExpandNumerator@Together[Expand[\[ScriptCapitalE]] //. E^x_ E^y_:>E^(x+y) /. E^x_:>E^CF[x]];


(* ::Input::Initialization:: *)
Unprotect[SeriesData];
SeriesData /: CF[sd_SeriesData] := MapAt[CF,sd,3];
SeriesData /: Expand[sd_SeriesData] := MapAt[Expand,sd,3];
SeriesData /: Simplify[sd_SeriesData] := MapAt[Simplify,sd,3];
SeriesData /: Together[sd_SeriesData] := MapAt[Together,sd,3];
SeriesData /: Collect[sd_SeriesData,specs__] := MapAt[Collect[#,specs]&,sd,3];
Protect[SeriesData];


(* ::Input::Initialization:: *)
\!\(\*SubscriptBox[\(SP\), \({}\)]\)[P_]:=P; \!\(\*SubscriptBox[\(SP\), \({\[Xi]_ \[Rule] x_, ps___}\)]\)[P_] := Expand[P//\!\(\*SubscriptBox[\(SP\), \({ps}\)]\)] /. f_. \[Xi]^d_.:>\!\(
\*SubscriptBox[\(\[PartialD]\), \({x, d}\)]f\)


(* ::Input::Initialization:: *)
Unprotect[NonCommutativeMultiply]; Attributes[NonCommutativeMultiply]={};
(NCM=NonCommutativeMultiply)[x_] := x;
NCM[x_,y_,z__] := (x**y)**z;
0**_=_**0=0;
(x_Plus)**y_:=(#**y)&/@x; x_**(y_Plus):=(x**#)&/@y;
B[x_,x_]=0; B[x_,y_] := x**y-y**x;
B[x_,y_,e_]:=B[x,y,e]=B[x,y];


(* ::Input::Initialization:: *)
DeclareAlgebra[U_Symbol, opts__Rule] := Module[{gp,sr,g,cp,M,pow,k=0,
gs=Generators /. {opts},
cs=Centrals /. {opts} /. Centrals -> {} },
(Subscript[#, U]=U@#)&/@gs;
gp=Alternatives@@gs; gp=gp|Subscript[gp, _];(* gens *)
sr=Flatten@Table[{g->++k, Subscript[g, i_]->{i,k}},{g,gs}]; (* sorting \[Rule] *) 
cp=Alternatives@@cs; (* cents *)
SetAttributes[M,HoldRest]; M[0,_]=0; M[a_,x_]:=a x;
CE[\[ScriptCapitalE]_]:=Collect[\[ScriptCapitalE],_U,Expand]/.E^x_:>E^Expand[x]/.$trim;
Subscript[U, i_][\[ScriptCapitalE]_]:=\[ScriptCapitalE]/.{t:cp:>Subscript[t, i],u_U:>(Subscript[#, i]&)/@u};
Subscript[U, i_][NCM[]]=pow[\[ScriptCapitalE]_,0]=U@{}=Subscript[1, U]=U[];
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[U@y_,U@x_]:=CE[-B[U@x,U@y]];
x_**(c_. Subscript[1, U]):=CE[c x]; (c_. Subscript[1, U])**x_:=CE[c x];
(a_. U[xx___,x_])**(b_. U[y_,yy___]) :=If[OrderedQ[{x,y}/.sr],
CE@M[a b/.$trim,U[xx,x,y,yy]],
U@xx**CE@M[a b/.$trim,U@y**U@x+B[U@x,U@y,$E]]**U@yy ];
U@{c_.*(l:gp)^n_,r___}/;FreeQ[c, gp]:= CE[c U@Table[l,{n}]**U@{r}];
U@{c_.*l:gp,r___} := CE[c U[l]**U@{r}];
U@{c_,r___}/;FreeQ[c, gp]:= CE[c U@{r}];
U@{l_Plus, r___} := CE[U@{#,r}& /@ l];
U@{l_,r___} := U@{Expand[l],r};
U[\[ScriptCapitalE]_NonCommutativeMultiply]:=U/@\[ScriptCapitalE];
Subscript[\[DoubleStruckCapitalO], U][specs___,poly_] := Module[{sp,null,vs,us},
sp=Replace[{specs}, l_List:>Subscript[l, null], {1}];
vs=Join@@(First /@ sp);
us=Join@@(sp /. Subscript[l_, s_] :> (l/.Subscript[x_, i_]:>Subscript[x, s]));
CE[Total[
CoefficientRules[poly, vs] /. (p_->c_) :> c U@(us^p)
]] /. Subscript[x_, null]:>x];
Subscript[\[DoubleStruckCapitalO], U][specs___,\[DoubleStruckCapitalE][L_,Q_,P_]]:=Subscript[\[DoubleStruckCapitalO], U][specs,SS@Normal[P E^(L+Q)]];
pow[\[ScriptCapitalE]_,n_]:=pow[\[ScriptCapitalE],n-1]**\[ScriptCapitalE];
Subscript[\[DoubleStruckCapitalS], U][\[ScriptCapitalE]_,ss___Rule] := CE@Total[
CoefficientRules[\[ScriptCapitalE],First/@{ss}]/.(p_->c_):>c NCM@@MapThread[pow,{Last/@{ss},p}]];
Subscript[\[Sigma], rs___][c_.*u_U] := (c/.Subscript[(t:cp), j_]:>Subscript[t, j/.{rs}])U[List@@(u/.Subscript[v_, j_]:>Subscript[v, j/.{rs}])];
Subscript[m, j_->k_][c_.*u_U] := CE[((c/.Subscript[(t:cp), j]->Subscript[t, k])DeleteCases[u,Subscript[_, j|k]])**U@@Cases[u,Subscript[w_, j]:>Subscript[w, k]]**U@@Cases[u,Subscript[_, k]]];
U /: c_.*u_U*v_U := CE[c u**v];
Subscript[S, i_][c_.*u_U]:= CE[((c/.Subscript[S, i][U,Centrals])DeleteCases[u,Subscript[_, i]])**Subscript[U, i][NCM@@Reverse@Cases[u,Subscript[x_, i]:>S@U@x]]];
Subscript[\[CapitalDelta], i_->j_,k_][c_.*u_U]:= CE[((c/.Subscript[\[CapitalDelta], i->j,k][U,Centrals])DeleteCases[u,Subscript[_, i]])**(NCM@@Cases[u,Subscript[x_, i]:>Subscript[\[Sigma], 1->j,2->k]@\[CapitalDelta]@U@x] /. NCM[]->U[])]; ]


(* ::Input::Initialization:: *)
Subscript[\[Sigma], rs___][\[ScriptCapitalE]_Plus] := Subscript[\[Sigma], rs]/@\[ScriptCapitalE];
Subscript[m, j_->j_]=Identity; Subscript[m, j_->k_][0] = 0;
Subscript[m, j_->k_][\[ScriptCapitalE]_Plus] := Simp[Subscript[m, j->k]/@\[ScriptCapitalE]];
Subscript[m, is___,i_,j_->k_][\[ScriptCapitalE]_]:=Subscript[m, j->k]@Subscript[m, is,i->j]@\[ScriptCapitalE];
Subscript[S, i_][\[ScriptCapitalE]_Plus] := Simp[Subscript[S, i]/@\[ScriptCapitalE]];
Subscript[\[CapitalDelta], is___][\[ScriptCapitalE]_Plus] := Simp[Subscript[\[CapitalDelta], is]/@\[ScriptCapitalE]];


(* ::Input::Initialization:: *)
DeclareAlgebra[CU,Generators->{y,a,x},Centrals->{t}];
B[Subscript[a, CU],Subscript[y, CU]]=-\[Gamma] Subscript[y, CU]; B[Subscript[x, CU],Subscript[a, CU]]=-\[Gamma] Subscript[x, CU];
B[Subscript[x, CU],Subscript[y, CU]]=2\[Epsilon] Subscript[a, CU]-t Subscript[1, CU];
(S@Subscript[y, CU]=-Subscript[y, CU]; S@Subscript[a, CU]=-Subscript[a, CU]; S@Subscript[x, CU]=-Subscript[x, CU];)
Subscript[S, i_][CU,Centrals]={Subscript[t, i]->-Subscript[t, i]};
\[CapitalDelta]@Subscript[y, CU]=CU@Subscript[y, 1]+CU@Subscript[y, 2]; \[CapitalDelta]@Subscript[a, CU]=CU@Subscript[a, 1]+CU@Subscript[a, 2]; \[CapitalDelta]@Subscript[x, CU]=CU@Subscript[x, 1]+CU@Subscript[x, 2];
Subscript[\[CapitalDelta], i_->j_,k_][CU,Centrals]={Subscript[t, i]->Subscript[t, j]+Subscript[t, k]};


(* ::Input::Initialization:: *)
DeclareAlgebra[QU, Generators -> {y,a,x}, Centrals -> {t,T}];
B[Subscript[a, QU],Subscript[y, QU]]=-\[Gamma] Subscript[y, QU]; B[Subscript[x, QU],Subscript[a, QU]]=-\[Gamma] QU@x;
B[Subscript[x, QU],Subscript[y, QU]]:=SS[Subscript[q, \[HBar]]-1]QU@{y,x}+Subscript[\[DoubleStruckCapitalO], QU][{a},SS[(1-T E^(-2\[Epsilon] a \[HBar]))/\[HBar]]];
(S@Subscript[y, QU]:=Subscript[\[DoubleStruckCapitalO], QU][{a,y},SS[-T^-1 E^(\[HBar] \[Epsilon] a) y]]; S@Subscript[a, QU]=-Subscript[a, QU]; S@Subscript[x, QU]:=Subscript[\[DoubleStruckCapitalO], QU][{a,x},SS[-E^(\[HBar] \[Epsilon] a)x]];)
Subscript[S, i_][QU,Centrals]={Subscript[t, i]->-Subscript[t, i], Subscript[T, i]->\!\(\*SubsuperscriptBox[\(T\), \(i\), \(-1\)]\)};
\[CapitalDelta]@Subscript[y, QU]:=Subscript[\[DoubleStruckCapitalO], QU][Subscript[{Subscript[y, 1],Subscript[a, 1]}, 1],Subscript[{Subscript[y, 2]}, 2],SS[Subscript[y, 1]+Subscript[T, 1] E^(-\[HBar] \[Epsilon] Subscript[a, 1]) Subscript[y, 2]]]; \[CapitalDelta]@Subscript[a, QU]=QU@Subscript[a, 1]+QU@Subscript[a, 2]; \[CapitalDelta]@Subscript[x, QU]:=Subscript[\[DoubleStruckCapitalO], QU][Subscript[{Subscript[a, 1],Subscript[x, 1]}, 1],Subscript[{Subscript[x, 2]}, 2],SS[Subscript[x, 1]+E^(-\[HBar] \[Epsilon] Subscript[a, 1]) Subscript[x, 2]]];
Subscript[\[CapitalDelta], i_->j_,k_][QU,Centrals]={Subscript[t, i]->Subscript[t, j]+Subscript[t, k],Subscript[T, i]->Subscript[T, j] Subscript[T, k]};


(* ::Input::Initialization:: *)
Subscript[SW, xy][U_,kk_] :=  Subscript[SW, xy][U,kk] =Block[{$U=U,$k=kk,$p=kk},Module[{G,F,fs,f,bs,e,b,es},
G=Simp[Table[\[Xi]^k/k!, {k,0, $k+1}] . NestList[Simp[B[Subscript[x, U] ,# ]]&, Subscript[y, U], $k+1]];
fs=Flatten@Table[Subscript[f, l,i,j,k][\[Eta]],{l,0,$k},{i,0, l},{j,0, l},{k,0, l}];
F=fs . (bs=fs/.Subscript[f, l_,i_,j_,k_][\[Eta]]:>\[Epsilon]^l U@{y^i,a^j,x^k});
es=Flatten[Table[Coefficient[e,b]==0,{e,{F-Subscript[1, U]/.\[Eta]->0,F**G-Subscript[y, U]**F-\!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Eta]\)]F\)}},{b,bs}]];
F=F/.DSolve[es,fs,\[Eta]][[1]];
\[DoubleStruckCapitalE][0,
\[Xi] x+\[Eta] y+(U /. {CU->-t \[Eta] \[Xi], QU-> \[Eta] \[Xi] (1-T)/\[HBar]}),
F+Subscript[0, $k]/.{E^_->1,U->Times}
] /. (v:\[Eta]|\[Xi]|t|T|y|a|x)->Subscript[v, 1]
]];
Subscript[tSW, xy_,i_,j_->k_]:=Subscript[SW, xy][$U,$k] /. {Subscript[\[Xi], 1]->Subscript[\[Xi], i],Subscript[\[Eta], 1]->Subscript[\[Eta], j],Subscript[(v:t|T|y|a|x), 1]->Subscript[v, k]};
Subscript[tSW, xa,i_,j_->k_]:=\[DoubleStruckCapitalE][Subscript[\[Alpha], j] Subscript[a, k],E^(-\[Gamma] Subscript[\[Alpha], j]) Subscript[\[Xi], i] Subscript[x, k],1];
Subscript[tSW, ay,i_,j_->k_]:=\[DoubleStruckCapitalE][Subscript[\[Alpha], i] Subscript[a, k],E^(-\[Gamma] Subscript[\[Alpha], i]) Subscript[\[Eta], j] Subscript[y, k],1];


(* ::Input::Initialization:: *)
(* Bug: The first line is valid only if \[DoubleStruckCapitalO](\[ExponentialE]^Subscript[P, 0])\[Equal]\[ExponentialE]^(\[DoubleStruckCapitalO](Subscript[P, 0])). *)
(* Bug: \[Xi] must be a symbol. *)
Subscript[Exp, Subscript[U_, i_],0][\[Xi]_,P_]:=Module[{LQ=Normal@P /. \[Epsilon]->0},
\[DoubleStruckCapitalE][\[Xi] LQ/.Subscript[(x|y), i]->0, \[Xi] LQ/.Subscript[(t|a), i]->0,1] ];
Subscript[Exp, Subscript[U_, i_],k_][\[Xi]_,P_]:=Block[{$U=U,$k=k},
Module[{P0,\[CurlyPhi],\[CurlyPhi]s,F,j,rhs,at0,at\[Xi]},
P0=Normal@P /. \[Epsilon]->0;
\[CurlyPhi]s=Flatten@Table[Subscript[\[CurlyPhi], j1,j2,j3][\[Xi]],{j2,0,k},{j1,0,2k+1-j2},{j3,0,2k+1-j2-j1}];
F=Normal@Last@Subscript[Exp, Subscript[U, i],k-1][\[Xi],P]+\[Epsilon]^k \[CurlyPhi]s . (\[CurlyPhi]s/.Subscript[\[CurlyPhi], js__][\[Xi]]:>Times@@\!\(\*SuperscriptBox[\({
\*SubscriptBox[\(y\), \(i\)], 
\*SubscriptBox[\(a\), \(i\)], 
\*SubscriptBox[\(x\), \(i\)]}\), \({js}\)]\));
rhs=Normal@Last@Subscript[m, i,j->i][\[DoubleStruckCapitalE][\[Xi] P0/.Subscript[(x|y), i]->0,\[Xi] P0/.Subscript[(t|a), i]->0, F+Subscript[0, k]]Subscript[m, i->j]@\[DoubleStruckCapitalE][0,0,P+Subscript[0, k]]];
at0=(#==0)& /@ Flatten@CoefficientList[F-1 /. \[Xi]->0, {Subscript[y, i],Subscript[a, i],Subscript[x, i]}];
at\[Xi]=(#==0)& /@ Flatten@CoefficientList[(\!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Xi]\)]F\))+P0 F-rhs, {Subscript[y, i],Subscript[a, i],Subscript[x, i]}];
\[DoubleStruckCapitalE][\[Xi] P0/.Subscript[(x|y), i]->0,\[Xi] P0/.Subscript[(t|a), i]->0, F+Subscript[0, k]] /. DSolve[And@@(at0\[Union]at\[Xi]),\[CurlyPhi]s,\[Xi]][[1]] ]]



