Abstract
In this paper we present a concept for a C\(++\) implementation of forward automatic differentiation of an arbitrary order using expression templates and template metaprogramming. In contrast to other expression template implementations, the expression tree in our implementation has only symbolic characteristics. The run-time code is then generated from the tree structure using template metaprogramming functions to apply the rules of symbolic differentiation onto the single operations at compile-time. This generic approach has the advantage that the template metaprogramming functions are replaceable which offers the opportunity to easily generate different specialized algorithms. We tested the functionality, correctness and performance of a prototype in different case studies for floating point as well as interval data types and compared it against other implementations.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Note that because of the introduction of type inference with the keyword auto in the new C\(++\) standard (C\(++\)11, formerly known as C\(++\)0x) [3] the usage of expression template and template metaprogramming libraries is extremely simplified for the user.
- 2.
Note that we additionally allow instances of the result type Derivative from Sect. 3.1.2 as leaf nodes. Hence, it is possible to work with intermediate results, e.g. res in Listing 3.
- 3.
The identifier of an independent variable is specified by the template parameter ID of the class Var, see Sect. 3.1.1.
- 4.
Note that the compiler can automatically deduce the template parameter D from the argument d.
- 5.
For example, the type of res from Listing 3 is Derivative<double, 2, VarList<’x’, ’y’>>.
References
Alexandrescu, A.: Modern C\(++\) design: generic programming and design patterns applied. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA (2001)
Aubert, P., Di Césaré, N., Pironneau, O.: Automatic differentiation in C\(++\) using expression templates and application to a flow control problem. Computing and Visualization in Science 3, 197–208 (2001)
Becker, P.: Working Draft, Standard for Programming Language C\(++\). Tech. Rep. N3242=11-0012, ISO/IEC JTC1/SC22/WG21 (2011)
Bendtsen, C., Stauning, O.: FADBAD, a flexible C\(++\) package for automatic differentiation. Technical Report IMM–REP–1996–17, Department of Mathematical Modelling, Technical University of Denmark, Lyngby, Denmark (1996)
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: elements of reusable object-oriented software. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA (1995)
Gil, J., Gutterman, Z.: Compile time symbolic derivation with C\(++\) templates. In: Proceedings of the 4th USENIX Conference on Object-Oriented Technologies and Systems, COOTS’98, pp. 249–264. USENIX Association, Berkeley, CA, USA (1998)
Gregor, D., Järvi, J., Powell, G.: Variadic templates (revision 3). Tech. Rep. N2080=06-0150, ISO/IEC JTC1/SC22/WG21 (2006)
Griewank, A., Juedes, D., Utke, J.: Algorithm 755: ADOL-C: A package for the automatic differentiation of algorithms written in C/C\(++\). ACM Transactions on Mathematical Software 22(2), 131–167 (1996). URL http://doi.acm.org/10.1145/229473.229474
Hammer, R., Ratz, D., Kulisch, U., Hocks, M.: C\(++\) Toolbox for Verified Computing I: Basic Numerical Problems. Springer-Verlag New York, Inc., Secaucus, NJ, USA (1997)
Myers, N.: A new and useful template technique: ”Traits”. C\(++\) Report 7(5), 32–35 (1995)
Nehmeier, M.: Generative programming for automatic differentiation in C\(++\)0x. Tech. Rep. 483, University of Würzburg (2011)
Phipps, E.T., Bartlett, R.A., Gay, D.M., Hoekstra, R.J.: Large-scale transient sensitivity analysis of a radiation-damaged bipolar junction transistor via automatic differentiation. In: C.H. Bischof, H.M. Bücker, P.D. Hovland, U. Naumann, J. Utke (eds.) Advances in Automatic Differentiation, Lecture Notes in Computational Science and Engineering, vol. 64, pp. 351–362. Springer, Berlin (2008). DOI 10.1007/ 978-3-540-68942-3{ _}31
Veldhuizen, T.: Expression templates. C\(++\) Report 7(5), 26–31 (1995)
Veldhuizen, T.: Using C\(++\) template metaprograms. C\(++\) Report 7(4), 36–43 (1995)
Veldhuizen, T.: C\(++\) templates are Turing complete. Tech. rep. (2003)
Acknowledgements
We would like to thank the three anonymous referees for their helpful comments and suggestions.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2012 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Nehmeier, M. (2012). Generative Programming for Automatic Differentiation. In: Forth, S., Hovland, P., Phipps, E., Utke, J., Walther, A. (eds) Recent Advances in Algorithmic Differentiation. Lecture Notes in Computational Science and Engineering, vol 87. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-30023-3_24
Download citation
DOI: https://doi.org/10.1007/978-3-642-30023-3_24
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-30022-6
Online ISBN: 978-3-642-30023-3
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)