11email: {tmohit,kdur,jeannin}@umich.edu
A formal proof of the Lax equivalence theorem for finite difference schemes
Abstract
The behavior of physical systems is typically modeled using differential equations which are too complex to solve analytically. In practical problems, these equations are discretized on a computational domain, and numerical solutions are computed. A numerical scheme is called convergent, if in the limit of infinitesimal discretization, the bounds on the discretization error is also infinitesimally small. The approximate solution converges to the “true solution” in this limit. The Lax equivalence theorem enables a proof of convergence given consistency and stability of the method.
In this work, we formally prove the Lax equivalence theorem using the Coq Proof Assistant. We assume a continuous linear differential operator between complete normed spaces, and define an equivalent mapping in the discretized space. Given that the numerical method is consistent (i.e., the discretization error tends to zero as the discretization step tends to zero), and the method is stable (i.e., the error is uniformly bounded), we formally prove that the approximate solution converges to the true solution. We then demonstrate convergence of the difference scheme on an example problem by proving both its consistency and stability, and then applying the Lax equivalence theorem. In order to prove consistency, we use the Taylor–Lagrange theorem by formally showing that the discretization error is bounded above by the power of the discretization step, where is the order of the truncated Taylor polynomial.
Keywords:
Lax equivalence theorem Finite difference scheme Convergence Taylor–Lagrange Theorem.1 Introduction
Physical systems are typically modeled by differential equations. For instance, the aerodynamics of an airplane can be represented by the Navier–Stokes equations [1], which are too complex to solve analytically.
Since analytical solutions are intractable for most practical problems of interest, numerical solutions are sought in a discretized domain. The process of discretization in space and time results in approximate solutions to the governing equations. A numerical scheme is called convergent, if in the limit of infinitesimal discretization, the bound on the discretization error is also infinitesimally small. Under these conditions, the numerical solution converges or approaches the analytic solution. This idea is formally articulated by the Lax equivalence theorem [26], which states that if a numerical method is consistent and stable, then it is convergent.
Proofs of consistency, stability, and convergence are typically performed by hand, making them prone to possible errors. Formal verification of mathematical proofs provides a much higher level of confidence of the correctness of manual proofs. Further, formal verification offers a pathway to leverage mathematical constructs therein, and to extend these proofs to more complex scenarios.
Recently, much effort has been dedicated to the definition of mathematical structures such as metric spaces, normed spaces, derivatives, limits etc. in a formal setting using proof assistants such as Coq [31, 8, 16, 28]. Using automatic provers and proof assistants, a number of works have emerged in the formalization of numerical analysis [5]. Pasca has formalized the properties of the Newton method [32]. Mayero et al. [29] presented a formal proof, developed in the Coq system, of the correctness of an automatic differentiation algorithm. Besides Coq, numerical analysis of ordinary differential equations has also been done in Isabelle/ HOL [20]. Immler et al. [19, 21, 22], present a formalization of ordinary differential equations and the verification of rigorous (with guaranted error bounds) numerical algorithms in the interactive theorem prover Isabelle/HOL. The formalization comprises flow and Poincaré map of dynamical systems. Immler [18] implements a functional algorithm that computes enclosures of solutions of ODEs in the interactive theorem prover Isabelle/HOL. In [9], Brehard et al. present a library to verify rigorous approximations of univariate functions on real numbers, with the Coq proof assistant. Brehard [11], worked on rigorous numerics that aims at providing certified representations for solutions of various problems, notably in functional analysis. Work has also been done in formalizing real analysis for polynomials [12]. Boldo and co-workers [5, 6, 4] have made important contributions to formal verification of finite difference schemes. They proved consistency, stability and convergence of a second-order centered scheme for the wave equation. However, the Lax equivalence theorem – sometimes referred to as the fundamental theorem of numerical analysis – which is central to finite difference schemes, has not been formally proven in the general case.
In this paper, we present a formal proof of the Lax equivalence theorem for a general family of finite difference schemes. We use the definitions of consistency and stability and prove convergence. To prove the consistency of a second-order centered scheme for the wave equation, Boldo et al. [6] made assumptions on the regularity of the exact solution. This regularity is expressed as the existence of Taylor approximations of the exact solution up to some appropriate order. Our formalization instead takes the Taylor–Lagrange theorem of [28], to prove the consistency of a finite difference scheme of any order. It should be noted that the order of accuracy of an explicit finite difference scheme depends on the number of points in the discretized domain (called stencils) appearing in the numerical derivative. Our approach is to carry the Taylor series expansion for each of those stencils using the Taylor–Lagrange theorem, and appropriately instantiate the order of the truncated polynomial, to achieve the desired order of accuracy. By incorporating the discretization error into the Lagrange remainder and proving an upper bound for the Lagrange remainder, we propose a rigorous method of proving consistency of a finite difference scheme.
Since the Lax equivalence theorem is an essential tool in the analysis of numerical schemes using finite differences, its formalization in the general case opens the door to the formalization and certification of finite difference-based numerical software. The present work will enable the formalization of convergence properties for a large class of finite difference numerical schemes, thereby providing formal proofs of convergence properties usually proved by hand, making explicit the underlying assumptions, and increasing the level of confidence in these proofs.
Overall this paper makes the following contributions:
-
•
We provide a formalization in the Coq proof assistant of a general form of the Lax equivalence theorem.
-
•
We prove consistency and stability of a second order accurate finite difference scheme for the example differential equation .
-
•
We formally apply the Lax equivalence theorem on this finite difference scheme for the example differential equation, thereby formally proving convergence for this scheme.
-
•
We also provide a generalized framework for a symmetric tri-diagonal (sparse) matrix in Coq. We define its eigen system and provide an explicit formulation of its inverse in Coq. We show that since the symmteric tri-diagonal matrix is normal, one can perform the stability analysis by just uniformly bounding the eigen values of the inverse. This is important because discretizations of mathematical model of physical systems are usually sparse [23].
This paper is structured as follows. In Section 2, we review the definitions of consistency, stability and convergence, state the Lax equivalence theorem [26, 33], and discuss its formalization in the Coq proof assistant. In Section 3, we discuss the consistency of a finite difference scheme. In particular, we consider the central difference approximation of the second derivative and formally prove the order of accuracy using the Taylor–Lagrange theorem in the Coq proof assistant. We also relate the pointwise consistency of the finite difference scheme with the Lax equivalence theorem, by instantiating it with an example. In Section 4, we discuss the generalized formalization of a symmetric tri-diagonal matrix and later instantiate it with the scheme to prove stability of the scheme. In Section 5, we apply the Lax equivalence theorem to the concrete finite difference scheme that we are considering. In Section 6, we conclude by summarizing key takeaways from the paper, and discussing future work.
2 Lax equivalence theorem
In this section, we review the definitions of consistency, stability and convergence, discuss the problem set up and state the Lax equivalence theorem [26]. In this paper and for the formalization, we choose to follow the presentation of Sanz-Serna and Palencia [33]. We also discuss the proof of the Lax equivalence theorem which is then formalized in the Coq proof assistant.
2.1 Consistency, Stability and Convergence
Definition 1 (The Continuous Problem [33])
Let (the space of solutions) and (the space of data) be normed spaces, both real or both complex. We consider a linear operator with domain and range . The problem to be solved is of the form
(1) |
Here is not assumed to be bounded, so that unbounded differential operators are included. The problem (1) is assumed to be well-posed, i.e., there exists a bounded, linear operator, , such that in , and that for , equation (1) has a unique solution, . Furthermore, the solution depends continuously on the data.
Definition 2 (The Approximate Problem [33])
Let be a set of positive numbers such that is the unique limit point of . For each , let be normed spaces and consider the approximate or discretized problem
(2) |
where is a linear operator .
We assume that for each , problem (2) is well-posed and there exists a solution operator, , i.e. . The true solution and the approximate solution can be related with each other by defining a bounded, linear operator, for each . Similarly, data can be related to data in a discrete space, by defining a restriction operator . For each , is also a bounded, linear operator. We assume that the operator norms can be uniformly bounded:
(3) |
where the constants are independent of . The true solution is compared with the discrete solution corresponding to the discretized datum . The family defines a method for the solution of (1) [33].
Definition 3 (Convergence [33])
Intuitively, this means that in the limit of the discretization step, , tending to zero, the numerical solution approaches the analytical solution . The analytical solution is the restriction of the true (analytical) solution, , onto the grid of size , and is the discrete solution, computed on the grid of size .
Definition 4 (Consistency [33])
Let be a given element in . The method is consistent at if
(5) |
A method is consistent if it is consistent at each in a set such that the image is dense in .
Intuitively, this means that in the limit of the discretization step, , tending to zero, the finite difference scheme approaches the differential equation , i.e., we are discretizing the right differential equation.
Definition 5 (Stability [33])
The method is stable if there exists a constant such that
(6) |
Intuitively, stability of the numerical scheme means that a small numerical perturbation does not allow the solution to blow up. Uniform boundedness of the inverse is a check on the conditioning of matrices (sensitivity to small perturbations), i.e., it ensures that the matrix is not ill-conditioned. Thus, if the numerical problem (2) were unstable, even though we were trying to solve the right differential equation, we would never converge to the true solution. Hence, both stability and consistency are sufficient for proving convergence of the numerical scheme.
The quantities within the norms (4) and (5) are, respectively, the global and local discretization errors.
Theorem 2.1 (Lax equivalence theorem [33])
Let be as above. If the method is consistent and stable, then it is convergent.
Proof
We start with the definition of convergence in (4),
2.2 Formalization in the Coq Proof Assistant
In this Section we show how we formalized the proof of the Lax equivalence theorem [33] in the Coq proof assistant. All of the Coq formal proofs mentioned in this paper, containing the proofs of consistency, stability and convergence of finite difference schemes, and of the Lax equivalence theorem, are available at http://www-personal.umich.edu/~jeannin/papers/NFM21.zip.
The Coquelicot library [8, 7] defines mathematical structures required for implementing the proof. Since we use Coquelicot and standard reals library which are based on classical axiomatization of reals, our proofs are also non-constructive [8]. We define the Banach spaces (complete normed spaces, complete in the metric defined by the norm [25]) using a canonical structure, CompleteNormedModule, in Coq [16].
The definitions of the true problem (1) and the approximate problem (2) require that the mappings and be linear, and the solution operators and be linear and bounded. The linear mappings and are defined as functions of . Boldo et al. [3] have defined linear mapping in the context of a ModuleSpace and bounded linear mapping in the context of a NormedModule in their formalization of the Lax Milgram Theorem in Coq [2, 15]. We extended these definitions in the context of CompleteNormedModule.
The definition of consistency (5) and convergence (4) hold in the limit of tending to zero. Thus, an important step in the proof is to express these limits in Coq. Formally, the notion of tending to at the limit point requires, for any , to find a neighborhood of such that any point of satisfies [8]. This notion has been formalized in Coquelicot [7] using the concept of filters. In topology, a filter is a set of sets, which is nonempty, upward closed, and closed under intersection [13]. It is commonly used to express the notion of convergence in topology. We have used a filter, locally x [27] to denote an open neighborhood of , and predicate filterlim [27] to formalize the notion of convergence (in the context of limits) of towards at limit point , i.e. . Therefore, the definition of consistency (5) is expressed as:
(is_lim (fun h:R => norm (minus (Ah h (rh h u)) (sh h (A u)))) 0 0
where the limits of functions is expressed using is_lim [8].
We next discuss the formalization of the statement of convergence of a finite difference scheme in Coq. We note that from Theorem 2.1, consistency and stability imply convergence. This notion is expressed in Coq as follows:
(is_lim (fun h:R => norm (minus (Ah h (rh h u)) (sh h (A u)))) 0 0 (*Consistency*) /\ (exists K:R , forall (h:R), operator_norm(Eh h)<=K ) (* Stability*) -> is_lim(fun h:R=>norm (minus (rh h (E(f))) (Eh h (sh h (f))))) 0 0) (*Convergence*).
where the operator norm is defined as and has been formally defined in [3].
The basic idea is that we bound the global discretization error ( above using the stability criterion, i.e. , and then prove that as the local discretization error ( tends to zero in the limit of tending to zero, the upper bound on the global discretization error tends to zero (using the property of limits). Using the property of norm , i.e. , we arrive at the inequality
In Coq, we define the lower bound of the inequality as a constant function with value as: fun _ => 0. Since the limit of a constant function is the constant itself, i.e. , and (Consistency), using the sandwich theorem for limits, . The sandwich theorem states that if we have functions obeying the inequality: and on some open neighborhood of , then . This proves the convergence of Definition 4 and completes the proof of the Lax equivalence theorem.
3 Proof of consistency of a sample finite difference scheme
A finite difference scheme (FD) approximates a differential equation with a difference equation. The derivatives are expressed in terms of function values at finite number of points in the dicretized domain. For instance, consider a simple differential equation, on a domain with boundary conditions and , where L is the length of the domain. A second order accurate finite difference approximation would be , where is the discretization step and is the point at which the difference equation is evaluated. We will refer to this as numerical scheme . Since we are computing a numerical approximation to the actual derivatives, we are interested in knowing the order of the discretization error.
Definition 6 (Discretization error)
Let denote the true derivative of a function and denote the finite difference approximation of the true derivative. The discretization error (commonly referred to as the truncation error) () is then defined as:
(7) |
If the function is analytic, it can be expressed as a Taylor series expansion at the point of evaluation. The truncation error is then evaluated by expressing the numerical derivatives in terms of a truncated Taylor polynomial and then taking a difference of the true derivative and the numerical derivative. This gives us an upper bound on the discretization error. If a numerical method is consistent, the truncation error can be expressed as:
when tends to zero, and where is the order of the truncated Taylor polynomial. We use this idea to formalize the proof of consistency of a finite difference scheme. This requires the use of an important theorem from calculus, the Taylor–Lagrange theorem.
Theorem 3.1 (Taylor–Lagrange theorem)
Suppose that is times differentiable on some interval containing the center of convergence and , and let be the order Taylor polynomial of at . Then where is the error term of from . i.e. , and for between and , the Lagrange remainder form of the error is given by the formula .
Martin-Dorel et al. [28] proved the Taylor–Lagrange theorem formally in Coq, and it is available in the Coq.Interval library [30, 10]. We used this formalization of the Taylor–Lagrange theorem to prove the consistency of a finite difference scheme.
We will specifically prove that for a central difference approximation of the second derivative, , expressed as : , the truncation error is quadratic in :
3.1 Proof of consistency for the finite difference scheme
We want to prove that for a central difference approximation of the second derivative in the numerical scheme , the truncation error, . By invoking the definition of Big-O notation, the theorem statement can be stated as:
(8) |
The equation (8) is stated formally in Coq as:
Theorem taylor_FD (x:R): Oab x ->exists gamma:R, gamma >0 /\ exists G:R, G>0/\ forall dx:R, dx>0 -> Oab (x+dx) -> Oab (x-dx)->(dx< gamma -> Rabs((D 0 (x+dx)- 2*(D 0 x) + D 0 (x-dx))*/(dx * dx)- D 2 x)<= G*(dx^2)).
where Oab x mean and D k x denotes derivative of with respect to x.
We start by introducing the following lemmas required to complete the proof.
Lemma 1 ()
Here, is the Lagrange remainder in the expansion of up to degree 3 and is defined as:
(9) |
Thus, Lemma 1 states that the Lagrange remainder is of order for all .
Lemma 2 ()
Here, is the Lagrange remainder in the expansion of up to degree 3 and is defined as:
(10) |
Thus, Lemma 2 states that the Lagrange remainder is of order for all .
Both the lemmas are a straightforward application of the Taylor–Lagrange theorem (Theorem 3.1), and are crucial to the formalization of the proof of the consistency of the finite difference scheme.
Next, we present an informal proof of the theorem followed by a discussion on the formal proof of the consistency theorem.
Proof
An important point to note is that the condition holds when , where is as defined in (8). We therefore choose, , where is such that, holds when , and is such that, holds when .
3.2 Formalization in the Coq Proof assistant
We followed the proof above and formalized it in the Coq proof assistant. To apply the Taylor–Lagrange theorem [28] to the consistency analysis of a central difference approximation, we broke down the theorem statement into two lemmas as discussed in the previous section. Therefore, in this section, we will discuss the proof of Lemma 1 and 2.
3.2.1 Proof of Lemma 1:
Formally Lemma 1 is stated in Coq as:
Lemma taylor_uupper (x:R): Oab x-> exists eta: R, eta>0 /\ exists M :R, M>0 /\ forall dx:R, dx>0 -> Oab (x+dx) -> (dx<eta -> Rabs(D 0 (x+dx)- Tsum 3 x (x+dx))<=M*(dx^4)).
In the proof of the Lemma, existential quantification associated with and has to be addressed. We chose as , since the interval in which we are studying Taylor–Lagrange for is . Since and , it seems logical to chose . For the choice of , we obtained extreme bounds in the interval. Since the function and its derivatives are continuous in a compact set , we are guaranteed to get maximum and minimum values. In Coq, we applied the lemma continuity_ab_max to obtain a maximum value, such that . Similarly, we apply the lemma continuity_ab_min to obtain a minimum value, such that .
Thus, is chosen as . With this choice of , we can bound the Lagrange remainder or the trunction error from above and thus prove Lemma 1.
3.2.2 Proof of Lemma 2:
Formally Lemma 2 is stated in Coq as:
Lemma taylor_ulower (x:R): Oab x -> exists delta: R, delta>0 /\ exists K :R, K>0 /\ forall dx:R, dx>0 ->Oab (x-dx) -> (dx<delta -> Rabs(D 0 (x-dx)-Tsum 3 x (x-dx))<=K*(dx^4)).
The proof of Lemma 2 follows the same approach as that of Lemma 1. Here, we chose as , since the interval in which we are studying Taylor–Lagrange theorem for , , and . We chose in the same way as we chose in Lemma 1 except that the interval in which we obtain maximum and minimum values for is in this case. Thus, , ,and .
To prove the main theorem statement on consistency, we break the statement into Lemma 1 and 2, by instantiating , and , where and have been defined as in Lemma 1 and 2 respectively, in the manner shown in section (3.1). To implement this instantiation, we have to carefully destruct the lemmas introduced in the theorem statement. Then, we simply apply lemma 1 and 2, to complete the main proof.
3.3 Relating pointwise consistency to the Lax equivalence theorem
In this section, we relate the proof of consistency from Section 3.1 with the Lax equivalence Theorem 2.1. The numerical discretization of the differential equation can be expressed in the discrete domain as:
(15) |
Comparing with the statement of consistency (5), we have
(16) |
Taking the vector norm in the sense, , equation (16) can be written as:
(17) |
and , trivially because of the boundary conditions we imposed, i.e. and . The norm used in (16) are in the space , i.e., .
This reduces to proving:
(18) |
But from the Taylor–Lagrange analysis discussed in section (3.1), we have
(19) |
where is a constant, and . Substituting , and using the inequality (19) and equation(18), we get
(20) |
But, . Hence, using the sandwich theorem, we prove that
3.4 Formalization in Coq
In order to represent, , we define of type: nat R. The boundary conditions are imposed as hypothesis statements:
Hypothesis u_0 : (D 0 (x 0))= 0. Hypothesis u_N: (D 0 (x N)) =0.
The differential equation is defined as:
Hypothesis u_2x: forall i:nat, (D 2 (x i)) =1.
Equation (18) is formalized as a lemma statement:
Lemma lim_sum:is_lim (fun h:R => sum_n_m (fun i:nat =>Rabs (( D 0 (x i -h) -2* (D 0 (x i)) + D 0 (x i +h))*/(h^2) -1)) 1%nat (pred N)) 0 0.
This is where we integrate the proof of pointwise consistency of the FD scheme from section (3).
The main theorem statement which is an application of the statement of consistency required in the proof of Lax equivalence theorem from section (2) is as follows:
Theorem consistency_inst: forall (U:X) (f:Y) (h:R) (uh: Xh h) (rh: forall (h:R), X -> (Xh h)) (sh: forall (h:R), Y->(Yh h)) (E: Y->X) (Eh:forall (h:R),(Yh h)->(Xh h)), is_lim (fun h:R => norm (minus (Ah h (rh h U)) (sh h (A U)))) 0 0.
We note here that the above-mentioned formalization is not unique to the second order scheme that we discussed. The approach we discuss can easily be generalized to verify consistency of any finite difference scheme. The crucial step in such a generalization is the appropriate instantiation of the matrix and the vectors and .
4 Stability of the scheme
In this section we discuss the stability of the scheme . From section 2, stability of a numerical scheme requires the solution operator to be uniformly bounded. We prove this by bounding the eigenvalues of uniformly. Eigenvalues of are just inverse of the eigenvalues of . A formal proof of this can be referred to in the Appendix 0.B.2.
We will first discuss a generalized framework for the formalization of stability for a symmetric tri-diagonal matrix in Coq. We denote this matrix with with for symmetry. This notation means that is on the diagonal, is on the upper diagonal and is on the lower diagonal. All the other entries are zero. Since we are treating stability from a spectral viewpoint, we next discuss the formalization of the Eigen system for .
4.1 Lemma to verify that the eigenvalues and eigenvectors belong to the spectrum of
Analytical expressions for the eigenvalues and eigenvectors of are given by:
. In Coq, we defined and as follows:
Definition Eigen_vec (m N:nat) (a b c:R):= mk_matrix N 1%nat (fun i j => sqrt ( 2 / INR (N+1))*(Rpower (a */c) (INR i +1 -1*/2))* sin(((INR i +1)*INR(m+1)*PI)*/INR (N+1))). Definition Lambda (m N:nat) (a b c:R):= mk_matrix 1%nat 1%nat (fun i j => b + 2* sqrt(a*c)* cos ( (INR (m+1) * PI)*/INR(N+1))).
Since naturals in Coq start with 0, we write INR (m+1) and INR i+1.
We then formally verify that the analytical expressions for the pair indeed belong to the spectrum of . From now on, we will refer to as for the sake of brevity. In Coq, we state this formally as:
Lemma eigen_belongs (a b c:R): forall (m N:nat), (2 < N)%nat -> (0 <= m < N)%nat -> a=c /\ 0<c-> (LHS m N a b c) = (RHS m N a b c).
where, and . Here we used the definition of eigenvalue-eigenvector, i.e., . Formalizing the proof of the lemma eigen_belongs was challenging due to the structure of the matrix . is a tri-diagonal matrix with non-zero entries on the diagonal, sub-diagonal and super-diagonal. The other entries are zero and hence the matrix is sparse.
(21) |
In Coq, we have to carefully destruct the matrix to separate the non-zero and zero sums in the LHS of equation (21). The idea is to do a case analysis on the row-index , and has been illustrated in figure (1) in the Appendix 0.B.4. Details on the formal proof of the zero and non-zero cases are presented in Appendix 0.B.4.
4.2 Lemma on the boundedness of the matrix norm for scheme
Here, we have used the definition of the spectral (2-norm): , where is the spectral radius of and is defined as the maximum eigen-value of A, i.e. . For the symmetric tri-diagonal matrix , and . Since , . Hence, we define the matrix norm in Coq as follows:
Definition matrix_norm (N:nat):= 1/ Rabs (Lambda_min N).
To show that the matrix norm is uniformly bounded, we need to show that is uniformly bounded. This is where we instantiate the tri-diagonal matrix with the scheme . Thus, we prove the following lemma in Coq:
Lemma spectral: forall(N:nat),(2<N)%nat -> 1/Rabs(Lambda_min N) <= L^2/4.
where is the length of the domain, independent of , and is constant throughout. Lambda_min is the minimum eigenvalue for the instantiated matrix, . We provide a paper proof of this bound in the Appendix 0.A.
To show that all the eigenvalues have the same bound, we prove that is the maximum eigenvalue of . The lemma statement is as follows:
Lemma eigen_relation: forall (i N:nat), (2<N)%nat ->(0<=i<N)%nat -> Rabs (lam i N) <= 1/ Rabs( Lambda_min N).
This completes the proof on the boundedness of the eigenvalues of . The lemma, eigen_relation also shows that the spectral radius of is , and justifies the defintion of matrix_norm.
We note that the definition of the matrix norm of is valid only if is a normal matrix . We therefore verify that is normal. The lemma statement is provided in the Appendix 0.B.3.
We also provide the proof that is diagonalizable in the Appendix 0.C. This helps us to formally establish that the eigen vectors are orthogonal and hence the eigen space is complete.
4.3 Main stability theorem
In this section, we integrate all of the previous lemmas to prove the main stability theorem (6).
Theorem stability: forall (u:X) (f:Y) (h:R) (uh: Xh h) (rh: forall (h:R), X -> (Xh h))(sh: forall (h:R), Y->(Yh h)) (E: Y->X) (Eh:forall (h:R), (Yh h)->(Xh h)), exists K:R , forall (h:R), operator_norm(Eh h)<=K.
where the operator norm is instantiated with the matrix norm using the following hypothesis:
Hypothesis mat_op_norm: forall (u:X) (f:Y) (h:R) (uh: Xh h) (rh: forall (h:R), X -> (Xh h))(sh: forall (h:R), Y->(Yh h)) (E: Y->X) (Eh:forall (h:R),(Yh h)->(Xh h)), operator_norm (Eh h) = matrix_norm m.
5 Application of the Lax equivalence theorem to the example problem
In this section, we apply the Lax equivalence theorem that we proved in Section 2 to a concrete differential equation and the numerical scheme given by . We recall that the proof of convergence using the Lax equivalence theorem requires that the difference scheme is consistent with respect to the differential equation and is stable. We discussed the proof of consistency of the scheme in Section 3 and the stability in Section 4. Thus, we apply these proofs to complete the proof of convergence for the scheme. We provide the theorem statement to verify convergence of the scheme in the Appendix 0.D.
6 Conclusion and Future work
This work investigated the formalization of convergence, stability and consistency of a finite difference scheme in the Coq proof assistant. Any continuously differentiable function can be approximated by a Taylor polynomial. The Lagrange remainder of a Taylor series provides an estimate of the truncation error and we formally proved that this error can be bound by power of the discretization step, , where is the order of the Taylor polynomial. We implemented the proof of the consistency of a finite difference scheme by breaking down the theorem statement into lemmas, each corresponding to function values at points neighboring the point of evaluation. These lemmas were proved individually by applying the Taylor–Lagrange theorem, the proof of which is already formalized in the Coq.Interval library [28]. Consistency and stability guarantees convergence as stated by the Lax equivalence theorem. Following the proof of the the Lax equivalence theorem, we formally proved convergence of a specific finite difference scheme. Specifically, we proved that the global discretization error could be bounded above by a constant times the local discretization error. Then, by applying the sandwich theorem for limits, we proved that the convergence condition is satisfied in the limit . In the process of formalizing the proof of stability for the numerical scheme, we also developed tools for linear algebra and spectral theory, for the Coquelicot definition of matrices in Coq, which can be reused. As noted earlier, the approach we follow is not specific to the sample numerical scheme, but can be easily extended to other numerical schemes with appropriate instantiation of the matrix , and vectors, , . Formalization of the proof of orthogonality of the eigenvectors helped us report the missing constant in that occurs in most textbooks/literature on numerical analysis.
This work considered the impact of the discretization error on the convergence of a numerical method to the exact solution. In a practical setting, floating point errors have to be also accounted for, as an accumulation of such errors can lead to deviations from the true solution. In future work, we will extend our results to incorporate floating point errors and their impact on the convergence of finite difference numerical schemes. We also plan on working with iterative solvers, which would be an extension of our current work on direct solvers (explicit inversion of the matrix ). We also plan on working with the Frama-C toolkit [14] for verification of existing programs and be able to discharge the generated verification conditions using the Coq proofs we present in this paper.
6.1 Effort and challenges:
The total length of the Coq code and proofs is about 14,000 lines, of which about 1200 lines are specific to the scheme. The rest of the formalization can be reused for a generic symmetric tridiagonal matrix. It took us about 15 months for the entire formalization. Much of the effort was spent on destructing the matrices and developing required linear algebra tools to handle the matrix manipulation. Since we are treating stability from a spectral point of view, lack of spectral theory for numerical analysis for the Coquelicot definition of matrices has been challenging for us. For the proof of consistency, the primary challenge was the right placement of the quantifiers to bound the Lagrange remainder using the definition of big- notation. To instantiate , we had to carefully destruct the lemmas into the main theorem. We believe that a generic library with an automated implementation of the big-O definitions would save considerable effort here. We also encountered issues in selecting appropriate instantiations for other existential parameters. In the proof of convergence, we had to carefully construct the application of properties of limit with filters of neighborhoods.
References
- [1] Navier-stokes equations. https://www.grc.nasa.gov/WWW/k-12/airplane/nseqs.html, (Accessed on 9/20/2020)
- [2] Boldo, S., Clément, F., Faissole, F., Martin, V., Mayero, M.: Elfic Coq library for formalization of Lax-Milgram theorem. https://www.lri.fr/~sboldo/elfic/index.html, (Accessed on 9/20/2020)
- [3] Boldo, S., Clément, F., Faissole, F., Martin, V., Mayero, M.: A Coq formal proof of the Lax-Milgram theorem. In: Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs. pp. 79–89. ACM (2017)
- [4] Boldo, S., Clément, F., Filliâtre, J.C., Mayero, M., Melquiond, G., Weis, P.: Formal proof of a wave equation resolution scheme: the method error. In: International Conference on Interactive Theorem Proving. pp. 147–162. Springer (2010)
- [5] Boldo, S., Clément, F., Filliâtre, J.C., Mayero, M., Melquiond, G., Weis, P.: Wave equation numerical resolution: a comprehensive mechanized proof of a c program. Journal of Automated Reasoning 50(4), 423–456 (2013)
- [6] Boldo, S., Clément, F., Filliâtre, J.C., Mayero, M., Melquiond, G., Weis, P.: Trusting computations: a mechanized proof from partial differential equations to actual program. Computers & Mathematics with Applications 68(3), 325–352 (2014)
- [7] Boldo, S., Lelay, C., Melquiond, G.: Hierarchy Coq library. http://coquelicot.saclay.inria.fr/html/Coquelicot.Hierarchy.html, (Accessed on 9/20/2020)
- [8] Boldo, S., Lelay, C., Melquiond, G.: Coquelicot: A user-friendly library of real analysis for Coq. Mathematics in Computer Science 9(1), 41–62 (2015)
- [9] Bréhard, F., Mahboubi, A., Pous, D.: A certificate-based approach to formally verified approximations. In: ITP 2019-Tenth International Conference on Interactive Theorem Proving. pp. 1–19 (2019)
- [10] Brisebarre, N., Joldeş, M., Martin-Dorel, É., Mayero, M., Muller, J.M., Paşca, I., Rideau, L., Théry, L.: Rigorous polynomial approximation using taylor models in Coq. In: NASA Formal Methods Symposium. pp. 85–99. Springer (2012)
- [11] Bréhard, F.: Numerical computation certified in functional spaces: A trilogue between rigorous polynomial approximations, symbolic computation and formal proof. Ph.D. thesis (2019)
- [12] Cohen, C.: Formalizing real analysis for polynomials (2010)
- [13] Cohen, C., Rouhling, D.: A formal proof in Coq of LaSalle’s invariance principle. In: International Conference on Interactive Theorem Proving. pp. 148–163. Springer (2017)
- [14] Cuoq, P., Kirchner, F., Kosmatov, N., Prevosto, V., Signoles, J., Yakobowski, B.: Frama-c. In: Eleftherakis, G., Hinchey, M., Holcombe, M. (eds.) Software Engineering and Formal Methods. pp. 233–247. Springer Berlin Heidelberg, Berlin, Heidelberg (2012)
- [15] Faissole, F.: Library on lax-milgram theorem (coqlm). https://www.lri.fr/~faissole/these\_coq.html, (Accessed on 12/30/2019)
- [16] Garillot, F., Gonthier, G., Mahboubi, A., Rideau, L.: Packaging mathematical structures. In: International Conference on Theorem Proving in Higher Order Logics. pp. 327–342. Springer (2009)
- [17] Hu, G., O’Connell, R.F.: Analytical inversion of symmetric tridiagonal matrices. Journal of Physics A: Mathematical and General 29(7), 1511 (1996)
- [18] Immler, F.: Formally verified computation of enclosures of solutions of ordinary differential equations. In: Badger, J.M., Rozier, K.Y. (eds.) NASA Formal Methods. pp. 113–127. Springer International Publishing, Cham (2014)
- [19] Immler, F.: A Verified ODE Solver and Smale’s 14th Problem. Dissertation, Technische Universität München, München (2018)
- [20] Immler, F., Hölzl, J.: Numerical analysis of ordinary differential equations in isabelle/hol. In: International Conference on Interactive Theorem Proving. pp. 377–392. Springer (2012)
- [21] Immler, F., Traut, C.: The flow of odes. In: International Conference on Interactive Theorem Proving. pp. 184–199. Springer (2016)
- [22] Immler, F., Traut, C.: The flow of odes: Formalization of variational equation and poincaré map. Journal of Automated Reasoning 62(2), 215–236 (2019)
- [23] Kirk, D.B., mei W. Hwu, W.: Chapter 10 - parallel patterns: Sparse matrix–vector multiplication: An introduction to compaction and regularization in parallel algorithms. In: Kirk, D.B., mei W. Hwu, W. (eds.) Programming Massively Parallel Processors (Second Edition), pp. 217 – 234. Morgan Kaufmann, Boston, second edition edn. (2013). https://doi.org/https://doi.org/10.1016/B978-0-12-415992-1.00010-9, http://www.sciencedirect.com/science/article/pii/B9780124159921000109
- [24] Knapp, M.P.: Sines and cosines of angles in arithmetic progression. Mathematics magazine 82(5), 371 (2009)
- [25] Kreyszig, E.: Introductory functional analysis with applications, vol. 1. wiley New York (1978)
- [26] Lax, P.D., Richtmyer, R.D.: Survey of the stability of linear finite difference equations. Communications on pure and applied mathematics 9(2), 267–293 (1956)
- [27] Lelay, C.: How to express convergence for analysis in coq (2015)
- [28] Martin-Dorel, É., Rideau, L., Théry, L., Mayero, M., Pasca, I.: Certified, efficient and sharp univariate taylor models in coq. In: 2013 15th International Symposium on Symbolic and Numeric Algorithms for Scientific Computing. pp. 193–200. IEEE (2013)
- [29] Mayero, M.: Using theorem proving for numerical analysis correctness proof of an automatic differentiation algorithm. In: International Conference on Theorem Proving in Higher Order Logics. pp. 246–262. Springer (2002)
- [30] Melquiond, G., Érik Martin-Dorel, Mayero, M., Pasca, I., Rideau, L., Théry, L.: Interval Coq Library. http://coq-interval.gforge.inria.fr/, (Accessed on 9/20/2020)
- [31] O’Connor, R.: Certified exact transcendental real number computation in coq. In: International Conference on Theorem Proving in Higher Order Logics. pp. 246–261. Springer (2008)
- [32] Pasca, I.: Formal Verification for Numerical Methods. Ph.D. thesis, Université Nice Sophia Antipolis (2010)
- [33] Sanz-Serna, J., Palencia, C.: A general equivalence theorem in the theory of discretization methods. Mathematics of computation 45(171), 143–152 (1985)
Appendix 0.A Proof of the uniform bound on the eigen values of
In this section, we provide a paper proof of the uniform boundedness of the eigenvalues of the scheme .
Proof
[Using the identity: ] | |||
Using the definition, , where L is the domain length, | |||
We prove the relation , by using the concavity of in . We define a concave function in Coq as follows:
Definition concave (f:R->R) (x y c:R):= 0<=c<=1 -> f(c*x + (1-c) * y) >= c* f x + (1-c) * f y.
The proof for is formalized as the following lemma statement in Coq:
Lemma spectral_intermed:forall(x:R),0<x<=PI/2 ->(x^2)/(sin x)^2 <=(PI^2)/4.
Appendix 0.B Lemmas required to complete the proof of stability:
0.B.1 Lemma to verify the invertibility of
In this subsection, we verify that the explicit form of the inverse [17] we use is indeed the inverse of , i.e. . In Coq, we state the following lemma to verify the invertibility of :
Lemma invertible_check (a b:R) : forall (N:nat), (2<N)%nat -> 0<a -> Mk N (b/a) <> 0 -> invertible N (Ah N a b a ) (inverse_A N a b ).
Here, is the determinant of of size . We used the recurrence relation [17]: . Overall, the approach is similar to the proof of the lemma eigen_belongs, i.e. we exploit the tridiagonal structure of . The proof required us to formalize some properties from combinatorics.
For the scheme that we are considering, . Two important steps that were required to complete the proof of for the scheme were:
-
1.
Proving that : We proved this using strong induction on and the recurrence relation described above. To get an intuition of why it is true, we observe the values of for initial values of :
-
2.
Proving that the determinant,
0.B.2 Lemmas on spectrum of
In this subsection, we prove that the eigenvalues of are just inverse of the eigenvalues of , while the eigenvectors are the same. This follows from the following informal proof:
Proof
We start with the definition of Eigen-system ,
In Coq, we define the following lemma to formalize this proof:
Lemma inverse_eigen (m N:nat) (a b:R) : (2< N)%nat -> (0<=m<N)%nat -> 0<a -> ((invertible N (Ah N a b a) (inverse_A N a b)) /\ (LHS m N a b a= RHS m N a b a)) ->(Eigen_vec m N a b a) = Mmult (inverse_A N a b) (Mmult (Eigen_vec m N a b a) (Lambda m N a b a)).
0.B.3 Lemma to verify that the is normal
In this subsection, we verify that is normal. This lemma is stated as:
Lemma inverse_is_normal (a b:R): forall (N:nat), Mmult (inverse_A N a b ) (mat_transpose N (inverse_A N a b )) = Mmult (mat_transpose N (inverse_A N a b )) (inverse_A N a b ).
0.B.4 Intermediate lemmas to complete the proof of the lemma eigen_belongs:
This proof requires some intermediate lemmas which verify certain properties which are as follows:
0.B.4.1 Lemmas on structure of the matrix:
In this subsection, we provide the lemmas that verify the structure of the matrix, i.e. the diagonal entries are , the sub-diagonal entries are and the super-diagonal entries are . Mathematically, the lemmas say: , , . For the first and last rows, we have the structure as: and . In Coq, we define the following lemmas to verify the above-mentioned structure:
Lemma coeff_prop_1 (a b c:R): forall (i N:nat), (2<N)%nat -> (0<i <N)%nat -> coeff_mat Hierarchy.zero (Ah N a b c) i (pred i) = a . Lemma coeff_prop_2 (a b c:R): forall (i N:nat), (2<N)%nat -> (i <N)%nat ->coeff_mat Hierarchy.zero (Ah N a b c) i i = b. Lemma coeff_prop_3 (a b c:R): forall (i N:nat), (2<N)%nat -> (i< pred N)%nat -> coeff_mat Hierarchy.zero (Ah N a b c) i (i + 1) = c.
0.B.4.2 Lemmas to handle the zeros case:

A good amount of effort was also required in extracting zero entries in the matrix and proving that their sum equals zero. This again exploits the structure of the matrix, illustrated in figure (1). Two important lemmas that played a pivotal role in this proof are :
Lemma sum_const_zero:forall(n m:nat),(n<=m)%nat-> sum_n_m(fun _=>0)n m=0.
Mathematically this means:
Lemma sum_n_m_zero(a:nat -> G)(n m:nat):(m<n)%nat -> sum_n_m a n m = zero.
Mathematically this means: , , where, is a function from naturals to an abelian group (G), in our case, it is reals. The first lemma was proved by us but the second one is already present in the Coquelicot library.
0.B.4.3 Lemmas to handle the non-zero case:
The other part of the proof is to equate the sum of non-zero entries in LHS to a non-zero entry in RHS. i.e. , where the represents the row of the matrix and denotes the component of the Eigen-vector and is a scalar. In Coq, considering , for example, would translate to the lemma statement:
Lemma i_0_j (a b c:R): forall (m N:nat), (2<N)%nat -> (0<=m<N)%nat -> a=c /\ 0<c-> mult (coeff_mat Hierarchy.zero (Ah N a b c ) zero 0) (coeff_mat Hierarchy.zero (Eigen_vec m N a b c ) 0 0) + mult (coeff_mat Hierarchy.zero (Ah N a b c ) zero 1) (coeff_mat Hierarchy.zero (Eigen_vec m N a b c ) 1 0) = mult (coeff_mat Hierarchy.zero (Eigen_vec m N a b c ) zero 0) (coeff_mat Hierarchy.zero (Lambda m N a b c ) 0 0).
We are not providing other lemmas here in the interest of space, but they can be referred in the attached code.
Appendix 0.C Diagonalization of
In this section, we discuss the lemmas required to prove that is diagonalizable, i.e. , where S is the matrix of eigenvectors and is a diagonal matrix of Eigen-values of . We first present an informal proof:
Proof
We start with the definition of an Eigensystem:
Here, we use the fact that , since S is orthonormal. We verify this by using the definition of inverse of matrices, i.e. . In Coq, we prove the following lemma:
Lemma Scond:forall (N:nat) (a b:R), (2<N)%nat -> 0<a -> Mmult (Sm N a b) (Stranspose N a b) = identity N /\ Mmult (Stranspose N a b) (Sm N a b) = identity N.
To prove the lemma Scond, we split the proof into two sub-proofs:
-
1.
i = j,
-
2.
For the first case, we have the condition that , i.e. . This reduces to proving that the sum of the following sine-squared series is 1.
(22) |
In Coq, we prove the following lemma to verify (22):
Lemma sin_sqr_sum: forall (i N:nat), (2<N)%nat /\ (0<=i<N)%nat -> sum_n_m (fun l:nat => (2/(INR(N+1)))* sin(((INR l+1)* INR (i+1)*PI)*/ INR (N+1)) ^2) 0 (pred N)=1.
Here, we make use of the following theorem from [24]:
Theorem 0.C.1
If and and n is a positive integer,
where . We state the Theorem 0.C.1, using the following hypothesis statement in Coq:
Hypothesis cos_series_sum: forall (a d:R) (N:nat), d <>0-> sum_n_m (fun l:nat => cos (a+(INR l)*d)) 0 (pred N)= sin(INR N*d/2)* cos(a+INR(N-1)*d/2)*/ sin(d/2).
We then use the hypothesis cos_series_sum to prove the lemma sin_sqr_sum.
For the second case, we have the orthogonality condition . This reduces to proving:
(23) |
since, is a constant, it can be taken outside the summation.
Using the trigonometric identity,
we can reduce (23) into sums of cosines as follows:
(24) |
Using Theorem (0.C.1), we can further reduce each sum in equation (24) into the product of sine and cosine. By doing some algebra, we prove that if and are simultaneously even or they are simultaneously odd, the sums in equation (24) cancel out. We further note that it is always the case that and are simultaneously even or they are simultaneously odd. We provide an informal proof of this fact as follows:
Proof
Case 1: is even:
Case 2: is odd:
and vice-versa for each cases. This completes the proof of orthogonality of the Eigen vectors. In Coq, we prove the following lemma to verify (24):
Lemma cos_sqr_sum: forall (i j N:nat), (2<N)%nat /\ (0<=i<N)%nat /\ (0<=j<N)%nat /\ (i<>j) -> sum_n_m (fun l:nat => mult(/INR(N+1)) (cos((INR(i) - INR(j)) * PI / INR (N + 1) + INR l * (INR(i) - INR(j)) * PI / INR (N + 1)) - cos(INR(i+j+2)*PI */ INR(N+1) + INR l * INR(i+j+2)*PI */ INR(N+1)))) 0 (pred N)=0.
Appendix 0.D Application of the Lax–Equivalence theorem to the scheme
We define the following theorem statement to prove the convergence of the numerical scheme in Coq:
Theorem scheme_convergence: forall (U:X) (f:Y) (h:R) (uh: Xh h) (rh: forall (h:R), X -> (Xh h)) (sh: forall (h:R), Y->(Yh h)) (E: Y->X) (Eh:forall (h:R), (Yh h)->(Xh h)), is_linear_mapping X Y Aop -> f=Aop U-> (* Hypothesis that A is a linear mapping from X to Y*) (forall (h:R),is_linear_mapping (Xh h) (Yh h) (Ah_op h))-> (* Hypothesis that Ah is a linear. mapping from Xh to Yh for each h*) (forall (h:R), is_bounded_linear X (Xh h) (rh h))-> (* Hypothesis that rh is a bounded linear operatior (restriction) from X to Xh for each h*) (forall (h:R),is_bounded_linear Y (Yh h) (sh h))-> (* Hypothesis that sh is a bounded linear operator (restriction) from Y to Yh*) is_bounded_linear Y X E -> (* Hypothesis that E is a bounded linear operator from Y to X*) U=E f-> (* Defining solution in continuous space (true solution)*) (forall (h:R), is_bounded_linear (Yh h) (Xh h) (Eh h)) -> (* Hypothesis that Eh is a bounded linear operator from Yh to Xh for each h*) (forall h:R, is_finite (operator_norm(Eh h))) -> (* Hypothesis that ||Eh|| is finite*) (uh= Eh h (sh h f))-> (* Defining a discrete solution uh*) ( Ah_op h uh = sh h f)-> (*f =fh*) (forall (h:R), rh h U= Eh h (Ah_op h (rh h U)))-> (*uh =Eh *Ah *uh, where Eh*Ah=I*) (forall h:R, minus (Ah_op h (rh h U)) (sh h (Aop U)) <> Hierarchy.zero)-> is_lim (fun h:R= norm (minus (rh h (E(f))) (Eh h (sh h (f))))) 0 0 . (*Convergence*)