Free Lie Algebras Routines

Pensieve header: A free-Lie calculator, pensieve://Projects/WKO4/ branch (most current), continues pensieve://2014-01/. Now with general generators.

To Do

* Add "?" help lines and/or tooltip popups.

* Revise LW and CW I/O; have declarable “generators”.

* Consider “trees and wheels printing”.

Prolog

BeginPackage["FreeLie`"];
Print["FreeLie` implements / extends ",
Sort@{"*","+","**","⟨⟩","∫","≡",ad,Ad,adSeries,AllCyclicWords,AllLyndonWords,AllWords,ASeries,AW,b,BCH,BooleanSequence,BracketForm,CC,Crop,CWSeries,D,Deg,DegreeScale,DerivationSeries,div,DK,EulerE,Exp,Inverse,j,J,JA,LieDerivation,LieMorphism,LieSeries,LS,LW,LyndonFactorization,New,RandomCWSeries,Randomizer,RandomLieSeries,RC,SeriesSolve, Support,tb,TopBracketForm,tr, UndeterminedCoefficients, Γ,ι,Λ,"$SeriesShowDegree",⎴,⏜,CW,CWS,BS,ℏ},
"."];
$SeriesShowDegree=3;
Begin["`Private`"];

“New”

SetAttributes[New, HoldAll];
(*New[type_[srn_], def_] := Module[   (* "srn" for "self-reference name" *)
{un}, (* "un" for "unique name" *)
un=Unique[ToString[type]<>"$"];
ReleaseHold[Hold[def] /. srn -> un];
type[un]
];*)
New[type_[srn_], def_] := (   (* "srn" for "self-reference name" *)
(*Print["new object of type ", type//ToString, " and srn ", srn];*)
ReleaseHold[Hold[def; type[srn]] /. srn -> Unique[ToString[type]<>"$"]]
);

Words and Lyndon Words

A Lyndon word is a word lexicographically smaller than all of its proper right factors.

AllWords[n_, ab_List] := AW @@@ Tuples[ab, n];
LW /: LW[] < LW[__] = True;
LW /: _LW < LW[] = False;
LW /: LW[x_, xs___] < LW[x_, ys___] := LW[xs] < LW[ys];
LW /: LW[x_, ___] < LW[y_, ___] /; (x=!=y) := OrderedQ[{x,y}];
LW /: x_LW >y_LW := y<x;
LW /: x_LW ≤ y_LW := !(y<x);
LW /: x_LW ≥ y_LW := !(x<y);
LyndonQ[w_AW] := And @@ (
(LW@@w<LW@@#)& /@ Table[Drop[w,i], {i,1,Length[w]-1}]);
AllLyndonWords[n_Integer, ab_List] := AllLyndonWords[n, ab] =
LW @@@ Select[AllWords[n, ab /. LW[w_]:>w], LyndonQ];
AllLyndonWords[{n_}, ab_List] := Join@@Table[AllLyndonWords[k,ab], {k,n}];
Deg[w_LW] := Length[w];
LyndonFactorization[w_LW /; Deg[w] == 1] := w;
LyndonFactorization[w_LW /; Deg[w] > 1] := Module[{rf},
rf=First[Sort[Table[Drop[w,i], {i,1,Length[w]-1}], Less]];
LW /@ {Drop[w, -Length[rf]], rf}];
LW[w_LW]:=w;
BracketForm[LW[c_]] := ToString[c];
BracketForm[w_LW] := BracketForm[w] = StringJoin[Flatten[{
"[", BracketForm /@ LyndonFactorization[w],"]"
}]];
BracketForm[expr_] := expr /. w_LW :> BracketForm[w];
topbracketform[LW[c_]] := c;
topbracketform[w_LW] := topbracketform[w] = Overscript[
Row[Riffle[topbracketform /@ LyndonFactorization[w], " "]],⎴];
TopBracketForm[LW[c_]] := Overscript[c, ⎴];
TopBracketForm[w_LW] := topbracketform[w];
TopBracketForm[w_CW] := Overscript[StringJoin@@(ToString /@ w), ⏜];
TopBracketForm[expr_] := expr /. w_LW|w_CW|w_DK :> TopBracketForm[w];

The Bracket for Lie Elements

b[0,_] =0; b[_,0]=0;
b[c_*(x_AW|x_LW), y_] := Expand[c b[x,y]];
b[x_, c_*(y_AW|y_LW)] := Expand[c b[x,y]];
b[x_Plus, y_] := b[#,y]& /@ x;
b[x_, y_Plus] := b[x,#]& /@ y;
b[w_LW, z_LW] := LWAdjoint[w][z];
ad[x_][y_]:=b[x,y];

LWAdjoint[w_] := LWAdjoint[w] = Module[{u},
u=Unique[LWAct];
u[z_] := u[z] = Which[
w===z, 0,
z<w, Expand[-b[z,w]],
Deg[w]==1, Join[w,z],
True, Module[{x,y},
{x,y}=LyndonFactorization[w];
If[y≥z,
Join[w,z],
b[x,LWAdjoint[y][z]]+b[LWAdjoint[x][z],y]
]
]
];
u
];

BooleanSequence

BooleanSequence[bs_Symbol][{dd_Integer}] := TopBracketForm[Append[
BS@@(Table[bs[d], {d, 0, dd}] //. {n_. True, True,rest___} :> {(n+1)True, rest}),
"..."
]];
BooleanSequence[bs_Symbol][e___] := bs[e];
Format[bs_BooleanSequence, StandardForm] := bs[{$SeriesShowDegree}];
BooleanSequence /: And[bss__BooleanSequence] := New[BooleanSequence[bs],
bs[d_Integer] := bs[d] = And @@ ((#[d])& /@ {bss})
];
BooleanSequence /: (ℏ^(k_.))*BooleanSequence[bs_Symbol] := New[BooleanSequence[nbs],
nbs[d_Integer] := bs[d-k]
];

LieSeries

LieSeries[ser_Symbol][{dd_Integer}] := Append[TopBracketForm[LS@@Table[ser[d], {d, dd}]],"..."];
LieSeries[ser_Symbol][e___] := ser[e];
Format[s_LieSeries, StandardForm] := TopBracketForm[s[{$SeriesShowDegree}]];
ShowLieSeries[d_Integer][s_LieSeries] := s[{d}];
LS[s_] := MakeLieSeries[s];
MakeLieSeries[s_LieSeries] := s;
MakeLieSeries[expr_] := MakeLieSeries[expr] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = Expand[expr /. w_LW /; Deg[w] ≠ d -> 0]
];
s1_LieSeries ≡ s2_LieSeries := New[BooleanSequence[bs],
bs[0]=True;
bs[d_Integer] := bs[d-1]&&(s1[d]==s2[d]);
];
Crop[s_LieSeries, d_Integer] := Crop[s,d] = New[LieSeries[ser],
ser[dd_Integer] := If[dd≤d, s[dd], 0]
];
RandomLieSeries[ab_List, opts___Rule] := Module[
{rand = Randomizer /. {opts} /. Randomizer -> (((RandomInteger[{-2Deg[#]!, 2Deg[#]!}])/(Deg[#]!))&)},
New[LieSeries[ser],
ser[d_Integer] := ser[d] = Plus @@ ((rand[#]*#)& /@ AllLyndonWords[d, ab])
]
];

AddLieSeries[ss___LieSeries] := AddLieSeries[ss] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = Plus @@ ((#[d])& /@ {ss})
];
LieSeries /: Plus[ss__LieSeries] := AddLieSeries[ss];
ScaleLieSeries[c_, s_LieSeries] := ScaleLieSeries[c, s] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = Expand[c*s[d]]
];
LieSeries /: c_*s_LieSeries := ScaleLieSeries[c,s];
LieSeries /: D[ls_LieSeries, vars__] := New[LieSeries[ser],
ser[d_Integer] := ser[d] = D[ls[d], vars]
];
IntegrateLieSeries[ls_LieSeries, {s_, s0_, s1_}] := IntegrateLieSeries[ls, {s, s0, s1}] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = Expand[(∫_s0^s1)ls[d]\[DifferentialD]s]
];
LieSeries /: Integrate[ls_LieSeries, {s_, s0_, s1_}] := IntegrateLieSeries[ls, {s,s0,s1}];

b[s1_LieSeries, s2_LieSeries] := b[s1,s2] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = (∑_(k=1)^(d-1))b[s1[k], s2[d-k]]
];
b[s_LieSeries, y_] := b[s, MakeLieSeries[y]];
b[x_, s_LieSeries] := b[MakeLieSeries[x], s];

EulerE, DegreeScale

LieSeries /: EulerE[s_LieSeries] := New[LieSeries[ser],
ser[d_Integer] := ser[d] = Expand[d*s[d]]
];
DegreeScale[h_][s_LieSeries|s_CWSeries] := New[Head[s][ser],
ser[d_Integer] := ser[d] = Expand[(h^d)s[d]]
];

adSeries, and Ad

Convention: ad(x)(z)=[x,z]. Satisfies ad([x,y])=[ad(x),ad(y)].

adSeries[1, x_LieSeries][ψ_LieSeries] := adSeries[1,x][ψ] = ψ;
adSeries[(ad^(n_.)), x_LieSeries][ψ_LieSeries] := adSeries[(ad^n),x][ψ] = New[LieSeries[ser],
ser[d_Integer] := ser[d] =  b[x,adSeries[(ad^(n-1)), x][ψ]][d]
];
adSeries[f_, x_LieSeries][ψ_LieSeries] := adSeries[f, x][ψ] = New[LieSeries[ser],
ser[d_Integer] := ser[d] = Module[{c},
Expand[Sum[
c=SeriesCoefficient[f,{ad, 0, k}];
If[c === 0, 0, c*adSeries[(ad^k), x][ψ][d]],
{k,0,d-1}
]]
]
];
adSeries[f_, x_][ψ_] := adSeries[f, MakeLieSeries[x]][MakeLieSeries[ψ]];
Ad[x_] := adSeries[E^ad, x];

LieDerivation, DerivationPower, DerivationSeries

LieDerivation[der_][es___] := der[es];
LieDerivation[rules___Rule] := LieDerivation[{rules}];
LieDerivation[rules_List] := LieDerivation[rules] = New[LieDerivation[der],
der[Support] = First /@ rules;
(der[w_LW] /; Deg[w] == 1) := (der[w] = MakeLieSeries[w /. Append[rules, _LW -> 0]]);
der[w_LW] := der[w] = Module[{x,y},
{x,y}=LyndonFactorization[w];
AddLieSeries[b[der[x],y], b[x,der[y]]]
];
der[s_LieSeries] := der[s] = New[LieSeries[ser],
ser[d_] := ser[d] = (∑_(k=1)^d)der[s[k]][d]];
der[as_ASeries] := der[as] = New[ASeries[ser],
ser[d_] := ser[d] = Sum[
Expand[as[k] /. w_AW :> Sum[
NonCommutativeMultiply[
Take[w, j-1],
ι[der[LW[w[[j]]]][d-k+1]],
Drop[w,j]
],
{j,k}
]],
{k,1, d}
]
];
der[cws_CWSeries] := der[cws] = New[CWSeries[ser],
ser[d_] := ser[d] = Sum[
Expand[cws[k] /. w_CW :> Sum[
tr[NonCommutativeMultiply[
AW@@Take[w, j-1],
ι[der[LW[w[[j]]]][d-k+1]],
AW@@Drop[w,j]
]],
{j,k}
]],
{k,1, d}
]
];
der[expr_][d_] := Expand[expr /. {w_LW :> der[w][d], s_LieSeries :> der[s][d]}];
];

LieDerivation /: Plus[ders__LieDerivation] := LieDerivation[Table[
u -> Total[#[u]& /@ {ders}],
{u, Union@@(#[Support]& /@ {ders})}
]];
LieDerivation /: c_*der_LieDerivation := LieDerivation[Table[
u -> (c der[u]),
{u, der@Support}
]];

b[der1_LieDerivation, der2_LieDerivation] := LieDerivation[Table[
u -> der1[der2[u]]-der2[der1[u]],
{u, (der1@Support)⋃(der2@Support)}
]];

DerivationPower[0, der_LieDerivation][ψ_LieSeries|ψ_CWSeries] := DerivationPower[0,der][ψ] = New[Head[ψ][ser],
ser[d_Integer] := ser[d] = ψ[d]
];
DerivationPower[n_Integer, der_LieDerivation][ψ_LieSeries|ψ_CWSeries] := DerivationPower[n,x][ψ] = New[Head[ψ][ser],
ser[d_Integer] := ser[d] =  der[DerivationPower[n-1,der][ψ]][d]
];
DerivationSeries[__][0] = 0;
DerivationSeries[f_, ld_LieDerivation][ψ_LieSeries|ψ_CWSeries] := DerivationSeries[f, ld][ψ] = New[Head[ψ][ser],
ser[d_Integer] := ser[d] = Module[{c},
Expand[Sum[
c=SeriesCoefficient[f,{der, 0, k}];
If[c==0, 0, c*DerivationPower[k, ld][ψ][d]],
{k,0,d}
]]
]
];
DerivationExp[ld_LieDerivation] := DerivationSeries[E^der, ld];
LieDerivation /: Exp[ld_LieDerivation] := DerivationExp[ld];
LieDerivation /: (E^(ld_LieDerivation)) := DerivationExp[ld];

LieMorphism

LieMorphism[mor_][es___] := mor[es];
LieMorphism[rules__Rule] := LieMorphism[{rules}];
LieMorphism[rules_List] := LieMorphism[rules] = New[LieMorphism[mor],
mor[Support] = First /@ rules;
(mor[w_LW] /; Deg[w] == 1) := (mor[w] = MakeLieSeries[w /. rules]);
mor[w_LW] := (mor[w] = b @@ (mor /@ LyndonFactorization[w]));
mor[AW[]] = MakeASeries[AW[]];
mor[AW[w_]] := mor[AW[w]] = ι[MakeLieSeries[LW[w] /. rules]];
mor[w_AW] := mor[w] = Module[{w1,w2},
w1=Take[w, Floor[Length[w]/2]];
w2=Drop[w, Floor[Length[w]/2]];
mor[w1]**mor[w2]
];
mor[w_CW] := tr[mor[AW@@w]];
mor[s_LieSeries] := mor[s] = New[LieSeries[ser],
ser[d_] := ser[d] = (∑_(k=1)^d)mor[s[k]][d]];
mor[cws_CWSeries] := mor[cws] = New[CWSeries[ser],
ser[d_] := ser[d] = (∑_(k=1)^d)mor[cws[k]][d]];
mor[expr_][d_] := Expand[expr /. (w_LW|w_AW|w_CW) :> mor[w][d]];
(* Added 150217, commented out later that day *) (*mor[expr_] := Expand[expr /. (w_LW|w_AW|w_CW) :> mor[w]]*)
];

LieMorphism /: Inverse[mor_LieMorphism] := InvertLieMorphism[mor];
InvertLieMorphism[mor_LieMorphism] := InvertLieMorphism[mor] =
LieMorphism[Table[
LW@u -> New[LieSeries[uimg],
uimg[1] = LW@u;
uimg[d_Integer] /; d>1 := uimg[d] = -(∑_(k=1)^(d-1))(mor[uimg[k]][d])
],
{u,mor[Support]}
]]

StableApply

StableApply[mor_LieMorphism, (type:(LieSeries|ASeries|CWSeries))[s_]] := (
StableApply[mor, type[s]] = New[type[ser],
ser[d_] := ser[d] = Nest[mor, type[s], d][d]
]
);

BCH

BCHBase = New[LieSeries[bch],
bch[1] = LW@"x"+LW@"y";
bch[d_Integer] := bch[d] = Expand[Plus[
adSeries[(E^(-ad)), MakeLieSeries[LW@"y"]][MakeLieSeries[LW@"x"]][d],
-adSeries[((1-(E^(-ad)))/ad)-1, LieSeries[bch]][EulerE[LieSeries[bch]]][d]
]/d]
];
BCH[x_, y_] := LieMorphism[{LW["x"] -> x, LW["y"] -> y}][BCHBase];

AW, ASeries, ι, σ

Unprotect[NonCommutativeMultiply];
x_**0=0; 0**y_=0;
(c_*x_AW) ** y_ := Expand[c(x**y)];
x_ ** (c_*y_AW) := Expand[c(x**y)];
x_Plus ** y_ := (#**y)& /@ x;
x_**y_Plus := (x**#)& /@ y;
Deg[w_AW] := Length[w];
AW[AW[w_]]:=AW[w];
AW[w1___] ** AW[w2___] := AW[w1,w2];
b[w_AW, z_AW] := w**z-z**w;

ASeries[ser_Symbol][{dd_Integer}] := AS@@Table[ser[d], {d, 0, dd}];
ASeries[as_Symbol][es___] := as[es];
Format[s_ASeries, StandardForm] := s[{$SeriesShowDegree}];
MakeASeries[as_CWSeries] := as;
MakeASeries[expr_] := MakeASeries[expr] = New[ASeries[ser],
ser[d_Integer] := ser[d] = Expand[expr /. w_AW /; Deg[w] ≠ d -> 0]
];
(s1_ASeries ** s2_ASeries) := (s1**s2) = New[ASeries[ser],
ser[d_Integer] := ser[d] = (∑_(k=0)^d)s1[k]**s2[d-k]];

ι[w_LW] /; Deg[w]==1 := AW@@w;
ι[w_LW] := ι[w] = b @@ (ι /@ LyndonFactorization[w]);
ι[expr_] := Expand[expr /. w_LW :> ι[w]];
ι[ls_LieSeries] := ι[ls] = New[ASeries[as],
as[0]=0;
as[d_] /; d>0 := as[d] = ι[ls[d]]
];

σ[y_LW, w_LW] /; Deg[y]==1 := σ[y,w] = Which[
y===w, AW[],
Deg[w]===1, 0,
True, Module[{w1,w2},
{w1,w2}=LyndonFactorization[w];
ι[w1]**σ[y,w2]-ι[w2]**σ[y,w1]
]
];
σ[y_, ls_LieSeries] := σ[y, ls] = New[ASeries[as],
as[d_] := as[d] = σ[LW[y], ls[d+1]]
];
σ[y_, expr_] := Expand[expr /. w_LW :> σ[LW[y], w]];

CW, CWSeries, tr, div

RotateToMinimal[l_]:=Module[
{bestl=l,rotatedl=RotateLeft[l]},
While[rotatedl=!=l,
bestl=First[Sort[{bestl,rotatedl}]];
rotatedl=RotateLeft[rotatedl]
];
bestl
];

Deg[w_CW] := Length[w];
AllCyclicWords[d_Integer, ab_List] := AllCyclicWords[d, ab] = Union[tr[AllWords[d, ab]]];
CWSeries[cws_Symbol][es___] := cws[es];
CWSeries[ser_Symbol][{dd_Integer}] := Append[TopBracketForm[CWS@@Table[ser[d], {d, dd}]], "..."];
Format[s_CWSeries, StandardForm] := TopBracketForm[s[{$SeriesShowDegree}]];
CWS[cws_] := MakeCWSeries[cws];
MakeCWSeries[cws_CWSeries] := cws;
MakeCWSeries[expr_] := MakeCWSeries[expr] = New[CWSeries[ser],
ser[d_Integer] := ser[d] = Expand[
expr /. w_CW :> If[Deg[w] == d , RotateToMinimal@w, 0]
]
];
RandomCWSeries[ab_List, opts___Rule] := New[CWSeries[ser],
Module[
{rand = Randomizer /. {opts} /. Randomizer -> (((RandomInteger[{-2Deg[#]!, 2Deg[#]!}])/(Deg[#]!))&)},
ser[d_Integer] := ser[d] = Plus @@ ((rand[#]*#)& /@ AllCyclicWords[d, ab])
]];
s1_CWSeries ≡ s2_CWSeries := New[BooleanSequence[bs],
bs[0]=True;
bs[d_Integer] := bs[d-1]&&(s1[d]==s2[d]);
];
AddCWSeries[ss___CWSeries] := AddCWSeries[ss] = New[CWSeries[ser],
ser[d_Integer] := ser[d] = Plus @@ ((#[d])& /@ {ss})
];
CWSeries /: Plus[ss__CWSeries] := AddCWSeries[ss];
ScaleCWSeries[c_, s_CWSeries] := ScaleCWSeries[c, s] = New[CWSeries[ser],
ser[d_Integer] := ser[d] = Expand[c*s[d]]
];
CWSeries /: c_*s_CWSeries := ScaleCWSeries[c,s];
IntegrateCWSeries[cws_CWSeries, {s_, s0_, s1_}] := IntegrateCWSeries[cws, {s, s0, s1}] = New[CWSeries[ser],
ser[d_Integer] := ser[d] = Expand[(∫_s0^s1)cws[d]\[DifferentialD]s]];
CWSeries /: Integrate[cws_CWSeries, {s_, s0_, s1_}] := IntegrateCWSeries[cws, {s,s0,s1}];

tr[w_AW] := tr[w] = CW@@(RotateToMinimal@w);
tr[expr_] := expr /. aw_AW :> tr[aw];
tr[as_ASeries] := tr[as] = New[CWSeries[cws], cws[d_] := cws[d] = tr[as[d]]];

(Subscript[tr, y_LW])[ls_LieSeries] /; Deg[y]==1 := tr[σ[y, ls]];

div[LW[y_], w_LW]  := div[LW@y,w] = tr[(AW@y)**σ[LW@y,w]];
div[y_, ls_LieSeries] := div[y, ls] = New[CWSeries[cws],
cws[d_] := cws[d] = div[LW[y], ls[d]]
];
div[y_, expr_] := Expand[expr /. w_LW :> div[LW[y], w]];
(Subscript[div, y_])[expr_] := div[y, expr];

The Meta-Cocycle JA

JA[-1, ___] = MakeCWSeries[0];
JA[n_, y_LW, μ_LieSeries, ss_] := JA[n,y,μ,ss] = Module[
{s, sμ, μs},
sμ = ScaleLieSeries[s, μ];
μs=StableApply[LieMorphism[{y -> Ad[ScaleLieSeries[1,sμ]][LW[z]]}], μ];
μs = μs // LieMorphism[{LW[z] -> y}];
IntegrateCWSeries[
AddCWSeries[
JA[n-1, y, μ, s] // LieDerivation[{y -> b[μs, y]}],
div[y, μs ]
],
{s,0,ss}
]
];
JA[y_LW, μ_LieSeries] := JA[y,μ] = Module[{s}, New[CWSeries[cws],
cws[d_Integer] := cws[d] = JA[d-1, y, μ, s][d] /. s->1
]];

⟨...⟩

SetAttributes[AngleBracket, Orderless];
⟨{λ___}⟩ := ⟨λ⟩;
(*⟨x_ -> 0, rest___⟩ := ⟨x->LS[0], rest⟩;*)
Support[⟨λ___⟩] := First /@ {λ};
λ_∖key_ := DeleteCases[λ, key -> _];
λ_ ∖ keys_List := Fold[#1∖#2&, λ, keys];
(Subscript[⟨λ___⟩, s_]) := s /. {λ};
(λ_AngleBracket)[d_] := ⟨Table[u -> (Subscript[λ, u])[d],{u, Support[λ]}]⟩;
AngleBracket /: EulerE[λ_AngleBracket] := MapAt[EulerE, λ, {All,2}];
Crop[λ_AngleBracket, d_] := MapAt[Crop[#,d]&, λ, {All,2}];
AngleBracket /: λ1_AngleBracket ≡ λ2_AngleBracket /; Support[λ1]==Support[λ2] :=
And @@ Table[(Subscript[λ1, s])≡(Subscript[λ2, s]), {s, Support[λ1]}];
AngleBracket /: Plus[λs__AngleBracket] := ⟨Table[
u -> Total[(Subscript[#, u])& /@ {λs}],
{u, Union@@(Support[#]& /@ {λs})}
]⟩;
AngleBracket /: c_*λ_AngleBracket := ⟨Table[
u -> Expand[c (Subscript[λ, u])],
{u, Support[λ]}
]⟩;
AngleBracket /: λ_AngleBracket // der_LieDerivation := MapAt[der, λ, {All,2}];
AngleBracket /: λ_AngleBracket // DerivationSeries[f_, ld_LieDerivation]:= MapAt[DerivationSeries[f,ld], λ, {All,2}];
AngleBracket /: λ_AngleBracket // mor_LieMorphism := MapAt[mor, λ, {All,2}];
AngleBracket /: Integrate[λ_AngleBracket, {s_, s0_, s1_}] := ⟨Table[u -> Integrate[(Subscript[λ, u]), {s,s0,s1}],{u, Support[λ]}]⟩;
λ_AngleBracket //  DegreeScale[h_] := MapAt[DegreeScale[h], λ, {All,2}];
b[λ1_AngleBracket, λ2_AngleBracket] := ⟨Table[s -> b[(Subscript[λ1, s]), (Subscript[λ2, s])],{s, Support[λ1]⋃Support[λ2]}]⟩;
AngleBracket /: D[λ_AngleBracket, vars__] := ⟨Table[s->D[(Subscript[λ, s]), vars], {s, Support[λ]}]⟩;

Tangential Derivations (Subscript[D, λ]), the tangential bracket tb

AngleBracket /: D[λ_AngleBracket] := LieDerivation[List@@λ /. (s_->λs_):>(LW[s]->b[LW[s],λs])];
AngleBracket /: (Subscript[D, λ_AngleBracket]) := D[λ];

tb[λ1_AngleBracket, λ2_AngleBracket] := ⟨Table[
s -> b[(Subscript[λ1, s]), (Subscript[λ2, s])] + (Subscript[D, λ1])[(Subscript[λ2, s])] - (Subscript[D, λ2])[(Subscript[λ1, s])],
{s, Support[λ1]⋃Support[λ2]}
]⟩;

CC, RC, (Subscript[ad, u])

AngleBracket /: CC[⟨λ___⟩] := LieMorphism[{λ} /. (s_->λs_):>(LW[s]->Ad[λs][LW[s]])];
CC[u_, γ_] := CC[⟨u->γ⟩];
(Subscript[CC, u_])[γ_] := CC[u,γ];
RC[λ_AngleBracket] := Inverse[CC[-λ]];
RC[u_, γ_] := RC[⟨u->γ⟩];
(Subscript[RC, u_])[γ_] := RC[u,γ];
ad[u_, γ_LieSeries] := LieDerivation[u->b[γ,u]];
(Subscript[ad, u_])[γ_] := ad[u,γ];

J, div, j

(Subscript[J, u_])[γ_] := (Subscript[J, u])[γ] = Module[{s},(∫_0^1)(γ // (Subscript[RC, u])[s γ] // (Subscript[div, u]) // (Subscript[CC, u])[-s γ])\[DifferentialD]s];

J[u_, γ_] := (Subscript[J, u])[γ];

div[λ_AngleBracket] := Sum[(Subscript[div, a])[(Subscript[λ, a])], {a, Support[λ]}];
j[λ_AngleBracket] := div[λ] // DerivationSeries[(((E^der)-1)/der), (Subscript[D, λ])];

Evaluating Lie Series in ⟨…⟩

LieMorphism[rules__Rule, keys_AngleBracket, br_] := LieMorphism[{rules}, keys, br];
LieMorphism[rules_List, keys_AngleBracket, br_] := New[LieMorphism[mor],
mor[Support] = First /@ rules;
(mor[w_LW] /; Deg[w] == 1) := (mor[w] = w /. rules);
mor[w_LW] := (mor[w] = br @@ (mor /@ LyndonFactorization[w]));
mor[expr_][d_] := Expand[expr /. w_LW :> mor[w][d]];
mor[ls_LieSeries] := mor[ls] = Module[{ser},
⟨Table[
ReleaseHold[Hold[
ser[]=Hold[AngleBracketFromLieMorphism[mor, ls, ss]];
ser[d_Integer] := ser[d] = (Subscript[((∑_(k=1)^d)mor[ls[k]][d]), ss]);
ss->LieSeries[ser]
] /. {ss->s, ser -> Unique[LieSeriesInAngleBracket]}],
{s, List@@keys}
]⟩]
];

BCH[x_, y_, keys_AngleBracket, br_] := LieMorphism[{LW["x"] -> x, LW["y"] -> y}, keys, br][BCHBase];
(Subscript[BCH, br_])[λ1_AngleBracket, λ2_AngleBracket] := BCH[λ1, λ2, ⟨Support[λ1]⋃Support[λ2]⟩, br];
adSeries[f_,λ1_AngleBracket, br_][λ2_AngleBracket] := LieMorphism[{LW["x"] -> λ1, LW["y"] -> λ2}, ⟨Support[λ1]⋃Support[λ2]⟩, br][adSeries[f, LW["x"]][LW["y"]]];
adSeries[f_,λ1_AngleBracket][λ2_AngleBracket] := adSeries[f,λ1,b][λ2];

Γ and Λ

(Subscript[Γ, 0,t_])[λ_AngleBracket] := t λ;
(Subscript[Γ, n_,t_])[λ_AngleBracket] := (Subscript[Γ, n,t])[λ] = (∫_0^t)(λ // (E^(-τ (Subscript[D, λ]))) // adSeries[(ad/((E^ad)-1)), (Subscript[Γ, n-1,τ])[λ]])\[DifferentialD]τ;
(Subscript[Γ, t_])[λ_AngleBracket] := (Subscript[Γ, t])[λ] = ⟨Table[
s -> New[LieSeries[ser],
With[{s=s}, ser[d_Integer] := ser[d] = ((Subscript[(Subscript[Γ, d-1,t])[λ], s]))[d]];
],
{s, Support[λ]}
]⟩;
Γ[λ_AngleBracket] := (Subscript[Γ, 1])[λ];
(*(Subscript[Γ, -1,_])[λ_AngleBracket] := ⟨Table[s->MakeLieSeries[0], {s, Support[λ]}]⟩;*)
(*(Subscript[Γ, n_,t_])[λ_AngleBracket] := (Subscript[Γ, n,t])[λ] = Module[{τ},
(∫_0^t)(λ // (E^(-τ (Subscript[D, λ]))) // adSeries[(ad/((E^ad)-1)), (Subscript[Γ, n-1,τ])[λ]])\[DifferentialD]τ
];*)
(*(Subscript[Γ, n_,t_])[λ_AngleBracket] := (Subscript[Γ, n,t])[λ] = Module[{τ,Γ0},
Γ0=(Subscript[Γ, n-1,τ])[λ];
⟨Table[
s->(∫_0^t)((Subscript[λ, s]) // (E^(-τ (Subscript[D, λ]))) // adSeries[(ad/((E^ad)-1)), (Subscript[Γ0, s])])\[DifferentialD]τ,
{s, Support[λ]}
]⟩
];*)

(Subscript[Λ, 0,t_])[λ_AngleBracket] := t λ;
(Subscript[Λ, n_,t_])[λ_AngleBracket] := (Subscript[Λ, n,t])[λ] = Module[{τ,Λ0},
Λ0=(Subscript[Λ, n-1,τ])[λ];
(∫_0^t)(λ // (E^(Subscript[D, Λ0])) // adSeries[(ad/((E^ad)-1)), Λ0, tb])\[DifferentialD]τ
];
(Subscript[Λ, t_])[λ_AngleBracket] := (Subscript[Λ, t])[λ] = ⟨Table[
s -> New[LieSeries[ser],
With[{s=s}, ser[d_Integer] := ser[d] = ((Subscript[(Subscript[Λ, d-1,t])[λ], s]))[d]];
],
{s, Support[λ]}
]⟩;
Λ[λ_AngleBracket] := (Subscript[Λ, 1])[λ];

SeriesSolve

LS[ab_List, coefs_] := New[LieSeries[ser],
ser[setter] = Null;
ser[d_Integer, UndeterminedCoefficients] := Cases[coefs @@@ AllLyndonWords[d, ab], _coefs];
ser[d_Integer] := If[ser[setter] =!= Null,
ser[setter][d]; ser[d],
Plus @@ ((#*coefs@@#)& /@ AllLyndonWords[d, ab])
];
];
CWS[ab_List, coefs_] := New[CWSeries[ser],
ser[setter] = Null;
ser[d_Integer, UndeterminedCoefficients] := Cases[coefs @@@ AllCyclicWords[d, ab], _coefs];
ser[d_Integer] := If[ser[setter] =!= Null,
ser[setter][d]; ser[d],
Plus @@ ((#*coefs@@#)& /@ AllCyclicWords[d, ab])
];
];

Options[SeriesSolve] = {
Arbitrator -> 0, (* should be 0 or a pure function that takes a list of unsettled variables and returns a list of their arbitrated values *)
ReportArbitrations -> True
};
SeriesSolve[unknown_, eqns_, opts___] /; Head[unknown]=!=List := SeriesSolve[{unknown}, eqns, opts];
SeriesSolve[unknowns_List, eqns_, opts___] := Module[{
arbitrator = Arbitrator /. {opts} /. Options[SeriesSolve],
report = ReportArbitrations /. {opts} /. Options[SeriesSolve],
solver, lineqs, gens, vars, sol, fvars,d
},
If[arbitrator===0, arbitrator = Replace[#, _->0, 1]&];
solver[0]=Null;
solver[n_] := (
solver[n-1];
(#[setter] = Null)& /@ (First /@ unknowns);
lineqs=eqns[n];
lineqs=If[Head[lineqs]===And, List @@ lineqs, List@lineqs];
gens=Union[Cases[lineqs, _LW|_CW, ∞]];
lineqs=Flatten[Replace[lineqs ,
lhs_==rhs_ :> ((Coefficient[lhs, #]==Coefficient[rhs,#])& /@ gens),
{1}]];
vars = Union@@((#[n, UndeterminedCoefficients])& /@ unknowns);
{sol}= Quiet[Solve[lineqs, vars], {Solve::svars}];
fvars=Complement[vars, First /@ sol];
If[TrueQ[report] && fvars =!={}, Print["Arbitrator called on ", fvars, "..."]];
MapThread[(#1=#2)& , {fvars, arbitrator[fvars]}];
sol /. (Rule -> Set);
(#[n]=#[n])& /@ (First /@ unknowns);
(#[setter] = solver)& /@ (First /@ unknowns);
solver[n]=Null;
);
(#[setter] = solver)& /@ (First /@ unknowns);
];

Epilog

End[]; EndPackage[];