Runge { Kutta Methods, Trees, and Maple

Selcuk J. Appl. Math.
Vol. 2, No. 1, pp. 3{15, 2001
Selcuk Journal of
Applied Mathematics
Runge { Kutta Methods, Trees, and Maple
On a Simple Proof of Butcher's Theorem and the
Automatic Generation of Order Conditions
Folkmar Bornemann
Center of Mathematical Sciences, Munich University of Technology, 80290 Munich,
Germany e-mail: bornemann@ma.tum.de
February 9, 2001
Summary. This paper presents a simple and elementary proof of
Butcher's theorem on the order conditions of Runge-Kutta methods.
It is based on a recursive denition of rooted trees and avoids combinatorial tools such as labelings and Faa di Bruno's formula. This
strictly recursive approach can easily and elegantly be implemented
using modern computer algebra systems like Maple for automatically
generating the order conditions. The full, but short source code is
presented and applied to some instructive examples.
Key words: numerical solution of ODEs, Runge-Kutta methods,
recursive representation of rooted trees, Butcher's theorem, automatic generation of order conditions, computer algebra systems.
Mathematics Subject Classication (1991): 65-01, 65L06, 65Y99
1. Introduction
A rst step towards the construction of Runge-Kutta methods is the
calculation of the order conditions that the coecients have to obey.
In the old days they were obtained by expanding the error term in
a Taylor series by hand, a procedure which for higher orders sooner
or later runs into diculties because of the largely increasing combinatorial complexity. It was a major break-through when Butcher 1] published his result of systematically describing order conditions by rooted trees. The proof of this result has evolved very much
in meantime, mainly under the inuence of Butcher's later work 3]
4
Folkmar Bornemann
and the contributions of Hairer and Wanner 7,6]. In this paper we
will present a simple and elementary proof of Butcher's theorem by
using very consequently the recursive structure of rooted trees. This
way we avoid lengthy calculations of combinatorial coecients, the
use of tree-labelings, or Faa di Bruno's formula as in 3,6]. Our proof
is very similar in spirit to the presentation of -series by Hairer in
Chapter 2 of his lecture notes 5].
As early as 1976 Jenks 8] posed the problem of automatically
generating order conditions for Runge-Kutta methods using computer algebra systems, but no replies were received. In 1988 Keiper of
Wolfram Research concluded that the method of automatically calculating Taylor expansions by brute force was bound to be very inecient. Naturally he turned to the elegant results of Butcher's. Utilizing
them, he wrote the Mathematica package Butcher.m, which has been
available as part of the standard distribution of Mathematica since
then. This package was later considerably improved by Sofroniou 9]
and oers a lot of sophisticated tools.
While teaching the simple proof of Butcher's result in a rst course
on numerical ODEs, the author realized that the underlying recursive
structure could also be exploited for a simple and elegant computer
implementation. This approach diers from the work of Sofroniou in
various respects. We will present the full source code in Maple and
some applications.
B
2. Runge-Kutta methods
The Runge-Kutta methods are one-step discretizations of initial-value
problems for systems of ordinary dierential equations,
= ( )
( 0) = 0
where the right-hand side : 0 ]
R Rd ! Rd is assumed
to be suciently smooth. The continuous evolution ( ) = tt0 0
of the initial-value problem is approximated in steps of length by
t+t t+t . This discrete evolution t+t is dened as an
approximation of the integral-equation representation
d
0
x
f t x f
x t
t T
x x t
x
x
x
t+t x = x +
Z t+
t
x
tx) d
(
f by appropriate quadrature formulas:
(1)
t+tx = x + s
X
i=1
i i
b k k
0
i= @ +
f
t
i
c x
+
s
X
j =1
a
ij k
1
jA
:
Runge { Kutta Methods, Trees, and Maple
5
The vectors i 2 Rd, = 1
, are called stages, is the stage
number. Following the standard notation, we collect the coecients
of the method into a matrix and two vectors
T
s =(
T
s
A = ( ij )ij 2 Rs s = ( 1
s) 2 R
1
s) 2 R
The method is explicit, if A is strictly lower triangular. The method
has order 2 N, if the error term expands to
t+t ; t+t = ( p+1)
In terms of the Taylor expansion of the error ; , the vanishing of
all lower order terms in just denes the conditions which have to
be satised by the coecients A, and of a Runge-Kutta method.
If we choose
k
i
a
::: s
b
s
b ::: b
c
c ::: c
:
p
x
x
O :
b
c
i=
c
s
X
j =1
a
ij it can be shown 6], that there is no loss of generality in considering
autonomous systems only, i.e., those with no dependence of on .
Doing so, the expressions t+t and t+t are likewise independent
of . We will write and for short, calling them the ow and
the discrete ow of the continuous resp. the discrete system.
f
t
x
x
t
x
x
3. Elementary dierentials and rooted trees
The Taylor expansions of both the phase ow and the discrete
ow are linear combinations of elementary dierentials like
x
x
f
000
(
0
0
f f f f f
)=
X
3
i f @ fj f f :
l @x m k
m
ijklm @ xi @ xj @ xk @ xl
@ f
@f
We will use the short multilinear notation of the left hand side for
the rest of the paper.
An elementary dierential can be expressed uniquely by the structure of how the subterms enter the multilinear maps. For instance,
looking at the expression (
) we observe that must be
a third derivative, since three arguments make it three-linear. This
structure can be expressed in general by rooted trees, e.g.,
f
@@r;;r expressing
000
0
r
er
0
f f
00
(
0
f f f f f
)
f f r
r
@@er;;r
f
expressing
f
000
00
(
0
)
f f f :
6
Folkmar Bornemann
Every node with children denotes a th derivative of , which is
applied as a multilinear map to further elementary dierentials, according to the structure of the tree. We start reading o this structure
by looking at the root. This denes a recursive procedure, if we observe the following: Having removed the root and its edges, a rooted
tree decomposes into rooted subtrees 1
n with strictly less
nodes. The roots of the subtrees 1
n are exactly the children
of 's root. This way a rooted tree can be dened as the unordered
list of its successors
(2)
= 1
# = 1+# 1+ +# n
n]
Here, we denote by # the order of a rooted tree , i.e., the number
of its nodes. The root itself can be identied with the empty list,
= ].
An application of this procedure shows for the examples above
that ( ( )) is expressed by ]] and ( ( ) ) is expressed
by ] ]. The reader will observe the perfect matching of parentheses and commas. In general the relation between a rooted tree
= 1
n ] and its corresponding elementary dierential ( )( )
is recursively dened by
( )
(n)
( ) = (n) ( ) (1 ) ( )
( )
The dot of multiplication denotes the multilinear application of the
derivative to the given arguments. Due to the symmetry of the linear map (n) , the order of the subtrees 1
n does not matter,
which means, that ( ) depends in a well-dened way on as an
unordered list only.
From = ] we deduce ( ) = . Analogously, each of the recursive denitions in the following will have a well-dened meaning
if applied to the single root = ], mostly by using the reasonable
convention that empty products evaluate to one and empty sums to
zero|a convention that is also observed by most computer algebra
systems.
n
n
f
::: ::: n
::: :::
f
0
f
00
:
f f
f
00
f
0
f f
::: f
f
x
f
x
f
x ::: f
x
x
:
n
n
f
::: f
f
f
4. A simple proof of Butcher's theorem
We are now in a position to calculate and denote the Taylor expansion
of the continuous ow in a clear and compact fashion.
Lemma 1. Given 2 p( Rd) the ow expands to
f
x
C
= +
x
X
# p
x
#
!
f ( )(x) + O( p+1 ):
Runge { Kutta Methods, Trees, and Maple
7
The coecients ! and belonging to a rooted tree = 1 : : : n ]
are recursively dened by
(3)
! = (# ) 1! :::
n!
= !
1
n
:::
n :
By we denote the number of di
erent ordered tuples (
1 : : : n )
which correspond to the same unordered list = 1 : : : n ].
Proof. The assertion is obviously true for
= 0. We proceed by
induction on . Using the assertion for , the multivariate Taylor
formula and the multilinearity of the derivatives we obtain
p
0
X #
( )= @ +
!
# p
0
p
X
1 (n) @ X
f x
f
x
f
1
( )
+ ( p+1 )A
O #1
1
!
1!
n=0
#1 p
+ ( p+1 )
p
#1 +:::+#n
X
X
= 1!
!
!
1
n
n=0 #1 +:::+#n p
=
f
n
p
p
(1 )
f
::: X
n f
1
(n )A
+ (
p+1 )
#n
n!
#n p
O n
f
(n)
f
(1 )
p
X
X
::: f
# =
n=0 =1 :::n ]
# p+1
X # =
# p+1
(n)
+ (
# ;1
O !
|
!
# ;1
!
:::
n
f
( )
:::
n p+1 )
1
+ (
1
O {z
:::
n
=
}
f
( )
O p+1):
Plugging this into the integral form of the initial value problem we
obtain
x = x+
Z
0
(
)
f x
d
= +
x
X
# p+1
#
!
f
( )
+ (
O p+2 )
which proves the assertion for + 1. ut
p
A likewise clear and compact expression can be calculated for the
Taylor expansion of the discrete ow.
8
Folkmar Bornemann
Lemma 2. Given 2 p( Rd) the discrete ow expands to
= + X # T A( ) ( )( ) + ( p+1 )
f
x
x
C
# p
b
f
x
x
O :
The vector A( ) 2 Rs, = 1 : : : n], is recursively dened by
=1
(4) A(i ) = A A(1 ) i A A(n ) i
Proof. Because of the denition (1)of the discrete ow we have to
prove that the stages i expand to
X # 1 () ()
+ ( p)
i=
Ai
:::
i
: : : s:
k
k
;
# p
f
O :
This is obviously the case for = 0. We proceed by induction on .
Using the assertion for , the denition of the stages i , the multivariate Taylor formula and the multilinearity of the derivatives we
obtain
p
p
p
k
k
0 0
11
X
# 1
i= @ + @
A A( ) i ( ) + ( p )AA
# p
0
p
X
X # ( ) ( )
1
(n) @
=
AA
i
n=0 !
# p
1
X #n (n) (n)A
+ (
n A A
f
x
;
f
O n
f
=
=
p
X
#n p
X
1
! #1 +:::+#n
n=0 n
:::
1
1
1
1 :::
f
1
:::
p
X
(n )
AA
X
i
p
#1 +:::+#n
f
(n)
# ;1
i
f
!
|
(1 )
1
n
1
:::
::: f
(n)
n Ai
{z }
n=0 =1 :::n ]
= # p+1
X # 1
( ) ( )
=
Ai
f
+ O( p+1)
# p+1
f
:::
O n + (
O A A(1) i p+1)
( ) ( )
f
p+1)
+ (
O p+1 )
;
which proves the assertion for + 1. ut
Comparing the coecients of the elementary dierentials in the
expansions of both the phase ow and the discrete ow, we immediately obtain Butcher's theorem 1].
p
Runge { Kutta Methods, Trees, and Maple
9
Theorem 1 (Butcher 1963). A Runge-Kutta-method ( A) is of
order 2 N for all 2 p( Rd), if the order conditions
T A( ) = 1 !
are satised for all rooted trees of order # .
b
p
f
C
b
=
p
5. Generating order conditions with Maple
The recursive constructions underlying the proof of Butcher's theorem can easily be realized using modern computer algebra systems
like Maple. We assume that the reader is familiar with this particular
package.
The recursive data-structure of a rooted tree itself can be realized
by self-reference as a list of rooted trees,
>
`type/tree`:=list(tree): f:=]:
Conveniently, we have given a name to the root = ]. Because
Maple's lists are ordered, we have to sort the trees recursively before
testing for equality:
TreeSort:=proc(beta::tree)
sort(map(TreeSort,beta))
end: # TreeSort
Now, here is an example for the tree representing the elementary differential ( ( ( )) ) = ( ( ( ) )). The corresponding
tree is obtained by erasing all the derivatives (n) from the expression
and replacing parentheses ( ) by ]:
f
00
f
00
f f
0
f
f
f
00
f f
00
f
0
f f
f
:::
>
>
:::
beta1]:=f,f]],f]: beta2]:=f,f],f]]:
evalb(TreeSort(beta1])=TreeSort(beta2]))
true
The denition (2)of the order # is simply expressed by the recursive
procedure
TreeOrder:=proc(beta::tree)
option remember
1+`+`(op(map(TreeOrder,beta)))
end: # TreeOrder
As an example, we take the tree that represents the elementary differential ( ( ( ) ( ) ) ):
f
>
00
f
000
f
0
f f
0
f f f
beta:=f],f],f],f]: TreeOrder(beta)
8
The denition (3)of ! is analogously expressed by:
10
Folkmar Bornemann
TreeFactorial:=proc(beta::tree)
option remember
TreeOrder(beta)*`*`(op(map(TreeFactorial,beta)))
end: # TreeFactorial
The above used tree of order 8 gives:
>
TreeFactorial(beta)
192
For the sake of completeness we also express the recursive denition (3)of using Maple:
TreeAlpha:=proc(beta::tree)
option remember
local n
n:=nops(beta)
nops(combinatpermute](beta,n))/n!*
`*`(op(map(TreeAlpha,beta)))
end: # TreeAlpha
An application to the above example yields:
>
TreeAlpha(beta)
1
2
We are now ready to map the recursive denition (4)of A( ) and of
the order condition T A( ) = 1 ! to Maple:
b
=
TreeA:=proc(beta::tree,no::posint)
option remember
local vars,val,son
vars:=i,j,k,l,m,p,q,r,u,v,w]
val:=1
for son in beta do
val:= val*Sum(avarsno],varsno+1]]*
TreeA(son,no+1),varsno+1]=1..s)
od
val
end: # TreeA
TreeOrderCondition:=proc(beta::tree)
Sum(bi]*TreeA(beta,1),i=1..s)=
1/TreeFactorial(beta)
end: # TreeOrderCondition
The coordinate index for the vector A( ) can be chosen from the
list i,j,k,l,m,p,q,r,u,v,w] and is passed by number as the sec-
Runge { Kutta Methods, Trees, and Maple
11
ond argument to TreeA. The order condition belonging to the above
example is obtained as follows:
>
0s
s
X
X
i@
i=1
1 s
X
1
j k )A (
i j ) = 192
j =1
TreeOrderCondition(beta)
b
j =1
a
i j
X
s
k=1
a
s
X
j k (
l=1
a
!2 X
s
k l )
(
k=1
a
a
Even the typesetting of this formula was done completely automatically, using Maple's ability to generate TEX-sources.
To generate all the order conditions for a given order , we need a
device that constructs the set of all trees with # . There are,
in principle, two dierent recursive approaches:
{ root-oriented: generate all trees of order # = by rst, listing
all integer partitions ; 1 = 1 + + n , = 1
; 1,
and next, setting = 1
n ] for all trees 1
n of order
# 1= 1
# = n . These trees have already been
generated by the recursion.
{ leaf-oriented: Add a leaf to each node of the trees ^ = 1
n]
^
of order # = ; 1, increasing thereby the order exactly by one.
This can be done recursively by adding a leaf to every node of the
subtrees 1
n.
The root-oriented approach was chosen by Sofroniou 9] in his Mathematica package Butcher.m. It requires an ecient integer partition
package and the handling of cartesian products. The leaf-oriented
approach is as least as ecient as the other one, but much easier to
code:
p
p
p
< p : : : p
:::
::: p
p
p
p
n
::: p
::: < p
::: p
::: Trees:=proc(order::posint)
option remember
local Replace,AddLeaf,all,trees
Replace:=proc(new::tree,old::posint,beta::tree)
sort(subsop(old=new,beta)) # order-independent...
end: # Replace
AddLeaf:=proc(beta::tree)
option remember
local val,child,new
val:= sort(],op(beta)]) for child from 1 to nops(beta) do
new:=AddLeaf(betachild])
val:=val union map(Replace,new,child,beta)
od
f
g
12
Folkmar Bornemann
val
end: # AddLeaf
f g
trees:= ] all:=trees]
to order-1 do
trees:=`union`(op(map(AddLeaf,trees)))
all:=op(all),trees]
od:
all
end: # Trees
Given an order this procedure generates a list of the sets of trees
for each order , e.g.,
p
q
>
p
Trees(4)
f]g f]]g f]]] ] ]]g f] ] ]] ]]]] ] ]]] ]] ]]g]
For instance, the number of trees for each order 10 is given by
the entries of the following list:
p
>
map(nops,Trees(10))
1 1 2 4 9 20 48 115 286 719]
The number of order conditions for the order = 10 can thus be
obtained by:
p
>
`+`(op(%))
1205
Finally, for concrete calculations one has to specify the number
of stages. The following procedure then generates the specic set of
equations for explicit Runge-Kutta methods:
s
OrderConditions:=proc(order::posint,stages::posint)
option remember
local eqs,vars,auto,explicit
explicit:=seq(seq(ai,j]=0,j=i..stages),
i=1..stages)
vars:=eval(seq(bi],i=1..stages),
seq(seq(ai,j],j=1..stages),i=1..stages),
seq(ci],i=1..stages),explicit) minus 0 auto:=eval(seq(sum(ai,j],j=1..stages)=ci],
i=1..stages),explicit)
eqs:=value(Eval(map(TreeOrderCondition,
`union`(op(Trees(order)))),s=stages))
eqs:=eval(eval(eqs,explicit),auto)
eqs,auto,vars
end: # OrderConditions
fg
Runge { Kutta Methods, Trees, and Maple
13
This way, we can automatically generate and typeset the order conditions for the classical explicit 4-stage Runge-Kutta methods of order 4:
>
OrderConditions(4,4): %1]
f 1+ 2+ 3+ 4=1
b
b2 c2
b
b
+
b3 c3
b
+
b4 c4
b4 a4
= 12
1
24
3
3 + 4
3 a3 2 c2 =
b2 c2
3
+
b3 c
1
6
1
3 3 2 2 + 4 4 ( 4 2 2 + 4 3 3) =
8
1
2
2
2
3 2 2 + 4 ( 4 2 2 + 4 3 3 ) =
12
1
2
2
2
2 + 3 3 + 4 4 = g
3
2 c2 + b4 (a4 2 c2 + a4 3 c3) =
b3 a3
b3 c
b3 a
b2 c
a
c
b
c
b
b
c
c
a
a
c
b
c
a
a
c
c
b c4
3
= 14
c
Remark 1. Even in the more recent literature one can nd examples
like 4], where order conditions for Runge-Kutta methods are generated by using a computer algebra system to calculate the Taylor
expansions of the ow and the discrete ow directly. This approach
is typically bound to scalar non-autonomous equations, i.e., = 1.
Besides being inecient for higher orders, it is well-known 2] that
for 5 additional order conditions for general systems make an
appearance, which do not show up in the scalar case.
d
p
6. Examples of usage
The following simple procedure tempts to solve the order conditions
for a given order and stage number by using brute force, i.e.,
Maple's solve-command. To simplify the task, the user is allowed to
supply a set pre of a priori chosen additional equations and assignments that he thinks to be helpful.
p
s
RungeKuttaMethod:=proc(p::posint,s::posint,pre::set)
# explicit methods only
local conds,auto,vars,eqs,sols,sol,val
conds,auto,vars:=OrderConditions(p,s)
eqs:=conds union auto union pre
sols:=solve(eqs,vars)
val:=NULL
for sol in sols do
14
Folkmar Bornemann
val:=val,
a=matrix(seq(seq(eval(ai,j],sol),j=1..i-1),
seq(0,j=i..s)],i=1..s)]),
b=vector(seq(eval(bi],sol),i=1..s)]),
c=vector(seq(eval(ci],sol),i=1..s)])]
od:
val
end: # RungeKuttaMethod
This way we can simply generate the general explicit 2-stage RungeKutta method of order = 2:
p
>
f
g
RungeKuttaMethod(2,2, b2]=theta )
" " 0 0#
1 1 #
= ; + 1 ] = 0 2
= 11 0
2
The next example is more demanding. In his book 3, p. 199] Butcher
describes an algorithm for the construction of explicit 6-stage methods of order = 5. The choices 6 = 1 and 2 = 0 together with the
free parameters 2 3 4 5 and 43 yield a unique method. Butcher
provides a two-parameter example by choosing 2 = 3 = 1 4 4 =
1 2 5 = 3 4 43 = . By just passing this additional information to
Maple's solve-command we obtain the following solution
a
b
p
c
c
c c c c
b
a
c
= c
>
>
>
>
= a
u c
= c
v
f
pre:= c2]=u,c3]=1/4,c4]=1/2,c5]=3/4,c6]=1,
b2]=0,a4,3]=v :
RungeKuttaMethod(5,6,pre): %1]
%%2],%%3]
g
2
0
66
66
1 ;1 + 8
66
32
6
= 66 ; 18 ;2 + 1 + 8 ; 4
66
66 3 ; + 1 ; 3 + 4
64 16
3
0
0
0 00
0
0
0 0 0 77
1 1
0
0 0 0 777
32
77
1
2
;
1
;8
0 0 0 77
7
3 ; 1 3 ; 3 9 0 0 77
77
16
4 4 16
5
; 141 ;6 + 7 + 24 ; 22 ; 141 6 ; 7 127 ;712 87 0
7 16 2 16 7 1 1 3 = 90 0 45 15 45 90 = 0 4 2 4 1
This result shows that the coecients 51 and 52 of Butcher's solution 3, p. 199] are in error, a fact that was already observed by
Sofroniou 9] using the Mathematica package Butcher.m.
u
u
u
a
v
vu
u
u
v
u
v
u
vu
v
u
v
vu
v
u
u
v
u
b
v
u
v
u
c
u
a
a
Runge { Kutta Methods, Trees, and Maple
15
References
1. Butcher, J. C. (1963): Coecients for the study of Runge-Kutta integration
processes, J. Austral. Math. Soc. 3, 185{201.
2. Butcher, J. C. (1963): On the integration processes of A. Huta, J. Austral.
Math. Soc. 3, 202{206.
3. Butcher, J. C. (1987): The Numerical Analysis of Ordinary Dierential Equations. Runge-Kutta Methods and General Linear Methods, John Wiley & Sons,
Chichester.
4. Gander, W. and Gruntz, D. (1999): Derivation of numerical methods using
computer algebra, SIAM Review 41, 577{593.
5. Hairer, E. (1999): Numerical Geometric Integration, Lecture notes of a course
given in 1998/99, http://www.unige.ch/math/folks/hairer/polycop.html.
6. Hairer, E., Nrsett, S. P., and Wanner, G. (1993): Solving Ordinary Dierential Equations I. Nonsti Problems, 2nd Edition, Springer-Verlag, Berlin,
Heidelberg, New York.
7. Hairer, E. and Wanner, G. (1974): On the Butcher group and general multivalue methods, Computing 13, 1{15.
8. Jenks, R. J., (1976): Problem # 11: Generation of Runge-Kutta equations,
SIGSAM Bulletin 10, 6.
9. Sofroniou, M. (1994): Symbolic derivation of Runge-Kutta methods, J. Symb.
Comp. 18, 265{296.