Certified Qualitative Analysis of the SIR ODE and Reusable Scalar Lemmas in Isabelle/HOL David B. Hulak, Arthur F. Ramos, Ruy J. G. B. de Queiroz Abstract We present a mechanically checked Isabelle/HOL bridge from the Picard–Lindelöf flow infrastructure in the Archive of Formal Proofs (AFP) to selected standard qualitative facts for the mass-action, closed-population classical susceptible–infectious–recovered (SIR) epidemic ODE. The epidemiological facts are classical; the contribution is reusable theorem infrastructure connecting the AFP local-flow construction to global forward existence, forward invariance of the nonnegative orthant (all three compartments nonnegative), conservation, monotonicity, the Kermack–McKendrick conserved phase-plane relation, compartment bounds, and threshold-ratio conditions governing pointwise infectious growth and interval-wide monotonicity. The finite-interval qualitative facts are proved first on bounded intervals. After the compact-continuation argument establishes global forward existence, those facts are transferred to the unique AFP forward flow on arbitrary finite intervals [ 0 , b ] [0,b] with b > 0 b>0 . We do not formalize stability, final-size, or asymptotic theory. For the forward initial-value problem in this unnormalized mass-action convention, β ​ S ​ ( 0 ) / γ \beta S(0)/\gamma is the initial effective threshold ratio governing initial infectious growth when I ⁡ ( 0 ) > 0 I(0)>0 ; it need not equal the fully susceptible disease-free-equilibrium quantity. The checked proof first establishes sign and conservation facts for the local AFP flow, then uses the conserved nonnegative simplex—a compact set containing each local-flow segment whose times are already known to exist—as the compactness witness for extending to all forward times. Thus the qualitative facts, under their stated side conditions, apply to the unique Isabelle/AFP SIR flow itself, not to an informally assumed trajectory. This packages selected textbook SIR qualitative reasoning as importable Isabelle theorem infrastructure. The reusable layer is an Isabelle library for homogeneous-linear scalar compartment arguments—equations of the form X ′ ​ ( t ) = f ⁡ ( t ) ​ X ​ ( t ) X^{\prime}(t)=f(t)X(t) —together with derivative-sign monotonicity, three-compartment conservation, and an SIR transfer bridge to the AFP flow infrastructure. The accompanying Isabelle artifact builds with Isabelle 2024 and AFP 2024, and its checked source theory files contain no sorry proof placeholders and no oops proof-abort commands. Keywords: Isabelle/HOL; formal verification; SIR epidemic model; compartmental models; ordinary differential equations; forward invariance; qualitative ODE analysis; proof engineering 1 Introduction Compartmental models are a cornerstone of mathematical epidemiology [ 24 , 1 , 10 , 7 , 4 , 16 , 27 ] . These models partition a population into distinct epidemiological compartments whose sizes evolve according to systems of ordinary differential equations (ODEs). Their qualitative analysis is non-numerical structural reasoning about trajectories: conservation laws, monotonicity, threshold conditions, forward invariance, and phase-plane structure such as the Kermack–McKendrick conserved level curves. These facts support understanding epidemic dynamics without closed-form solutions. The concrete case is the closed-population susceptible–infectious–recovered (SIR) system S^{\prime}=-\beta SI , I^{\prime}=\beta SI-\gamma I , and R^{\prime}=\gamma I , where S , I , and R denote susceptible, infectious, and recovered compartments; the standard notation is made precise in Section 4 . One such qualitative fact is the conserved Kermack–McKendrick level-curve relation in the (S,I) phase plane; Section 4.9 gives the precise finite-interval statement and positivity condition. Making these qualitative facts machine-checkable matters for downstream formal epidemiology: for example, a later verified numerical-bound argument or model-extension proof can import sign, conservation, and threshold side conditions instead of assuming them informally. We present a mechanically checked Isabelle/HOL formalization of these qualitative SIR facts, organized around reusable scalar lemmas for compartmental models. Here the certification claim is specific: the artifact builds under Isabelle 2024 and AFP 2024, and each displayed theorem faithfully summarizes a checked Isabelle statement. The novelty is formal-methods infrastructure—the checked AFP-flow bridge and reusable interfaces—rather than new epidemiological mathematics. At the architectural level, a central mechanization pitfall is circularity: all-forward-time invariance cannot be a premise for proving all-forward-time existence. In particular, one cannot assume that a trajectory remains for all future times in a compact nonnegative simplex before the continuation argument has established that those future times exist. Only solution prefixes whose times already lie in the maximal existence interval are available for the compact-continuation argument. Section 4.3 gives the proof order; sign and conservation facts on existing local prefixes provide the compact-continuation witness: a compact set containing the existing local trajectory, used by the AFP continuation theorem to extend the local flow. Definition 1.1 (Forward invariance) . In this paper, a set K\subseteq\mathbb{R}^{3} of SIR states is forward invariant for the class of differentiable triples satisfying the SIR ODE (stated above; formalized in Section 4 ) on [a,b] , when every solution whose state triple (S(a),I(a),R(a)) lies in K at its left endpoint has its state triple (S(t),I(t),R(t)) in K for every t\in[a,b] . This definition fixes terminology used throughout. In the finite-interval statements below, “starts” means at the left endpoint a ; the flow bridge specializes this to initial time 0 . For ordinary mathematical reading, this means differentiable SIR trajectories satisfying the ODE on the interval. In the main application, K is the nonnegative orthant; the formal theorem is proved in the SIR_solution locale, a named, parameterized proof context ( Section 2.4 ) whose assumptions include nonnegative initial data. Despite their ubiquity, the qualitative properties of compartmental models are often presented at a mathematical level that suppresses mechanization-relevant hypotheses. In textbook presentations of the SIR model [ 24 , 16 , 5 , 4 ] , nonnegativity is usually handled as part of the biologically meaningful state space or by a boundary argument, while existence, uniqueness, and differentiability hypotheses are delegated to standard ODE theory or left in the background. In this development, mechanization forces these assumptions into the open: we prove nonnegativity from the SIR ODE and nonnegative initial conditions, then connect the result to a Picard–Lindelöf construction of the SIR flow. The compactness argument may use only invariants already proved on existing local-flow prefixes. Because SIR-family models are building blocks for richer formal epidemiology, even qualitative proof obligations such as nonnegativity, conservation, and threshold monotonicity are worth making explicit. For example, a threshold statement is only biologically meaningful for trajectories that remain in the nonnegative orthant (the set where all compartment values are nonnegative). For readers interested in formalized reasoning, the reusable architecture has three layers: scalar calculus lemmas, SIR-specific locale instantiation, and AFP flow globalization. The proof-engineering difficulty is preserving theorem side conditions across these layers, not redoing the textbook algebra by hand. Concretely, the checked bridge must align endpoint derivative conventions, within-interval and full-neighbourhood derivative facts, theorem-side-condition traceability, and compact continuation without assuming the global invariants being proved. Section 6.6 gives a concrete downstream import scenario. Contributions. 1. A reusable Isabelle/HOL lemma library for homogeneous-linear scalar compartmental ODE arguments, equations of the form X^{\prime}(t)=f(t)X(t) , and three-compartment conservation ( Section 3 ), providing: • Generic integrating-factor representation for scalar equations X^{\prime}=f(t)X with continuous coefficient f . • Scalar sign preservation: nonnegative initial value implies nonnegative trajectory. • Interface wrappers for derivative-sign monotonicity. • A three-compartment conservation theorem. 2. An instantiation for the classical SIR model ( Section 4 ), proving: • Instantiation of the AFP Picard–Lindelöf/flow infrastructure for the SIR vector field. • Global forward existence for nonnegative initial data. • Uniqueness of the forward trajectory generated by the SIR vector field. • Forward invariance of the nonnegative orthant from initial conditions. • Integrating-factor integral representations for S and I . • Conservation of total population ( S+I+R=N ). • Monotonicity of S (nonincreasing) and R (nondecreasing). • The Kermack–McKendrick phase-plane invariant: a conserved level-curve relation in the (S,I) plane (under S(a)>0 ). • The initial effective threshold ratio ( Section 4.11 ), \mathcal{R}_{\mathrm{init}}=\beta S(a)/\gamma , with pointwise growth/decline conditions, distinct from the fully susceptible disease-free equilibrium (DFE) basic reproduction quantity. • Monotonicity of I (nonincreasing) on [a,b] when \mathcal{R}_{\mathrm{init}}\leq 1 . • Stationary infection condition: when I(t)>0 , I^{\prime}(t)=0\iff S(t)=\gamma/\beta . • Boundedness ( 0\leq X(t)\leq N for all compartments, from nonnegative initial data). 3. A non-circular proof architecture from assumptions to solutions. The scalar SIR_solution locale records the qualitative theorems for any differentiable solution on a finite interval. The SIR_ODE locale proves sign and conservation facts for the local AFP flow, uses compact continuation to derive the unique global forward solution from \beta>0 , \gamma>0 , and nonnegative initial data, and interprets (i.e., instantiates) the scalar locale on every interval [0,b] . This avoids the concrete circularity pitfall of using global nonnegativity as a premise for the compact witness that is itself needed to justify global existence. Approach. The development is structured as a locale-based framework. The framework theory proves results for arbitrary differentiable functions, and the SIR locale specializes them once its ODE hypotheses match the generic theorem assumptions. The S and I equations are homogeneous linear in their own compartments, so the integrating-factor method yields sign-preserving integral representations; the R equation is handled by derivative-sign monotonicity. The separate existence theory then uses the AFP ODE library to obtain the unique SIR flow and transfer the qualitative theorems to it. Globalizing the flow means proving that the maximal AFP existence interval contains every nonnegative time, not assuming a global solution in advance. Outline. Section 2 reviews the Isabelle interfaces used by the proofs, including the derivative endpoint convention central to the framework’s interface choices. Section 3 presents the reusable lemmas, centered on the integrating-factor theorem. Section 4 instantiates them for SIR and connects them to the AFP flow; its SIR results include forward invariance, the Kermack–McKendrick invariant, threshold theorems, and boundedness. Section 5 positions the result against adjacent theorem-proving and formal-methods work. Section 6 covers assumptions, proof-engineering observations, limitations, artifact details ( Section 6.5 ), and future work, and Section 7 closes with the main takeaway. Throughout, displayed theorem statements are faithful prose summaries of checked Isabelle facts and are written to include their mathematical hypotheses. Isabelle-facing identifiers are set in sans-serif type, as in SIR_solution , and identify the corresponding artifact constants or locales; monospace names such as Compartmental_Model denote source-level theory or session names. 2 Background 2.1 Isabelle/HOL and HOL-Analysis Isabelle is a generic interactive theorem prover; its most widely used object logic, Higher-Order Logic (HOL), is the basis of Isabelle/HOL [ 29 ] . The system provides a rich type system, a powerful simplifier, and the structured Isar proof language [ 37 ] , which supports proofs inspectable at a higher level than tactic traces alone. In this development, Isar and locales make the reusable calculus lemmas visible as theorem contexts rather than hidden proof scripts. HOL functions are total, meaning defined on every input of their type. Consequently, an interval solution is represented by a total function; the ODE and qualitative properties are asserted only on the interval under discussion. This representation is one reason the endpoint derivative convention below must be stated explicitly: the function exists everywhere, while the theorem hypotheses and conclusions are interval-scoped. Typographically, ordinary mathematical notation such as S(t) and I(t) states paper-level functions and quantities, while sans-serif names such as has_real_derivative mark checked Isabelle constants and theorem names, and typewriter names such as HOL-Analysis mark theory names or syntax excerpts. In Isabelle 2024, HOL-Analysis provides the real and multivariate analysis infrastructure used throughout the development: topological and normed vector spaces, Fréchet/field/real derivatives, integration on intervals, monotonicity consequences of the Mean Value Theorem, and the standard transcendental functions \exp and \ln [ 17 ] . Its type-class hierarchy lets the same library lemmas apply uniformly across reals, Euclidean spaces, and other compatible structures. The next two subsections spell out the particular derivative and integration interfaces that drive the formalized proofs. The paper uses the real-derivative interface, which is implemented via the more general Fréchet derivative. The Archive of Formal Proofs (AFP) entry for ordinary differential equations provides Picard–Lindelöf/flow infrastructure: local flows, maximal existence intervals, and uniqueness for locally Lipschitz vector fields. Its SIR instantiation is introduced in Section 4.3 . Readers mainly interested in the SIR theorem package can skim the next two subsections; their takeaway is that the checked interval theorems deliberately use full-neighbourhood derivatives at endpoints, while FTC facts first arrive as within-interval derivatives. 2.2 Derivatives in Isabelle For real-valued functions f:\mathbb{R}\to\mathbb{R} , Isabelle provides the abbreviation (f has_real_derivative D) (at x) which asserts that f has derivative D at point x (in the full neighbourhood). Such functions are total HOL functions on \mathbb{R} ; interval statements restrict where the theorem concludes facts, not where the function is defined. Values outside the interval matter only insofar as they witness these full-neighbourhood derivative assumptions. The derivative abbreviation is definitionally equal to has_field_derivative , which in turn reduces to the general Fréchet derivative has_derivative with a linear multiplication map, i.e. the linear map h\mapsto D\cdot h (scalar multiplication by D ). In practice, this means that has_real_derivative at an interior point of [a,b] uses a two-sided limit, not just a one-sided limit from within the interval. Thus, at the endpoints of [a,b] , the formal assumption is stronger than a one-sided interval derivative: the function must be differentiable in a full open neighbourhood of every point in [a,b] , including the endpoints. This makes the scalar lemmas slightly stronger than the usual textbook interval lemmas, but it is a deliberate interface choice rather than a mathematical change to the SIR model. In the SIR application below, trajectories arise from a flow defined on an open existence interval, so the convention is satisfied on finite closed subintervals after global existence is established. Key combination rules used in our development, shown schematically: • DERIV_mult : product rule, \frac{d}{dt}(f(t)g(t))=f^{\prime}(t)g(t)+f(t)g^{\prime}(t). • DERIV_chain2 : chain rule, (g\circ f)^{\prime}=g^{\prime}(f(x))\cdot f^{\prime}(x) . • DERIV_isconst2 : the HOL-Analysis constancy rule used here; in the interval form relevant below, zero derivative on (a,b) together with continuity on [a,b] gives constancy on [a,b] . Schematically: \bigl(\forall x\in(a,b).\,f^{\prime}(x)=0\bigr)\ \wedge\ f\text{ is continuous on }[a,b]\quad\Longrightarrow\quad\forall x,y\in[a,b].\,f(x)=f(y). • DERIV_atLeastAtMost_imp_continuous_on : differentiability on [a,b] implies continuity on [a,b] . 2.3 Integration in Isabelle Our forward invariance proofs rely on the Fundamental Theorem of Calculus. In HOL-Analysis, this is available as: • integral_has_real_derivative : if f is continuous on [a,b] and t\in[a,b] , then \lambda x.\,\int_{a}^{x}f(s)\,ds has derivative f(t) at t within [a,b] ; this is a within-derivative, i.e. a derivative relative to the interval topology, not yet a full-neighbourhood derivative. Informally, the checked statement has the shape \bigl((\lambda x.\,\int_{a}^{x}f(s)\,ds)\ \text{{has\_real\_derivative}}\ f(t)\bigr)\ \text{{at}}\ t\ \text{{within}}\ \{a..b\}. Isabelle’s interval integral is the Henstock–Kurzweil gauge integral; we mention this only to identify the HOL-Analysis interface. For the continuous functions used here on compact intervals, it agrees with the usual Riemann/Lebesgue value. The key interface subtlety for our proofs is the conversion between interval-relative and full-neighbourhood derivatives: • at_within_Icc_at : for a