(* ::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\\People\\Kuno"];
<< FreeLie.m


(* ::Input::Initialization:: *)
Basis[n_,m_]:=Union@@Table[DK[j,#]&/@AllLyndonWords[m,Range[j-1]],{j,2,n}]


(* ::Input::Initialization:: *)
Subscript[d, n_][\[ScriptCapitalE]_]:=Expand[\[ScriptCapitalE]/.dk_DK:>Plus[
dk^\[Sigma]@@Range[2,n+1],
Sum[(-1)^i dk^Join[\[Sigma]@@Range[i-1],\[Sigma][{i,i+1}],\[Sigma]@@Range[i+2,n+1]],{i,n}],
(-1)^(n+1) dk
]]


(* ::Input::Initialization:: *)
r[n_,m_]:=r[n,m]=Module[{dk,B0,B1,b0,b1,db0,mat},
B0=Basis[n,m];
If[B0=={},Return[0]];
B1=Basis[n+1,m]/.DK->dk;
mat=Table[
db0=Subscript[d, n][b0]/.DK->dk/.dk[k_,x_Plus]:>(dk[k,#]&/@x)/.dk[k_,c_?NumberQ*x_]:>c*dk[k,x];
Table[Coefficient[db0,b1],{b1,B1}],
{b0,B0}
];
MatrixRank[mat]
]


(* ::Input::Initialization:: *)
Betti[n_,m_]:=Length[Basis[n,m]]-r[n-1,m]-r[n,m]



