Function Repository Resource:

BakerCampbellHausdorffTerms (1.1.0) current version: 1.2.0 »

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 (6) 

Order-1 of Baker-Campbell-Hausdorff formula for two operators:

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

Order-2 of 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]=

Order-3 of 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 the two above results are the same:

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

Show the final result is the same as :

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

Order-4 of Baker-Campbell-Hausdorff formula for two operators:

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

Verify explicitly the two above results are the same:

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

Show the final result is the same as :

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

Order-2 of Baker-Campbell-Hausdorff formula for three symbolic matrices:

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

Order-3 of Baker-Campbell-Hausdorff formula for three operators with Composition as the action:

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

Scope (2) 

Order-3 of Baker-Campbell-Hausdorff formula with NonCommutativeMultiply as the action between operators:

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

Show order-3 of Baker-Campbell-Hausdorff formula, for four operators:

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

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

In[19]:=
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[19]=

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

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

Options (2) 

Show order-3 of Baker-Campbell-Hausdorff formula for two operators by holding the commutator form:

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

Show order-2 of Baker-Campbell-Hausdorff formula for four symbolic matrices by holding the commutator form:

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

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