User manual for bch, a program for the fast computation of the Baker-Campbell-Hausdorff and similar series
aa r X i v : . [ c s . M S ] F e b User manual for bch , a program for the fast computation of theBaker–Campbell–Hausdorff and similar series
Harald Hofst¨atter
Reitschachersiedlung 4/6, 7100 Neusiedl am See, Austria [email protected]
Abstract
This manual describes bch , an efficient program written in the C programming languagefor the fast computation of the Baker–Campbell–Hausdorff (BCH) and similar Lie series.The Lie series can be represented in the Lyndon basis, in the classical Hall basis, or in theright-normed basis of E.S. Chibrikov. In the Lyndon basis, which proves to be particularlyefficient for this purpose, the computation of 111 013 coefficients for the BCH series up toterms of degree 20 takes less than half a second on an ordinary personal computer andrequires negligible 11 MB of memory. Up to terms of degree 30, which is the maximumdegree the program can handle, the computation of 74 248 451 coefficients takes 55 hours butstill requires only a modest 5.5 GB of memory.
We consider the element H = log(e A e B ) = ∞ X k =1 ( − k +1 k (cid:0) e A e B − (cid:1) k = ∞ X k =1 ( − k +1 k (cid:18) X i + j> i ! j ! A i B j (cid:19) k (1)in the ring Q hh A , B ii of formal power series in the non-commuting variables A and B withrational coefficients. This element H is commonly called the Baker–Campbell–Hausdorff(BCH) series. A classical result known as the Baker–Campbell–Hausdorff theorem (see,e.g., [5]) states that H is a Lie series, which means that the homogeneous components H n ofdegree n = 1 , , . . . in H = ∞ X n =1 H n , (2)can be written as linear combinations of A and B and (possibly nested) commutator terms in A and B , i.e., they are elements of the free Lie algebra L Q ( A , B ) generated by A and B .The program bch computes the terms of the Lie series H up to terms of a given maximaldegree N , where H (or more precisely, each component H n , n = 1 , . . . , N ) is optionallyrepresented in the Lyndon basis, the right-normed basis of E.S. Chibrikov [2], or the classicalHall basis. Furthermore, the program can straightforwardly be extended to compute therepresentation in an arbitrary generalized Hall basis.In addition to H = log(e A e B ), the program bch can compute the Lie series also for ex-pressions like the symmetric BCH series log(e A e B e A ), the BCH series with 3 generatorslog(e A e B e C ), or the more complex expression log(e B e A e B + [ B, [ A,B ] e A e B ) with a commu-tator in an exponential. The program can straightforwardly be extended to handle arbitraryexpressions of the form X = log(e Φ s · · · e Φ ) , (3)1here the Φ i are Lie polynomials with rational coefficients in two or more non-commutingvariables. Here we only describe the main ideas on which the implementation of bch is based, detailswill be available in [8].The program bch is implemented in the C programming language according to the C99(or later) standard. It uses khash.h from the klib library [10], which is a very efficientimplementation of hash tables. Apart from khash.h it is self-contained, i.e., independent ofexternal libraries except the standard C library.In particular, the program uses no library for multi-precision integer or rational arith-metic. Instead all calculations are carried out in pure integer arithmetic using the 128 bitinteger type __int128_t , which is available for most current C compilers on current hard-ware. With this integer type computations of the BCH series up to degree N = 30 arepossible. To avoid calculations with rational numbers, the program first determines a com-mon denominator for all rational numbers that can occur during the computation (see [6],[7]), then all calculations are reorganized in such a way that they can actually be carried outin pure integer arithmetic.In a preliminary step, the program computes the coefficients of all Lyndon words up todegree N in the power series of the given expression X of the form (3) using an adaptationof the algorithm from [9]. In the special case X = log(e A e A ) it alternatively uses the algo-rithm from the appendix of [7] and exploits the symmetry that the coefficient of the word A q B q · · · ( A ∨ B ) q m is invariant under permutations of the exponents q , . . . , q m , see [4].Next, the program transforms the coefficients of the Lyndon words into coefficients of Liebasis elements in the Lie series. For the Lyndon basis and the right-normed Chibrikov basisthis is done by solving a linear system whose matrix consists of coefficients of Lyndon wordsin basis elements.In the Lyndon basis case this matrix with integer entries is triangular with all diagonalelements equal 1, which is a consequence of [11, Theorem 5.1]. Thus, this integer systemis readily solved in integer arithmetic with no further denominators introduced. Here theperformance bottleneck is actually the computation of the coefficient matrix, for which a newefficient algorithm has been developed, for details see [8].In the right-normed Chibrikov basis case, the coefficient matrix is no longer triangular,but it still has determinant ±
1, and its leading principal minors are all equal ±
1. It followsthat the matrix has a LU -decomposition with triangular matrices L , U whose entries areall integers and whose diagonal elements are equal ±
1. This LU -decomposition can becomputed in pure integer arithmetic using Gaussian elimination without any row or columnpermutations. Again solving such a linear system introduces no further denominators.In the Hall basis case, the program first computes the representation of the Lie seriesin the Lyndon basis, and then uses a standard rewriting algorithm (see [11, Section 4.2])applied to the Lyndon basis elements to obtain a representation in the Hall basis. Becausethis rewriting algorithm is carried out in integer arithmetic, again no further denominatorsare introduced.The special case X = log(e A e B ) allows a significant optimization in the Lyndon basis orright-normed Chibrikov basis case, if N is even: Here the Lie series is computed using theabove method only up to terms of degree N −
1. The terms of degree N can then efficientlybe computed using a formula due to E. Eriksen, see [3, Section III.A]. Note that this formula is applicable only if N is even, so that, unfortunately, this idea cannot be applied
2s a final remark on the implementation we note that the computation can be organized insuch a way that homogeneous components H ( a,b ) of H are computed completely independentlyof each other. Here a finely homogeneous component H ( a,b ) of multi-degree ( a, b ) is of degree a in A and of degree b in B such that H n = X a + b = n H ( a,b ) . Thus, the computations of these components can be done in parallel, giving a simple buteffective parallelization strategy, which has been implemented using OpenMP.
The source code can be downloaded from the GitHub repository https://github.com/HaraldHofstaetter/BCH
On a Unix-like system with gcc compiler available just type $ make in a directory containing the source code, which causes the shared library libbch.so and theexecutable bch to be created. To use a different compiler, the
Makefile has to be adaptedaccordingly. bch program
The program invoked without any arguments produces the following output: $ ./bch+1/1*A+1/1*B+1/2*[A,B]+1/12*[A,[A,B]]+1/12*[[A,B],B]+1/24*[A,[[A,B],B]]-1/720*[A,[A,[A,[A,B]]]]+1/180*[A,[A,[[A,B],B]]]+1/360*[[A,[A,B]],[A,B]]+1/180*[A,[[[A,B],B],B]]+1/120*[[A,B],[[A,B],B]]-1/720*[[[[A,B],B],B],B]
This is the BCH series (i.e., the Lie series for log(e A e B )) up to terms of degree N = 5represented in the Lyndon basis.Arguments have the form parameter=value Such arguments may be combined arbitrarily. The following parameters are available (withdefault values in square brackets):
N[=5]
The maximal degree up to which the Lie series is computed. recursively. ./bch N=8+1/1*A+1/1*B+1/2*[A,B]+1/12*[A,[A,B]]+1/12*[[A,B],B]+1/24*[A,[[A,B],B]]-1/720*[A,[A,[A,[A,B]]]]+1/180*[A,[A,[[A,B],B]]]+1/360*[[A,[A,B]],[A,B]]+1/180*[A,[[[A,B],B],B]]+1/120*[[A,B],[[A,B],B]]-1/720*[[[[A,B],B],B],B]-1/1440*[A,[A,[A,[[A,B],B]]]]+1/720*[A,[[A,[A,B]],[A,B]]]+1/360*[A,[A,[[[A,B],B],B]]]+1/240*[A,[[A,B],[[A,B],B]]]-1/1440*[A,[[[[A,B],B],B],B]]+1/30240*[A,[A,[A,[A,[A,[A,B]]]]]]-1/5040*[A,[A,[A,[A,[[A,B],B]]]]]+1/10080*[A,[A,[[A,[A,B]],[A,B]]]]+1/3780*[A,[A,[A,[[[A,B],B],B]]]]+1/10080*[[A,[A,[A,B]]],[A,[A,B]]]+1/1680*[A,[A,[[A,B],[[A,B],B]]]]+1/1260*[A,[[A,[[A,B],B]],[A,B]]]+1/3780*[A,[A,[[[[A,B],B],B],B]]]+1/2016*[[A,[A,B]],[A,[[A,B],B]]]-1/5040*[[[A,[A,B]],[A,B]],[A,B]]+13/15120*[A,[[A,B],[[[A,B],B],B]]]+1/10080*[[A,[[A,B],B]],[[A,B],B]]-1/1512*[[A,[[[A,B],B],B]],[A,B]]-1/5040*[A,[[[[[A,B],B],B],B],B]]+1/1260*[[A,B],[[A,B],[[A,B],B]]]-1/2016*[[A,B],[[[[A,B],B],B],B]]-1/5040*[[[A,B],B],[[[A,B],B],B]]+1/30240*[[[[[[A,B],B],B],B],B],B]+1/60480*[A,[A,[A,[A,[A,[[A,B],B]]]]]]-1/15120*[A,[A,[A,[[A,[A,B]],[A,B]]]]]-1/10080*[A,[A,[A,[A,[[[A,B],B],B]]]]]+1/20160*[A,[[A,[A,[A,B]]],[A,[A,B]]]]-1/20160*[A,[A,[A,[[A,B],[[A,B],B]]]]]+1/2520*[A,[A,[[A,[[A,B],B]],[A,B]]]]+23/120960*[A,[A,[A,[[[[A,B],B],B],B]]]]+1/4032*[A,[[A,[A,B]],[A,[[A,B],B]]]]-1/10080*[A,[[[A,[A,B]],[A,B]],[A,B]]]+13/30240*[A,[A,[[A,B],[[[A,B],B],B]]]]+1/20160*[A,[[A,[[A,B],B]],[[A,B],B]]]-1/3024*[A,[[A,[[[A,B],B],B]],[A,B]]]-1/10080*[A,[A,[[[[[A,B],B],B],B],B]]]+1/2520*[A,[[A,B],[[A,B],[[A,B],B]]]]-1/4032*[A,[[A,B],[[[[A,B],B],B],B]]]-1/10080*[A,[[[A,B],B],[[[A,B],B],B]]]+1/60480*[A,[[[[[[A,B],B],B],B],B],B]] basis[=0] With default value basis=0 the result is represented in the Lyndon basis; with value basis=1 in the right-normed Chibrikov basis: $ ./bch basis=1+1/1*A+1/1*B-1/2*[B,A]-1/12*[A,[B,A]]+1/12*[B,[B,A]]+1/24*[B,[A,[B,A]]]+1/720*[A,[A,[A,[B,A]]]]-1/360*[B,[A,[A,[B,A]]]]+1/120*[A,[B,[A,[B,A]]]]-1/120*[B,[B,[A,[B,A]]]]+1/360*[A,[B,[B,[B,A]]]]-1/720*[B,[B,[B,[B,A]]]]
With value basis=2 the result is represented in the classical Hall basis: $ ./bch basis=2+1/1*A+1/1*B-1/2*[B,A]+1/12*[[B,A],A]-1/12*[[B,A],B]+1/24*[[[B,A],A],B]-1/720*[[[[B,A],A],A],A]-1/180*[[[[B,A],A],A],B]+1/180*[[[[B,A],A],B],B]+1/720*[[[[B,A],B],B],B]-1/120*[[[B,A],A],[B,A]]-1/360*[[[B,A],B],[B,A]] generators[=ABC...]
This parameter enables alternative names for the generators: $ ./bch generators=xy+1/1*x+1/1*y+1/2*[x,y]+1/12*[x,[x,y]]+1/12*[[x,y],y]+1/24*[x,[[x,y],y]]-1/720*[x,[x,[x,[x,y]]]]+1/180*[x,[x,[[x,y],y]]]+1/360*[[x,[x,y]],[x,y]]+1/180*[x,[[[x,y],y],y]]+1/120*[[x,y],[[x,y],y]]-1/720*[[[[x,y],y],y],y] expression[=0] • expression=0 – compute Lie series for log(e A e B ), the classical BCH formula. • expression=1 – compute Lie series for log(e A e B e A ), the symmetric BCH formula: $./bch expression=1+1/1*A+1/1*B-1/24*[A,[A,B]]+1/12*[[A,B],B]+7/5760*[A,[A,[A,[A,B]]]]-7/1440*[A,[A,[[A,B],B]]]+1/360*[[A,[A,B]],[A,B]]+1/180*[A,[[[A,B],B],B]]+1/120*[[A,B],[[A,B],B]]-1/720*[[[[A,B],B],B],B] expression=2 – compute Lie series for log(e A e B e A ), another symmetric version of the BCHformula: $./bch expression=2+2/1*A+1/1*B-1/6*[A,[A,B]]+1/6*[[A,B],B]+7/360*[A,[A,[A,[A,B]]]]-7/180*[A,[A,[[A,B],B]]]+1/45*[[A,[A,B]],[A,B]]+1/45*[A,[[[A,B],B],B]]+1/30*[[A,B],[[A,B],B]]-1/360*[[[[A,B],B],B],B] • expression=3 – compute Lie series for log(e A e B e C ), a BCH formula with three differentexponentials: $./bch expression=3 N=4+1/1*A+1/1*B+1/1*C+1/2*[A,B]+1/2*[A,C]+1/2*[B,C]+1/12*[A,[A,B]]+1/12*[A,[A,C]]+1/12*[[A,B],B]+1/3*[A,[B,C]]+1/6*[[A,C],B]+1/12*[[A,C],C]+1/12*[B,[B,C]]+1/12*[[B,C],C]+1/24*[A,[[A,B],B]]+1/12*[A,[A,[B,C]]]+1/12*[A,[[A,C],B]]+1/24*[A,[[A,C],C]]+1/12*[A,[B,[B,C]]]+1/12*[[A,[B,C]],B]+1/12*[A,[[B,C],C]]+1/12*[[A,C],[B,C]]+1/24*[B,[[B,C],C]] • expression=4 – compute Lie series for log(e A e B e − A e − B ): $./bch expression=4+1/1*[A,B]+1/2*[A,[A,B]]-1/2*[[A,B],B]+1/6*[A,[A,[A,B]]]-1/4*[A,[[A,B],B]]+1/6*[[[A,B],B],B]+1/24*[A,[A,[A,[A,B]]]]-1/12*[A,[A,[[A,B],B]]]+1/12*[[A,[A,B]],[A,B]]+1/12*[A,[[[A,B],B],B]]-1/24*[[[[A,B],B],B],B] • expression=5 : – compute Lie series for log(e B e A e B + [ B, [ A,B ] e A e B ), a more compli-cated version of the BCH formula, which is constructed in such a way that besides A + B all terms have degree ≥ $./bch expression=5+1/1*A+1/1*B+1/2880*[A,[A,[A,[A,B]]]]-7/8640*[A,[A,[[A,B],B]]]+1/2160*[[A,[A,B]],[A,B]]+7/12960*[A,[[[A,B],B],B]]+1/4320*[[A,B],[[A,B],B]]-41/155520*[[[[A,B],B],B],B] The program can easily be extended to handle additional expressions of the form (3), seeSubsection 6.5 below. table output[=0 or =1 depending on size of result ] With table_output=0 the result is displayed as a linear combination of commutators. Thisis the default if the result consists of less than 200 terms. With table_output=1 , on theother hand, the result is displayed in tabular form. Each row of the table corresponds toa basis element of the respective Lie basis, where by default, for the Lyndon or the Hallbasis ( basis=0 or basis=2 ), the index, the indices of the left and the right factors, and thecoefficient of the basis element is displayed. This information uniquely determines the basiselement, which follows from the fact that for Hall and Lyndon bases the factors h ′ , h ′′ of basiselements h = [ h ′ , h ′′ ] of degree ≥ ./bch table_output=10 1 0 0 1/11 1 1 0 1/12 2 0 1 1/23 3 0 2 1/124 3 2 1 1/125 4 0 3 0/16 4 0 4 1/247 4 4 1 0/18 5 0 5 -1/7209 5 0 6 1/18010 5 3 2 1/36011 5 0 7 1/18012 5 2 4 1/12013 5 7 1 -1/720 For the right-normed basis ( basis=1 ) the factors of the basis element are not necessarilybasis elements themselves, so that instead of these factors the foliage of the basis element(i.e., the commutator written without commas and brackets) is displayed, which uniquelydetermines the basis element in this case. $ ./bch basis=1 table_output=10 1 A 1/11 1 B 1/12 2 BA -1/23 3 ABA -1/124 3 BBA 1/125 4 AABA 0/16 4 BABA 1/247 4 BBBA 0/18 5 AAABA 1/7209 5 BAABA -1/36010 5 ABABA 1/12011 5 BBABA -1/12012 5 ABBBA 1/36013 5 BBBBA -1/720
The displayed items can be customized by specifying the following parameters which shouldbe self-explanatory: • print index[=1] • print degree[=1] • print multi degree[=0] • print factors[=1 or =0 depending on basis] • print foliage[=0 or =1 depending on basis] • print basis element[=0] • print coefficient[=1] ./bch table_output=1 print_basis_element=1 print_multi_degree=10 1 (1,0) 0 0 A 1/11 1 (0,1) 1 0 B 1/12 2 (1,1) 0 1 [A,B] 1/23 3 (2,1) 0 2 [A,[A,B]] 1/124 3 (1,2) 2 1 [[A,B],B] 1/125 4 (3,1) 0 3 [A,[A,[A,B]]] 0/16 4 (2,2) 0 4 [A,[[A,B],B]] 1/247 4 (1,3) 4 1 [[[A,B],B],B] 0/18 5 (4,1) 0 5 [A,[A,[A,[A,B]]]] -1/7209 5 (3,2) 0 6 [A,[A,[[A,B],B]]] 1/18010 5 (3,2) 3 2 [[A,[A,B]],[A,B]] 1/36011 5 (2,3) 0 7 [A,[[[A,B],B],B]] 1/18012 5 (2,3) 2 4 [[A,B],[[A,B],B]] 1/12013 5 (1,4) 7 1 [[[[A,B],B],B],B] -1/720 Note that if the parameter verbosity_level is set to a value ≥ verbosity level[=0] With verbosity_level set to a value ≥ at the leading position.With verbosity_level set to a value ≥ $ ./bch N=20 verbosity_level=1 | head -n 40
17 7710 7710 16510 13864 bch program
We document the performance of typical runs of the bch program on an ordinary personalcomputer. More specifically, the computer system was a a 3.0 GHz Intel Core i5-2320 pro-cessor with 4 CPU cores and 8 GB of RAM running an Ubuntu Linux operating system. TheC compiler was gcc version 9.3.0. The memory usage was measured with /usr/bin/time .For the test runs of the program we used different maximum degrees N and different bases.The results are as follows: (Here, dimension is the number of basis elements of degree ≤ N and = 0.) Lyndon basis: N dimension .
04 sec 4628 kB20 111013 76760 0 .
22 sec 10932 kB22 401428 276474 2 .
13 sec 33008 kB24 1465020 1005917 54 .
43 sec 115 MB26 5387991 3690268 16 min 16 sec 427 MB28 19945394 13632278 3 h 57 min 1.4 GB30 74248451 50657857 54 h 46 min 5.5 GB
Classical Hall basis: N dimension .
35 sec 81248 kB20 111013 109697 2 .
12 sec 428 MB22 401428 398313 20 min 53 sec 2.6 GB
Right-normed Chibrikov basis: N dimension .
76 sec 58300 kB20 111013 76748 21 .
52 sec 637 MB22 401428 276463 21 min 53 sec 6.9 GBFor the Lyndon basis, the maximum degree N = 30 that the program can in principlehandle could actually be achieved. For the other bases, N = 22 was the limit due to memoryconstraints (the computer system had 8 GB of RAM).8t is natural to compare the performance of our program with that of other implementa-tions of algorithms for computing the BCH series up to terms of high degree. Ref. [1] is theonly recently published report of such an implementation that we know of. Results obtainedwith this implementation are available at .It should be acknowledged that these results served us well in verifying the computations ofour bch program.For the implementation of [1] in Mathematica a completely different and more sophis-ticated approach than ours was used. This approach, which is based on a Lie algebraicstructure of labeled rooted trees, has the obvious disadvantage that it is not easily adaptedto arbitrary expressions of the form (3). Thus, only the classical and the symmetric BCHseries are handled in [1].In [1] it is reported that the computation of the BCH series up to terms of degree N = 20in the classical Hall basis required less than 15 min CPU time and 1.5 GB of memory on a2.4 GHz Intel Core 2 Duo processor with 2 GB of RAM. For the computation in the Lyndonbasis it required 3.6 GB of memory, but no specific information about the CPU time is given,only that it required more time than the computation in the classical Hall basis. This hasto be compared with our implementation, which requires only 0.22 sec CPU time and 11 MBof RAM for the Lyndon basis, and 2.12 sec CPU time and 428 MB of RAM for the classicalHall basis. These numbers speak for themselves, even if direct comparisons of differentimplementations in different programming languages that run on different hardware must beinterpreted with caution. libbch library The main() function of the executable bch , which is defined in the source file bch.c , essen-tially does nothing else than processing the command line arguments and then calling theappropriate functions from the libbch library, which perform the actual computations. Inthe same way, these functions can also be called from a user-defined program, which has tobe linked to the shared library libbch.so for this purpose. Each such program should in-clude the header file bch.h , which contains declarations for the functions and data structuresprovided by the library. The source file bch.c for the executable bch can serve as a modelfor the usage of the libbch library.In the following we give an excerpt from the header file bch.h covering essential decla-rations together with some necessary explanations. It has been tried to use names for thefunctions and their arguments that are as self-explanatory as possible, and that are consis-tent with the names of the corresponding parameters for the bch program as described inSection 4.
Essentially all computations of the libbch library are carried out in pure integer arithmetic,a large part of them in 128 bit integer arithmetic (the other part can be done using integerswith fewer bits). In bch.h the 128 bit integer type
INTEGER is defined as an alias for thebuilt-in type __int128_t : typedef __int128_t INTEGER; Although such 128 bit integers are available for most modern C compilers, the C standardlibrary does not provide functions for converting such integers to strings, or print them on9tandard output. The libbch library provides such functions and also functions for convert-ing and printing rational numbers, which are specified by their numerators and denominatorsof type
INTEGER . Note that the rational numbers are reduced to lowest terms first. int str_INTEGER(char *str, INTEGER x);int str_RATIONAL(char *str, INTEGER num, INTEGER den);void print_INTEGER(INTEGER x);void print_RATIONAL(INTEGER num, INTEGER den);
The functions str_INTEGER and str_RATIONAL write to a character string str which has tobe long enough to contain the output including a terminating ’\0’ . They return the numberof characters written (excluding the terminating ’\0’ ). If str is NULL , then these functionsreturn the number of characters that would have been written in case of a proper outputstring str . The following two functions compute respectively the classical BCH series (i.e., the Lie seriesfor log(e A e B )) and the symmetric BCH series (i.e., the Lie series for log(e A e B e A ) ): lie_series_t* BCH(int maximum_degree, int basis);lie_series_t* symBCH(int maximum_degree, int basis); Here the argument maximum_degree specifies the maximum degree up to which terms of theLie series shall be computed. The argument basis specifies the basis in which the resultingLie series shall be represented, where the values 0,1,2 respectively correspond to the Lyndonbasis, the right-normed Chibrikov basis, and the classical Hall basis. These functions returna pointer to a structure of type lie_series_t which contains the resulting Lie series. Thisstructure should be considered as an opaque data type for which access to its data is providedby data access functions (see below). void set_verbosity_level(int verbosity_level);
If the verbosity level is set to a value ≥ before calling the functions BCH or symBCH , thenthese function print some useful information about the performance of the computation tothe standard output. int dimension(lie_series_t *LS);int maximum_degree(lie_series_t *LS);int number_of_generators(lie_series_t *LS);INTEGER denominator(lie_series_t *LS);INTEGER numerator_of_coefficient(lie_series_t *LS, int i);int degree(lie_series_t *LS, int i);int degree_of_generator(lie_series_t *LS, int i, uint8_t g);int left_factor(lie_series_t *LS, int i);int right_factor(lie_series_t *LS, int i);int str_foliage(char *str, lie_series_t *LS, int i, char *generators);int str_basis_element(char *str, lie_series_t *LS, int i, char *generators);int str_coefficient(char *str, lie_series_t *LS, int i);void print_foliage(lie_series_t *LS, int i, char *generators);void print_basis_element(lie_series_t *LS, int i, char *generators);void print_coefficient(lie_series_t *LS, int i); LS is a pointer which was previously returned by the functions BCH or symBCH (or lie_series , see below). The argument i is the index of the basis element, forwhich the respective information is requested. The argument g in degree_of_generator specifies the (index of the) generator for which the degree in the basis element with index i is requested. The argument generators should be a string like "ABCDEFG" containing atposition 0 the name for generator 0, at position 1 the name for generator 1, etc.The functions str_foliage , str_basis_element , and str_coefficient write to a char-acter string str which has to be long enough to contain the output including a terminating ’\0’ . They return the number of characters written (excluding the terminating ’\0’ ). If str is NULL , then these functions return the number of characters that would have been writtenin case of a proper output string str .The functions left_factor and right_factor respectively return the index of the leftfactor h ′ and the index of the right factor h ′′ of the basis element h = [ h ′ , h ′′ ] with index i .Note that the result is well-defined only if the Lie series LS was generated with basis equal0 (Lyndon basis) or equal 2 (classical Hall basis), and if the basis element h with index i hasdegree ≥ void free_lie_series(lie_series_t *LS); Besides Lie series for log(e A e B ) and log(e A e B e A ) ), also Lie series for arbitrary expressions ofthe form (3) can be computed. Such expressions are represented as binary expression trees,for the generation of which the libbch library provides the following functions: expr_t* identity(void);expr_t* generator(uint8_t g);expr_t* sum(expr_t* arg1, expr_t* arg2);expr_t* difference(expr_t* arg1, expr_t* arg2);expr_t* product(expr_t* arg1, expr_t* arg2);expr_t* negation(expr_t* arg);expr_t* term(int numerator, int denominator, expr_t* arg);expr_t* exponential(expr_t* arg);expr_t* logarithm(expr_t* arg);expr_t* commutator(expr_t* arg1, expr_t* arg2); These functions return a pointer to a structure of type expr_t which represents a node of theexpression tree and contains data, depending on the type of the node, like pointers to subex-pressions, the index of a generator, or numerator and denominator of a rational coefficient.For example, the following code generates the expression log(e B e A e B + [ B, [ A,B ] e A e B ): expr_t *A = generator(0);expr_t *B = generator(1);expr_t* expression =logarithm(product(product(product(product(exponential(term(1, 6, B)), exponential(term(1, 2, A))),exponential(sum(term(2, 3, B),term(1, 72, commutator(B, commutator(A, B)))))),exponential(term(1, 2, A))), exponential(term(1, 6, B)))); lie_series_t* lie_series(int number_of_generators, expr_t* expression,int maximum_degree, int basis); Regarding arguments and return value, this function is analogous to the functions
BCH and symBCH , with the exception of additional arguments number_of_generators and expression .Here, number_of_generators is the number of generators occurring in the expression (ormore precisely the highest index plus 1 of all generators occurring in the expression). In theabove example it should have the value 2.For cleaning up, the following function frees all resources that were allocated for anexpression: void free_expr(expr_t* expression);
Expressions should be freed in the same order as they were generated, i.e., for the aboveexample: free_expr(A);free_expr(B);free_expr(expression);
References [1] F. Casas and A. Murua, An efficient algorithm for computing the Baker–Campbell–Hausdorff series andsome of its applications,
J. Math. Phys. , 033513 (2009).[2] E.S. Chibrikov, A right normed basis for free Lie algebras and Lyndon–Shirshov words, Journal ofAlgebra (2006), 593–612.[3] E. Eriksen, Properties of higher-order commutator products and the Baker–Campbell–Hausdorff formula,
J. Math. Phys. (1968), 790–796.[4] K. Goldberg, The formal power series for log e x e y , Duke Math. J. (1956), 13–21.[5] H. Hofst¨atter, A relatively short self-contained proof of the Baker–Campbell–Hausdorff theorem, Expo-sitiones Mathematicae , to appear.[6] H. Hofst¨atter, Denominators of coefficients of the Baker–Campbell–Hausdorff series, available at https://arxiv.org/abs/2010.03440 .[7] H. Hofst¨atter, Smallest common denominators for the homogeneous components of the Baker-Campbell-Hausdorff series, available at https://arxiv.org/abs/2012.03818 .[8] H. Hofst¨atter, Fast computation of the Baker–Campbell–Hausdorff and similar series, in preparation.[9] H. Hofst¨atter, W. Auzinger, and O. Koch, An Algorithm for Computing Coefficients of Words in Ex-pressions Involving Exponentials and Its Application to the Construction of Exponential Integrators, In:M. England, W. Koepf, T. Sadykov, W. Seiler, and E. Vorozhtsov (eds),
Computer Algebra in ScientificComputing, CASC 2019 , Lecture Notes in Computer Science , Springer, Cham, 2019.[10] Klib, A standalone and lightweight C library, available at https://github.com/attractivechaos/klib .[11] C. Reutenauer, Free Lie Algebras, Oxford University Press, Oxford 1993. Of course, it is possible to generate more general expressions than those of the form (3). For such moregeneral expression, the result of the function lie series does not necessarily make any sense, since it cannotbe guaranteed that such expressions can be represented as Lie series or even as formal power series.does not necessarily make any sense, since it cannotbe guaranteed that such expressions can be represented as Lie series or even as formal power series.