Shock with Confidence: Formal Proofs of Correctness for Hyperbolic Partial Differential Equation Solvers
Abstract.
First-order systems of hyperbolic partial differential equations (PDEs) occur ubiquitously throughout computational physics, commonly used in simulations of fluid turbulence, shock waves, electromagnetic interactions, and even general relativistic phenomena. Such equations are often challenging to solve numerically in the non-linear case, due to their tendency to form discontinuities even for smooth initial data, which can cause numerical algorithms to become unstable, violate conservation laws, or converge to physically incorrect solutions. In this paper, we introduce a new formal verification pipeline for such algorithms in Racket, which allows a user to construct a bespoke hyperbolic PDE solver for a specified equation system, generate low-level C code which verifiably implements that solver, and then produce formal proofs of various mathematical and physical correctness properties of the resulting implementation, including stability, flux conservation, and physical validity. We outline how these correctness proofs are generated, using a custom-built theorem-proving and automatic differentiation framework that fully respects the algebraic structure of floating-point arithmetic, and show how the resulting C code may either be used to run standalone simulations, or integrated into a larger computational multiphysics framework such as Gkeyll.
1. Introduction
Systems of hyperbolic partial differential equations (PDEs) constitute a highly general class of mathematical models for phenomena involving waves, or the wave-like propagation of information, including water waves in hydrodynamic modeling(Vreugdenhil, 1994), blast waves in explosives modeling(Fickett, 1985), gravitational waves in general relativity(Auger and Plagnol, 2017)111Indeed, the Einstein field equations themselves can be cast in a purely hyperbolic form(Gorard, 2024)., and even traffic waves in vehicular traffic flows(Musha and Higuchi, 1978). When systems of hyperbolic PDEs are non-linear, they have a tendency to form discontinuities after finite time (even for arbitrarily smooth initial data)(Toro and Billett, 2000), such as shock waves and contact discontinuities. Such discontinuities are notoriously challenging to capture using standard numerical techniques such as finite difference methods, since the discontinuous solution to the PDE system does not exist in the strong sense (only in the weak/distributional sense), and such methods will therefore typically violate certain crucial conservation laws (such as conservation of energy, or conservation of momentum) in the presence of such discontinuities(Harten et al., 1976). This has led to the development of a variety of finite volume algorithms, and specifically high-resolution shock-capturing (HRSC) schemes(Toro, 2009), which capture these non-linear discontinuities by solving the weak/integral form of the PDE system directly, in a manner which fully guarantees conservation. However, Godunov’s theorem222Linear, monotonicity-preserving schemes cannot be more than first-order accurate(Laney, 1998)., a central result in the theory of numerical methods for hyperbolic PDEs, implies that naive algorithms have a tendency to produce spurious oscillations (i.e. violations of the total variation diminishing, or TVD, property(Harten, 1983)), or otherwise to introduce new extrema into the solution (i.e. violations of the monotonicity-preservation property). One way around this highly distressing theorem is to sacrifice either linearity or higher-order accuracy of the method in the vicinity of shock waves. To make matters worse, since thermodynamic quantities such as entropy tend to be discontinuous across shocks, some methods may converge to mathematically correct but physically invalid solutions (e.g. solutions which decrease total entropy), unless certain additional entropy conditions are satisfied(Osher, 1984).
In this paper, we introduce a new technique for producing formally verified implementations of high-resolution shock-capturing schemes, with provable mathematical and physical correctness properties. We develop a domain-specific language in Racket(Felleisen et al., 2015) for representing arbitrary first-order systems of hyperbolic PDEs, from which verifiable C code can then be automatically synthesized, implementing a variety of bespoke first- and second-order accurate finite volume algorithms to solve them. We also introduce a suite of novel automated theorem-proving and automatic differentiation tools which fully respect the algebraic properties of floating-point arithmetic (e.g. allowing commutativity but not associativity of floating-point addition and multiplication), and which thus implement only strictly correctness-preserving algebraic transformations of the corresponding C code. We show how it is possible to use these tools to prove fundamental correctness properties of the underlying first-order numerical schemes, such as (strict) hyperbolicity-preservation, , and stability, local Lipschitz continuity (a sufficient condition for physical correctness), and flux conservation. We also demonstrate how it is possible to prove correctness properties of the flux extrapolation algorithms necessary to extend these schemes to second-order spatial accuracy, such as symmetry and TVD. Each generated proof is, itself, a symbolic piece of Racket code that can be independently run and verified, and is therefore able to act as a standalone certificate of correctness for some aspect of the algorithm. This pipeline is also able to produce both entirely standalone verified solvers, as well as verified solvers that can be integrated into a larger computational multiphysics framework such as Gkeyll333https://gkeyll.readthedocs.io/en/latest/ (with the larger framework handling all non-verified simulation tasks, such as parallelism, grid generation, and data input/output). The underlying theory behind the finite volume solvers used within Gkeyll can be found in (Hakim et al., 2006).
Section 2 begins with preliminary background material on the mathematical properties of high-resolution shock-capturing schemes. In 2.1, we briefly introduce explicitly conservative finite volume numerical methods, as well as the four model equation systems (linear advection, inviscid Burgers’, perfectly hyperbolic Maxwell’s, and isothermal Euler) that will be used throughout the paper. In 2.2, we introduce the Lax-Friedrichs inter-cell flux function, and outline sufficient conditions to guarantee its hyperbolicity-preservation, CFL stability, and local Lipschitz continuity (with the latter condition itself being a sufficient condition for physical/thermodynamic correctness). In 2.3, we introduce the Roe approximate Riemann solver, and again outline sufficient conditions to guarantee its hyperbolicity-preservation and flux conservation (i.e. jump continuity). In 2.4, we describe how to extend the first-order Lax-Friedrichs and Roe solvers to be second-order accurate in space via flux extrapolation, outline sufficient conditions on the flux limiters to guarantee that the resulting second-order schemes be symmetric and total variation diminishing (TVD), and also introduce the four flux limiters (minmod, monotonized-centered, superbee and van Leer) that are used throughout the paper.
Section 3 presents the main methodology and results of the paper. In 3.1, we outline how we encode hyperbolic PDE systems in Racket, and how the automatic C code generator works. In 3.2, we introduce the core of the symbolic theorem-prover, outlining the algorithm for reducing an arbitrary symbolic Racket expression to a normal form, whilst respecting the algebraic structure of floating-point arithmetic. In 3.3, we describe the algorithm for performing automatic differentiation on arbitrary Racket expressions, enabling one to compute symbolic gradients, Jacobians, Hessians, etc. In 3.4, we outline how these methods may be combined to produce automatic proofs of (strict) hyperbolicity, CFL stability, convexity/local Lipschitz continuity, and flux continuity properties of Lax-Friedrichs and Roe solvers. In 3.5, we describe the algorithm for performing variable transformations and evaluating symbolic limits of Racket expressions for the purpose of proving symmetry and second-order TVD properties of flux limiters.
In 3.6, we present our main results: full proofs of correctness for Lax-Friedrichs and Roe solvers for the linear advection, inviscid Burgers’, and perfectly hyperbolic Maxwell’s equations, with partial/conditional proofs of correctness in the case of the isothermal Euler equations, along with full proofs of correctness for the minmod and monotonized-centered flux limiters, with partial proofs of correctness for the superbee and van Leer limiters. We end in Section 4 with some concluding remarks and directions for future research.
Our Racket implementation of the formal verification pipeline can be found at444https://github.com/ammarhakim/gkylcas/. The corresponding provably-correct C implementations, which have been integrated into the Gkeyll code, can be found at555https://github.com/ammarhakim/gkylzero/.
2. Preliminaries
2.1. Hyperbolic PDE Solvers
For the purposes of this paper, we consider homogeneous systems of (potentially non-linear) first-order hyperbolic PDEs, expressed in the generic conservation law form:
(1) |
where represents the vector of conserved variables and represents the matrix of fluxes of those variables. We can discretize such a system of PDEs in both space and time, using a uniform grid spacing of and a time-step of , indexed by subscripts () and superscripts ():
(2) |
respectively. Specifically, we employ a finite volume discretization, in which the conserved variable vector at time is taken to be constant within each cell (and therefore piecewise constant across the entire domain), and we adopt the shorthand to denote this value. The value of the conserved variable vector within each cell can then be evolved in time by means of the explicitly conservative update formula(Toro, 2009):
(3) |
where and represent inter-cell fluxes, i.e. the interpolated fluxes of the conserved variables between cells and , and between cells and , respectively. Different choices of inter-cell flux function give rise to different finite volume schemes, exhibiting different numerical properties(LeVeque, 2011).
In what follows, we shall focus on four one-dimensional model equation systems in particular, covering all possible combinations of linear vs. non-linear and scalar vs. vector. The first two are purely 1D scalar equations of the form:
(4) |
namely the linear advection equation with flux (for an arbitrary constant advection velocity ), and the non-linear inviscid Burgers’ equation with flux . In each case, the conserved variable simply represents an arbitrary advected quantity. The second two are 1D vector equation systems of the form:
(5) |
namely the linear perfectly hyperbolic Maxwell’s equations(Munz et al., 2000), with conserved variable vector:
(6) |
and flux vector:
(7) |
and the non-linear isothermal Euler equations, with conserved variable vector:
(8) |
and flux vector:
(9) |
For the perfectly hyperbolic Maxwell’s equations, the conserved variables correspond to the , and components of the electric and magnetic field vectors and , as well as the correction potentials and for cleaning divergence errors in and , respectively. are arbitrary constants representing the speed of light, and the propagation speeds of electric and magnetic divergence errors, respectively. For the isothermal Euler equations, the conserved variables correspond to the fluid density , and the , and components of the fluid momentum , and (with , and representing the , and components of the fluid velocity, which are not conserved). is an arbitrary constant representing the thermal velocity of the fluid.
2.2. The Lax-Friedrichs Flux
One of the simplest choices of inter-cell flux function is the Lax-Friedrichs (finite difference) flux(Lax, 1954)(LeVeque, 1992):
(10) |
A finite volume solver based on a Lax-Friedrichs inter-cell flux will satisfy the following properties(Breuß, 2004):
Theorem 2.1.
A Lax-Friedrichs solver preserves hyperbolicity(Hartman, 1960) (i.e. preserves well-posedness of the Cauchy problem along all non-characteristic hypersurfaces) for an arbitrary hyperbolic PDE system if the flux Jacobian with respect to the conserved variable vector :
(11) |
is diagonalizable, with purely real eigenvalues.
Theorem 2.2.
A Lax-Friedrichs solver maintains , and stability for an arbitrary hyperbolic PDE system if the CFL stability condition(Courant et al., 1967):
(12) |
is satisfied, where denotes the largest absolute eigenvalue of the flux Jacobian .
Theorem 2.3.
A Lax-Friedrichs solver preserves local Lipschitz continuity of the discrete flux function with respect to the discrete conserved variables (i.e. preserves the property that, in every neighborhood of possible values of , there exists a restriction of the discrete flux function to which has strictly bounded first derivatives in ) for an arbitrary hyperbolic PDE system if the continuous flux function is itself locally Lipschitz continuous with respect to the continuous conserved variables .
Theorem 2.4.
A sufficient condition for the continuous flux function for an arbitrary hyperbolic PDE system to be locally Lipschitz continuous with respect to the continuous conserved variables is for the componentwise Hessian with respect to :
(13) |
to be positive semidefinite (i.e. symmetric/Hermitian with non-negative eigenvalues), for each scalar flux component of .
The significance of hyperbolicity-preservation is that it is a necessary condition for the solver to remain deterministic, i.e. to prevent discrete solutions from becoming multi-valued(Hartman, 1960). Note that the flux Jacobian being symmetric/Hermitian is a sufficient but not necessary condition for the solver to preserve hyperbolicity. The significance of the CFL stability condition is that, at least for a Lax-Friedrichs solver, CFL stability subsumes all other standard notions of numerical stability (e.g. , and stability) within a single condition(Courant et al., 1967). Finally, the significance of the local Lipschitz continuity condition, as well as the slightly stronger convexity condition, is that these constraints are sufficient to guarantee that the solver will converge to the physically correct (i.e. thermodynamically consistent) solution in the presence of weak, nonlinear waves, such as shock waves in hydrodynamics(Breuß, 2004).
2.3. The Roe Flux
A more sophisticated choice of inter-cell flux function is the Roe (linearized Riemann problem) flux(Roe, 1981):
(14) |
In the above, we assume an inter-cell Roe matrix , which is a linearized approximation to the flux Jacobian that is taken to be constant between cells and , satisfying consistency with the exact Jacobian in the appropriate limit:
(15) |
such that are the eigenvalues of , are the (right) eigenvectors of , and are the components of the inter-cell jump in the conserved variables , as represented in the eigenbasis:
(16) |
A finite volume solver based on a Roe inter-cell flux will satisfy the following properties(Wesseling, 2001):
Theorem 2.5.
A Roe solver preserves hyperbolicity for an arbitrary hyperbolic PDE system if the Roe matrix is diagonalizable, with purely real eigenvalues.
Theorem 2.6.
A Roe solver is flux-conservative (i.e. exactly conserves the components of the conserved variable vector ) if it satisfies the flux jump condition:
(17) |
Note that Theorem 2.5 regarding Roe solvers is essentially identical in content to Theorem 2.1 regarding Lax-Friedrichs solvers, but with the exact flux Jacobian replaced by the linearized inter-cell approximation . Note, moreover, that a Lax-Friedrichs solver is guaranteed to conserve the components of automatically, and does not require any additional conditions (such as those in Theorem 2.6) to hold. Finally, note that the CFL stability and local Lipschitz continuity criteria for Lax-Friedrichs solvers apply to Roe solvers too, i.e. a Roe solver for a given PDE system will not be CFL stable unless the corresponding Lax-Friedrichs solver is also CFL stable, etc.
2.4. Flux Extrapolation and Limiters
The Lax-Friedrichs and Roe solvers described above are, naively, only first-order accurate in space. In order to achieve second-order spatial accuracy, it is necessary to replace the piecewise constant approximations of the conserved variable vector with piecewise linear approximations instead(Van Leer, 1979). At the boundary between cells and , the left- and right-sided extrapolated values of are given by:
(18) |
and:
(19) |
respectively, while at the boundary between cells and , the left- and right-sided extrapolated values of are given by:
(20) |
and:
(21) |
respectively, where is a ratio of successive gradients of (computed componentwise):
(22) |
The function in the above is a flux limiter(LeVeque, 2011), intended to limit the spatial derivatives arising within the reconstruction so as to damp any spurious oscillations that might otherwise appear in the vicinity of steep gradients or true discontinuities. Since all quantities are computed componentwise, it is sufficient to think of the flux limiter as being a scalar function of a scalar ratio of gradients .
A second-order spatially accurate scheme can now be constructed by taking the left- and right-extrapolated values and and evolving them forward by a half time-step , to obtain the evolved states and :
(23) |
and:
(24) |
respectively. The inter-cell flux for the second-order scheme is now evaluated in the usual way, but with the left and right cell states and replaced by the evolved boundary-extrapolated states and , respectively, i.e. for the case of Lax-Friedrichs fluxes, one has:
(25) |
and for the case of Roe fluxes, one has:
(26) |
for Roe matrix .
Flux limiters, and the resulting second-order extrapolations that they enable, satisfy the following properties:
Theorem 2.7.
A flux limiter will act symmetrically (i.e. will act equivalently on forward and backward gradients) if it satisfies the symmetry condition:
(27) |
Theorem 2.8.
A second-order scheme extrapolated from an underlying first-order Lax-Friedrichs or Roe solver will be second-order TVD (total variation diminishing), i.e. one will have:
(28) |
where denotes the total variation of the solution at time :
(29) |
if the flux limiter satisfies the Sweby criteria(Sweby, 1984):
(30) | ||||
(31) | ||||
(32) | ||||
(33) | ||||
(34) |
with .
In what follows, we shall focus upon four standard flux limiters in particular, all of which had previously been implemented as part of the Gkeyll code, namely the minmod limiter(Roe, 1986):
(35) |
the monotonized-centered limiter(Van Leer, 1977):
(36) |
the superbee limiter(Roe, 1986):
(37) |
and the van Leer limiter(Van Leer, 1974):
(38) |
3. Methodology and Results
3.1. Automatic Code Generation
Before we proceed with formally verifying various properties of finite volume schemes in Racket, it is first necessary for us to be able to generate reliable C implementations which certifiably match the symbolic Racket expressions being reasoned about. To this end, we introduce a general data structure for representing hyperbolic PDE systems in Racket, consisting of four lists of symbolic Racket expressions: cons-exprs representing the conserved variable vector, flux-exprs representing the flux vector, max-speed-exprs representing the maximum wave-speed estimates (used for enforcing the CFL stability condition), and parameters representing any additional simulation parameters (such as equation of state variables). For example, the equations representing the density and -momentum components of the isothermal Euler equation system are represented in our Racket implementation as follows, assuming a thermal velocity :
Each of the Racket expressions in these lists may then be converted recursively into a string representing a functionally equivalent C expression, using the function convert-expr:
The base case of convert-expr converts any symbol or number directly into its corresponding string. Any single- or multi-argument function, e.g. (abs arg) or (max arg1 arg2), is converted into its C equivalent, e.g. fabs(arg) or fmax(arg1, arg2), with convert-expr being called on all interior expressions. Finally, any elementary arithmetic operation, e.g. (+ arg1 arg2 ...), has convert-expr mapped over each argument, and the results are interspersed with the corresponding arithmetic symbol, e.g. +, in C. We have generally erred on the side of over-generating parentheses in the resulting C code, in order to guarantee that the order of operations remains identical between the C and Racket versions of mathematical expressions. Conditional expressions in Racket are either converted into the corresponding ternary operators in C:
or are converted directly into if statements. Finally, the strings generated by convert-expr are spliced into a template for a generic finite volume solver using format. Appropriate templates exist for both entirely standalone solvers, and for bespoke solver modules that can be integrated into the larger Gkeyll code.
3.2. Symbolic Theorem-Proving
At its core, our automated theorem-proving framework is based upon a symbolic simplification algorithm, which aims to reduce every symbolic Racket expression to some canonical algebraic form. Although such simplification algorithms are standard in computer algebra, our particular application makes this task non-trivial in two respects. First, we wish for our simplification algorithm to be based on a globally confluent(Robinson and Voronkov, 2001) and strongly normalizing(Baader and Nipkow, 1999) underlying rewriting system, since such rewriting systems exhibit highly desirable correctness and termination properties for the type of algebraic/equational theorem-proving with which we are concerned. This places certain restrictions on the kinds of rewriting rules that we are able to include, since many algebraically correct transformations, such as those corresponding to commutativity of addition or multiplication:
cannot be safely included without risking breaking the strong normalization property of the rewriting system (and hence termination of the theorem-prover). Second, since the variables over which we are reasoning typically represent floating-point numbers, and specifically doubles in C, many standard algebraic rules, such as associativity of addition or multiplication:
cannot safely be assumed to hold (except in certain restricted cases) due to the accumulation of truncation errors. For instance, in floating-point arithmetic(Goldberg, 1991):
(39) |
To this end, we have tried wherever possible to admit only to those algebraic transformations that are permitted under the IEEE 754 standard for floating-point arithmetic(IEEE Computer Society et al., 2008).
The particular collection of algebraic rewriting rules used within our theorem-prover is somewhat complex and ad hoc, so we shall only summarize the salient elements here. The basic structure consists of a recursively-defined symbolic-simp-rule function of the form:
The first few rules shown above are examples of elementary algebraic properties(Bläsius and Bürckert, 1992), such as the existence of 0 as a (left) additive identity, the existence of 1 as a (left) multiplicative identity, the existence of 0 as a (left) annihilator for multiplication, etc. The next rule is an example of how symbolic-simp-rule is mapped over each term within an elementary arithmetic operation such as (+ arg1 arg2 ...) (similar mappings are performed for operations such as (abs arg) or (max arg1 arg2), with each subexpression being recursively simplified). Finally, if none of the rewriting rules match the expression, then the expression has reached a normal form and is returned verbatim. The symbolic simplifier itself then consists of a single function symbolic-simp which recursively calls symbolic-simp-rule until a fixed point is achieved (i.e. until the expression stops changing):
In order to facilitate the reduction of all symbolic expressions to a canonical form, rewriting rules exist to move all numerical constants or coefficients to the left of non-numerical expressions within sums or products:
to collect “like” terms together within sums and differences (via the distributive property):
and to evaluate any arithmetic expressions or operations involving purely numerical values directly:
etc. A more complicated set of rules and heuristics exist regarding whether and when to expand brackets, factorize subexpressions, and so on. Algebraic rules are also defined for standard mathematical functions such as (sqrt ...) or (abs ...), stating for instance that the square root of the square of a quantity, or the square of the square root of a quantity, is equal to the quantity itself:
or that the absolute value of the negation of a quantity is equal to the quantity itself:
or that the (max ...) and (min ...) functions satisfy (at least in the binary case):
(40) |
and:
(41) |
respectively, i.e:
etc.
3.3. Automatic Differentiation
In order to compute symbolic derivatives of arbitrary Racket expressions, we implement a minimalistic automatic differentiation algorithm, again restricting ourselves to assume only those algebraic properties which hold for arbitrary floating-point numbers. Any Racket expression expr may then be differentiated symbolically with respect to the variable var, by means of the function symbolic-diff:
The base case of symbolic-diff evaluates the derivative of any symbol or numerical constant to 0, unless that symbol matches the variable with respect to which one is differentiating, in which case it evaluates to 1. For any sum of the form (+ arg1 arg2 ...), symbolic-diff is mapped over each term, reflecting the linearity of differentiation (and likewise for differences). For any product of the form (* arg1 arg2 ...), symbolic-diff is applied to each term in the product separately (with all other terms being kept fixed), with the results then being summed together:
reflecting the product rule of differentiation, etc. Certain standard mathematical functions, such as (sqrt ...), also have their derivatives specifically encoded wherever they are well-defined:
With the ability to differentiate arbitrary scalar functions thus in place, the symbolic Jacobian of a list of symbolic Racket expressions exprs, evaluated with respect to a list of symbolic Racket variables vars, may now be computed via a straightforward symbolic-jacobian function:
Likewise for the symbolic gradient of a single symbolic Racket expression expr, with respect to a list of symbolic Racket variables vars, via the symbolic-gradient function:
The symbolic Hessian (symbolic-hessian) of a symbolic Racket expression may therefore be computed as a composition of the two:
3.4. Stability, Hyperbolicity and Convexity
In order to prove that a given Lax-Friedrichs solver meets the CFL stability criterion listed in Theorem 2.2, it is sufficient to compute the flux Jacobian by evaluating:
and then to compute its symbolic eigenvalues, which for instance can be done in the case of a 2x2 matrix using:
where we have simply encoded the explicit solutions of the characteristic polynomial for the 2x2 matrix:
(42) |
i.e:
(43) |
We can now proceed to apply (abs ...) to each symbolic eigenvalue, and then compare the absolute eigenvalues against the expressions in max-speed-exprs (after mapping symbolic-simp over the two lists of expressions, reducing them to their respective normal forms) in order to confirm that they are indeed identical. Since the time-steps within the generated C code are computed directly from the elements of max-speed-exprs as:
(44) |
where is the largest value in max-speed-exprs, this condition is sufficient to guarantee CFL stability under Theorem 2.2 provided that , which is also verified by the theorem-prover during the initialization step:
In order to prove that a given Lax-Friedrichs solver meets the hyperbolicity-preservation criterion listed in Theorem 2.1, one must, furthermore, determine whether each of the symbolic eigenvalues of the flux Jacobian corresponds to a real number. For this purpose, we introduce an is-real function:
The base case of is-real treats any real numerical constant as a real number, and any simulation parameter or conserved variable is also assumed to be real by default. This latter condition is then enforced during the simulation initialization step itself:
We enforce that the set of real numbers is closed under operations like addition, subtraction, and multiplication, e.g:
etc., and also that the set of reals remains closed under division so long as the denominator is non-zero, and under square roots so long as the argument is non-negative; these latter two conditions are enforced via the additional functions is-non-zero and is-non-negative, which will be described momentarily.
Moreover, strict hyperbolicity-preservation of a given Lax-Friedrichs solver can be proven (in the 2x2 case) by proving that the symbolic eigenvalues of the flux Jacobian are not only real but also distinct, using the are-distinct function:
The base case of are-distinct treats any pair of non-equal numerical constants as distinct. Pairs of expressions of the form or are then also treated as distinct, provided that the expressions or are themselves non-zero, respectively:
where the function is-non-zero treats all non-zero numerical constants as non-zero, as its base case:
It also treats all simulation parameters as non-zero, and enforces this condition, using similar logic to what was previously described for is-real. Finally, it treats the product of any two non-zero expressions as non-zero:
Finally, in order to prove that a given Lax-Friedrichs solver meets the local Lipschitz continuity criterion listed in Theorems 2.3 and 2.4, it is sufficient to compute the symbolic Hessian by evaluating:
for each flux-expr in the list flux-exprs, and then to compute its symbolic eigenvalues using symbolic-eigvals2 (at least in the 2x2 case), in order to confirm that each symbolic eigenvalue is non-negative. Non-negativity can be checked using the is-non-negative function:
whose base case treats all non-negative numerical constants as non-negative. Moreover, we enforce that the sum, product or quotient of two non-negative numbers is always non-negative, e.g:
etc. Although we have described these techniques in the context of proving the hyperbolicity-preserving and strict hyperbolicity-preserving properties of Lax-Friedrichs solvers via Theorem 2.1, we note that the same techniques can be used to prove the hyperbolicity-preserving and strict hyperbolicity-preserving properties of Roe solvers also, via Theorem 2.5, by exploiting the fact that a valid symbolic Roe matrix can be calculated as an average of the two symbolic flux Jacobians:
(45) |
and the reality and distinctness of its eigenvalues can therefore be verified in exactly the same way as for . The flux conservation/jump continuity condition can be verified purely algebraically, by simply confirming that the two sides of the equation in Theorem 2.6 both reduce to the same canonical form using symbolic-simp.
3.5. Symbolic Limits and Symmetry
In order to determine whether a given flux limiter satisfies the symmetry condition presented in Theorem 2.7, it is necessary to perform a variable transformation throughout the expression for , in order to determine whether this transformed expression is algebraically equivalent to . For this purpose, we use the recursively-defined variable-transform function:
which applies itself recursively to all subexpressions, and replaces any subexpression it finds which matches var with a new subexpression matching new-var. For the second-order total variation diminishing (TVD) condition presented in Theorem 2.8, we use a strictly stronger set of conditions which imply (but are not equivalent to) the Sweby criteria, namely the limiting conditions that:
(46) |
(47) |
assuming that for all , combined with the condition that be a (non-strictly) concave function:
(48) |
These symbolic limits of the form are evaluated via the evaluate-limit function, which first performs a variable transformation (using the extended reals ), and then recursively simplifies until the limiting expression achieves a fixed point:
where evaluate-limit-rule encodes valid algebraic simplification rules over the extended reals (a specialized subset of the algebraic rules encoded by symbolic-simp-rule).
3.6. Results
For the two scalar PDEs (i.e. the linear advection and inviscid Burgers’ equations), the hyperbolicity-preservation, CFL stability and local Lipschitz continuity properties of the Lax-Friedrichs solver, and the hyperbolicity-preservation and flux conservation (jump continuity) properties of the Roe solver, can all be proved directly and without further complication, as outlined in Tables 1 and 2. For the two vector PDE systems (i.e. the perfectly hyperbolic Maxwell’s equations and isothermal Euler equations), slightly more work is required. In order to ensure that the theorem-prover never needs to manipulate any higher-dimensional (i.e. beyond 2x2) matrices, we first “factorize” these equation systems into coupled pairs of PDEs, with each pair being dealt with independently. Maxwell’s equations effectively “factorize” into four coupled pairs of linear advection equations, for the and components, the and components, the and components, and the and components, respectively. The isothermal Euler equations effectively “factorize” into a non-linear pair of equations for the and components, and a linear pair of equations for the and components (since the and momentum components can each be regarded as being advected linearly with a speed of at each time-step). As shown in Tables 3 and 4, for all four coupled systems constituting the perfectly hyperbolic Maxwell’s equations, the hyperbolicity-preservation, strict hyperbolicity-preservation, CFL stability and local Lipschitz continuity properties of the Lax-Friedrichs solver, and the hyperbolicity-preservation, strict hyperbolicity-preservation and flux conservation (jump continuity) properties of the Roe solver, can all be proved unproblematically. However, for the two coupled systems constituting the isothermal Euler equations, several properties cannot immediately be proven: for the Lax-Friedrichs solver, proofs cannot be found for the local Lipschitz continuity property for the and components, or for the strict hyperbolicity-preservation property for the and components, while for the Roe solver, proofs cannot be found for any of the properties for the and components, or for the strict hyperbolicity-preservation property for the and components. It is worth expanding upon each of these “failure” cases in greater detail.
Equation | Hyperbolicity (Lax) | Stability (Lax) | Local Lipschitz (Lax) |
---|---|---|---|
Linear Advection | 33 | 45 | 39 |
Inviscid Burgers’ | 90 | 116 | 96 |
Equation | Hyperbolicity (Roe) | Conservation (Roe) |
---|---|---|
Linear Advection | 55 | 92 |
Inviscid Burgers’ | 120 | 188 |
Equations | Hyperbolicity (Lax) | Strict Hyperbolicity (Lax) | Stability (Lax) | Local Lipschitz (Lax) |
Maxwell’s ( and ) | 499 | 502 | 575 | 272 |
Maxwell’s ( and ) | 627 | 630 | 711 | 452 |
Maxwell’s ( and ) | 729 | 735 | 803 | 450 |
Maxwell’s ( and ) | 731 | 737 | 805 | 450 |
Isothermal Euler ( and ) | 1462 | 1465 | 1558 | - |
Isothermal Euler ( and ) | 1189 | - | 1329 | 251 |
Equations | Hyperbolicity (Roe) | Strict Hyperbolicity (Roe) | Conservation (Roe) |
Maxwell’s ( and ) | 616 | 619 | 412 |
Maxwell’s ( and ) | 826 | 829 | 643 |
Maxwell’s ( and ) | 871 | 877 | 642 |
Maxwell’s ( and ) | 873 | 879 | 642 |
Isothermal Euler ( and ) | - | - | - |
Isothermal Euler ( and ) | 1315 | - | 498 |
Flux Limiter | Symmetry | Second-Order TVD |
minmod | 863 | 513 |
monotonized-centered | 4171 | 2251 |
superbee | - | 2125 |
van Leer | 244 | - |
By interrogating the attempted proof of local Lipschitz continuity for the Lax-Friedrichs solver for the and components, we see that the theorem-prover succeeds in reducing the problem of proving flux convexity to the problem of proving that the inequality:
(49) |
always holds. However, in the absence of any guarantee that , it is unable to proceed further. Thus, we see that the theorem-prover has correctly concluded that it is unable to guarantee local Lipschitz continuity of the flux function in the absence of the additional constraint that the fluid density always be strictly positive (which the solver in isolation does not guarantee). The theorem-prover is also correct to conclude that strict hyperbolicity-preservation for the Lax-Friedrichs solver for the and components does not hold, due to the presence of a repeated “” eigenvalue within the flux Jacobian . Likewise, by interrogating the attempted proofs of hyperbolicity- and strict hyperbolicity-preservation for the Roe solver for the and components, we see that the theorem-prover reduces these problems to the problem of proving that the quantities:
(50) |
are always real and distinct, which itself can only be true if the inequality:
(51) |
is satisfied, where , and , denote the fluid density and fluid momentum within the left and right cells and , respectively. Therefore, once again, we find that the theorem-prover correctly determines that these properties cannot be guaranteed in the absence of some form of positivity restriction on the fluid density . Similarly, the presence of the repeated “” eigenvalue within the Roe matrix for the and components implies that strict hyperbolicity-preservation does not hold here either. Hence, we see that the only property for which the theorem-prover truly fails (i.e. where it does not succeed in finding a proof for a statement which is unconditionally true) is the flux conservation/jump continuity condition for the Roe solver for the and components.
For the minmod and monotonized-centered flux limiters, the symmetry and second-order TVD properties can both be proved directly and unproblematically, as shown in Table 5. However, we see that the theorem-prover fails to find valid proofs for the symmetry property of the superbee limiter, and the second-order TVD property of the van Leer limiter. As in the case of the flux conservation condition for the isothermal Euler Roe solver, this is due entirely to present algebraic limitations of the simplification algorithm (since these properties certainly do hold, unconditionally, in the case of these limiters); these limitations can presumably be circumvented via the judicious introduction of stronger symbolic simplification rules into symbolic-simp-rule and related functions.
4. Conclusions and Future Work
In this paper, we have introduced a new formal verification pipeline in Racket for first-order hyperbolic PDE solvers, with a particular emphasis upon finite volume, high-resolution shock-capturing methods. Although the resulting automated theorem-proving framework still exhibits some notable limitations, we see that it is nevertheless able to produce full proofs of correctness for several linear and non-linear hyperbolic PDE solvers (with both first- and second-order spatial accuracy), and to produce conditional/partial proofs of correctness for others. These general correctness results encompass both mathematical (e.g. hyperbolicity-preservation) and physical (e.g. thermodynamic validity) notions of correctness. At present, this pipeline constitutes around 15,000 lines of Racket in total, although the vast majority of this is boilerplate for the purposes of synthesizing functionally complete C code (both in the standalone case, and for integration into the Gkeyll codebase, which includes automatic synthesis of header files, regression tests, etc.): the core theorem-proving, automatic differentiation, and symbolic limit evaluation routines fit within just a few hundred lines of Racket each, and it is likely that these can all be optimized further. We consider this work to be a successful proof-of-concept, representing a solid foundation upon which further such verification pipelines may be built, expanding into a wider variety of numerical solvers, equation systems, reconstruction algorithms, and discretization schemes.
In addition to reinforcing the weak points in the existing theorem-prover, such as adding new and more powerful rewriting rules (for instance, those needed to complete the proofs of correctness for the superbee and van Leer flux limiters) and introducing more systematic techniques for proving conditional results (such as those needed to complete the formalization of the conditional correctness proofs for the isothermal Euler solvers), we intend to expand this overall framework in several key directions. One such direction involves introducing formal verification tools for ordinary differential equation (ODE) integrators too, including the kinds of both explicit (e.g. strong stability-preserving Runge-Kutta(Gottlieb et al., 2001)) and implicit (e.g. time-centered Crank-Nicolson) ODE integrators used within the Gkeyll code, for instance when coupling hydrodynamic and electromagnetic PDE systems together(Wang et al., 2020) or handling geometric source terms in general relativity(Gorard et al., 2024). Being able to automate the deduction of properties such as absolute stability regions for explicit Runge-Kutta integrators would, in itself, be an important and highly useful advance. Another major frontier of expansion would be the formalization of the kinds of modal discontinuous Galerkin (DG) algorithms used for solving kinetic equations within codes such as Gkeyll(Juno et al., 2018), for which properties like stability and entropy convexity are significantly more subtle and fragile than they are in the case of finite volume solvers, depending sensitively upon particular choices of basis functions(Juno, 2020), etc. Overall, it is hoped that the construction of formally verified simulations, of the kind described here, will become an increasingly pervasive methodology throughout scientific computing in general, and within computational physics in particular.
Acknowledgements.
J.G. was partially funded by the Princeton University Research Computing group. J.G. and A.H. were partially funded by the U.S. Department of Energy under Contract No. DE-AC02-09CH1146 via an LDRD grant. The development of Gkeyll was partially funded by the NSF-CSSI program, Award Number 2209471. J.G. thanks Nikola Bukowiecka for her proofreading and suggestions.References
- (1)
- Auger and Plagnol (2017) Gerard Auger and Eric Plagnol. 2017. An overview of gravitational waves: theory, sources and detection. World scientific, New Jersey.
- Baader and Nipkow (1999) Franz Baader and Tobias Nipkow. 1999. Term rewriting and all that (1st paperback edition ed.). Cambridge University Press, Cambridge New York Melbourne Madrid Cape Town.
- Bläsius and Bürckert (1992) Karl Hans Bläsius and Hans-Jürgen Bürckert (Eds.). 1992. Deduktionssysteme: Automatisierung des logischen Denkens (2., völlig überarbeitete und erweiterte auflage ed.). Oldenbourg, München Wien.
- Breuß (2004) Michael Breuß. 2004. The correct use of the Lax–Friedrichs method. ESAIM: Mathematical Modelling and Numerical Analysis 38, 3 (May 2004), 519–540. doi:10.1051/m2an:2004027
- Courant et al. (1967) R. Courant, K. Friedrichs, and H. Lewy. 1967. On the Partial Difference Equations of Mathematical Physics. IBM Journal of Research and Development 11, 2 (March 1967), 215–234. doi:10.1147/rd.112.0215
- Felleisen et al. (2015) Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, Shriram Krishnamurthi, Eli Barzilay, Jay McCarthy, and Sam Tobin-Hochstadt. 2015. The Racket Manifesto. In 1st Summit on Advances in Programming Languages (SNAPL 2015) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 32), Thomas Ball, Rastislav Bodik, Shriram Krishnamurthi, Benjamin S. Lerner, and Greg Morriset (Eds.). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 113–128. doi:10.4230/LIPIcs.SNAPL.2015.113
- Fickett (1985) Wildon Fickett. 1985. Introduction to detonation theory. Univ. of California Pr, Berkeley.
- Goldberg (1991) David Goldberg. 1991. What every computer scientist should know about floating-point arithmetic. Comput. Surveys 23, 1 (March 1991), 5–48. doi:10.1145/103162.103163
- Gorard (2024) Jonathan Gorard. 2024. Computational General Relativity in the Wolfram Language using Gravitas II: ADM Formalism and Numerical Relativity. arXiv:2401.14209 [gr-qc] https://arxiv.org/abs/2401.14209
- Gorard et al. (2024) Jonathan Gorard, Ammar Hakim, James Juno, and Jason M. TenBarge. 2024. A Tetrad-First Approach to Robust Numerical Algorithms in General Relativity. arXiv:2410.02549 [gr-qc] https://arxiv.org/abs/2410.02549
- Gottlieb et al. (2001) Sigal Gottlieb, Chi-Wang Shu, and Eitan Tadmor. 2001. Strong Stability-Preserving High-Order Time Discretization Methods. SIAM Rev. 43, 1 (Jan. 2001), 89–112. doi:10.1137/S003614450036757X
- Hakim et al. (2006) A. Hakim, J. Loverich, and U. Shumlak. 2006. A high resolution wave propagation scheme for ideal Two-Fluid plasma equations. J. Comput. Phys. 219, 1 (Nov. 2006), 418–442. doi:10.1016/j.jcp.2006.03.036
- Harten (1983) Ami Harten. 1983. High resolution schemes for hyperbolic conservation laws. J. Comput. Phys. 49, 3 (March 1983), 357–393. doi:10.1016/0021-9991(83)90136-5
- Harten et al. (1976) A. Harten, J. M. Hyman, P. D. Lax, and B. Keyfitz. 1976. On finite‐difference approximations and entropy conditions for shocks. Communications on Pure and Applied Mathematics 29, 3 (May 1976), 297–322. doi:10.1002/cpa.3160290305
- Hartman (1960) Philip Hartman. 1960. A lemma in the theory of structural stability of differential equations. Proc. Amer. Math. Soc. 11, 4 (Aug. 1960), 610–620. doi:10.1090/S0002-9939-1960-0121542-7
- IEEE Computer Society et al. (2008) IEEE Computer Society, Institute of Electrical and Electronics Engineers, and IEEE-SA Standards Board (Eds.). 2008. IEEE standard for floating-point arithmetic. Institute of Electrical and Electronics Engineers, New York, NY.
- Juno (2020) James Juno. 2020. A Deep Dive into the Distribution Function: Understanding Phase Space Dynamics with Continuum Vlasov-Maxwell Simulations. arXiv:2005.13539 [physics.plasm-ph] https://arxiv.org/abs/2005.13539
- Juno et al. (2018) J. Juno, A. Hakim, J. TenBarge, E. Shi, and W. Dorland. 2018. Discontinuous Galerkin algorithms for fully kinetic plasmas. J. Comput. Phys. 353 (Jan. 2018), 110–147. doi:10.1016/j.jcp.2017.10.009
- Laney (1998) Culbert B. Laney. 1998. Computational Gasdynamics (1 ed.). Cambridge University Press. doi:10.1017/CBO9780511605604
- Lax (1954) Peter D. Lax. 1954. Weak solutions of nonlinear hyperbolic equations and their numerical computation. Communications on Pure and Applied Mathematics 7, 1 (Feb. 1954), 159–193. doi:10.1002/cpa.3160070112
- LeVeque (1992) Randall J. LeVeque. 1992. Numerical Methods for Conservation Laws. Birkhäuser Basel, Basel. doi:10.1007/978-3-0348-8629-1
- LeVeque (2011) Randall J. LeVeque. 2011. Finite volume methods for hyperbolic problems (10. printing ed.). Cambridge Univ. Press, Cambridge.
- Munz et al. (2000) C.-D. Munz, P. Omnes, R. Schneider, E. Sonnendrücker, and U. Voß. 2000. Divergence Correction Techniques for Maxwell Solvers Based on a Hyperbolic Model. J. Comput. Phys. 161, 2 (July 2000), 484–511. doi:10.1006/jcph.2000.6507
- Musha and Higuchi (1978) Toshimitsu Musha and Hideyo Higuchi. 1978. Traffic Current Fluctuation and the Burgers Equation. Japanese Journal of Applied Physics 17, 5 (May 1978), 811–816. doi:10.1143/JJAP.17.811
- Osher (1984) Stanley Osher. 1984. Riemann Solvers, the Entropy Condition, and Difference Approximations. SIAM J. Numer. Anal. 21, 2 (April 1984), 217–235. doi:10.1137/0721016
- Robinson and Voronkov (2001) John Alan Robinson and Andrei Voronkov. 2001. Handbook of automated reasoning. Elsevier MIT Press, Amsterdam New York Cambridge, Mass.
- Roe (1981) P.L Roe. 1981. Approximate Riemann solvers, parameter vectors, and difference schemes. J. Comput. Phys. 43, 2 (Oct. 1981), 357–372. doi:10.1016/0021-9991(81)90128-5
- Roe (1986) P L Roe. 1986. Characteristic-Based Schemes for the Euler Equations. Annual Review of Fluid Mechanics 18, 1 (Jan. 1986), 337–365. doi:10.1146/annurev.fl.18.010186.002005
- Sweby (1984) P. K. Sweby. 1984. High Resolution Schemes Using Flux Limiters for Hyperbolic Conservation Laws. SIAM J. Numer. Anal. 21, 5 (Oct. 1984), 995–1011. doi:10.1137/0721062
- Toro (2009) E. F. Toro. 2009. Riemann solvers and numerical methods for fluid dynamics: a practical introduction (3rd ed ed.). Springer, Dordrecht New York.
- Toro and Billett (2000) E. F. Toro and S. J. Billett. 2000. Centred TVD schemes for hyperbolic conservation laws. IMA J. Numer. Anal. 20, 1 (Jan. 2000), 47–79. doi:10.1093/imanum/20.1.47
- Van Leer (1974) Bram Van Leer. 1974. Towards the ultimate conservative difference scheme. II. Monotonicity and conservation combined in a second-order scheme. J. Comput. Phys. 14, 4 (March 1974), 361–370. doi:10.1016/0021-9991(74)90019-9
- Van Leer (1977) Bram Van Leer. 1977. Towards the ultimate conservative difference scheme III. Upstream-centered finite-difference schemes for ideal compressible flow. J. Comput. Phys. 23, 3 (March 1977), 263–275. doi:10.1016/0021-9991(77)90094-8
- Van Leer (1979) Bram Van Leer. 1979. Towards the ultimate conservative difference scheme. V. A second-order sequel to Godunov’s method. J. Comput. Phys. 32, 1 (July 1979), 101–136. doi:10.1016/0021-9991(79)90145-1
- Vreugdenhil (1994) C. B. Vreugdenhil. 1994. Numerical Methods for Shallow-Water Flow. Water Science and Technology Library, Vol. 13. Springer Netherlands, Dordrecht. doi:10.1007/978-94-015-8354-1
- Wang et al. (2020) Liang Wang, Ammar H. Hakim, Jonathan Ng, Chuanfei Dong, and Kai Germaschewski. 2020. Exact and locally implicit source term solvers for multifluid-Maxwell systems. J. Comput. Phys. 415 (Aug. 2020), 109510. doi:10.1016/j.jcp.2020.109510
- Wesseling (2001) Pieter Wesseling. 2001. Principles of Computational Fluid Dynamics. Springer Series in Computational Mathematics, Vol. 29. Springer Berlin Heidelberg, Berlin, Heidelberg. doi:10.1007/978-3-642-05146-3