Ev3: A Library for Symbolic Computation in C++ using n-ary Trees Leo Liberti LIX, ´ Ecole Polytechnique, 91128 Palaiseau, France (liberti@lix.polytechnique.fr) 3 october 2003 Abstract Ev3 is a callable C++ library for performing symbolic computation (calculation of symbolic derivatives and various expression simplification). The purpose of this library is to furnish a fast means to use symbolic derivatives to third-party scientific software (e.g. nonlinear optimization, solution of nonlinear equations). It is small, easy to interface, even reasonably easy to change; it is written in C++ and the source code is available. One feature that makes Ev3 very efficient in algebraic manipulation is that the data structures are based on n-ary trees. 1 Introduction Computer Algebra Systems (CAS) have helped mathematicians, physicists, engineers and other scientists enormously since their appearance. CASes are extremely useful in performing complex symbolic calcu- lations quickly. They do not generally require particular programming skills, yet they manage to carry out numerical analysis, symbolic manipulation and graph plotting in 2 and 3 dimensions. The range of existing CASes is impressive, both commercially available (e.g. Mathematica, Maple, Matlab, Mathcad, Reduce, Mupad etc.) and as free software (e.g. Maxima, GAP, yacas, Singular, GiNaC etc.); however most of them (with the notable exception of GiNaC, see below) fall short on the external Application Programming Interface (API), i.e. it is difficult, or impossible in many cases, to create a program in a compiled language, say in C/C++ or Fortran, which can use the external CAS facilities. This is a serious hindrance for user applications with programming requirements that go beyond those offered by the CAS proprietary language, or for those applications that need to be coded in a compiled language for efficiency, but would still benefit from the CAS facilities. The need for CAS-type libraries designed to be used from an API arises as the complexity or the commercial viability of the application gets higher. Thus, having experienced the benefits of CASes from the command line, so to speak, users now want to incorporate these functionalities in their own programs. This paper presents Ev3, a callable C++ library designed to perform simple symbolic manipulation. “Simple” in this context means symbolic differentiation and various expression simplifications. Thus, Ev3 is very useful for those scientific applications that need to compute derivatives, like for example continuous nonlinear programming or nonlinear equation solving. The reason why we have chosen to keep Ev3 “simple”, i.e. to limit the range of symbolic algorithms included in Ev3, is that we expect advanced users to take the source code and modify it to suit their own needs. For example, if an application needs a symbolic integration routine, Ev3’s data structures and basic methods can be used as a starting point. We did our best in keeping Ev3’s source code small, readable, well structured and easily extendable. Ev3 can be downloaded from http://www.lix.polytechnique.fr/ liberti/Ev3-1.0.tar.gz. Ev3 records mathematical expressions in a tree-like data structure (called n-ary tree) where each node has an arbitrary number of direct subnodes. Monomials of all degrees (including constants) are represented by the leaf nodes of the tree, and mathematical operators by the intermediate nodes. Entire subexpressions can be easily changed, substituted or deleted. New expressions can be formed in a