Skip to main content

Generative Programming for Automatic Differentiation

  • Conference paper
  • First Online:
Recent Advances in Algorithmic Differentiation

Part of the book series: Lecture Notes in Computational Science and Engineering ((LNCSE,volume 87))

  • 1875 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 84.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 109.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 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. 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. 3.

    The identifier of an independent variable is specified by the template parameter ID of the class Var, see Sect. 3.1.1.

  4. 4.

    Note that the compiler can automatically deduce the template parameter D from the argument d.

  5. 5.

    For example, the type of res from Listing 3 is Derivative<double, 2, VarList<’x’, ’y’>>.

References

  1. Alexandrescu, A.: Modern C\(++\) design: generic programming and design patterns applied. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA (2001)

    Google Scholar 

  2. 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)

    Google Scholar 

  3. Becker, P.: Working Draft, Standard for Programming Language C\(++\). Tech. Rep. N3242=11-0012, ISO/IEC JTC1/SC22/WG21 (2011)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. 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)

    Google Scholar 

  6. 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)

    Google Scholar 

  7. Gregor, D., Järvi, J., Powell, G.: Variadic templates (revision 3). Tech. Rep. N2080=06-0150, ISO/IEC JTC1/SC22/WG21 (2006)

    Google Scholar 

  8. 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

    Google Scholar 

  9. 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)

    Google Scholar 

  10. Myers, N.: A new and useful template technique: ”Traits”. C\(++\) Report 7(5), 32–35 (1995)

    Google Scholar 

  11. Nehmeier, M.: Generative programming for automatic differentiation in C\(++\)0x. Tech. Rep. 483, University of Würzburg (2011)

    Google Scholar 

  12. 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

    Google Scholar 

  13. Veldhuizen, T.: Expression templates. C\(++\) Report 7(5), 26–31 (1995)

    Google Scholar 

  14. Veldhuizen, T.: Using C\(++\) template metaprograms. C\(++\) Report 7(4), 36–43 (1995)

    Google Scholar 

  15. Veldhuizen, T.: C\(++\) templates are Turing complete. Tech. rep. (2003)

    Google Scholar 

Download references

Acknowledgements

We would like to thank the three anonymous referees for their helpful comments and suggestions.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Marco Nehmeier .

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics