Free Lie Algebras Routines

Lazy Evaluation Version

Pensieve header: A free-Lie calculator with lazy evaluation for series; continues 2012-07, continued 2012-09.

Global Definitions

$SeriesShowDegree=3; $SeriesCompareDegree = 3;

Words and Lyndon Words

A Lyndon word is a word lexicographically smaller than all of its proper right factors; see http://katlas.math.toronto.edu/drorbn/AcademicPensieve/Projects/FreeLie/index.html

LyndonQ[AW[w_String]] := And @@ (
OrderedQ[{w, #}]& /@ Table[StringDrop[w,i], {i,1,StringLength[w]-1}]
);
AllWords[0, _List] = {AW[""]};
AllWords[n_ /; n>0, ab_List] := AllWords[n, ab] = AW /@ Flatten[Outer[
StringJoin[#1, #2]&,
First /@ AllWords[n-1, ab],
ab
]];
AllLyndonWords[n_Integer, ab_List] := LW @@@ Select[AllWords[n, ab], LyndonQ];
AllLyndonWords[{n_}, ab_List] := Join@@Table[AllLyndonWords[k,ab], {k,n}];
LyndonFactorization[LW[w_String] /; StringLength[w] == 1] := LW[w];
LyndonFactorization[LW[w_String] /; StringLength[w] > 1] := Module[
{rf},
rf=First[Sort[Table[StringDrop[w,i], {i,1,StringLength[w]-1}]]];
LW /@ {StringDrop[w, -StringLength[rf]], rf}
];
LW[s_Symbol] := LW[ToString[s]];
LW[LW[w_]]:=LW[w];
LW /: LW[x_] ≤ LW[y_] := OrderedQ[{x,y}];
LW /: x_LW ≥y_LW := y≤x;
LW /: x_LW > y_LW := !(x≤y);
LW /: x_LW<y_LW := !(y≤x);
Format[LW[w_], StandardForm] := Defer[⟨w⟩];
BracketForm[w_LW] /; Deg[w]==1 := w[[1]];
BracketForm[w_LW] := BracketForm[w] = StringJoin[Flatten[{
"[",
BracketForm /@ LyndonFactorization[w],
"]"
}]];
⟨w__⟩:=LW[w];
LW[is__Integer] := LW[StringJoin@@(StringTake["1234567890abcdefghijklmnopqrstuvwxyz", {#}]& /@ {is})];
Deg[LW[x_]] := StringLength[x];

{LyndonQ[AW@"abba"], LyndonQ[AW@"ababb"]}

{AllWords[3, {"1", "2"}], AllLyndonWords[{3}, {"1", "2"}]}

Table[Length[AllLyndonWords[k, {"1", "2"}]], {k,10}]

Table[Length[AllLyndonWords[k, {"1", "2", "3"}]], {k,10}]

BracketForm[LW["12122"]]

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, LW[First[w]<>First[z]],
True, Module[{x,y},
{x,y}=LyndonFactorization[w];
If[y≥z,
LW[First[w]<>First[z]],
b[x,LWAdjoint[y][z]]+b[LWAdjoint[x][z],y]
]
]
];
u
];

b[LW["112"], LW["122"]]

Outer[b, AllLyndonWords[{3}, {"1", "2"}], AllLyndonWords[{3}, {"1", "2"}]] // MatrixForm

Union[Flatten[Outer[(b[#1,#2]+b[#2,#1])&,
AllLyndonWords[{6}, {"1", "2"}], AllLyndonWords[{6}, {"1", "2"}]
]]]

Outer[(b[#1,b[#2,#3]]+b[#2,b[#3,#1]]+b[#3,b[#1,#2]])&,
AllLyndonWords[{5}, {"1", "2"}], AllLyndonWords[{5}, {"1", "2"}], AllLyndonWords[{5}, {"1", "2"}]
] // Flatten // Union

LieSeries

LieSeries[ser_Symbol][{dd_Integer}] := LS@@Table[ser[d], {d, dd}];
LieSeries[ser_Symbol][e___] := ser[e];
Format[s_LieSeries, StandardForm] := s[{$SeriesShowDegree}];
ShowLieSeries[d_Integer][s_LieSeries] := s[{d}];
MakeLieSeries[s_LieSeries] := s;
MakeLieSeries[expr_] := MakeLieSeries[expr] = MakeLieSeries[Unique[MakeLieSeries], expr];
MakeLieSeries[ser_Symbol, expr_] := (
ser[] = Hold[MakeLieSeries[ser, expr]];
ser[d_Integer] := ser[d] = Expand[expr /. w_LW /; Deg[w] ≠ d -> 0];
LieSeries[ser]
);
s1_LieSeries ≡ s2_LieSeries := And @@ ((s1[#]==s2[#])& /@ Range[$SeriesCompareDegree]);

Print /@ {ts1=⟨"1122"⟩ // MakeLieSeries, ts1[], ts1 /@ Range[6]};

AddLieSeries[ss___LieSeries] := AddLieSeries[ss] = Module[{ser},
ser=Unique[AddLieSeries];
ser[] = Hold[AddLieSeries[ss]];
ser[d_Integer] := ser[d] = Plus @@ ((#[d])& /@ {ss});
LieSeries[ser]
];
ScaleLieSeries[c_, s_LieSeries] := ScaleLieSeries[c, s] = Module[{ser},
ser=Unique[ScaleLieSeries];
ser[] = Hold[ScaleLieSeries[c,s]];
ser[d_Integer] := ser[d] = Expand[c*s[d]];
LieSeries[ser]
];
(* LieSeries /: c_*s_LieSeries := ScaleLieSeries[c,s]; *)
b[s_LieSeries, y_] := b[s, MakeLieSeries[y]];
b[x_, s_LieSeries] := b[MakeLieSeries[x], s];

b[s1_LieSeries, s2_LieSeries] := b[s1,s2] = Module[{ser},
ser=Unique[b];
ser[] = Hold[b[s1,s2]];
ser[d_Integer] := ser[d] = Sum[
b[s1[k], s2[d-k]],
{k,1,d-1}
];
LieSeries[ser]
];
b[s_LieSeries, y_] := b[s, MakeLieSeries[y]];
b[x_, s_LieSeries] := b[MakeLieSeries[x], s];

{ts2=⟨"122"⟩+⟨"11122"⟩ // MakeLieSeries, ts3=b[ts1,ts2], ts3[], ts3 /@ Range[10]}

LieSeries /: EulerE[s_LieSeries] := Module[{ser},
ser=Unique[EulerE];
ser[] = Hold[EulerE[s]];
ser[d_Integer] := ser[d] = Expand[d*s[d]];
LieSeries[ser]
];

{ts4=EulerE[ts3], ts4[], ts4 /@ Range[10]}

adPower, adSeries, and Ad

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

{xs=MakeLieSeries[LW["x"]], ys=MakeLieSeries[LW["y"]], ts5=adPower[0,xs][ys], ts5[], ts5 /@ Range[5]}

adPower[3,xs][ys] /@ Range[5]

{adSeries[E^(-ad), xs][ys] /@ Range[5], adSeries[E^(-ad), ys][xs] /@ Range[5]}

Ad[xs][ys][5]

Ad[xs][ys][]

LieDerivation, DerivationPower, DerivationSeries

LieDerivation[der_][es___] := der[es];
LieDerivation[rules_List] := LieDerivation[rules] = LieDerivation[Unique[LieDerivation], rules];
LieDerivation[der_Symbol, rules_List] := (
der[]=Hold[LieDerivation[der, 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] = Module[{ser},
ser=Unique[LieDerivationOnLieSeries];
ser[] = Hold[der[s]];
ser[d_] := ser[d] = Sum[
der[s[k]][d],
{k,1, d}
];
LieSeries[ser]
];
der[as_ASeries] := der[as] = Module[{ser},
ser=Unique[LieDerivationOnASeries];
ser[] = Hold[der[as]];
ser[d_] := ser[d] = Sum[
Expand[as[k] /. AW[w_] :> Sum[
NonCommutativeMultiply[
AW[StringTake[w, j-1]],
ι[der[LW[StringTake[w,{j}]]][d-k+1]],
AW[StringDrop[w,j]]
],
{j,k}
]],
{k,1, d}
];
ASeries[ser]
];
der[cws_CWSeries] := der[cws] = Module[{ser},
ser=Unique[LieDerivationOnCWSeries];
ser[] = Hold[der[cws]];
ser[d_] := ser[d] = Sum[
Expand[cws[k] /. CW[w_] :> Sum[
tr[NonCommutativeMultiply[
AW[StringTake[w, j-1]],
ι[der[LW[StringTake[w,{j}]]][d-k+1]],
AW[StringDrop[w,j]]
]],
{j,k}
]],
{k,1, d}
];
CWSeries[ser]
];
der[expr_][d_] := Expand[expr /. {w_LW :> der[w][d], s_LieSeries :> der[s][d]}];
LieDerivation[der]
);

Print /@ {
ld1=LieDerivation[{⟨1⟩ -> b[⟨3⟩, ⟨1⟩]}],
ld1[],
(# -> ld1[#][{4}])& /@ AllLyndonWords[{3}, {"1", "2"}],
(⟨"112"⟩ // ld1 //ld1)[{5}]
};

DerivationPower[0, der_LieDerivation][ψ_LieSeries] := DerivationPower[0,der][ψ] = Module[{ser},
ser=Unique[DerivationPower];
ser[] = Hold[DerivationPower[0,der][ψ]];
ser[d_Integer] := ser[d] = ψ[d];
LieSeries[ser]
];
DerivationPower[n_Integer, der_LieDerivation][ψ_LieSeries] := DerivationPower[n,x][ψ] = Module[{ser},
ser=Unique[DerivationPower];
ser[] = Hold[DerivationPower[n,der][ψ]];
ser[d_Integer] := ser[d] =  der[DerivationPower[n-1,der][ψ]][d];
LieSeries[ser]
];
DerivationSeries[__][0] = 0;
DerivationSeries[f_, ld_LieDerivation][ψ_LieSeries] := DerivationSeries[f, ld][ψ] = Module[{ser},
ser=Unique[DerivationSeries];
ser[] = Hold[DerivationSeries[f,ld][ψ]];
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}
]]
];
LieSeries[ser]
];
DerivationExp[ld_LieDerivation] := DerivationSeries[E^der, ld];

⟨"112"⟩ // MakeLieSeries // DerivationExp[LieDerivation[{⟨1⟩ -> b[⟨3⟩, ⟨1⟩]}]] // ShowLieSeries[6]

⟨"122"⟩ // MakeLieSeries // DerivationExp[LieDerivation[{⟨1⟩ -> b[⟨3⟩, ⟨1⟩]}]] // ShowLieSeries[6]

LieMorphism

LieMorphism[mor_][es___] := mor[es];
LieMorphism[rules_List] := LieMorphism[rules] = LieMorphism[Unique[LieMorphism], rules];
LieMorphism[mor_Symbol, rules_List] := (
mor[]=Hold[LieMorphism[mor, 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_]] /; StringLength[w] == 1) := (mor[w] = ι[MakeLieSeries[LW[w] /. rules]]);
mor[AW[w_]] := mor[w] = Module[{w1,w2},
w1=StringTake[w, Floor[StringLength[w]/2]];
w2=StringDrop[w, Floor[StringLength[w]/2]];
(mor[AW[w1]])**(mor[AW[w2]])
];
mor[CW[w_]] := tr[mor[AW[w]]];
mor[s_LieSeries] := mor[s] = Module[{ser},
ser=Unique[LieMorphismOnLieSeries];
ser[] = Hold[mor[s]];
ser[d_] := ser[d] = Sum[
mor[s[k]][d],
{k,1, d}
];
LieSeries[ser]
];
mor[cws_CWSeries] := mor[cws] = Module[{ser},
ser=Unique[LieMorphismOnCWSeries];
ser[] = Hold[mor[s]];
ser[d_] := ser[d] = Sum[
mor[cws[k]][d],
{k,1, d}
];
CWSeries[ser]
];
mor[expr_][d_] := Expand[expr /. (w_LW|w_AW|w_CW) :> mor[w][d]];
LieMorphism[mor]
);

Print /@ {
lm0=LieMorphism[{LW["x"] -> LW["y"]}],
LW["x"] // lm0,
AW["x"] // lm0,
CW["x"] // lm0};

Print /@ {
lm1=LieMorphism[{LW["x"] -> Ad[LW["y"]][LW["x"]]}],
lm1[],
lm1[LW["y"]],
lm1[LW["x"]],
lm1[LW["x"]][4],
lm1[⟨"xxy"⟩],
lm1[⟨"xxy"⟩][8],
lm1[AW["x"]],
lm1[CW["x"]]
};

StableApply

StableApply[mor_LieMorphism, (type:(LieSeries|ASeries|CWSeries))[s_]] := (
StableApply[mor, type[s]] = Module[{ser},
ser=Unique[StableApply];
ser[] = Hold[StableApply[mor, type[s]]];
ser[d_] := ser[d] = Nest[mor, type[s], d][d];
type[ser]
]
);

BCH

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

{BCHBase, BCHBase[], BCHBase[8]}

{BCH[LW["y"], LW["z"]], BCH[LW["y"], LW["z"]][6]}

{
t1=BCH[LW["x"], BCH[LW["y"], LW["z"]]],
t2=BCH[BCH[LW["x"], LW["y"]], LW["z"]],
t1==t2,
Table[t1[d]==t2[d], {d,10 }]
} // Timing

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[AW[w_]] := StringLength[w];
AW[AW[w_]]:=AW[w];
AW[w1_String] ** AW[w2_String] := 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] = MakeCWSeries[Unique[MakeASeries], expr];
MakeASeries[ser_Symbol, expr_] := (
ser[] = Hold[MakeASeries[ser, expr]];
ser[d_Integer] := ser[d] = Expand[expr /. w_AW /; Deg[w] ≠ d -> 0];
ASeries[ser]
);
(s1_ASeries ** s2_ASeries) := (s1**s2) = Module[{ser},
ser=Unique[NonCommutativeMultiply];
ser[] = Hold[s1**s2];
ser[d_Integer] := ser[d] = Sum[
s1[k]**s2[d-k],
{k,0,d}
];
ASeries[ser]
];

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

ι[BCHBase[3]]

{as=ι[BCHBase], as[5]}

σ[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] = Module[{as},
as=Unique[σ];
as[] = Hold[σ[y,ls]];
as[d_] := as[d] = σ[LW[y], ls[d+1]];
ASeries[as]
];
σ[y_, expr_] := Expand[expr /. w_LW :> σ[LW[y], w]];

(#->σ[1, #])& /@ AllLyndonWords[{5}, {"1","2"}]

{σ["x", BCHBase][5], σ["y", BCHBase][5]}

CW, CWSeries, tr, div

Deg[CW[w_]] := StringLength[w];
CWSeries[cws_Symbol][es___] := cws[es];
CWSeries[ser_Symbol][{dd_Integer}] := CWS@@Table[ser[d], {d, dd}];
Format[s_CWSeries, StandardForm] := s[{$SeriesShowDegree}];
MakeCWSeries[cws_CWSeries] := cws;
MakeCWSeries[expr_] := MakeCWSeries[expr] = MakeCWSeries[Unique[MakeCWSeries], expr];
MakeCWSeries[ser_Symbol, expr_] := (
ser[] = Hold[MakeCWSeries[ser, expr]];
ser[d_Integer] := ser[d] = Expand[expr /. w_CW /; Deg[w] ≠ d -> 0];
CWSeries[ser]
);
s1_CWSeries ≡ s2_CWSeries := And @@ ((s1[#]==s2[#])& /@ Range[$SeriesCompareDegree]);
AddCWSeries[ss___CWSeries] := AddCWSeries[ss] = Module[{ser},
ser=Unique[AddCWSeries];
ser[] = Hold[AddCWSeries[ss]];
ser[d_Integer] := ser[d] = Plus @@ ((#[d])& /@ {ss});
CWSeries[ser]
];
ScaleCWSeries[c_, s_LieSeries] := ScaleCWSeries[c, s] = Module[{ser},
ser=Unique[ScaleCWSeries];
ser[] = Hold[ScaleCWSeries[c,s]];
ser[d_Integer] := ser[d] = Expand[c*s[d]];
CWSeries[ser]
];
(* CWSeries /: c_*s_CWSeries := ScaleCWSeries[c,s]; *)
IntegrateCWSeries[cws_CWSeries, {s_, s0_, s1_}] := IntegrateCWSeries[cws, {s, s0, s1}] = Module[{ser},
ser=Unique[IntegrateCWSeries];
ser[]=Hold[IntegrateCWSeries[cws, {s, s0, s1}]];
ser[d_Integer] := ser[d] = Expand[Integrate[cws[d], {s,s0,s1}]];
CWSeries[ser]
];

tr[w_AW] := tr[w] = CW[RotateToMinimal@@w];
tr[expr_] := expr /. aw_AW :> tr[aw];
tr[as_ASeries] := tr[as] = Module[{cws},
cws=Unique[tr];
cws[] = Hold[tr[as]];
cws[d_] := cws[d] = tr[as[d]];
CWSeries[cws]
];

tr[AW["yxxyxx"]]

t1=σ["y", BCHBase] //tr

t1[5]

div[y_LW, w_LW] /; Deg[y]==1 := div[y,w] = tr[(AW@@y)**σ[y,w]];
div[y_, ls_LieSeries] := div[y, ls] = Module[{cws},
cws=Unique[div];
cws[] = Hold[div[y,ls]];
cws[d_] := cws[d] = div[LW[y], ls[d]];
CWSeries[cws]
];
div[y_, expr_] := Expand[expr /. w_LW :> div[LW[y], w]];

{div["x", BCHBase][7], div["y", BCHBase][7]}

t1=MakeCWSeries[CW["xyxyyyy"]] // LieDerivation[{LW["x"] -> MakeLieSeries[b[LW["x"], LW["z"]]]}]

t1 /@ Range[10]

The Meta-Cocycle J

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

Print /@ {y0=LW["y"], μ0=BCHBase,
J[0,y0,μ0, s],
J[1,y0,μ0, s],
J[2,y0,μ0, s],
J[y0, μ0]
};

CWS[s CW["y"],(1/2) s CW["xy"]+(1/2) (s^2) CW["xy"],(1/12) s CW["xxy"]+(1/4) (s^2) CW["xxy"]+(1/6) (s^3) CW["xxy"]-(1/12) s CW["xyy"]-(1/4) (s^2) CW["xyy"]-(1/6) (s^3) CW["xyy"]] /. s->1

$SeriesCompareDegree=$SeriesShowDegree=8;
J[3,y0,μ0, s]≡J[4,y0,μ0, s]

J[y0, μ0][6]