Removed debug output.
[cadabra.git] / doc / paper.tex
bloba28e6277bb26d7c8008bb949d04f4553c332d6bf
1 \documentclass{elsart}
2 \usepackage{yjsco}
3 \usepackage{amsmath}
4 \usepackage{fancyvrb}
5 \usepackage[numbers,sort&compress]{natbib}
6 \usepackage{hypernat}
7 \usepackage{hyperref}
8 \usepackage{graphicx}
9 \usepackage{xspace}
10 \newcommand{\bs}{$\backslash$}
11 \newcommand{\Cpp}{\leavevmode\rm{\hbox{C\hskip -0.1ex\raise 0.5ex\hbox{\tiny ++}}}\xspace}
13 \setlength{\skip\footins}{18pt plus 4pt minus 2 pt}
15 \makeatletter
16 \def\ps@copyright{}
17 \makeatother
19 \fvset{frame=lines,framerule=0.1pt,framesep=8pt,numbers=none,xleftmargin=5ex,fontfamily=tt,fontsize=\small}
20 \newenvironment{screen}{\vspace{1ex}\Verbatim}{\endVerbatim\vspace{1ex}}
22 \begin{document}
23 \begin{flushright}
24 AEI-2006-037\\cs.SC/0608005
25 \end{flushright}
26 \begin{frontmatter}
27 %\title{Cadabra: a field-theory motivated symbolic computer algebra
28 %system}
29 \title{A field-theory motivated approach to symbolic computer algebra}
30 \author{Kasper Peeters}
31 \address{Max-Planck-Institut f\"ur Gravitationsphysik, Albert-Einstein-Institut\\Am M\"uhlenberg
32 1, 14476 Golm, GERMANY}
33 \ead{kasper.peeters@aei.mpg.de}
34 \begin{abstract}
35 Field theory is an area in physics with a deceptively compact
36 notation. Although general purpose computer algebra systems, built
37 around generic list-based data structures, can be used to represent
38 and manipulate field-theory expressions, this often leads to
39 cumbersome input formats, unexpected side-effects, or the need for a
40 lot of special-purpose code. This makes a direct translation of
41 problems from paper to computer and back needlessly time-consuming
42 and error-prone. A prototype computer algebra system is presented
43 which features \TeX-like input, graph data structures, lists with
44 Young-tableaux symmetries and a multiple-inheritance property
45 system. The usefulness of this approach is illustrated with a number
46 of explicit field-theory problems.
47 \end{abstract}
48 \end{frontmatter}
50 % 11.10.-z Field theory (for gauge field theories, see 11.15.-q)
51 % 02.70.Wz Symbolic computation (computer algebra)
53 \section{Field theory versus general-purpose computer algebra}
55 For good reasons, the area of general-purpose computer algebra programs
56 has historically been dominated by what one could call ``list-based''
57 systems. These are systems which are centred on the idea that, at the
58 lowest level, mathematical expressions are nothing else but nested
59 lists (or equivalently: nested functions, trees, directed acyclic
60 graphs,~\ldots). There is no doubt that a lot of mathematics indeed
61 maps elegantly to problems concerning the manipulation of nested
62 lists, as the success of a large class of LISP-based computer algebra
63 systems illustrates (either implemented in LISP itself or in another
64 language with appropriate list data structures). However, there are
65 certain problems for which a pure list-based approach may not be the
66 most elegant, efficient or robust one.
68 That a pure list-based approach does not necessarily lead to the
69 fastest algorithms is of course well-known. For e.g.~polynomial
70 manipulation, there exists a multitude of other representations which
71 are often more appropriate for the problem at hand. An area for which
72 the limits of a pure list-based approach have received less attention
73 consists of what one might call ``field theory'' problems. Without
74 attempting to define this term rigorously, one can have in mind
75 problems such as the manipulation of Lagrangians, field equations or
76 symmetry algebras; the examples discussed later will define the class
77 of problems more explicitly. The standard physics notation in this
78 field is deceptively compact, and as a result it is easy to overlook
79 the amount of information that is being manipulated when one handles
80 these problems with pencil and paper. As a consequence, problems such
81 as deriving the equations of motion from an action, or verifying
82 supersymmetry or BRST invariance, often become a tedious transcription
83 exercise when one attempts to do them with existing general-purpose
84 computer algebra systems. Here, the inadequateness of simple lists is
85 not so much that it leads to sub-optimal, slow solutions (although
86 this certainly also plays a role at some stage), but rather that it
87 prevents solutions from being developed at~all.
89 To make the problems more concrete, let us consider a totally
90 arbitrary example of the type of expressions which appear in field
91 theory. A typical Lagrangian or Noether charge might contain terms of
92 the type
93 \begin{equation}
94 \label{e:ex1}
95 \int\!{\rm d}^nx\, \frac{\partial}{\partial x^\lambda} \Big(F_{\mu\nu\rho}\, \psi^{\mu} \Big)\, \psi^{\nu}\,.
96 \end{equation}
97 Let us take, purely as an example, ~$F_{\mu\nu\rho}$ to be a
98 commuting field strength of some two-form field, $\psi^\mu$ an
99 anti-commuting vector, and $x^\mu$ to label an~$n$-dimensional space.
100 Traditionally, one would represent~\eqref{e:ex1} in the computer as a
101 nested list, which in tree-form would take the form\vspace{2ex}
102 \begin{center}
103 \includegraphics[height=5cm]{exp2.eps}\\[2ex]
104 \end{center}
105 The precise details do not matter here; the important point is that
106 the expression takes the form of a multiply nested list. However, this
107 list can only be the starting point, since expression~\eqref{e:ex1} clearly
108 contains much more information than just the tree structure. This
109 leads to a number of ``standard'' problems which field-theory computer
110 algebra systems have to face: \medskip
112 \begin{itemize}
113 \item The names of contracted indices do not matter, in fact, it is
114 only the contraction which is relevant. The nested list structure
115 does not capture the cyclic graph-structure inherent in the
116 expression. How do we make a list-based program aware of this fact,
117 especially when doing substitutions? (this problem is more
118 colloquially known as the ``dummy index'' problem).
119 \item The expression is, for the ``outside world'', an object with two
120 free indices, $\lambda$ and $\rho$. However, these indices, or graph
121 edges, occur at different depths in the tree. How can we access the
122 nested list by the free edges of the tree?
123 \item The reason why $F$ and $\psi$ should stay as children of the
124 diff node is that they depend on~$x$. Where do we store this
125 information? And how do we make algorithms aware of~it?
126 \item The diff and $\psi$ child nodes of the prod node cannot be moved
127 through each other, because the diff node contains a $\psi$. In
128 other words, the diff node ``inherits'' the anti-commutativity from
129 one of its child nodes. How do we handle this?
130 \item The anti-symmetry of~$F$ relates several contraction patterns.
131 However, there are more complicated symmetries present in the
132 expression. The Bianchi identity on the field strength, for
133 instance, is a multi-term relation involving the indices
134 on~$F$ and the index on diff. How do we make the program aware of
135 this identity, and how do we take it into account when reducing
136 expressions to a canonical form?
137 \item For physicists, the simplest way to write expressions such
138 as~\eqref{e:ex1} is to use \TeX{} notation, for example
139 \begin{equation*}
140 \verb|\int d^nx \partial_{\lambda} ( F_{\mu\nu\rho} \psi^{\mu} ) \psi^{\nu}|
141 \end{equation*}
142 Being able to input expressions like this would eliminate a large
143 number of errors in transcribing physics problems to computer algebra
144 systems, and make it much easier to use the computer as a scratch pad
145 for tedious calculations (in particular, it would eliminate a good
146 part of the learning curve of the program). Although \TeX{} notation
147 certainly lacks the semantics to be used as input language for a
148 generic computer algebra system (see e.g.~\cite{fateman99parsing} for
149 a discussion of this problem), it is not hard to come up with a subset
150 of \TeX{} notation which is both easily understandable and
151 mathematically unambiguous. But how do we teach an existing general
152 purpose system to deal with input of this type?
153 \end{itemize}
154 \medskip
156 This collection of problems suggest that a general-purpose system
157 based on ``nested lists'' is a rather bare-bones tool to describe
158 field-theory problems. The nested list is just one of the many
159 possible views or representations of the (rather heavily labelled)
160 graph structure representing the expression. While it is perfectly
161 possible to tackle many of the problems mentioned above in a
162 list-based system (as several tensor algebra packages for general
163 purpose computer algebra systems
164 illustrate~\cite{e_xact,e_balf1,Klioner:1997sv,parker1}), this may not
165 be the most elegant, efficient or robust approach (the lack of a
166 system which is able to solve all of the sample problems in
167 section~\ref{s:examples} in an elegant way exemplifies this point). By
168 endowing the core of the computer algebra system with data structures
169 which are more appropriate for the storage of field-theory
170 expressions, it becomes much simpler to write a computer algebra
171 system which can resolve the problems listed above.\footnote{There are
172 of course \emph{other subclasses} of field-theory problems for which
173 some of the points raised here are irrelevant and efficient computer
174 algebra systems have been developed; see e.g.~\cite{Vermaseren:2000nd}
175 for an example.}
177 The remainder of this paper describes the key ingredients in an
178 approach taken in the prototype computer algebra system ``cadabra''.
179 Full details of this program, including source code, binaries and a
180 reference manual, can be found at the web site~\cite{kas_cdb}.
183 \section{Design goals and implementation}
184 \label{s:structure}
186 This section describes in more detail the main features of the cadabra
187 program: the internal graph views of the tree structure, its handling
188 of node symmetries and the use of a multiple-inheritance property
189 system. In addition to these features, cadabra also has a number of
190 other characteristics which make it especially tuned to the
191 manipulation of ``field theory'' problems. An important
192 characteristic which should not remain unmentioned is the fact that
193 cadabra accepts \TeX{}-like notation for tensorial expressions,
194 making it much easier to transcribe problems from and to paper. The
195 program can be used both from a text-based command-line interface as
196 well as from a graphical front-end or from within
197 \TeX{}macs~\cite{vdH:Gut}. I will not discuss the \TeX{} input/output
198 in detail, but examples can be found in section~\ref{s:examples}.
200 \subsection{Graph structure}
201 \label{s:graph}
203 Cadabra is a standalone program written in~\Cpp. As in most other
204 computer algebra systems, the internal data storage used in cadabra is
205 that of a tree. Concretely, this is implemented using a custom tree
206 container class~\cite{kas_tree} based on STL ideas~\cite{b_muss1}.
207 However, what sets the program apart from other systems is that a)~the
208 tree structure contains more data than usual, to make it easier to
209 represent field-theory problems in a compact way, and b)~the tree
210 manipulation algorithms offer several ways of viewing and
211 modifying this tree. In more detail: \medskip
213 \begin{itemize}
214 \item The nodes of the tree carry so-called ``parent-relation''
215 information, which determine how child nodes are related to parent
216 nodes. As an example of such a relation, consider the
217 expression~$T^{\mu}{}_{\nu}(x)$. This is stored as a node~$T$, with
218 three children~$\mu$, $\nu$ and $x$, which have parent relations
219 ``superscript'', ``subscript'' and ``argument'' respectively (more
220 relations can easily be added in the future if necessary). A common
221 way of storing this information is e.g.~\mbox{\tt T[mu, -nu, x]} or
222 \mbox{\tt T[up[mu], dn[nu], x]}, but both have their disadvantages:
223 the first form does not allow us to store~$T^{-\mu}{}_{\nu}(x)$,
224 while the second form introduces an additional layer of overhead. A
225 format similar to the second case is also used in
226 Stensor~\cite{maccallum1}, albeit using a different syntax; it has
227 the disadvantage that it is neither a very convenient representation
228 for the computer (especially not when the implementation is in \Cpp),
229 nor a representation which is convenient for the user, as it is quite
230 distinct from \TeX{} notation.
231 \item The tree class not only provides a way to access the nodes of
232 the graph by pre- or post-order traversal, but also
233 provides iterators which access e.g.~only all indices of a node. In
234 the example~\eqref{e:ex1}, an index iterator acting on the {\tt
235 diff} node would return, in turn, the~$\mu$, $\nu$, $\rho$, $\mu$
236 and $\lambda$ indices. This makes it easy to write fast
237 low-level routines which deal directly with the tensor structure of
238 an expression.
239 \item The tree manipulation algorithms are aware of the meaning of
240 ``contracted nodes'' (contracted indices). Whenever one expression
241 graph is inserted into another one, the algorithms automatically ensure
242 that labels which are used to denote contracted indices (i.e.~edges
243 which connect two nodes) are relabelled appropriately. Names are
244 chosen by using property lists (see section~\ref{s:properties}).
245 \item The contraction detection mechanism can deal with sub- or
246 superscripts which do not denote indices, as in
247 e.g.~$A^\dagger$. This is achieved by attaching a special property
248 to the symbol (see section~\ref{s:properties} for more details).
249 \end{itemize}
250 \medskip
252 The enhanced tree structure can be modified at the level of the user
253 interface through standard list manipulation commands, or at the level
254 of custom modules written in~\Cpp.
256 \subsection{Symmetries}
257 \label{s:symmetries}
259 A second issue which cadabra addresses differently from other computer
260 algebra systems is that of node symmetries. It is common in computer
261 algebra systems that there is a generic way to specify so-called
262 \emph{mono-term} symmetries. These are symmetries which relate one
263 particular ordering of arguments to another one, up to a possible
264 overall sign. Cadabra can of course find canonical representations for
265 tensors with mono-term symmetries (using an external
266 implementation~\cite{e_xact} of the double-coset
267 algorithm~\cite{port2}; an alternative backtracking algorithm for
268 mono-term symmetries is described in~\cite{dres1}).
270 However, mono-term symmetries do not exhaust the symmetries of tensors
271 transforming in generic representations of the Lorentz group. They do
272 not include Garnir symmetries of Young tableaux. Examples of such
273 symmetries are the Ricci identity for Riemann tensors,
274 \begin{equation}
275 R_{m n p q} + R_{m p q n} + R_{m q n p} = 0\,,
276 \end{equation}
277 or the Bianchi identity for field strengths. These identities relate
278 more than two terms, and are therefore also called \emph{multi-term}
279 symmetries. Despite the clear importance of being able to take such
280 identities into account, there are very few computer algebra systems
281 which have implemented a solution. The implementation
282 in~\cite{parker1} simply uses a large set of transformation rules for
283 Riemann tensor monomials. These rules were constructed by hand, and
284 are only available for Riemann tensor monomials up to third order
285 (i.e.~it would require tedious work to construct such rules for more
286 general expressions, involving more than just the Riemann or Ricci
287 tensors). An alternative approach is taken
288 in~\cite{maccallum1,ilyi1,e_balf1}, in which the set of all identities
289 for a particular tensor is used to rewrite a given expression in
290 canonical form. This idea of handling multi-term symmetries using a
291 sum-substitution algorithm goes back to at least~\cite{hornf1}.
293 Cadabra, instead, uses Young projector methods internally for all
294 index symmetry handling. The underlying idea is that by applying a
295 Young projector to a tensor, its multi-term symmetries become
296 manifest. This allows one to construct a basis of tensor monomials
297 constructed from arbitrary tensors, and to decompose a given monomial
298 on any preferred basis.\footnote{In order to determine the number of
299 terms in a basis of monomials of tensors, cadabra relies on an
300 external program for the computation of tensor product representations
301 (using the LiE program~\cite{e_cohe1}).} This method was first
302 described in~\cite{Green:2005qr}. For e.g.~Riemann tensors, the idea
303 is to replace all tensors by their equivalent form
304 \begin{equation}
305 \label{e:Rproj}
306 R_{a b c d} \rightarrow
307 \tfrac{1}{3}\big( 2\, R_{a b c d} - R_{a d b c} + R_{a c b d} \big)\,.
308 \end{equation}
309 The expression on the right-hand side manifestly satisfies the cyclic
310 Ricci identity, even if one only knows about the mono-term symmetries
311 of the Riemann tensor. Using the projector~\eqref{e:Rproj} it is easy
312 to show e.g.~that~$2\,R_{a b c d} R_{a c b d} = R_{a b c d} R_{a b c
313 d}$. The monomial on the left-hand side maps to
314 \begin{equation}
315 \begin{aligned}
316 R_{a b c d} R_{a c b d} \rightarrow \tfrac{1}{3} \big( R_{a b c d} R_{a c b d}
317 + R_{a b c d} R_{a b c d} \big)\,,
318 \end{aligned}
319 \end{equation}
320 while $R_{a b c d} R_{a b c d}$ maps to twice this expression, thereby
321 proving the identity.
323 Writing each term in a sum in a canonical form by
324 using~\eqref{e:Rproj} would typically lead to extremely large
325 expressions, and not be very convenient for subsequent
326 calculations. However, the same algorithm can also be used to write a
327 sum in a ``minimal'' form.\footnote{``Minimal'' here does not
328 necessarily mean that the expression has been reduced to the shortest
329 possible form, which is a problem which to the best of my knowledge
330 remains unresolved. That is, while the algorithm removes dependent
331 terms, as in $2\,R_{a b c d} + 2\,R_{b c a d} + R_{c a b d} \rightarrow
332 R_{a b c d} + R_{b c a d}$ (because the third term is found to be
333 expressible as a linear combination of the first two), it does not
334 reduce this further to $- R_{c a b d}$ (typical cases are of course
335 more complicated than this example).} That is, by projecting each
336 term using~\eqref{e:Rproj} the program can perform the simplification
337 \begin{equation}
338 R_{a b c d} R_{a c b d} + R_{a b c d} R_{a b c d}
339 \rightarrow 3\,R_{a b c d} R_{a c b d}\,,
340 \end{equation}
341 i.e.~express the second term in terms of the first one. This does not
342 define a canonical form (the expression could equally well have been
343 written using~$R_{a b c d} R_{a b c d}$), but it does systematically
344 eliminate terms which can be written as linear combinations of other
345 terms.
348 \subsection{Properties}
349 \label{s:properties}
351 A third problem for which cadabra takes a different approach from
352 other systems is that of ``typing'' of symbols and expressions. In
353 cadabra, the meaning of symbols or expressions is determined by
354 associating \emph{properties} to them. Properties can be simple, such
355 as ``being an integer'', or ``being anti-symmetric in all indices'',
356 or ``being an index which is not to be summed over'' (cf.~the
357 discussion in section~\ref{s:graph}). They can also be more complicated
358 and composite, such as ``being an anti-commuting spinor in the
359 left-handed Weyl representation of the eight-dimensional Lorentz
360 group''.
362 The general problem of deducing properties of composite objects from
363 the properties of their constituents is a hard (see
364 e.g~\cite{weib1}). Cadabra takes a pragmatic approach, trying to
365 provide a useful property system for concrete problems rather than
366 trying to be complete or mathematically rigorous. Properties are
367 implemented as a standard multiple-inheritance tree of \Cpp
368 objects. The association to symbols is stored in a map, which relates
369 patterns to pointers to property objects.\footnote{It is important
370 that such properties are implemented at a low level. Most computer
371 algebra systems would allow one to implement e.g.~handling of sets of
372 non-commuting objects using user-defined property testing functions
373 and appropriate transformation rules. It is a much harder problem to
374 make sure that all routines of the underlying system use these
375 properties efficiently and correctly.} This makes it relatively easy
376 to make properties inherit from each other. An example of an
377 inherited property is the property {\tt PartialDerivative}, which
378 inherits from {\tt TableauBase}, so that the symmetry information of
379 objects on which a partial derivative acts are automatically
380 propagated.
382 Nodes can inherit properties from child nodes. A simple situation in
383 which this is useful is for instance when one uses accents to mark
384 symbols, as in e.g.~$\bar{\psi} \psi$. If {\tt \bs{}psi} is declared
385 to be self-anticommuting, we obviously want the~{\tt
386 \bs{}bar\{\bs{}psi\}} tree to have this property as well. When
387 scanning for properties of nodes, the internal algorithms take into
388 account such inheritance of properties. Inheritance of a property is,
389 itself, again implemented as a property (in the example above, the
390 {\tt \bs{}bar} node is declared to have the property {\tt
391 PropertyInherit}, while more fine-tuned inheritance is implemented by
392 deriving from a templated {\tt Inherit} class, as in e.g.~{\tt
393 Inherit<Spinor>}).\footnote{This is similar to Macsyma's types
394 and features: the property which is attached to a symbol is like a
395 `type', while all properties which the symbol inherits from child
396 nodes are like `features'. Property inheritance can also be found
397 other systems, e.g.~Axiom~\cite{daly1}.}
399 Not all property inheritance is, however, as simple as propagating the
400 information up from a deeper lying node. More complicated property
401 inheritance occurs when nodes have to ``compute'' their properties
402 from properties of the child nodes. This occurs for instance when we
403 want to know how products of symbols commute among each other. For
404 such cases, there are more complicated property classes, for instance
405 {\tt CommutingAsProduct} or {\tt CommutingAsSum}. Similarly, there is
406 a property {\tt IndexInherit} which indicate that nodes should make
407 the indices of their child nodes visible to the outside world. Other
408 composite property objects can easily be added to the system.
411 \section{Typical examples}
412 \label{s:examples}
414 In this section, the three main points discussed in the previous
415 section main text (enhanced tree data structures \& algorithms, the
416 use of representation theory to classify object symmetries, and the
417 use of properties) will be illustrated with a number of explicit
418 examples. These examples are meant to be readable without further
419 information about the program language. As such, they also illustrate
420 the ease with which tensorial expressions can be fed into the program.
421 Full details of the input language and transformation algorithms can
422 be found in the manual~\cite{kas_cdb}.
424 \subsection{Index handling and substitution}
426 When doing computations by hand, we do index relabelling almost
427 automatically when a clash occurs. However, unless the computer
428 program is aware of this problem at a low level, clashes are bound to
429 occur frequently. Consider first the standard type of relabelling,
430 illustrated by the expressions
431 \begin{equation}
432 C = A^2\,,\quad \text{with}\quad A = B_{m n} B_{m n}\quad\text{and}\quad
433 B_{n p} = T_{m n} T_{m p}\,.
434 \end{equation}
435 In cadabra one can e.g.~do\footnote{As alluded to in the first
436 section, the notation used here is not generic~\TeX{} but rather a
437 well-defined subset, with some additional conventions required to
438 make the input unambiguous. An example of such a convention is the
439 use of spaces to separate indices; further details about the input
440 format conventions can be found in the reference
441 manual~\cite{kas_cdb}.}
442 \begin{screen}
443 {m,n,p,q#}::Indices(vector).
444 C:= A A;
445 @substitute!(%)( A = B_{m n} B_{m n} );
446 @substitute!(%)( B_{n p} = T_{m n} T_{m p} );
447 \end{screen}
448 where the meaning of the hash symbol on the declaration of the~$q$
449 index (in the first line) will become clear soon. The result is
450 \begin{screen}
451 C:= T_{q2 m} T_{q2 n} T_{q3 m} T_{q3 n} T_{q4 p} T_{q4 q1} T_{q5 p} T_{q5 q1};
452 \end{screen}
453 This type of relabelling and automatic index generation is not an
454 entirely uncommon feature to find in tensor algebra systems, although
455 it is often implemented in an add-on package. The situation becomes
456 more complicated when we have indices which do not occur at the same
457 level, for instance
458 \begin{equation}
459 C = A^2\,,\quad \text{with} \quad
460 A = \partial_m (B_n B_p + C_{n p} ) B_{m n p}\quad\text{and}\quad
461 B_n = T_{n m} S_{m}\,.
462 \end{equation}
463 Few systems know how to deal with these types of expressions
464 elegantly (i.e.~without requiring a cumbersome input format). The
465 reason is that the derivative carries an index, but the objects in the
466 product on which it acts carry indices too, and these indices do not
467 all occur at the same depth of the expression tree. The cadabra
468 instructions, however, remain equally simple as in the previous example,
469 \begin{screen}
470 {m,n,p,q#}::Indices(vector).
471 \partial{#}::Derivative.
472 C:= A A;
473 @substitute!(%)( A = \partial_{m}( B_n B_p + C_{n p} ) B_{m n p} );
474 @substitute!(%)( B_n = T_{n m} S_{m} );
475 \end{screen}
476 The result comes out as the expected
477 \begin{screen}
478 C:= \partial_{m}(T_{n q4} S_{q4} T_{p q5} S_{q5} + C_{n p}) B_{m n p}
479 \partial_{q1}(T_{q2 q6} S_{q6} T_{q3 q7} S_{q7} + C_{q2 q3}) B_{q1 q2 q3};
480 \end{screen}
481 Finally, it of course happens frequently that more than one type of
482 index appears in an expression, labelling tensors in different
483 spaces. Consider for instance,
484 \begin{equation}
485 C = A^2\quad\text{with}\quad A_{m \mu} = \bar{\psi}\Gamma_{m p} \psi\, B_{p \mu}\,,
486 \end{equation}
487 where the roman and Greek indices cannot be interchanged at will,
488 because they refer to flat and curved spaces respectively. This
489 example translates to
490 \begin{screen}
491 {\mu, \rho, \nu#}::Indices(curved).
492 {m, n, p, q#}::Indices(flat).
493 C:= A_{m \nu} A_{m \nu};
494 @substitute!(%)( A_{m \mu}
495 = \bar{\psi}\Gamma_{m p} \psi B_{p \mu \rho} C_{\rho});
496 \end{screen}
497 with the expected result
498 \begin{screen}
499 C:= \bar{\psi} \Gamma_{m p} \psi B_{p \nu \rho} C_{\rho}
500 \bar{\psi} \Gamma_{m n} \psi B_{n \nu \mu} C_{\mu};
501 \end{screen}
502 All this type of relabelling is done by the internal tree manipulation
503 algorithms, which ensures that no algorithm can lead to inconsistent
504 expressions. New dummy indices are taken from the appropriate sets,
505 using the property information associated to the various indices.
508 \subsection{Canonicalisation and Young-tableaux methods}
510 As long as one deals only with symmetric or antisymmetric tensors,
511 many computer algebra systems are able to write tensor monomials in a
512 canonical form (although efficient algorithms for very large numbers
513 of indices or very large numbers of identical tensors have only
514 surfaced relatively recently,
515 see~\cite{Portugal:1998qi,port2,e_xact,e_canon}). Generic algorithms
516 for multi-term Garnir symmetries, such as the Ricci or Bianchi
517 identity, are much less widespread; see the discussion in
518 section~\ref{s:symmetries}. Cadabra is the first system to label
519 tensors by Young tableaux and to use Young projector methods to handle
520 multi-term symmetries.
522 A common problem in which multi-term symmetries play an important role
523 is the construction of a basis of all tensor monomials of a given
524 length dimension. Determining the number of elements of such a basis
525 is a relatively straightforward exercise in group
526 theory~\cite{Fulling:1992vm}. In order to actually construct the
527 basis, cadabra uses the Young projector method described in the
528 appendix of~\cite{Green:2005qr}. As an example, let us construct a
529 basis of monomials cubic in the Riemann tensor,
530 \begin{screen}
531 {m,n,p,q,r,s,t,u,v,w,a,b}::Indices(vector).
532 {m,n,p,q,r,s,t,u,v,w,a,b}::Integer(0..9).
533 R_{m n p q}::RiemannTensor.
535 basisR3:= R_{m n p q} R_{r s t u} R_{v w a b};
536 @all_contractions(%);
538 @canonicalise!(%):
539 @substitute!(%)( R_{m n m n} -> R ):
540 @substitute!(%)( R_{m n m p} -> R_{n p} );
541 \end{screen}
542 After a declaration of the objects to be used, the program determines
543 in one step all possible independent contractions of three Riemann
544 tensors. The last two lines only serve to rewrite the result in terms
545 of Ricci tensors and scalars, after which the output takes the form
546 \begin{screen}
547 basisR3:= \{ R_{m n p q} R_{m p r s} R_{n r q s},
548 R R_{q r} R_{q r},
549 R_{n p} R_{n q p r} R_{q r},
550 R_{n p} R_{n q r s} R_{p r q s},
551 R R_{p q r s} R_{p q r s},
552 R_{n p} R_{n r} R_{p r},
553 R_{m n p q} R_{m r p s} R_{n r q s},
554 R R R \};
555 \end{screen}
556 This result is equivalent to the basis given in the ``${\mathcal R}^0_{6,3}$''
557 table on page~1184 of~\cite{Fulling:1992vm}.
559 It is also possible to decompose any given tensor monomial on a
560 previously constructed basis. Take for example the basis of
561 Weyl tensor monomials of fourth order. This basis can be read off from
562 the tables of~\cite{Fulling:1992vm},
563 \begin{equation}
564 \begin{aligned}
565 W_1 &= W_{m n a b} W_{n p b c} W_{p s c d} W_{s m d a}\,,\\[1ex]
566 W_2 &= W_{m n a b} W_{n p b c} W_{m s c d} W_{s p d a}\,,\\[1ex]
567 W_3 &= W_{m n a b} W_{p s b a} W_{m n c d} W_{p s d c}\,,\\[1ex]
568 W_4 &= W_{m n a b} W_{m n b a} W_{p s c d} W_{p s d c}\,,\\[1ex]
569 W_5 &= W_{m n a b} W_{n p b a} W_{p s c d} W_{s m d c}\,,\\[1ex]
570 W_6 &= W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c}\,,\\[1ex]
571 W_7 &= W_{m n}{}^{[m n} W_{p q}{}^{p q} W_{r s}{}^{r s} W_{t u}{}^{t u]}\,.
572 \end{aligned}
573 \end{equation}
574 If we want to find the decomposition
575 \begin{equation}
576 W_{p q r s} W_{p t r u} W_{t v q w} W_{u v s w}- W_{p q r s} W_{p q t u} W_{r v t w} W_{s v u w}
577 = W_2 - \tfrac{1}{4} W_6\,,
578 \end{equation}
579 using ``classical'' methods, we would need to figure out the right way
580 to repeatedly apply the Ricci cyclic identity to the left-hand side of
581 this expression. The appropriate program to decompose the left-hand
582 side on the seven-term basis and prove this identity is
583 \begin{screen}
584 {m,n,p,q,r,s,t,u,v,w,a,b,c,d,e,f}::Indices(vector).
585 W_{m n p q}::WeylTensor.
587 W1:= W_{m n a b} W_{n p b c} W_{p s c d} W_{s m d a};
588 W2:= W_{m n a b} W_{n p b c} W_{m s c d} W_{s p d a};
589 W3:= W_{m n a b} W_{p s b a} W_{m n c d} W_{p s d c};
590 W4:= W_{m n a b} W_{m n b a} W_{p s c d} W_{p s d c};
591 W5:= W_{m n a b} W_{n p b a} W_{p s c d} W_{s m d c};
592 W6:= W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c};
593 W7:= W_{m n}^{m n} W_{p q}^{p q} W_{r s}^{r s} W_{t u}^{t u};
594 @asym!(%){^{m},^{n},^{p},^{q},^{r},^{s},^{t},^{u}}:
595 @substitute!(%)( W_{a b}^{c d} -> W_{a b c d} ):
596 @indexsort!(%):
597 @collect_terms!(%):
598 @canonicalise!(%):
599 @collect_terms!(%);
601 basisW4:= { @(W1), @(W2), @(W3), @(W4), @(W5), @(W6), @(W7) };
603 W_{p q r s} W_{p t r u} W_{t v q w} W_{u v s w}
604 - W_{p q r s} W_{p q t u} W_{r v t w} W_{s v u w};
605 @decompose!(%){ @(basisW4) };
606 @list_sum!(%);
607 @collect_terms!(%);
608 \end{screen}
609 Most of this code is self-explanatory. The first two lines declare the
610 symbols and objects to be used, the next block of lines declares the
611 basis and performs the eight-fold anti-symmetrisation for the last
612 basis element.\footnote{Commands such as {\tt @collect\_terms} can
613 be added to a list of default rules to be applied automatically;
614 they have been included here so that all steps are explicit.}
615 The decomposition is done with the last three lines. The
616 final output of this small program reads
617 \begin{screen}
618 {0, 1, 0, 0, 0, -1/4, 0 };
619 \end{screen}
620 Internally, this involved a Young-projection of all tensors in the
621 basis, a projection of the tensors in the expression which we want to
622 decompose, and a solution of a system of linear
623 equations~\cite{Green:2005qr}. The internal algorithm is completely
624 generic and applies to tensor monomials with arbitrary symmetries.
626 \subsection{Properties and property inheritance}
628 A typical class of problems in which one handles tensors of both
629 commuting and anti-commuting type is the construction of
630 supersymmetric actions. This class of problems also shows the use of
631 implicit dependence of tensors on coordinates, as well as inheritance
632 of spinor and anti-commutativity properties.
634 Consider as a trivial example -- which is nevertheless not easy to
635 reproduce with other computer algebra systems -- the invariance of the
636 super-Maxwell action
637 \begin{equation}
638 S = \int\!{\rm d^4}x\, \Big[ -\frac{1}{4} (f_{ab})^2 -
639 \frac{1}{2}\bar{\lambda}\gamma^a \partial_a \lambda\Big]\,,
640 \end{equation}
641 (where~$f_{ab} = \partial_a A_b - \partial_b A_a$) under the
642 transformations
643 \begin{equation}
644 \delta A_a = \bar{\epsilon}\gamma_a \lambda\,,\quad
645 \delta \lambda = -\frac{1}{2} \gamma^{a b} \epsilon\, f_{a b}\,.
646 \end{equation}
647 The object properties for this problem are
648 \begin{screen}
649 { a,b,c,d,e }::Indices(vector).
650 \bar{#}::DiracBar.
651 { \partial{#}, \ppartial{#} }::PartialDerivative.
652 { A_{a}, f_{a b} }::Depends(\partial, \ppartial).
653 { \epsilon, \gamma_{#} }::Depends(\bar).
654 \lambda::Depends(\bar, \partial).
655 { \lambda, \gamma_{#} }::NonCommuting.
656 { \lambda, \epsilon }::Spinor(dimension=4, type=Majorana).
657 { \epsilon, \lambda }::SortOrder.
658 { \epsilon, \lambda }::AntiCommuting.
659 \lambda::SelfAntiCommuting.
660 \gamma_{#}::GammaMatrix.
661 \delta{#}::Accent.
662 f_{a b}::AntiSymmetric.
663 \delta_{a b}::KroneckerDelta.
664 \end{screen}
665 Note the use of two types of properties: those which apply to a single
666 object, like {\tt Depends}, and those which are associated to a list
667 of objects, like {\tt AntiCommuting}. Clearly $\partial_a \lambda$ and
668 $\epsilon$ are anti-commuting too, but the program figures this out
669 automatically from the fact that {\tt $\backslash$partial} has a {\tt
670 PartialDerivative} property associated to it.
672 The actual calculation is an almost direct transcription of the
673 calculation one would do by hand.\footnote{This example makes use of a
674 set of default rules, to wit ``{\tt ::PostDefaultRules(
675 @@prodsort!(\%), @@rename\_dummies!(\%), @@canonicalise!(\%),
676 @@collect\_terms!(\%) )}'', which mimick the automatic rewriting
677 behaviour of many other computer algebra systems and get invoked
678 automatically at each step. See~\cite{kas_cdb} for more details.}
679 First we define the supersymmetry transformation rules and the action,
680 which can be entered as in~\TeX{},
681 \begin{screen}
682 susy:= { \delta{A_{a}} = \bar{\epsilon} \gamma_{a} \lambda,
683 \delta{\lambda} = -(1/2) \gamma_{a b} \epsilon f_{a b} };
685 S:= -(1/4) f_{a b} f_{a b}
686 - (1/2) \bar{\lambda} \gamma_{a} \partial_{a}{\lambda};
687 \end{screen}
688 Showing invariance starts by applying a variational derivative,
689 \begin{screen}
690 @vary!(%)( f_{a b} -> \partial_{a}{\delta{A_{b}}} - \partial_{b}{\delta{A_{a}}},
691 \lambda -> \delta{\lambda} );
693 @distribute!(%);
694 @substitute!(%)( @(susy) ): @prodrule!(%): @distribute!(%): @unwrap!(%);
695 \end{screen}
696 After these steps, the result is (shown exactly as it appears in the
697 graphical and the \TeX{}macs~\cite{vdH:Gut} front-ends)%
698 \begin{equation}
699 S = \bar{\epsilon} \gamma_{a} \partial_{b} \lambda\, f_{ab}
700 + \frac{1}{4} \overline{\gamma_{ab} \epsilon} \gamma_{c}
701 \partial_c\lambda\, f_{ab}
702 + \frac{1}{4} \bar{\lambda}\gamma_a \gamma_{bc} \epsilon \partial_a f_{bc}\,.
703 \end{equation}
704 Since the program knows about the properties of gamma matrices it can
705 rewrite the Dirac bar, and then we do one further partial integration,
706 \begin{screen}
707 @rewrite_diracbar!(%);
708 @substitute!(%)( \partial_{c}{f_{a b}} -> \ppartial_{c}{f_{a b}} ):
709 @pintegrate!(%){\ppartial}:
710 @rename!(%){"\ppartial"}{"\partial"}:
711 @prodrule!(%): @unwrap!(%);
712 \end{screen}
713 What remains is the gamma matrix algebra, a rewriting of the
714 derivative of the Dirac bar as the Dirac bar of a derivative, and
715 sorting of spinors (which employs inheritance of the {\tt Spinor} and
716 {\tt AntiCommuting} properties as already alluded to earlier),
717 \begin{screen}
718 @join!(%){expand}: @distribute!(%): @eliminate_kr!(%):
719 @substitute!(%)( \partial_{a}{\bar{\lambda}} -> \bar{\partial_{a}{\lambda}} );
720 @spinorsort!(%):
721 \end{screen}
722 The result is (after partial integration) a Bianchi identity on the
723 field strength, and thus invariance of the action.
725 While this example is rather simple, and does not require a computer
726 algebra system for its solution, it illustrates that the extended tree
727 structure together with the property system make it possible to
728 manipulate expressions in a way which closely resembles what one would
729 do when solving the problem with pencil and paper. Several more
730 complicated examples will be discussed in the
731 upcoming~\cite{kas_cdb_hep}.
734 \section{Summary}
736 I have presented a new prototype computer algebra system which is
737 designed to be an easy-to-use scratch pad for problems encountered in
738 field theory. The current library of algorithms include functionality
739 to deal with bosonic and fermionic tensors, spinors, gamma matrices,
740 differential operators and so on, all through the use of a
741 multiple-inheritance property mechanism. Cadabra is the first system
742 which handles generic multi-term tensor symmetries using a
743 Young-projector based algorithm. It is also the first system which
744 accepts input in~\TeX{} form, eliminating tedious translation steps
745 and making programs much easier to read for new users. Finally, the
746 source code of the system is freely available and the reference guide
747 contains extensive documentation explaining how to add new algorithm
748 modules to the program.
751 \section*{Acknowledgements}
753 I am grateful to Jos\'e Martin-Garcia for inspiring discussions and
754 for help with the use of his {\tt xPerm} code~\cite{e_xact} for
755 mono-term canonicalisation. I thank the anonymous referee for
756 extensive comments which have substantially improved this paper.
758 \setlength{\bibsep}{4pt}
759 %\bibliographystyle{kasper}
760 %\bibliography{kasbib}
761 \begingroup\raggedright\begin{thebibliography}{23}
762 \expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi
764 \bibitem[Fateman and Caspi(1999)]{fateman99parsing}
765 R.~J. Fateman and E.~Caspi, ``Parsing {{\TeX}} into mathematics'', {\em SIGSAM
766 Bulletin (ACM Special Interest Group on Symbolic and Algebraic Manipulation)}
767 {\bf 33} (1999), no.~3, 26.
769 \bibitem[Martin-Garcia(????)]{e_xact}
770 J.~Martin-Garcia, ``{xPerm and xAct}'',
771 \url{http://metric.iem.csic.es/Martin-Garcia/xAct/index.html}.
773 \bibitem[{Balfag\'on} et~al.(????){Balfag\'on}, {Castellv\'\i}, and
774 {Ja\'en}]{e_balf1}
775 A.~{Balfag\'on}, P.~{Castellv\'\i}, and X.~{Ja\'en}, ``Tools of tensor
776 calculus'', \url{http://baldufa.upc.es/xjaen/ttc/}.
778 \bibitem[Klioner(1997)]{Klioner:1997sv}
779 S.~A. Klioner, ``{EinS: A Mathematica package for computations with indexed
780 objects}'',
781 \href{http://xxx.lanl.gov/abs/gr-qc/0011012}{{\tt gr-qc/0011012}}.
782 %%CITATION = GR-QC 0011012;%%.
784 \bibitem[Parker and Christensen(1994)]{parker1}
785 L.~Parker and S.~M. Christensen, ``Mathtensor : A system for doing tensor
786 analysis by computer'', Addison-Wesley, 1994.
788 \bibitem[Vermaseren(2000)]{Vermaseren:2000nd}
789 J.~A.~M. Vermaseren, ``New features of {FORM}'',
790 \href{http://xxx.lanl.gov/abs/math-ph/0010025}{{\tt math-ph/0010025}}.
791 %%CITATION = MATH-PH 0010025;%%.
793 \bibitem[Peeters(2006)]{kas_cdb}
794 K.~Peeters, ``Cadabra: tutorial and reference guide'', 2006,
795 \url{http://www.aei.mpg.de/~peekas/cadabra/}.
797 \bibitem[van~der Hoeven(2001)]{vdH:Gut}
798 J.~van~der Hoeven, ``{GNU TeXmacs: A free, structured, wysiwyg and technical
799 text editor}'', in ``Le document au XXI-i\`eme si\`ecle'', D.~Flipo, ed.,
800 vol.~39--40, pp.~39--50.
801 \newblock Metz, 14--17 mai 2001.
802 \newblock Actes du congr\`es GUTenberg. \url{http://www.texmacs.org}.
804 \bibitem[Peeters(2006)]{kas_tree}
805 K.~Peeters, ``Tree.hh'', 2006, \url{http://www.aei.mpg.de/~peekas/tree/}.
807 \bibitem[Musser and Saini(1996)]{b_muss1}
808 D.~R. Musser and A.~Saini, ``{STL} tutorial and reference guide, {C++}
809 programming with the standard template library'', Addison Wesley, 1996.
811 \bibitem[MacCallum and Skea(1994)]{maccallum1}
812 M.~A.~H. MacCallum and J.~E.~F. Skea, ``{SHEEP: A computer algebra system for
813 general relativity}'', in ``Algebraic computing in general relativity'',
814 M.~J. {Rebou\c{c}as} and W.~L. Roque, eds., pp.~1--172.
815 \newblock Oxford, 1994.
817 \bibitem[Portugal(1999)]{port2}
818 R.~Portugal, ``Algorithmic simplification of tensor expressions'', {\em J.\
819 Phys.} {\bf A32} (1999) 7779--7789.
821 \bibitem[Dresse(1993)]{dres1}
822 A.~Dresse, ``Polynomial poisson structures and dummy variables in computer
823 algebra'', PhD thesis, Universit\'e Libre de Bruxelles, 1993.
825 \bibitem[Ilyin and Kryukov(1996)]{ilyi1}
826 V.~A. Ilyin and A.~P. Kryukov, ``{ATENSOR} - {REDUCE} program for tensor
827 simplification'', {\em Comp.\ Phys.\ Commun.} {\bf 96} (1996) 36--52.
829 \bibitem[Hornfeldt(1979)]{hornf1}
830 L.~Hornfeldt, ``A system for automatic generation of tensor algorithms and
831 indicial tensor calculus, including substitution of sums'', in ``Proceedings
832 of EUROSAM 79'', Ng, ed., vol.~72 of {\em Lecture Notes in Computer Science},
833 pp.~279--290.
834 \newblock Springer, 1979.
836 \bibitem[Cohen et~al.(1998)Cohen, van Leeuwen, and Lisser]{e_cohe1}
837 A.~Cohen, M.~van Leeuwen, and B.~Lisser, ``{LiE} v.~2.2'', 1998,
838 \url{http://wwwmathlabo.univ-poitiers.fr/~maavl/LiE/}.
840 \bibitem[Green et~al.(2005)Green, Peeters, and Stahn]{Green:2005qr}
841 M.~B. Green, K.~Peeters, and C.~Stahn, ``Superfield integrals in high
842 dimensions'', {\em JHEP\,} {\bf 08} (2005) 093,
843 \href{http://xxx.lanl.gov/abs/hep-th/0506161}{{\tt hep-th/0506161}}.
844 %%CITATION = HEP-TH 0506161;%%.
846 \bibitem[Weiberl and Gonnet(1991)]{weib1}
847 T.~Weiberl and G.~H. Gonnet, ``An algebra of properties'', in ``Proceedings of
848 the ISSAC-91 Conference, Bonn'', pp.~352--359.
849 \newblock 1991.
851 \bibitem[Daly(2005)]{daly1}
852 T.~Daly, ``Axiom volume 1: tutorial'', Lulu press, 2005.
854 \bibitem[Portugal(1998)]{Portugal:1998qi}
855 R.~Portugal, ``An algorithm to simplify tensor expressions'', {\em Comp.\
856 Phys.\ Commun.} {\bf 115} (1998) 215--230,
857 \href{http://xxx.lanl.gov/abs/gr-qc/9803023}{{\tt gr-qc/9803023}}.
858 %%CITATION = GR-QC 9803023;%%.
860 \bibitem[Portugal(????)]{e_canon}
861 R.~Portugal, ``{The Canon package}'',
862 \url{http://www.cbpf.br/~portugal/Canon.html}.
864 \bibitem[Fulling et~al.(1992)Fulling, King, Wybourne, and
865 Cummins]{Fulling:1992vm}
866 S.~A. Fulling, R.~C. King, B.~G. Wybourne, and C.~J. Cummins, ``Normal forms
867 for tensor polynomials. 1: The {Riemann} tensor'', {\em Class.\ Quant.\
868 Grav.} {\bf 9} (1992)
869 1151.
870 %%CITATION = CQGRD,9,1151;%%.
872 \bibitem[Peeters(????)]{kas_cdb_hep}
873 K.~Peeters, ``{Introducing Cadabra: a symbolic computer algebra system for
874 field theory problems}'', {\tt hep-th/0701238}.
876 \end{thebibliography}\endgroup
878 \end{document}