Table of Contents
Fetching ...

Optimising Code Generation with haggies

Thomas Reiter

TL;DR

haggies is an open-source code-generation backend that converts large algebraic expressions into optimized, language-specific numerical code. It combines a type inference system with multivariate Horner factorization and common subexpression elimination, followed by linear-scan register allocation, to produce compact, fast executable code through flexible pattern-based templates. The approach scales to very large expressions typical in one-loop quantum field theory calculations and is demonstrated across diverse examples (RK integrator, Gaussian quadrature, color algebra, amplitude calculations, interval solvers). By separating the computer algebra from output templates, haggies enables re-use across languages and projects, facilitating integration with existing CAS workflows and large-scale computational pipelines.

Abstract

This article describes haggies, a program for the generation of optimised programs for the efficient numerical evaluation of mathematical expressions. It uses a multivariate Horner-scheme and Common Subexpression Elimination to reduce the overall number of operations. The package can serve as a back-end for virtually any general purpose computer algebra program. Built-in type inference that allows to deal with non-standard data types in strongly typed languages and a very flexible, pattern-based output specification ensure that haggies can produce code for a large variety of programming languages. We currently use haggies as part of an automated package for the calculation of one-loop scattering amplitudes in quantum field theories. The examples in this articles, however, demonstrate that its use is not restricted to the field of high energy physics.

Optimising Code Generation with haggies

TL;DR

haggies is an open-source code-generation backend that converts large algebraic expressions into optimized, language-specific numerical code. It combines a type inference system with multivariate Horner factorization and common subexpression elimination, followed by linear-scan register allocation, to produce compact, fast executable code through flexible pattern-based templates. The approach scales to very large expressions typical in one-loop quantum field theory calculations and is demonstrated across diverse examples (RK integrator, Gaussian quadrature, color algebra, amplitude calculations, interval solvers). By separating the computer algebra from output templates, haggies enables re-use across languages and projects, facilitating integration with existing CAS workflows and large-scale computational pipelines.

Abstract

This article describes haggies, a program for the generation of optimised programs for the efficient numerical evaluation of mathematical expressions. It uses a multivariate Horner-scheme and Common Subexpression Elimination to reduce the overall number of operations. The package can serve as a back-end for virtually any general purpose computer algebra program. Built-in type inference that allows to deal with non-standard data types in strongly typed languages and a very flexible, pattern-based output specification ensure that haggies can produce code for a large variety of programming languages. We currently use haggies as part of an automated package for the calculation of one-loop scattering amplitudes in quantum field theories. The examples in this articles, however, demonstrate that its use is not restricted to the field of high energy physics.

Paper Structure

This paper contains 73 sections, 29 equations, 4 figures, 3 tables, 1 algorithm.

Figures (4)

  • Figure 1: A Feynman diagram contributing to the process $gg\rightarrow b\bar{b}b\bar{b}$ at next-to-leading order in QCD.
  • Figure 2: Structure of the program haggies. Dashed lines denote data flow, continuous lines stand for control flow.
  • Figure 3: AST representation of the expression $5/2xyf(x)-xf(x)\cdot(y-1)+3y^2$; here, the second term is already expanded. The dotted lines separate basis and exponents inside a product. A mixed tree/array representation is used to guarantee quick access to the elements. The character '@' is used here to denote a pointer.
  • Figure 4: Results obtained for the Lorenz oscillator as specified in Equation \ref{['eq:lorenz-osc']} for $0\leq t\leq20$ with $\vec{y}(0)=(0,1,20)$ and a precision of $10^{-6}$. The graphics on the left shows the solution integrated with the Runge-Kutta-Fehlberg method, which is fourth order. The second graph compares the evolution of the second coordinate for different methods. Both plots are generated for a goal precision of $10^{-6}$. At $t>18$ the integration becomes unreliable. For $10^{-7}$ (not shown) all curves would follow the Fehlberg method, which does not change substantially by increasing the precision beyond $10^{-6}$.