Function Repository Resource:

BakerCampbellHausdorffTerms

Source Notebook

Generate terms in the Baker–Campbell–Hausdorff expansion

Contributed by: Mohammad Bahrami

ResourceFunction["BakerCampbellHausdorffTerms"][{op1,op2,,opm},n]

generates the order-n term of the Baker-Campbell-Hausdorff expansion of operators {op1,op2,,opm}.

ResourceFunction["BakerCampbellHausdorffTerms"][{op1,op2,,opm},n,alg]

generates the order-n term of the Baker-Campbell-Hausdorff expansion of operators {op1,op2,,opm}, where alg can be a NonCommutativeAlgebra object, {Dot,n},Dot,Composition,TensorProduct or NonCommutativeMultiply.

Details and Options

The Baker-Campbell-Hausdorff (BCH) expansion is defined as with alg as the underlying operation between the non-commutative operators opi. The degree-n term in the BCH expansion is the part that involves n Lie algebra elements combined through n-1 nested commutators and coefficients.
The BCH formula solves eXeY=eZ for noncommutative operators X and Y in a Lie algebra.
The BCH expansion is the sum of terms over n.
If the algebra argument is omitted, NonCommutativeAlgebra with the default property values is used.
ResourceFunction["BakerCampbellHausdorffTerms"] take the following option:
"CommutatorForm"Falsewhen True, it will hold the commutator form, otherwise it will compute the commutation.

For example, for two operators, the commutator form follows the formula where is iterative j commutation

ResourceFunction["BakerCampbellHausdorffTerms"] requires version 14.3 or higher of the Wolfram Language.

Examples

Basic Examples (7) 

Generate the first-order term of the Baker–Campbell–Hausdorff formula for two operators:

In[1]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 1]
Out[1]=

Generate the second-order term of the Baker–Campbell–Hausdorff formula for two operators:

In[2]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 2]
Out[2]=

Show the formula in the commutator form:

In[3]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 2, "CommutatorForm" -> True] // TraditionalForm
Out[3]=

Release the commutator form and show the expanded formula:

In[4]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 2, "CommutatorForm" -> True] // ReleaseHold
Out[4]=

Generate the third-order term of the Baker–Campbell–Hausdorff formula for two operators:

In[5]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3] // NonCommutativeExpand
Out[5]=

Show the formula in the commutator form:

In[6]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3, "CommutatorForm" -> True] // TraditionalForm
Out[6]=

Verify explicitly that the two results above are identical:

In[7]:=
Nest[ReleaseHold, ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3, "CommutatorForm" -> True], 2] - ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3] // NonCommutativeExpand
Out[7]=

Show that the result is identical to :

In[8]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3] - 1/12 (Commutator[x, Commutator[x, y]] - Commutator[y, Commutator[x, y]]) // NonCommutativeExpand
Out[8]=

Generate the fourth-order Baker–Campbell–Hausdorff term for two operators:

In[9]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4] // NonCommutativeExpand
Out[9]=

Show that the result is identical to :

In[10]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4] - (-(1/24) Commutator[x, Commutator[y, Commutator[x, y]]]) // NonCommutativeExpand
Out[10]=

Show that the result is identical to :

In[11]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4] - (-(1/24) Commutator[y, Commutator[x, Commutator[x, y]]]) // NonCommutativeExpand
Out[11]=

Compute the fourth-order Baker–Campbell–Hausdorff term for two operators in commutator form:

In[12]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4, "CommutatorForm" -> True] // TraditionalForm
Out[12]=

Verify explicitly that the results above are identical:

In[13]:=
Nest[ReleaseHold, ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4, "CommutatorForm" -> True], 3] - ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 4] // NonCommutativeExpand
Out[13]=

Compute the second-order Baker–Campbell–Hausdorff term for three symbolic matrices:

In[14]:=
ResourceFunction["BakerCampbellHausdorffTerms"][
  Table[MatrixSymbol["x" <> ToString[j], \[FormalN]], {j, 3}], 2, Dot] // NonCommutativeExpand[#, Dot] &
Out[14]=

Compute the third-order Baker–Campbell–Hausdorff term for three operators with Composition as the action:

In[15]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y, w}, 3, Composition] // NonCommutativeExpand[#, Composition] &
Out[15]=

Compute the third-order Baker–Campbell–Hausdorff term for two operators with NonCommutativeMultiply as the action between operators:

In[16]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3, NonCommutativeMultiply] // NonCommutativeExpand[#, NonCommutativeMultiply] &
Out[16]=

Show the third-order Baker–Campbell–Hausdorff term for four operators with Dot as the action between operators:

In[17]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y, z, w}, 3, Dot] // NonCommutativeExpand[#, Dot] &
Out[17]=

Scope (2) 

Show a few terms of Baker-Campbell-Hausdorff formula 𝒵=Log(ⅇX1X2…ⅇXn) with three non-commutative operators Xj:

In[18]:=
With[{ops = Table[ToString[Subscript[x, j], StandardForm], {j, 3}]},
 Grid[Table[{ToString[Subscript[\[ScriptCapitalZ], j], StandardForm], ResourceFunction["BakerCampbellHausdorffTerms"][ops, j, Dot] // NonCommutativeExpand[#, Dot] &}, {j, 4}], Frame -> All, Alignment -> Left]]
Out[18]=

Show the commutator form of 𝒵=Log(ⅇX1X2):

In[19]:=
Grid[Table[{ToString[Subscript[\[ScriptCapitalZ], j], StandardForm], ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, j, "CommutatorForm" -> True] // TraditionalForm}, {j, 5}], Frame -> All, Alignment -> Left]
Out[19]=

Options (2) 

Show the third-order Baker–Campbell–Hausdorff term for two operators while preserving the commutator form:

In[20]:=
ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, 3, "CommutatorForm" -> True] // TraditionalForm
Out[20]=

Show the second-order Baker–Campbell–Hausdorff term for four symbolic matrices in commutator form:

In[21]:=
ResourceFunction["BakerCampbellHausdorffTerms"][
  Table[MatrixSymbol["x" <> ToString[j], \[FormalN]], {j, 4}], 2, Dot,
   "CommutatorForm" -> True] // TraditionalForm
Out[21]=

Applications (19) 

Annihilation and creation operators: (5) 

The single-mode photon field satisfies the Bosonic commutation relation.

For the expression , compute the second-order term in the Baker–Campbell–Hausdorff series:

In[22]:=
ResourceFunction[
 "BakerCampbellHausdorffTerms"][{\[Mu] a, \[Nu] SuperDagger[a]}, 2]
Out[22]=

Define a function that simplifies an noncommutative polynomial in a and a:

In[23]:=
ClearAll[NCPolynomialReductionBosonic]
NCPolynomialReductionBosonic[exp_, scalars_ : {}] := NonCommutativePolynomialReduce[
   exp, {Commutator[a, SuperDagger[a]] - 1}, {a, SuperDagger[a]}, NonCommutativeAlgebra[<|"ScalarVariables" -> scalars|>]][[-1]]

Reduce (simplify) it:

In[24]:=
NCPolynomialReductionBosonic[%, {\[Mu], \[Nu]}]
Out[24]=

Compute the third-order term of the Baker–Campbell–Hausdorff series:

In[25]:=
ResourceFunction[
 "BakerCampbellHausdorffTerms"][{\[Mu] a, \[Nu] SuperDagger[a]}, 3]
Out[25]=

Reduce it:

In[26]:=
NCPolynomialReductionBosonic[%, {\[Mu], \[Nu]}]
Out[26]=

Likewise, the higher order terms disappear as well. Thus one finds: .

Canonical position and momentum (4) 

Define canonical position and momentum operators and :

In[27]:=
q = (a + SuperDagger[a])/Sqrt[2]; p = (a - SuperDagger[a])/(I Sqrt[2]);

Verify :

In[28]:=
NCPolynomialReductionBosonic@Commutator[q, p]
Out[28]=

Compute the second-order term of the Baker–Campbell–Hausdorff series for :

In[29]:=
NCPolynomialReductionBosonic[
 ResourceFunction[
  "BakerCampbellHausdorffTerms"][{I \[Alpha] q, I \[Beta] p}, 2], {\[Alpha], \[Beta]}]
Out[29]=

Show that the higher-order terms are zero:

In[30]:=
Table[NCPolynomialReductionBosonic[
  ResourceFunction[
   "BakerCampbellHausdorffTerms"][{I \[Alpha] q, I \[Beta] p}, n], {\[Alpha], \[Beta]}], {n, 3, 6}]
Out[30]=

Thus it means .

Displacement operator (3) 

With the displacement operator as 𝒟(α)=α a-α*a, show that .

Compute the second-order term of the Baker–Campbell–Hausdorff series:

In[31]:=
NCPolynomialReductionBosonic[
 ResourceFunction[
  "BakerCampbellHausdorffTerms"][{\[Alpha] SuperDagger[a] - Conjugate[\[Alpha]] a, \[Beta] SuperDagger[a] - Conjugate[\[Beta]] a}, 2], {\[Alpha], \[Beta]}]
Out[31]=

Show that the higher-order Baker–Campbell–Hausdorff terms vanish:

In[32]:=
Table[NCPolynomialReductionBosonic[
  ResourceFunction[
   "BakerCampbellHausdorffTerms"][{\[Alpha] SuperDagger[a] - Conjugate[\[Alpha]] a, \[Beta] SuperDagger[a] - Conjugate[\[Beta]] a}, n], {\[Alpha], \[Beta]}], {n, 3, 6}]
Out[32]=

Compute the second through fifth terms in the BCH series of 𝒟(α1)𝒟(α2)𝒟(α3) and verify :

In[33]:=
Table[NCPolynomialReductionBosonic[
  ResourceFunction["BakerCampbellHausdorffTerms"][
   Table[Subscript[\[Alpha], j] SuperDagger[a] - Conjugate[Subscript[\[Alpha], j]] a, {j, 3}], n], Table[Subscript[\[Alpha], j] , {j, 3}]], {n, 2, 5}]
Out[33]=

SU(2) spin rotations (4) 

Set up the variables and their SU(2) algebra[Ji,Jj]=ⅈϵijkJk with ϵ the 3-dimensional Levi-Civita totally antisymmetric tensor. Note that in our relations we do not include quadratic identities such as Jj2=𝕀, because these are representation-dependent (e.g., for Pauli matrices) rather than algebraic identities.

Given the algebra and variables, define a function to reduce a polynomial in Jj (Cartesian basis):

In[34]:=
ClearAll[NCPolynomialReductionSU2]
NCPolynomialReductionSU2[exp_, vars_, scalars_ : {}, scale_ : 1] /; Length[vars] == 3 := NonCommutativePolynomialReduce[exp, DeleteCases[0]@
    Flatten@(Outer[Commutator, vars, vars] - I scale TensorContract[
         TensorProduct[LeviCivitaTensor[3], vars], {{3, 4}}]), {vars},
    NonCommutativeAlgebra[<|"ScalarVariables" -> scalars|>]][[-1]]

Consider the relation Log[-δt θ1J1-δt θ2J2]=-δt Heff. Our goal to find effective Hamiltonian describing the above rotations. We will use rotation angles θj and also time variable δt. We should set them as scalar variable in the algebra.

Define noncommutative variables and scalars:

In[35]:=
vars = Table[Subscript[J, j], {j, 3}];
scalars = Append[Table[Subscript[\[Theta], j], {j, 3}], \[Delta]t];

Compute the second-order Baker–Campbell–Hausdorff term for -δt θ1J1-δt θ2J2:

In[36]:=
NCPolynomialReductionSU2[#, vars, scalars] &@
 ResourceFunction[
  "BakerCampbellHausdorffTerms"][{-I \[Delta]t Subscript[\[Theta], 1]
     Subscript[J, 1], -I \[Delta]t Subscript[\[Theta], 2] Subscript[J,
     2]}, 2]
Out[36]=

Compute Heff up to the second order of δt:

In[37]:=
Sum[NCPolynomialReductionSU2[
    ResourceFunction[
     "BakerCampbellHausdorffTerms"][{-I \[Delta]t Subscript[\[Theta], 1] Subscript[J, 1], -I \[Delta]t Subscript[\[Theta], 2]
        Subscript[J, 2]}, n], vars, scalars], {n, 3}]/(-I \[Delta]t) // Expand
Out[37]=

Numerical example (3) 

Consider xy=A with , .

Compute the first 10 terms of the Baker–Campbell–Hausdorff series for A:

In[38]:=
x = \[Alpha] PauliMatrix[3]; y = {{0, \[Beta]}, {0, 0}};
A = Sum[ResourceFunction["BakerCampbellHausdorffTerms"][{x, y}, n, Dot], {n, 11}];
A // MatrixForm
Out[40]=

For A12 element of the matrix, show that the Taylor series of the function below matches the result above:

In[41]:=
Normal[\[Beta] Series[(2 \[Alpha])/(
    1 - Exp[-2 \[Alpha]]), {\[Alpha], 0, 10}]] == A[[1, 2]]
Out[41]=

Therefore, one gets

Publisher

Mads Bahrami

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.2.0 – 17 November 2025
  • 1.1.0 – 29 October 2025
  • 1.0.0 – 23 July 2025

Source Metadata

Related Resources

License Information