Manuscript Offprint
arXiv:2609.37728Formal Reasoning about Performance Models
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
MOUSSA LABBADI, Bretagne INP–ENIB, IRDL (CNRS UMR 6027), France
RUPAK MAJUMDAR, Max Planck Institute for Software Systems (MPI-SWS), Germany
V.R. SATHIYANARAYANA, Max Planck Institute for Software Systems (MPI-SWS), Germany
SADEGH SOUDJANI, University of Birmingham, United Kingdom, and MPI-SWS, Germany
Discrete-event simulation is a standard technique for modelling and analysing the performance of computer systems, networks, and services. Although simulation tools are widely used, reasoning about the correctness and performance guarantees of the models they implement remains largely ad-hoc: simulation outputs are interpreted statistically, but there is no logical foundation for deductive reasoning about their behaviour. We present a core imperative calculus that captures the essential constructs common to discrete-event simulators—asynchronous execution, continuous and discrete sampling from distributions, and time-based event scheduling through a global event queue. On top of this calculus, we develop a proof system for reasoning about almost-sure reachability and expected reaching time properties. Our main result is a sound and complete proof rule for these properties. Our framework generalizes deductive reasoning for (discrete-time) probabilistic programs to the setting of performance models, in which continuous time and continuous-probability distributions are central. We have implemented the proof rules in a tool embedded in Lean. We demonstrate the applicability of our proof rule by deriving proofs of almost sure reachability and expected time for a number of case studies, including client-server examples that go beyond analytic solutions from queueing theory as well as convergence behaviours in network routing protocols. Establishing the soundness and completeness of our proof rules requires significantly more complex arguments than in the discrete-time setting. This is due to the to the fundamentally discontinuous nature of the operational semantics, and to the measure-theoretic challenges of continuous time and probability distributions.
1 Introduction
Discrete-event simulation underlies modern performance modeling of computer systems, distributed services, and communication networks [28, 36, 56]. Simulation frameworks allow engineers to prototype performance-related algorithms, such as scheduling policies, admission control, and load-balancing strategies before service deployment. Yet, despite decades of engineering practice, reasoning about these systems' performance remains empirical: performance and stability are evaluated by repeated simulation and statistical estimation rather than by formal proofs. This empirical approach fails to provide guarantees. As systems incorporate asynchronous flows and complex real-time feedback, we increasingly need formal reasoning principles to answer questions related to stability and resilience: Does the backlog in the system clear almost surely? Is the expected response time finite? Does the system remain stable under all arrival rates? Providing a sound and complete logical framework to answer such questions has been an open challenge.
Classical program logics offer deductive methods for correctness and termination of sequential programs [5, 33, 45]. However, these frameworks reason about step-based computations without an explicit model of real time or event scheduling. In contrast, discrete-event systems feature (i) a global event queue ordered by timestamps, (ii) probabilistic and continuous delay distributions, and (iii) interleaving of asynchronous components through event posting. Simulation languages define their semantics operationally but provide no proof theory [46]. Existing probabilistic program logics handle almost-sure termination [37, 43, 47, 49], but do not account for event-driven scheduling and continuous-time events. Algebraic frameworks [4, 24] model finite-state packet-processing
Authors' Contact Information: Moussa Labbadi, Bretagne INP–ENIB, IRDL (CNRS UMR 6027), Brest, France, moussa.labbadi@enib.fr; Rupak Majumdar, Max Planck Institute for Software Systems (MPI-SWS), Kaiserslautern, Germany, rupak@mpi-sws.org; V.R. Sathiyanarayana, Max Planck Institute for Software Systems (MPI-SWS), Kaiserslautern, Germany, sramesh@mpi-sws.org; Sadegh Soudjani, University of Birmingham, United Kingdom, and MPI-SWS, Kaiserslautern, Germany, sadegh@mpi-sws.org.
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
behaviors in communication networks, but lack support for continuous sampling and event-driven dynamics. Consequently, there is currently no sound and complete proof system for reasoning about performance and termination properties of probabilistic discrete-event systems.
We address this gap by introducing DES, a core calculus that abstracts the key mechanisms shared by discrete-event simulators. DES systems consist of finite sets of procedures; each may perform sequential computation, make discrete probabilistic choices, sample from (continuous) probability distributions, and schedule future procedure calls asynchronously. Their execution is driven by a global event scheduler that dequeues the earliest event in time order and executes its procedure body. Our language captures the essence of simulation engines in a minimal, mathematically precise form suitable for reasoning.
We study almost-sure reachability (is a target reached with probability one?) and expected reaching time for DES systems. These are fundamental questions in performance analysis. We show sound and complete proof rules for these properties. The rule for almost-sure reachability requires drift and variant functions, similar to discrete-time, countable state models. The rule for expected reaching time requires a supermartingale function that dominates the hitting time.
While sound and complete proof rules have been studied for discrete-time probabilistic programs, reasoning about DES introduces new mathematical challenges. When we allow sampling over time and other continuous distributions, the state space is uncountable and can have uncountably many successors. Thus, our semantics involve the theory of Markov processes over general topological spaces. Existing techniques related to proving stability of Markov processes assume that the process is continuous (weak Feller) [44, 51]. Unfortunately, this assumption does not hold for DES systems! The trajectory of a DES system for two close states may be very different, e.g., because the code makes a conditional decision or because one handler is executed before the other.
Dealing with uncountable state and non-continuous dynamics makes our proof very difficult. Our proof of completeness requires new and subtle topological arguments based on petite sets and their properties [51, 62], as well as topological arguments (Egorov's theorem) that connects pointwise convergence of measurable functions with uniform convergence.
We have formalized DES and our proof rules in Leonides. Leonides embeds DES in Lean [18]. Given a DES system, together with drift and variant candidates, Leonides provides custom tactics to discharge proof obligations arising out of our proof rules. We have used Leonides to prove several variations of client–server systems with feedback, timeouts, and retries, a canonical performance model used in service-level analysis [28, 31, 38]. Expressed in DES, this model becomes an infinite-state probabilistic system with scheduled events representing arrivals, completions, and timeouts. The almost-sure reachability property we prove consists in proving that some queues in the system empty out almost surely from any configuration; this corresponds to checking that the system is stable and backlogs are cleared and is a critical performance property in request-response systems. The expected reaching time shows the expected time for backlogs to clear. Our proof rules are able to show this property, even when the underlying model does not fall into an analytically tractable subclass of queueing systems.
As a larger case study, we prove a routing protocol from networking [21] that shows a surprising time synchronization among distributed nodes. Synchronization occurs even in the presence of jitter—which was added to ensure that nodes do not synchronize! [21] explored this phenomenon using network simulations and simulations of a simple discrete Markov model. We show the first formal proof that synchronization occurs almost surely in the protocol. These examples demonstrate that DES and Leonides captures many fundamental models in performance evaluation, including those going beyond analytical closed-form solutions from queueing theory, as well as real protocols for which deductive verification was not possible before.
In summary, we make the following contributions:
(1) Core calculus for discrete-event simulation. We formalize DES, a minimal imperative language capturing asynchronous concurrency, probabilistic choice, sampling from continuous distributions, continuous-time evolution, and time-based event scheduling. We define operational semantics for DES that model interaction between probabilistic execution and the global event scheduler, and show that these semantics produce Markov processes.
(2) Proof system. We present the first sound and complete proof rule for reasoning about almost-sure reachability and expected reaching time for DES systems.
(3) Tool and case studies. We develop Leonides, a mechanized proof environment for DES embedded in Lean. Leonides formalizes the semantics of DES, mechanizes the soundness of our proof system, and provides tactics for proving almost-sure reachability and expected reaching-time properties. We demonstrate its effectiveness on a number of performance models for server systems and network routing protocols.
Our results establish a bridge between formal program verification and performance modeling. By providing a sound and complete logical foundation for discrete-event systems, we move beyond simulation-based validation toward provable performance guarantees and open the way for formal reasoning tools for system performance.
A Client-Server Model System 1 shows a simple simulation model for a client-server example. The Client procedure models request arrivals: it schedules a request to the server right away and also schedules the next request arrival after an exponentially distributed delay , creating an infinite Poisson arrival process. The SendReq procedure enqueues the request at the server and schedules the server to serve it. When scheduled, the server dequeues a request and serves it if it is idle (i.e., not already serving a different request). Serving a request takes time; in the model, the time is drawn from an independent exponential distribution . Upon completion, if there are further tasks in the queue, the server picks a new task. Otherwise, the state variable idle is set, which signifies that the server is not currently processing a request.
This example is the “hello world” of performance simulation. It already shows several features that we model: (a) imperative sequential computation, (b) asynchronous invocation, (c) real-time evolution, (d) (continuous and discrete) probabilistic choice. Since we have not put a bound on the queue size, the program is also infinite-state. The combination of these features takes the example outside of known program logics.
Almost-Sure Reachability: Specifications and a Proof Rule An important question in a client-server example is whether the server has enough capacity to serve arriving requests. One way to formulate this question is to ask whether the queue becomes empty almost surely, from any starting
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
1 proc Client() = 2 req := ...; // generate request 3 post(SendReq, req, ); 4 // schedule next arrival 5 post(Client, exp( )); 6 7 proc SendReq(req) = 8 // enqueue request 9 queue := enqueue(queue, req); 10 // post Server task 11 post(Server, ); 12 13 proc : 14 queue, idle := [], true; 15 post(Client, exp( )); 16 proc Server() = 17 if idle and not queue_empty then 18 idle := false; 19 req := dequeue(queue); 20 post(FinishReq, req, exp( )); 21 22 proc FinishReq(req) = 23 ...; // service completion 24 if not queue_empty then 25 // schedule more tasks 26 req := dequeue(queue); 27 post(FinishReq, req, exp( )); 28 else 29 idle := true;
Sys. 1. A client server example: clients send requests based on an exponential distribution with rate , server completion time is an (independent) exponential distribution with rate , requests are queued in an unbounded queue. The system is an encoding of an M/M/1 queue in DES.
configuration. We are also interested in showing the expected time before this event happens, which answers the question how long the system takes, on average, to clear backlog.
Our proof rule will ask for two kinds of certificates. First, a drift certificate that will assign a non-negative number to each state of the system that will not increase in expectation on each step of the program. Second, a variant certificate will assign a non-negative number to each state, and require two conditions: (a) the variant decreases in each step with some positive probability bounded away from zero, and (b) the variant at any state is bounded by some (known) function of the drift at that state. Our proof rule will show that if these two conditions hold, then the program will reach a given state almost surely.
Our goal in this example is to prove that the queue becomes empty almost surely. Accordingly, we use the size of the queue as candidate to both the drift and the variant. Under the assumption that , we will show that this queue size satisfies the drift and variant conditions. On a global level, the execution of our example is a sequence of events that either add or remove elements from the queue. The queue grows when Client fires and shrinks when FinishReq fires. Because , the queue shrinks at a greater rate than it grows, and hence, the size of the queue drifts toward zero, making it a valid drift. Similarly, because , at each event, it is more likely for the queue to shrink; thus, the queue size is also a valid variant. Note that this size is clearly non-negative, and zero only at goal states. Thus, the queue empties almost surely. Under the same stability assumption , our expected-time proof rule additionally constructs a supermartingale that upper-bounds the expected time until the queue first becomes empty, showing that the expected backlog-clearing time is finite. We provide exact details in Section 4.
While classical queueing theory can derive these particular bounds, the strength of our approach is that we can prove similar properties even in cases where closed form solutions are not available: for example, when we add common features such as throttling, retries, or exponential backoff.
3 The DES Language
We now formally define DES, a core language for simulation, and its semantics as a Markov process.
SYSTEMS sys ::= { def₁, def₂, ..., defₖ, proc p₀() = com } PROCEDURES def ::= proc p(y₁, y₂, ..., yₖ) = com COMMANDS com ::= skip | x := e | x ~ D | com₁; com₂ | com₁ ⊕ₚ com₂ | if(b) then com₁ else com₂ | post(p, e₁, e₂, ..., eₖ, Dₜ) | x := now() | x := peek()
Fig. 1. Syntax of DES. We assume syntactic categories for constants , global variables , local variables , procedure names , and probability distributions and over and respectively. is a distinguished member of Procs used for the initial procedure. and are arithmetic and boolean expressions over .
3.1 Syntax
Figure 1 shows the syntax of our language DES. Systems in DES are defined by a set of procedures that includes a distinguished initial procedure. Each procedure is a command that is paired with a set of variable parameters. Variables take on values from the set of real numbers . Commands are imperative blocks of code that randomly manipulate these real-valued variables. DES offers the standard imperative control constructs and probabilistic choice operators inspired by existing probabilistic programming languages [41, 47]. These are and , and they enable discrete and continuous probabilistic choice respectively. Note that DES does not offer support for the looping constructs such as while; nonetheless, loops can be simulated using the event queue detailed below.
DES provides primitives to insert procedures into a global event queue to be executed at a later time. Time is real-valued, and is measured by the non-negative reals . The operation of DES dequeues the earliest procedure from this event queue for execution. The primitive post schedules procedures by sampling a real-time delay from a distribution over . The command post( ) schedules the execution of the procedure with arguments , at the future time now , where now is the (global) current time and is sampled from the distribution over . We assume the existence of independent syntactic categories for describing distributions over that include standard distributions such as the exponential distributions exp, Dirac (point) distributions , uniform distributions unif, and Gaussian distributions normal. In addition to post, DES provides primitives now() and peek() to allow commands read-only access to the event queue. These reveal the current global time now and the scheduled time of the next pending event in the queue. Using this event queue, a DES system can simulate loops by posting continuation with delay 0 using .
3.2 Markov Processes as Operational Semantics
We will define the operational semantics of DES as discrete-time Markov processes. In the following, we assume some familiarity with measure theory and probability, such as sigma algebras, probability spaces, filtration, and expectation of random variables (see, e.g., [11] for background).
Definition 1. A discrete-time Markov process (MP) is a tuple , where is any set referred to as the state space, is equipped with a sigma algebra , and is a conditional stochastic kernel that assigns to each state a probability measure over the measurable space . Additionally, for every measurable set , the function is measurable.
In addition to , we use to denote the -step transition kernel, where and for all .
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
The dynamics of a Markov process unfold as follows. Let denote the state at time step . Given the current state , the next state is drawn according to the probability measure . For each process, we fix a distinguished initial state . We write to denote the probability measure over infinite trajectories induced by .
The semantics of DES systems define discrete-time Markov processes. We now give the notation we need to define these semantics. A program state is a partial function that maps a finite subset of GVars ∪ LVars to R. We write for the set of all program states, S for the set of all DES systems derivable using the syntax in Fig. 1, and C for the set of all commands derivable in DES.
A pending event is a tuple , where is the scheduled time of the event, id is an unique (linearly-ordered) event identifier used for deterministic tie-breaking, is a procedure name, and are the values of the arguments of . We assume that the event identifiers id come from . Intuitively, a pending event corresponds to a call to procedure with arguments scheduled to be executed at time .
The operational semantics of DES maintains finite priority queues of pending events. Ordering on is lexicographic on , i.e., for two equal timestamps, the lower id wins. We write for the set of all finite priority queues of events .
A DES configuration is a tuple , where is a priority queue of pending events such that for all scheduled times of pending events in , is a global system environment containing the syntax of a finite set of procedures, is a program state that maps all global and local variables used in , now is the current time, and is a DES command representing the state of the execution of the current procedure. Configurations are denoted by , and we use to denote the set of all configurations. The initial configuration of a DES system is , where is the command in ascribed to the initial procedure and is a distinguished initial program state. For a configuration , let , , , , and denote its queue, DES system, program state, time, and command, respectively.
Informal Overview: One Step. The operational semantics of DES is defined by a relation that assigns to configuration a distribution over configurations that arise in one step.
Let us first intuitively describe these steps. A one-step in a DES system can be classified into two kinds: (1) a scheduler dequeue step that pops the event with the minimal scheduled time and id (i.e., with the highest priority) from the event queue for execution, and (2) an execution step of the body of a procedure that can insert new events into the queue and transforms program state.
A scheduler dequeue step is performed when the queue is not empty and the current command is skip. Under these conditions, the scheduler picks the event in with minimal in the lexicographic ordering of . This transitions the execution to a new configuration with being the body of the procedure defined in and produced by augmenting with the values of for each parameter in the definition of . Thus, the time jumps ahead to and the body com of the procedure is executed with arguments . If is not described in , .
The body of every procedure is a loop-free imperative probabilistic program with side-effects enabled by post that insert elements into Q. Note that, because each command is loop-free, every procedure always terminates. Thus, without post, their semantics is a natural generalization of standard operational semantics for straight-line probabilistic programs. These semantics are standard for the deterministic constructs [37, 47]. The probabilistic command executes with probability and with probability . The sampling command samples a value from according to the probability distribution and assigns to the variable . This behaviour is captured by the operational semantics shown in Fig. 2.
ASSIGN
SAMPLE
NOW
PROB
PEEK
CONCAT
DEQUE
POST
Fig. 2. Operational Semantics of DES. The relation assigns to each configuration a probability distribution over the set of all configurations. is obtained by setting the variable in to the value of the expression in ; generalizes this to a tuple of variables . is the Dirac (point) distribution that assigns probability 1 to the singleton . peek(Q) is the timestamp of , or (a designated top element of ) when is empty. is a pushforward operation that samples the output of the function according to the distribution . is the distribution produced by sampling a value according to and taking the distribution associated to it by .
Posts are the novel feature of DES. They perform probabilistic sampling from continuous distributions over time and produce a queue side-effect. Suppose in the current configuration , where . Suppose the evaluation of the expressions yield values ; these are the aforementioned deterministic evaluations. Then the post step is a probabilistic transition that yields a probability measure over configurations that maps any measurable set of configurations to
where is a fresh id greater than all identifiers in and . Intuitively, we sample a delay from the distribution , create a fresh monotone identifier (to preserve deterministic tie-breaking), and return the point configuration with the queue extended by and the post command evaluated to skip. The effect is a probabilistic enqueueing of exactly one event.
Example 1. Consider a system S consisting of two procedures proc and proc . The execution of this system proceeds as follows. The initial configuration of the system is . The scheduler dequeues , sets now = 0, and then begins executing the initial procedure . This moves
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
the execution to ( , , , 0, post( , 1, dist( )). The semantics samples a delay and enqueues , where is a fresh symbol greater than . Then, the scheduler picks the minimal time , sets now = and starts executing . Since this does not post any new tasks, the program terminates after finishes executing. Note that time only increases in a scheduler step. If several post calls produce different sampled delays, the scheduler always selects the event with the smallest sampled scheduled time next.
One-Step Operational Semantics: Formal Details. To formally define the semantics, we need two additional notions. The first is the pushforward measure. Given two measurable spaces and , a measurable function , and a measure over , the pushforward measure is the measure given by
Intuitively, is the distribution of over when is sampled from according to .
The second is the composition of a kernel and a measure. In a measurable space , a kernel is a function that assigns a probability measure over to each element in . Thus, the composition of a kernel and a measure over the space is given by
Intuitively, the measure is obtained by first sampling a point according to and then taking the resulting distribution over according to .
Let represent the Borel -algebra over . The operational semantics of DES is given by the relation that recursively assigns a probability measure over the space to each configuration in , as shown in Fig. 2. Thus, means that the semantics assigns the measure over to the configuration .
Notice that configurations with skip commands and empty queues are not related by ; thus, these configurations are terminal configurations. Moreover, an assignment of a full probability measure as the effect of each command is only possible because every command that can be written in DES is loop-free and thus, always terminating. For every configuration with a non-skip command, the distribution assigned by assigns measure 1 to the set of configurations with a skip command. Thus, the small-steps of commands are compiled into a single DES step.
From Steps to Traces: Markov Processes Semantics. The one-step relation induces a discrete-time Markov process evolving in the measurable space of all configurations . For any configuration with according to the semantics defined in Fig. 2, the transition kernel is defined as for all . For every terminal configuration , define . It is easy to see that for every , the function is measurable. We denote by probability measure over the infinite trajectories of this chain induced by .
4 Almost-Sure Reachability and Expected Reach Time for DES
We are interested in proving the almost-sure reachability of distinguished goal states in Markov processes and DES systems. The almost-sure reachability question asks: does a DES system S reach a measurable set Goal with probability 1?
Formally, let be a discrete-time Markov process. Let Goal be a distinguished measurable subset of X. Define the first hitting time as
Here, is a random variable equal to the state reached in steps and is the initial state. The reachability probability of Goal is the probability that is finite. We say almost surely reaches Goal if .
We can state the same problems on DES systems. Let be a DES system with a distinguished variable goal initialized to 0. The almost-sure reachability question asks: does reach a configuration in which goal = 1 with probability 1? Let Goal be the set of configurations with . Then, reaches goal almost surely iff the Markov process reaches the set Goal almost surely. The semantics of DES as Markov processes implies that these notions are measure-theoretically well-defined.
In addition to the almost sure reachability question, we are interested in the expected time to reach the goal. In DES systems, time is a part of the configuration—meaning the DES time is subsumed into the states of the Markov process defining its semantics. Thus, expected time of DES systems is not the expected value of the number of steps in the Markov process; it is the expected value of the time in configurations reached with . Formally, for the Markov process defining a DES system, let be a random variable equal to the value of the DES time reached in steps. Then, the expected time of a DES system is given by .
4.1 Proof Rules for Almost-Sure Reachability: Overview
In this section, we will define proof rules to reason about almost-sure reachability and upper bounds on the expected reach time. Proof rules are deduction rules that form a part of a proof system within a formal program logic [60]. They are useful in enabling the deduction of complex program properties, including termination [43, 49] and reachability [44]. They are composed of finite collections of certificates (a.k.a. witnesses): functions that map program states to numbers that satisfy certain properties.
We will introduce our proof rules in two steps. We will begin with proof rules for almost sure reachability for general Markov processes, and show that they are sound and complete. This is a general theorem of independent interest in the theory of Markov processes. The technical difficulty over related results is that general Markov processes underlying DES systems do not satisfy continuity assumptions imposed by available results [44, 51].
We then describe a compositional proof rule for DES systems that provides certificates per procedure. We argue about the soundness and completeness of this rule by translating the certificates to and from the Markov processes defining their semantics.
For both Markov processes and for DES systems, our proof rule will be made up of several classes of witnesses:
The Invariant. In program verification, an invariant is a Boolean function that, if true at a state, will remain true at every successor of that state. For DES systems, an invariant is a measurable set of configurations such that and, for all , where the semantics induces .
Drift or Supermartingales. A supermartingale is a non-negative function V of the full state that, in expectation, does not increase at each execution step. In probability theory, supermartingales are stochastic processes whose value is non-increasing in expectation throughout its progression. Supermartingales have a long history in proving properties of probabilistic programs [2, 14], and have recently been used to characterize their almost-sure termination [43, 49].
Variants A (probabilistic) variant is a non-negative function U defined on full states that decreases at each execution step by a minimum value with a minimum probability. These variants are the probabilistic generalization of ranking functions, which for non-probabilistic programs, are classical
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
Proof Rule 4.1: Almost-Sure Reachability for Markov processes
To show that the chain almost surely reaches a measurable target Goal , find
-
A measurable invariant Goal containing the initial state ,
-
A measurable exempt set with Goal ,
-
A measurable supermartingale V and variant U, both mapping , and
-
Assistant functions ,
such that the following are true:
V1 : Drift Criterion. The supermartingale V vanishes exactly on the exempt set, , and does not increase outside it:
V2 : Variant Criterion. For all and ,
Fig. 3. The rule for deducing almost-sure reachability for Markov processes.
certificates for proving program termination [5, 6, 60]. Variants are essential in the effectiveness of supermartingales, and work together to demonstrate termination of probabilistic programs [43, 49].
These are the familiar constructs from the theory of countable Markov chains [43, 49]. This is to be expected, because our results subsume those.
4.2 Proof Rules for Almost-Sure Reachability: Markov Processes
Rule 4.1 shows our proof rule. The rule asks for a measurable supermartingale V and a measurable variant U over the state space. The invariant Inv asked by the rule is a measurable subset of X such that and for all . From a goal state, the chain may leave the invariant with positive probability. The exempt set T is a measurable set between Goal and Inv; it collects the states near Goal where the supermartingale V is 0.
The condition (V1) ensures that V is a supermartingale that is zero on the exempt set (and hence on the goal), and that it is non-increasing in expectation outside the exempt set. The condition (V2) ensures that the variant is bounded on every sublevel set of the supermartingale, that it is zero on the goal set, and that it decreases with positive probability bounded away from zero within each of its own sublevel sets. Observe that on T, so instantiating V2 at leaves throughout T.
Note that the rule of Majumdar et al. [44] differs from Rule 4.1 by indexing its functions d and with the supermartingale instead of the variant. This choice of indexing makes their rule unsound, as we show in our supplementary material.
A proof rule for establishing almost-sure reachability is sound if, whenever its premises hold for a Markov process , its trajectory reaches Goal almost surely. It is complete if, for every Markov process that reaches Goal almost surely, witnesses matching the premises of the rule exist.
THEOREM 2. Rule 4.1 is sound and complete.
1 proc 2 post(p1, x, ) 3 proc p1(y) = if (y < 1/2) then goal := 0 4 else goal := 1
Sys. 2. A DES system whose semantics is not weak-Feller.
PROOF DISCUSSION. The proof is very technical. We only give intuitions here; see the supplementary material for details. The proof of soundness is an extension of the techniques from [43, 44, 49]. Their completeness proofs however require assumptions not met by DES; thus, we use new techniques to prove completeness.
At a high level, our rule is sound for the following reasons. First, the supermartingale V in Drift Condition V1 provides a means to partition the space of configurations X into concentric “circles” around Goal. For example, the sublevel set is exactly the exempt set T, the “innermost circle”, defines the next circle, and so on. Because V is required to be a supermartingale only outside T and vanishes on T, the stopped process , where is the first time the system enters T, is a non-negative supermartingale. The Martingale Convergence Theorem of Doob [19] then ensures the system does not escape to infinitely many higher circles.
The variant function U is used to measure progress within these circles. The Variant Condition V2 implies that U will be bounded from above in each sublevel set of V; in particular, since on T, the variant is bounded on T. Such bounded variants are effective for showing reachability within these sublevel sets [47, Lemma 7.5.1]. This means that, whenever the system is inside a given circle (i.e., a bounded sublevel set of V), it reaches Goal with a non-zero minimum probability at each circle. Because the system almost surely revisits some circle infinitely often, a zero-one law of probabilistic processes gives the soundness of the rule.
The completeness proof is much more challenging, and we briefly review why existing completeness proofs do not imply our results.
Using techniques from Markov chain theory [22, 23, 50], completeness for almost-sure termination was only established recently [43] for probabilistic programs evolving over countable state spaces. Their proof critically relies on the countability of the state space, allowing an enumeration of states such that the probability of reaching states “far to the right” in the enumeration is small. For general Markov processes, the state space contains a continuous component and their techniques do not apply. Continuous components are necessary for DES systems as we explicitly model time and continuous distributions over time.
Using machinery from the theory of topological recurrent Markov chains [51], Majumdar et al. [44] demonstrated a semi-completeness result for stochastic dynamical systems evolving over general state spaces endowed with topologies. However, they required these systems to meet certain continuity assumptions over this topology that ensured that “nearby” states behaved “similarly”. More precisely, they assumed a weak Feller property, i.e., that for any open set O in the topology, where gives the probability of jumping from any state x to O.
Unfortunately, general Markov processes and, in particular, Markov processes arising out of DES systems, need not be weak Feller. Sys. 2 describes an explicit counterexample. After executing the initial procedure , the execution reaches the configuration with queue , with sampled uniformly from . A DEQUEUE step deterministically empties the queue, sets the local variable to , and sets the command to the body of procedure p1. Let be a small open set around goal = 1, and take the configuration where the local variable . It is easy to see that , as configurations with (meaning ) can be arbitrarily close to . However, .
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
1 proc Walk() = u ~ unif(0,1); 2 if u ≤ 2^{-[x]} then x := normal(x, 1); 3 post(Walk, exp(1.4))
4 proc ; 5 post(Walk, )
Sys. 3. The backoff walk : a symmetric random walk whose steps are attempted with a probability that decays geometrically in the current level.
Instead, the completeness of our proof rule can be established using recent advances in the theory of discrete-time Markov processes [62]. First, we produce an irreducible chain using the almost-sure reachability property; this gives us the invariant. We then use insights from Xu et al. [62] to produce a countable increasing cover over the state space X such that each element in the cover satisfies a petiteness criterion. The key step uses Egorov's theorem to convert pointwise convergence into uniform convergence on all but a negligible part of the state space. This argument removes the weak Feller requirement from previous approaches [44, 51]. We then produce supermartingales using the structure of the cover using petite sets. This division of the state space naturally induces a variant that marks a state using its position in the growing sequence.
The full proof, including measure-theoretic details, is in the supplementary material.
Example 3. Take the system of System 3, a walk under exponential backoff: from level a Gaussian step is attempted only with probability , and stalls (stays put) otherwise, inducing the kernel
We prove almost-sure reachability of Goal = with . Since is discontinuous at every integer, is not weak Feller (so, previous rules do not apply) and the Gaussian step is beyond pGCL and its continuous extensions [10, 47]. Reachability nonetheless holds, as the geometric number of stalls between attempts is almost surely finite.
Take the exempt set and the witnesses
with and denoting the standard normal density and cumulative distribution functions. For , a stall leaves unchanged, so outside its drift is that of the plain Gaussian step damped by : for , since and, for , the Mills bound [12, 52] gives (equality only as )—so is the tightest exempt set for this choice of .
The variant shows why V2 needs . A stall fixes U and an attempted step raises it half the time; it falls only on a step drawing below , of probability , which vanishes as , so no constant works. But at states with we have , hence and the variant descends with probability . The example also shows the utility of the exempt set: without it, we cannot easily describe a supermartingale that decreases in expectation in and is zero on .
For countable state spaces, a chain is irreducible if, for any pair of states, there is a finite path of non-zero probability linking the states. This notion is generalized using measure-theoretic constructions to apply in our setting.
Informally, a set C is petite if there is a common measure on the state space that provides a uniform lower bound on the probability of reaching measurable subsets after a random number of steps, regardless of the starting point in C.
4.3 Almost-Sure Reachability: Proof Rule for DES
In principle, one could use Rule 4.1 to reason about the almost-sure reachability of DES systems by applying it on the Markov process defining its semantics. However, that would require building monolithic certificates over the space of all configurations of the DES system. We now provide a compositional proof rule for DES systems. The main difference from Rule 4.1 is that, instead of a single supermartingale and a single variant function, the rule asks for a supermartingale and variant for each procedure defined in the system. These witnesses are only evaluated at configurations where the command is the body of the procedure. As we shall show later, we can compose these witnesses together to get global supermartingales and variants on the state space.
Notation. To describe our proof rule, we need some additional notation. A tuple of an event queue, a program state, and a timestamp is called a full state, denoted by . The set of full states is denoted by , where is the set of event queues and is the set of program states. Recall that configurations are denoted by and , , , , and denotes its queue, DES system, program state, time, and command, respectively. Thus, full states are produced from configurations by dropping its command. For a configuration , let denote the full state . Full states carry the sigma-algebra of the sets with , so a function on is measurable exactly when is measurable in . For functions over full states, we overload to mean . Finally, when the context is clear, we let denote the body of procedure defined in the DES system .
Our proof rule for DES systems decomposes Rule 4.1 by asking for functions that defined on full states rather than configurations. Because full states lack the command information, this new proof rule must ask for supermartingales and variants for each procedure defined in the system S. For each procedure p with body in S, the proof rule uses the supermartingales and variants for p only at command configurations with command .
Recall that, the operational semantics executes a DES system by executing its loop-free procedures first, and then dequeues a procedure from the event queue for execution. Thus, the proof rule must compare a procedure witness against the witness of the successor procedure reached after a dequeue in its supermartingale and variant conditions.
Our proof rule formalizes this using dequeue witnesses. Call a configuration a command configuration if , a dequeue configuration if and , and a terminal configuration otherwise. The relation defining the operational semantics of DES systems ensures that, from any command configuration, the successor configuration is almost surely a dequeue configuration. The dequeue witnesses used in our proof rule are functions and that affect a dequeue to produce the successor procedure witnesses and . For a full state , let and let denote the full state , where . Then, and .
Condition A in Rule 4.2 requires that each supermartingale is 0 exactly on and each variant is 0 exactly on Goal; in particular vanishes throughout . Condition B formally specifies the supermartingale property over procedures at states outside . Note that, after executing the body of a procedure, configurations with skip commands are reached almost surely. The semantics of DES is to dequeue these configurations deterministically. performs this dequeue and outputs the value of the correct procedure supermartingale for condition B. The conditions in C relate to the variant, and use the auxiliary functions , and asked by the rule.
Condition C(a) means that the variants U are bounded from above by a function (H) of the supermartingale V. Because on T, instantiating Condition C(a) at forces throughout T; that is, the variant is automatically bounded on the exempt set, which is what lets it carry the system to Goal once V has confined it to T. Condition C(b) formally specifies the variant
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
Proof Rule 4.2: Almost-Sure Reachability for DES
To show that a DES S almost surely reaches a measurable target Goal , find
-
A measurable invariant Goal containing the initial configuration ,
-
A measurable exempt set of full states with Goal ,
-
Measurable procedure supermartingales and variants for each defined in mapping to ,
-
Assistant functions ,
such that
A. Witnesses vanish exactly on their target sets: for each defined in , iff , and iff ,
and for each with ,
B. Supermartingale at procedures outside : if for defined in and , then ,
C. Variant conditions: for each ,
a. Variants are bounded: if , then for each defined in ,
b. At procedures: if for some defined in , , and , then ,
Fig. 4. The proof rule for deducing the almost-sure reachability of DES systems.
property at procedures outside Goal: at states where , the variant decreases by at least with probability at least .
THEOREM 4. Rule 4.2 is sound and complete.
To prove the soundness of Rule 4.2, we show that certificates from the rule can be translated into certificates for Rule 4.1. We prove completeness by translating the certificates of Rule 4.1 to Rule 4.2. Let S be a DES system and let be its associated Markov process.
From DES to Markov chains. Take a collection of certificates proving that a DES system S almost surely reaches a measurable set Goal of configurations. Let Inv be the invariant for the DES system. Define the restricted invariant Inv' as
Here, is the collection of procedures defined in . restricts to configurations at which dequeues are imminent ( ) or configurations reached immediately after dequeues ( for some ). Recall that the semantics of DES commands implies that from command configurations, systems reach dequeue or terminal configurations almost surely. Thus, is an invariant and trivially contains the initial configuration. Because Goal is reached almost surely under and , a measurable subset also reached almost surely must be included in . Thus, the certificates restricted to still prove the almost-sure reachability of
Proof Rule 4.3: Expected Time to Reach the Goal for DES
To bound the expected time for a DES S to reach a measurable target Goal , first show that S reaches Goal almost surely, and additionally find
-
A measurable invariant Goal containing the initial configuration ,
-
For each , a measurable supermartingale bounding the expected time to reach the goal set, mapping to ,
inducing the dequeue witness , such that
A. Dominates the clock on the goal: for each and each full state , , and for each with ,
B. Supermartingale at procedures: if for and , then .
Then, the expected time to reach Goal is at most .
Fig. 5. Bounding the expected time to reach the goal set.
Goal. A global supermartingale V and variant U can be constructed from the local witnesses and using the functions and as follows.
The configurations with a given command form a measurable set and the map is measurable, so V and U are measurable whenever every and is. Because and already perform the deterministic dequeue step, the composed V and U satisfy the Drift Criterion V1 and Variant Criterion V2 exactly where Conditions B and C hold for S—that is, outside the exempt set T, which carries across the translation unchanged—so if Rule 4.1 is sound, then Rule 4.2 is sound.
From Markov chains to DES. Take a collection of certificates proving that the chain (C, ) almost surely reaches Goal. We assume that Goal is constructed from a set G of full states of S such that Goal = . Let be the invariant for the Markov chain. Again, define the reduced invariant from (2); it will contain a measurable part of Goal and the initial state of S. Because , the properties of the witnesses V and U apply over . The procedure and dequeue witnesses can be defined by reversing the prior translations from DES to Markov chains.
Thus, completeness of Rule 4.1 implies completeness of Rule 4.2.
4.4 Bounding the Expected Reach Time
Next, we give a proof rule for bounding the expected time to reach the goal in DES systems. Recall that time is a part of the DES configuration, and is updated at each dequeue step. Thus, time is effectively a program variable, and the expected reach time is therefore the expected value of the program variable t representing the global clock at the first configuration with goal = 1.
The standard technique to establish upper bounds on program variables is to apply Park induction. In our setting, this translates to a supermartingale W that dominates the time at the goal, i.e.,
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani

(a) Classical M/M/1 queue.
(b) M/M/1 queue in DES.
Fig. 6. M/M/1 queue, two views. (a) The classical model of the M/M/1 queue, a birth-death Markov chain on the queue length (up w.p. , down w.p. , goal ), on which is a certificate. (b) The same queue as a DES system. A configuration carries the residual delay of the one already-scheduled event, giving the client-headed and server-headed states. A service completion at empties the queue and reaches the goal (dashed). With in the state, is no longer a supermartingale.
for . Intuitively, can be understood as the expected value of the time at the Goal from plus . As in Rule 4.2, this function can also be decomposed into per-procedure functions . Condition A ensures the remainder is zero on Goal and Condition B forces it to absorb, in expectation, the passage of time at each dequeue.
Notice that Rule 4.3 requires Rule 4.2. This is necessary for soundness. If Goal is reached with probability strictly less than one, the true expected time to reach Goal is . However, finite W satisfying the supermartingale conditions of Rule 4.3 can exist because W is no longer constrained by condition A in diverging runs.
THEOREM 5. Rule 4.3 is sound and complete.
The soundness and completeness of this rule follows from expressing the expected time as a least fixed point and the computation of the fixed point using Park induction [32, 41] (see, e.g., Feng et al. [20, Theorem 5]). For soundness, the conditions make a pre-fixed point of the operation, and so it dominates the least fixed point. For completeness, note that if Goal is reached almost surely, then the expected time to reach goal satisfies the constraints.
Note that one cannot bound the expected reach time of DES systems by bounding the expected value of the Goal’s hitting time in the Markov process . The symmetric random walk System 3 can be edited so that each post of Walk to will induce , but because these infinitely many steps happen at the same logical timestep, the expected time to reach the goal is trivially 0.
4.5 Exponential Distributions and Rate-Based Event Sources
While our rules are complete, finding explicit certificates can be tricky, especially if the program configuration does not capture the right abstraction. Consider the following example.
Example 6. Consider the client-server example from System 1 that models an M/M/1 queueing system from queueing theory. For this example, classical queueing theory answers the almost-sure reachability question: the queue empties almost surely iff the arrival rate is at most the service rate . The textbook argument models the system as a continuous-time Markov chain whose states correspond to the number of elements waiting in the server's queue. With this representation, the queue size is a supermartingale and a variant. The supermartingale has non-positive drift away from the empty state and the variant decreases with positive probability .
This certificate, however, does not discharge our proof rule, which requires a certificate on the configurations of a DES execution. The illustration in Fig. 6 contrasts the classical M/M/1 chain post_rate(p, λ, e) ≅ if Λ = 0 then post(tick, δ(0)); tid := tid + 1; Λ := Λ ∪ {(λ, tid, p, e)}
proc tick() = if Λ ≠ 0 then tp := peek(); if tp = now() then post(tick, δ(0)) else te ~ exp(R), (where R = ∑(λ_... ...) ∈ Λ λ); (λ, id, q, v) ~ pick(Λ) each with prob λ/R; if now() + te < tp then Λ := Λ \ { (λ, id, q, v) }; post(q, v, δ(te)); post(tick, δ(te)) else post(tick, δ(tp - now())
Fig. 7. Compiling post_rate into DES: a post_rate command desugars (top) to maintain a global rate-source set and arm the administrative procedure tick (bottom), which runs the exponential race.
with its DES execution. Because DES systems are headed by procedures, every state of the DES M/M/1 is either a Client state or a Server state. The Client deterministically increments the queue size n and posts a new client to the event queue with a delay sampled at the exponential rate . Similarly, the Server decrements n and posts a new server with a delay sampled at rate . Thus, the only randomness at a state is the time at which the next event fires, determined by comparing the sampled delay with the residual time to the next pending event in the event queue, modeled as in Fig. 6. At a server state, the server samples a fresh delay according to rate . With probability the server's delay is shorter than the residual , the next state remains a server state. With the remaining probability, the next state is a client state. At the client, the transitions are symmetric with rate . Thus, the arrival and service rates do not compete at the same configuration.
Thus, the queue length alone is not a supermartingale (in fact, increases deterministically at a Client state). By our completeness results, certificates for the DES M/M/1 can be obtained for . But they cannot be pure functions of the queue length. For example, when , we find
where and . The supermartingale holds with equality in the Client phase and with slack in the Server phase, and the variant drops by a fixed amount on a race outcome of probability . When , the supermartingale can be expressed as the Snell envelope [58] of the process, but there is no simple closed form.
The reason why the classical model of M/M/1 queues is a continuous-time Markov chain (CTMC) is the memoryless property of the exponential distribution and the accompanying properties of racing exponentials. In the CTMC model, when the queue is non-empty, the Server and the Client sample from their exponential distributions simultaneously. The lowest sample wins, and the winner procedure is executed with time moved forward. By the property of racing exponentials, the value of this lowest sample is exponentially distributed with rate . Then, by memorylessness, the loser's residual delay (the variable in Fig. 6) is probabilistically equivalent to a fresh exponential sample at the loser's rate. This justifies the CTMC model of the M/M/1 system.
Given the importance of exponential distributions in simulations, we augment DES with syntactic sugar that directly implements them. This additional syntax (compiled into ghost state) makes many proofs simpler: for example, we recover the classical certificates from queueing theory.
We define a primitive post_rate(p, , , ..., ) that schedules a single execution of procedure p on arguments , ..., after a delay sampled from an exponential distribution with rate . post_rate captures the common idiom where a procedure is repeatedly fired at a rate given by an exponential distribution, for example, the arrival rate of clients and service rate of servers in System 1.
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
1 proc Client() = 14 proc Server() = 2 req := ...; // generate request 15 if idle and not queue_empty then 3 post(SendReq, req, ); 16 idle := false; 4 // arrivals at rate 17 req := dequeue(queue); 5 post_rate(Client, ); 18 post_rate(FinishReq, , req); 6 19 7 proc SendReq(req) = 20 proc FinishReq(req) = 8 queue := enqueue(queue, req); 21 ...; // service completion 9 post(Server, ); 22 if not queue_empty then 10 23 req := dequeue(queue); 11 proc : 24 post_rate(FinishReq, , req); 12 queue, idle := [], true; 25 else 13 post_rate(Client, ); 26 idle := true;
Sys. 4. System 1 with its exponential posts replaced by post_rate.
post_rate is syntactic sugar. Fig. 7 rewrites any system using post_rate into a plain DES system that uses only post and the read-only primitives now() and peek(). The compilation keeps the currently-active sources in an ordinary global variable . This variable contains a finite set of quadruples of a rate, a fresh identifier, a procedure, and its argument values. Together with the procedure tick, post_rate simulates the exponential rates. Observe that must hold several copies of the same source, just as the event queue can hold several copies of the same event. When tick fires (Fig. 7) it samples an aggregate delay , where , together with a source, drawn with probability . It fires that source if beats the next queued event, and otherwise re-arms, discarding the sample.
At first glance post_rate(p, , e) resembles post(p, e, ): they induce the same distribution over firing times. The difference between post_rate and post is apparent when several procedures are posted with exponential delays simultaneously, such as in the M/M/1 queue of Fig. 6. A post is resolved with a sampling of the exponential to produce a delay that determines its point of entry into the event queue. A post_rate instead does not sample its delay immediately. Instead, it stores the procedure in the program state, and inserts a special procedure tick (shown in Fig. 7) into the queue with delay. tick then assembles all exponential rates and runs an exponential race; if the winning delay beats the next pending event in the queue, it inserts only that winner into the event queue. tick then posts itself to execute right after the next real procedure. The remaining post_rate procedures resample their delays in the exponential race the next time tick is executed. In this way, post_rate simulates precisely the CTMC modeling of exponential clocks. For the M/M/1 queue, this means the residual delays in Fig. 6 are no longer part of the configuration and the queue size satisfies the drift criterion.
This compilation allows us to apply Rule 4.2 and Rule 4.3 directly to the compiled program. For any configuration with the operational semantics giving , define the kernel
This kernel automatically sequences an execution of tick immediately after each one-step execution from c. (Essentially, this is the CONCAT rule of Fig. 2.) A procedure’s body may both post events directly (with post) and arm rate sources (with post_rate); the next procedure is then whichever wins the race tick runs between the imminent committed Q-event and the active rate clocks. Thus, using instead of in the conditions in Rule 4.2 and Rule 4.3 gives sound and complete proof rules for reachability and expected reach time for programs using post_rate.
As an illustration, System 4 recasts the example of System 1 using post_rate. The model is otherwise unchanged. Let us understand why discharges the rule in the modified model by reading the proof rule's conditions with . The only exponential sources in the rate-based model are the Client with rate , and the server with rate . tick races them both, so from any busy configuration ( ) the next real procedure is the Client arrival with probability , sending , or the Server completion with probability , sending . This is exactly the process of the left in Fig. 6. Thus, when , the drift of is
5 Implementation and Case Studies
5.1 Mechanization in Lean
We have implemented reasoning about DES in our tool Leonides. Leonides encodes a mechanization of the DES calculus, its rate-aware dequeue semantics, and the proof rules of Rules 4.2 and 4.3 as a shallow embedding in the Lean 4 proof assistant, on top of MATHLIB's measure theory. Every DES system and certificate in this section is described explicitly in the embedding. The user supplies a program in DES and the certificates as input and the embedding emits the proof obligations for our proof rules as sorry-ed goals, which we then discharge separately.
Leonides implements a system-agnostic proof tactic, flauto, that closes the emitted goals. flauto implements several search heuristics and can call SMT solvers. However, it is not always automatic and users may need to provide system-specific lemmas or lemmas about probability distributions. In our experience, a small number of lemmas are needed, on top of generic lemmas that we provide as part of the tool (such as properties of the exponential distribution). The completed development leaves no sorry and depends only on Lean's standard classical axioms. All the following case studies have been formalized in Leonides.
Our choice of embedding in Lean was driven by three considerations: proofs involving measure theory can be subtle and we wanted the guarantees of the Lean checker; proof obligations require mathematical reasoning about distributions that are not easily automatable using SMT; and the relatively mature search tactics (e.g., aesop) already available in Lean that discharges most obligations automatically.
5.2 Benchmarks: Variations on Client-Server Systems
Our first case study revisits the simple client-server example of Section 2 through a family of variations, summarized in Table 1. In each, the goal is the same: verify that every queue in the system eventually empties, from any initial configuration. For each variation the table lists a supermartingale V with its one-step drift and a variant U that drops by at least d with probability at least , in the sense of Rule 4.2. Here, n ranges over the number of jobs in the queue. These global witnesses decompose into the local ones the rule asks for (Section 4.2); their per-procedure forms, with the offsets that make each witness vanish exactly on its target set and the assistant function H, the system code, and the machine-checked proofs are all provided in Leonides.
The Basic example is the M/M/1 client-server system: requests arrive at rate and are served at rate . Its certificate is , which drains at rate . Its Feedback variation re-enqueues a completed request with probability , capturing closed-loop client-server interactions as in web traffic and other service systems [57]. The certifies it, but the variant reduces with a slightly lower probability.
The Feedback with priority variation maintains k priority queues: a new request enters the highest priority, and a finished request is re-enqueued at one priority lower with probability p, completing
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
| Variation | Drift: , | Variant: ; , |
|---|---|---|
| Basic | ||
| Feedback | ||
| Feedback with priority () | ||
| Two servers in series | ||
| Client with timeout |
Table 1. Supermartingale and variant functions for the client-server variations: the reachability supermartingale with its drift , and the variant , which drops by with probability .
after at most levels. This models prioritizing new requests over long-running sessions, as when establishing new connections takes precedence over long-context LLM conversations. Certificates for reachability sum the queue sizes across the priority queues. The variant weights level by its index, , so that a completing request lowers by at least , ordering the descent by priority.
The Two servers in series and servers in series variations form a pipeline with service rates : a request enters at stage 1 and, on a stage- completion, moves to stage , departing when the last server finishes. The state records a per-stage occupancy for each server. The linear sum is no longer sufficient, so the supermartingale takes on the quadratic form . Its drift is negative outside a finite set, which the exempt set absorbs; the diagonal form needs , and cross terms cover the whole stable region . The variant weights the stages upstream-first, , so advancing a job to a later stage strictly lowers ; its descent probability is set by the slowest stage, .
Finally, Client with timeout and retries models a client that sets a timeout of units on each request. If the request is not completed within , the client retries, up to times. A retry re-sends the request, and the server reprocesses every copy (there is no local caching), so the job queue may hold duplicate copies of a request. The client stops retrying once it receives a response, tracked by a per-request flag; copies already enqueued are still served. In this row counts the copies not yet served, the remaining retry budget, and the pending deadlines, which both witnesses carry with the same weight. Its certificate augments the workload with a phase term that tracks the imminent timeout, paired with a retry-budget variant. Here ret is a request's used retries, and a request is live while unanswered with budget remaining, so is the total remaining retry budget; , with total rate and the current and next event times, measures how imminent the next timeout is; and the constants and are positive exactly on the tight stability region . The full system, certificates, and proofs are given in Leonides; together the two witnesses certify reachability and a finite expected time on .
1 proc r1_beginRead() = 2 r1_toRead = true; 3 if (not r1_sending) then 4 r1_toRead = false; 5 r1_reading = true; 6 // perform read computation 7 post(r1_finishRead, ); 8 9 proc r1_finishRead() = 10 r1_reading = false; 11 if (r1_toSend) then 12 // SYNCHRONIZED 13 goal = 1; 14 r1_toSend = false; 15 r1_sending = true; 16 // perform send computation 17 post(r1_finishSend, ); 18 if (r1_toSchedule) then 19 r1_toSchedule = false; 20 // Restart routing protocol 21 post(r1_beginSend, 22 unif(T_p - T_r, T_p + T_r)); 23 24 proc p_0() = 25 post(r1_beginSend, unif(0, T_p)); 26 post(r2_beginSend, unif(0, T_p));
27 proc r1_beginSend() = 28 r1_toSend = true; 29 post(r2_beginRead, ); 30 if (not r1_reading) then 31 r1_toSend = false; 32 r1_sending = true; 33 // perform send computation 34 post(r1_finishSend, ); 35 36 proc r1_finishSend() = 37 r1_sending = false; 38 if (r1_toRead) then 39 // SYNCHRONIZED 40 goal = 1; 41 r1_toRead = false; 42 r1_reading = true; 43 // perform read computation 44 post(r1_finishRead, ); 45 r1_toSchedule = true; 46 else 47 // UNSYNCHRONIZED 48 // Restart routing protocol 49 post(r1_beginSend, 50 unif(T_p - T_r, T_p + T_r));
Sys. 5. The Periodic Messages model. We omit explicit descriptions of these procedures for router r2 for brevity; there are procedures r2_* for each procedure r1_* that manipulate r2 variables accordingly. Notice the blue post of r2_beginRead; in r2_beginSend, this becomes r1_beginRead. The posts of rbeginSend set the routing timer for router r. Note that all booleans are initially false.
5.3 Case Study: Almost Sure Synchronization of Routing Protocols
We now demonstrate the value of our techniques using a practical example from the literature on networked systems. In 1993, Floyd and Jacobson [21] discovered a pattern of periodic packet drops occurring near core routers at the New England Academic and Research Network. These drops were thought to have been caused by routing updates, which are protocols used by routers to update information on network topology, such as RIP [29] and IGRP [30]. These protocols run at periodic intervals. Routers executing these protocols are assumed to be independent; meaning that they all begin executing the protocol at different times. Because these protocols are run periodically, network architects at the time assumed that the routers would remain unsynchronized. However, Floyd and Jacobson found that routers executing any of a family of these protocols would eventually become synchronized, meaning that they would all execute the protocol at the same time. This synchronization causes delays through periodic packet drops, as routers across the network update their routing tables at the same time.
We will demonstrate this synchronization using our certificates. We will model the general Periodic Messages model by Floyd and Jacobson that several routing protocols conform to [29, 30] as a DES system. We note that Floyd and Jacobson augmented their findings with a discrete-time Markovian model to explore further the limits of this synchronization. Their model makes strong
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
assumptions on the time distances between different routing clusters. Our modeling of the Periodic Messages model makes none of these assumptions.
We first denote the following constants: (1) is the computation time needed for a router to send or receive a message, (2) is the period of the routing protocol, and (3) is a random jitter that is added to the period. It is assumed that , and, for the synchronization certificate below, that (the small-jitter regime; the large-jitter case is discussed as future work).
We describe a 2 router system in Sys. 5. In it, routers r1 and r2 are initialized at a uniformly picked time between 0 and the period . Routers executing the protocol either send or receive messages. Routers require time units to process incoming and outgoing messages. They begin the protocol by deciding to send messages pertaining to updates to the network, and end the protocol by scheduling the next send by (approximately) setting a routing timer to . In the middle of the protocol, they complete the send and process pending incoming updates.
We note a few features of this model. (1) Routers cannot send and receive messages simultaneously. Thus, when a router wishes to send a message when it is busy processing an incoming message, it must wait until the incoming message has been processed. This is because the information in the incoming messages may affect the content of the message the router wishes to send. (2) When a router decides to send a message, the other router is immediately notified of an incoming message. This is to model negligible transmission delays between the routers. (3) A uniform jitter of is introduced when setting the routing timer. A small models differences in the computation time for message processing, while a large models deliberate jitter included in the protocol specification.
We represent this model using procedures that define the actions of the routers at the beginning and ends of sends and receives. At the beginnings, routers successfully schedule the ends when the routers are not already busy. Notice that when beginning a send, the other router is immediately notified to begin a read. The recipient router will choose to begin processing the incoming message if it isn't busy sending. At the ends, the routers check and perform pending actions. Critically, when ending sends, when the router attends to existing pending reads first before setting the routing timer to schedule the next execution of the protocol.
The two routers have synchronized when they both begin executing the protocol within a unit time window. When unsynchronized, a router begins by sending a routing message, which takes time. This send is simultaneously processed by the receiving router. The sending router then resets its timer and schedules its next execution. However, when routers are synchronized, the receiving router will begin a send before it finishes processing its incoming message. This forces the sending router to process this message before scheduling its routing timer. Thus, because of the proximity of the timer expirations, both routers must additionally process incoming messages sent by the other before resetting the timer, adding an additional processing time for each. Scaling this behaviour up from 2 to N routers means that all synchronized routers will spend time only processing routing messages. This can cause delays, disrupting quality of service.
5.3.1 Certifying Synchronization. We will demonstrate certificates proving that these routers synchronize almost-surely. Accordingly, we set the distinguished variable goal to 1 when a router must receive a message before processing a send or vice versa. Our certificates will demonstrate the almost-sure reachability of this Goal set. Because of our completeness results, our proof rule promises similar certificates to reason about the more complex case of N routers.
It is intuitive to expect witnesses of synchronization to capture a notion of a “time distance” between the routers. This time distance would measure the time gap between the beginnings of their protocol executions. The protocol is designed to keep this distance constant in expectation.

Fig. 8. The timeline of unsynchronized execution. Events and mark the points when R1 and R2 began and ended their executions. The current time is marked at . marks the point when R1's timer would expire. marks the point when R2's timer is expected to expire. and are the remaining time to reset the timers for routers R2 and R1. is the expected delay from the expiry of R1's timer to R2's timer.
However, the jitter when setting the routing timer causes it reduce with some probability at each restart. Thus, this time distance is a suitable witness candidate for certifying reachability.
Let us examine this notion of distance in more detail. Notice that, outside of synchronization, the protocol follows a fixed cyclic shape. When router r1 begins its protocol while router r2 is idling, this distance corresponds to the remaining time in 's routing timer. If , the routers are synchronized. Assume , and trace the distance's evolution during execution. After time units, r1 completes its send and resets its routing timer to in expectation. The execution then jumps forward to the expiration of 's timer. Because and, by protocol design, , r1 is idle at this stage. A similar derivation of the distance measure produces the remaining time in r1's routing timer . This variance is captured by Fig. 8.
To address this variance, we always measure the time difference to the beginning of 's next protocol execution and the beginning of 's protocol execution. That is, we compare , the initial remaining time on 's timer, with , the remaining time when begins its second execution. As demonstrated in Fig. 8, we estimate as to be the value it will take in expectation.
To measure this time distance using the per-procedure certificates of Rule 4.2, we must record the aforementioned cyclical behaviour of the protocol outside of synchronization. We define an invariant to track this cycle and restrict the event queue to respect this cycle. Outside of synchronization, one router leads (say r1), and the queue cycles deterministically through the entries r1_beginSend, r2_beginRead, r1_finishSend, r2_finishRead, and then r2_beginSend begins the mirror cycle with the roles swapped. All other configurations are absorbed by Goal or by a deterministic path to synchronization once the time distance goes below .
We use per-procedure supermartingales to measure this time distance. For a full state , let be the time at the event . Similarly, is the time at the event . For each full state outside synchronization, define the functions
These functions represent the aforementioned distance measure. bs1, bs2, fs1, and fs2 correspond to the beginSend and finishSend procedures for routers r1 and r2 respectively.
Outside of the goal set, the read procedures are triggered by send procedures from other routers. While they are performed at the same time as the sends (r2_beginRead occurs immediately after r1_beginSend at the same time stamp and r2_finishRead occurs immediately after r1_finishSend), the “distances” between the routers must be measured differently. This is because the “distance”
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
between the routers is measured by the distance between the beginSend events of both routers. At beginRead events of router r1, the beginSend of router r2 occurred at the same time. Thus, set
However, at finishRead events of either router, outside of synchronization, two beginSend events must exist in the event queue. The next beginSend to fire after a r1_finishRead is r1_beginSend, and after a r2_finishRead it is r2_beginSend (router i's own timer expires before the peer's). We therefore set each to the value takes when that beginSend fires — that is, evaluated at , which is independent of :
Here, br1, br2, fr1, and fr2 correspond to the beginRead and finishRead procedures for routers r1 and r2 respectively.
For each procedure p, define
Here is the distance witness for the unsynchronized region; under the assumption it is non-negative on all reachable states, so the middle case of is a defensive boundary value that does not arise (the +1 keeps continuous at ). Synchronization – the and collision states – is instead handled by a bounded, deterministic dispatch sequence with and a matching variant.
Note that, because the supermartingales only decreases at the finishSend procedures, it is insufficient as a variant. However, it can be transformed into a variant by scaling the supermartingale appropriately. This defines the variants (for states with non-zero supermartingale values) as a descent-ladder offset plus a uniform additive constant :
It can be shown that the variants decrease by at each step with probability at least . This is because, at each finishSend, the routing timer is reset from unif(, ), so the now-independent supermartingales and reduce by with that much probability. In Leonides, we have mechanized this example with these certificates with a precise invariant, proving that synchronization is almost sure, validating the simulations of [21].
6 Related Work
Probabilistic program reasoning. A large body of work has studied logical and algorithmic reasoning principles for probabilistic programs [9, 37, 47, 64]. Classical approaches generalize ranking functions to the probabilistic setting via ranking supermartingales [14, 15, 25, 48]. Subsequent work developed stochastic invariants [17] and supermartingale-based proof rules for almost-sure and quantitative termination [16, 34]. More recently, sound and relatively complete Hoare-style proof systems have been established for both qualitative and quantitative termination of probabilistic programs [43, 49]. These systems, while foundational, address untimed probabilistic programs; they do not model continuous time, event scheduling, or explicitly timed performance properties.
DES and performance modeling. DES is a well-established paradigm for modeling performance in computer systems and networks. Practical frameworks such as OMNeT++ [59], ns-3 [56], and SimPy [46] provide rich simulation constructs and efficient runtime engines, but reasoning about correctness or performance properties is typically empirical, based on repeated simulation and statistical analysis. Complementary to these, formal modelling frameworks such as PEPA [31] and Modest [13, 27] provide compositional, semantically grounded approaches to describing stochastic and timed behaviour. While these formalisms support analytical reasoning and quantitative verification, they target abstract finite-state models rather than general-purpose, event-driven simulation programs. In contrast, classical queueing theory provides analytic reasoning techniques for idealized models such as M/M/1 and M/M/k queues [38]. However, these models assume fixed stochastic structures and do not support general compositional reasoning over event-driven programs.
Formal methods for stochastic systems. Formal verification frameworks for stochastic and timed systems—including probabilistic model checking and temporal logics such as PCTL and CSL—enable algorithmic analysis of Markov chains and Markov decision processes [8]. These approaches target finite-state transition systems and differ fundamentally from our deductive proof system, which reasons about the operational semantics of a general event-driven language. To our knowledge, no prior work provides a sound and complete proof system for performance and termination properties of discrete-event models.
Certificates for stochastic systems. Our approach draws on established proof rules for termination of probabilistic programs, in particular the use of ranking supermartingales and variant functions [43, 47, 49], together with classical drift conditions from Markov chain theory [23, 51]. These constructs provide quantitative measures of progress toward termination or target satisfaction. For linear stochastic systems, appropriate drift and variant functions can often be synthesized by solving linear matrix inequalities, while for polynomial dynamics, polynomial or SOS optimization can be employed to find suitable certificates. However, such functions need not always be semi-algebraic even when the underlying dynamics are polynomial [39, 40].
Our work also connects to the rich literature on barrier-based reasoning in control and formal verification. Barrier certificates [3, 42, 54] offer locally checkable sufficient conditions for safety properties and have been generalized to stochastic and hybrid settings [1, 35]. Converse results establishing necessity of such certificates are comparatively rare, which either are developed for non-probabilistic systems [55, 61] or raise restrictive assumptions [63]. In contrast, our framework derives such almost-sure guarantees by integrating variant-based progress reasoning with the semantics of discrete-event programs.
In addition, we note that certification methods for continuous-time Markov chains (CTMCs) remain relatively underexplored. For example, the sampling-based verification approach for uncertain parametric CTMCs [7] highlights the challenge of uncertain rates in CTMCs but does not directly provide certificate functions in the sense of ranking supermartingales or variant functions. Complementary to this, neural continuous-time supermartingale certificates [53] provide a general framework for synthesizing supermartingale-style certificates in continuous-time stochastic dynamical affine systems, including reachability guarantees. However, completeness in all these cases remained open. Our framework builds on these ideas by offering explicit drift/variant style certificates for discrete-event and continuous-time stochastic systems under almost-sure reachability semantics, bridging classical Markov-chain drift conditions with variant-based progress reasoning.
7 Conclusion
Our paper takes an initial step in deductive verification for performance in an expressive programming model capturing the core features of discrete-event simulators, including infinite state,
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
continuous time, probabilistic choice, and event-driven execution. We provide sound and complete proof rules for almost sure reachability and expected reaching time for this language. Our tool Leonides is able to semi-automatically discharge the proof obligations for many interesting examples. We are also able to formally analyze a famous stochastic routing protocol from the networking literature.
Acknowledgments
This research was sponsored in part by the Deutsche Forschungsgemeinschaft project 389792660 TRR 248–CPEC (see https://perspicuous-computing.science). The research of S. Soudjani is supported by the following grants: EIC 101070802, ERC 101089047, and EIC 101306368.
References
[1] Alessandro Abate, Mirco Giacobbe, and Diptarko Roy. 2024. Stochastic omega-regular verification and control with supermartingales. In Proceedings of the 36th International Conference on Computer Aided Verification (CAV 2024) (Lecture Notes in Computer Science, Vol. 15925). Springer, Cham, Switzerland, 395–419.
[2] Alessandro Abate, Mirco Giacobbe, and Diptarko Roy. 2025. Quantitative supermartingale certificates. In International Conference on Computer Aided Verification. Springer, 3–28.
[3] A.D. Ames, S. Coogan, M. Egerstedt, G. Notomista, K. Sreenath, and P. Tabuada. 2019. Control barrier functions: Theory and applications. In ECC. IEEE, 3420–3431.
[4] Carolyn Jane Anderson, Nate Foster, Arjun Guha, Jean-Baptiste Jeannin, Dexter Kozen, Cole Schlesinger, and David Walker. 2014. NetKAT: semantic foundations for networks. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (San Diego, California, USA) (POPL '14). Association for Computing Machinery, New York, NY, USA, 113–126. doi:10.1145/2535838.2535862
[5] Krzysztof R Apt, Frank S De Boer, and Ernst-Rüdiger Olderog. 2009. Verification of sequential and concurrent programs. Springer.
[6] Krzysztof R. Apt and Gordon D. Plotkin. 1986. Countable nondeterminism and random assignment. J. ACM 33, 4 (1986), 724–767. doi:10.1145/6490.6494
[7] Thom S. Badings, Nils Jansen, Sebastian Junges, Marielle Stoelinga, and Matthias Volk. 2022. Sampling-Based Verification of CTMCs with Uncertain Rates. In Computer Aided Verification, Sharon Shoham and Yakir Vizel (Eds.). Springer International Publishing, Cham, 26–47.
[8] Christel Baier and Joost-Pieter Katoen. 2008. Principles of model checking. MIT Press.
[9] Jialu Bao, Emanuele D'Osualdo, and Azadeh Farzan. 2025. Bluebell: An Alliance of Relational Lifting and Independence for Probabilistic Reasoning. Proc. ACM Program. Lang. 9, POPL (2025), 1719–1749. doi:10.1145/3704894
[10] Kevin Batz, Joost-Pieter Katoen, Francesca Randone, and Tobias Winkler. 2025. Foundations for Deductive Verification of Continuous Probabilistic Programs: From Lebesgue to Riemann and Back. Proc. ACM Program. Lang. 9, OOPSLA1 (2025), 421–448. doi:10.1145/3720429
[11] Patrick Billingsley. 2017. Probability and measure. John Wiley & Sons.
[12] Z. W. Birnbaum. 1942. An Inequality for Mill's Ratio. Ann. Math. Statist. 13, 2 (1942), 245–246. doi:10.1214/aoms/1177731611
[13] Henrik Bohnenkamp, Pedro R. D'Argenio, Holger Hermanns, and Joost-Pieter Katoen. 2006. MODEST: A Compositional Modeling Formalism for Hard and Softly Timed Systems. IEEE Trans. Softw. Eng. 32, 10 (Oct. 2006), 812–830. doi:10.1109/TSE.2006.104
[14] Aleksandar Chakarov and Sriram Sankaranarayanan. 2013. Probabilistic Program Analysis with Martingales. In Computer Aided Verification - 25th International Conference, CAV 2013, Saint Petersburg, Russia, July 13-19, 2013. Proceedings (Lecture Notes in Computer Science, Vol. 8044), Natasha Sharygina and Helmut Veith (Eds.). Springer, 511–526. doi:10.1007/978-3-642-39799-8_34
[15] Krishnendu Chatterjee, Hongfei Fu, and Petr Novotný. 2020. Termination Analysis of Probabilistic Programs with Martingales. In Foundations of Probabilistic Programming, Gilles Barthe, Joost-Pieter Katoen, and Alexandra Silva (Eds.). Cambridge University Press, 221–258. doi:10.1017/9781108770750.008
[16] Krishnendu Chatterjee, Amir Kafshdar Goharshady, Tobias Meggendorfer, and Dorde Zikelic. 2022. Sound and Complete Certificates for Quantitative Termination Analysis of Probabilistic Programs. In Computer Aided Verification - 34th International Conference, CAV 2022, Haifa, Israel, August 7-10, 2022, Proceedings, Part I (Lecture Notes in Computer Science, Vol. 13371), Sharon Shoham and Yakir Vizel (Eds.). Springer, 55–78. doi:10.1007/978-3-031-13185-1_4
[17] Krishnendu Chatterjee, Petr Novotný, and Dorde Zikelić. 2017. Stochastic invariants for probabilistic termination. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. 145–160.
[18] Leonardo De Moura, Soonho Kong, Jeremy Avigad, Floris Van Doorn, and Jakob von Raumer. 2015. The Lean theorem prover (system description). In International Conference on Automated Deduction. Springer, 378–388.
[19] J. L. Doob. 1953. Stochastic processes. John Wiley & Sons, New York. viii+654 pages. MR 15,445b. Zbl 0053.26802..
[20] Shenghua Feng, Mingshuai Chen, Han Su, Benjamin Lucien Kaminski, Joost-Pieter Katoen, and Naijun Zhan. 2023. Lower Bounds for Possibly Divergent Probabilistic Programs. Proc. ACM Program. Lang. 7, OOPSLA1 (2023), 696–726. doi:10.1145/3586051
[21] Sally Floyd and Van Jacobson. 1993. The synchronization of periodic routing messages. In Conference proceedings on Communications architectures, protocols and applications. 33–44.
[22] F.G. Foster. 1951. Markov chains with an enumerable number of states and a class of cascade processes. Math. Proc. Cambridge Philos. Soc. 47 (1951), 77–85.
[23] F.G. Foster. 1953. On the stochastic matrices associated with certain queuing processes. Ann. Math. Statistics 24 (1953), 355–360.
[24] Nate Foster, Dexter Kozen, Konstantinos Mamouras, Mark Reitblatt, and Alexandra Silva. 2016. Probabilistic NetKAT. In Programming Languages and Systems - 25th European Symposium on Programming, ESOP 2016, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2016, Eindhoven, The Netherlands, April 2-8, 2016, Proceedings (Lecture Notes in Computer Science, Vol. 9632), Peter Thiemann (Ed.). Springer, 282–309. doi:10.1007/978-3-662-49498-1_12
[25] Hongfei Fu and Krishnendu Chatterjee. 2019. Termination of Nondeterministic Probabilistic Programs. In Verification, Model Checking, and Abstract Interpretation - 20th International Conference, VMCAI 2019, Cascais, Portugal, January 13-15, 2019, Proceedings (Lecture Notes in Computer Science, Vol. 11388), Constantin Enea and Ruzica Piskac (Eds.). Springer, 468–490. doi:10.1007/978-3-030-11245-5_22
[26] Geoffrey Grimmett and David Stirzaker. 2020. Probability and random processes. Oxford university press.
[27] Ernst Moritz Hahn, Arnd Hartmanns, Holger Hermanns, and Joost-Pieter Katoen. 2013. A compositional modelling and analysis framework for stochastic hybrid systems. Form. Methods Syst. Des. 43, 2 (Oct. 2013), 191–232. doi:10.1007/s10703-012-0167-z
[28] Mor Harchol-Balter. 2013. Performance modeling and design of computer systems: queueing theory in action. Cambridge University Press.
[29] C. Hedrick. 1988. Routing Information Protocol. https://datatracker.ietf.org/doc/html/rfc1058 RFC 1058.
[30] C. L. Hedrick. 1991. An Introduction to IGRP. Technical Report. Rutgers University. Available as a technical report.
[31] Jane Hillston. 1996. A compositional approach to performance modelling. (1996).
[32] Peter Hitchcock and David Michael Ritchie Park. 1972. Induction Rules and Termination Proofs. In Automata, Languages and Programming, Colloquium, Paris, France, July 3-7, 1972, Maurice Nivat (Ed.). North-Holland, Amsterdam, 225–251.
[33] C. A. R. Hoare. 1969. An Axiomatic Basis for Computer Programming. Commun. ACM 12, 10 (1969), 576–580. doi:10.1145/363235.363259
[34] Mingzhang Huang, Hongfei Fu, and Krishnendu Chatterjee. 2018. New Approaches for Almost-Sure Termination of Probabilistic Programs. In Programming Languages and Systems - 16th Asian Symposium, APLAS 2018, Wellington, New Zealand, December 2-6, 2018, Proceedings (Lecture Notes in Computer Science, Vol. 11275), Sukyoung Ryu (Ed.). Springer, 181–201. doi:10.1007/978-3-030-02768-1_11
[35] P. Jagtap, S. Soudjani, and M. Zamani. 2020. Formal synthesis of stochastic systems via control barrier certificates. IEEE TAC 66, 7 (2020), 3097–3110.
[36] Raj Jain. 1991. The Art of Computer Systems Performance Analysis: Techniques for Experimental Design, Measurement, Simulation, and Modeling. Wiley.
[37] Benjamin Lucien Kaminski. 2019. Advanced weakest precondition calculi for probabilistic programs. Ph.D. Dissertation. RWTH Aachen University, Germany. http://publications.rwth-aachen.de/record/755408
[38] Leonard Kleinrock. 1975. Queueing Systems, Volume 1: Theory. Wiley.
[39] Arash Bahari Kordabad, Rupak Majumdar, Harshit Jitendra Motwani, and Sadegh Soudjani. 2025. On Certificates for Almost Sure Reachability in Stochastic Systems. arXiv preprint arXiv:2507.20194 (2025).
[40] Arash Bahari Kordabad, Rupak Majumdar, and Sadegh Soudjani. 2025. Sum-of-Squares Certificates for Almost-Sure Reachability of Stochastic Polynomial Systems. arXiv preprint arXiv:2510.25513 (2025).
[41] Dexter Kozen. 1985. A Probabilistic PDL. J. Comput. Syst. Sci. 30, 2 (1985), 162–178. doi:10.1016/0022-0000(85)90012-1
[42] A. Lavaei, S. Soudjani, A. Abate, and M. Zamani. 2022. Automated verification and synthesis of stochastic hybrid systems: A survey. Automatica 146 (2022), 110617.
[43] Rupak Majumdar and V. R. Sathiyanarayana. 2025. Sound and Complete Proof Rules for Probabilistic Termination. Proc. ACM Program. Lang. 9, POPL (2025), 1871–1902. doi:10.1145/3704899
[44] Rupak Majumdar, V. R. Sathiyanarayana, and Sadegh Soudjani. 2024. Necessary and Sufficient Certificates for Almost Sure Reachability. IEEE Control. Syst. Lett. 8 (2024), 2703–2708. doi:10.1109/LCSYS.2024.3507279
[45] Zohar Manna. 2003. Mathematical Theory of Computation. Dover Publications, Inc., USA.
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
[46] Norm Matloff. 2008. Introduction to discrete-event simulation and the simpy language. Davis, CA. Dept of Computer Science. University of California at Davis. Retrieved on August 2, 2009 (2008), 1–33.
[47] Annabelle McIver and Carroll Morgan. 2005. Abstraction, Refinement and Proof for Probabilistic Systems. Springer. doi:10.1007/B138392
[48] Annabelle McIver and Carroll Morgan. 2005. Abstraction, refinement and proof for probabilistic systems. Springer.
[49] Annabelle McIver, Carroll Morgan, Benjamin Lucien Kaminski, and Joost-Pieter Katoen. 2018. A new proof rule for almost-sure termination. Proc. ACM Program. Lang. 2, POPL (2018), 33:1–33:28. doi:10.1145/3158121
[50] Jean-François Mertens, Ester Samuel-Cahn, and Shmuel Zamir. 1978. Necessary and Sufficient Conditions for Recurrence and Transience of Markov Chains, in Terms of Inequalities. Journal of Applied Probability 15, 4 (1978), 848–851. http://www.jstor.org/stable/3213440
[51] Sean P. Meyn and Richard L. Tweedie. 2012. Markov Chains and Stochastic Stability (2nd ed.). Springer Science & Business Media, New York, NY, USA. doi:10.1007/978-1-4419-0033-5
[52] John P. Mills. 1926. Table of the Ratio: Area to Bounding Ordinate, for Any Portion of Normal Curve. Biometrika 18, 3/4 (1926), 395–400. doi:10.2307/2331957
[53] Grigory Neustroev, Mirco Giacobbe, and Anna Lukina. 2025. Neural continuous-time supermartingale certificates. In Proceedings of the AAAI Conference on Artificial Intelligence, Vol. 39. 27538–27546.
[54] S. Prajna, A. Jadbabaie, and G.J. Pappas. 2007. A framework for worst-case and stochastic safety verification using barrier certificates. IEEE TAC 52, 8 (2007), 1415–1428.
[55] S. Prajna and A. Rantzer. 2005. On the necessity of barrier certificates. IFAC Proceedings Volumes 38, 1 (2005), 526–531.
[56] George F Riley and Thomas R Henderson. 2010. The ns-3 network simulator. In Modeling and tools for network simulation. Springer, 15–34.
[57] Bianca Schroeder, Adam Wierman, and Mor Harchol-Balter. 2006. Open Versus Closed: A Cautionary Tale. In 3rd Symposium on Networked Systems Design and Implementation (NSDI 2006), May 8-10, 2007, San Jose, California, USA, Proceedings, Larry L. Peterson and Timothy Roscoe (Eds.). USENIX. http://www.usenix.org/events/nsdi06/tech/schroeder.html
[58] J. L. Snell. 1952. Applications of Martingale System Theorems. Trans. Amer. Math. Soc. 73, 2 (1952), 293–312. doi:10.1090/S0002-9947-1952-0050209-9
[59] András Varga and Rudolf Hornig. 2008. An overview of the OMNeT++ simulation environment. In Proceedings of the 1st international conference on Simulation tools and techniques for communications, networks and systems & workshops. 1–10.
[60] Glynn Winskel. 1993. The Formal Semantics of Programming Languages: An Introduction. The MIT Press. doi:10.7551/mitpress/3054.001.0001
[61] R. Wisniewski and C. Sloth. 2015. Converse barrier certificate theorems. IEEE TAC 61, 5 (2015), 1356–1361.
[62] Lifeng Xu, Shaoyi Zhang, and Ren Zhang. 2018. A Note on Foster-Lyapunov Drift Condition for Recurrence of Markov Chains on General State Spaces. Journal of Theoretical Probability 31 (2018), 1923–1928. doi:10.1007/s10959-017-0777-x
[63] B. Xue. 2024. Sufficient and Necessary Barrier-like Conditions for Safety and Reach-avoid Verification of Stochastic Discrete-time Systems. arXiv preprint arXiv:2408.15572 (2024).
[64] Noam Zilberstein, Dexter Kozen, Alexandra Silva, and Joseph Tassarotti. 2025. A Demonic Outcome Logic for Randomized Nondeterminism. Proc. ACM Program. Lang. 9, POPL (2025), 539–568. doi:10.1145/3704855
A Soundness and Completeness Proofs
A.1 Soundness
Briefly, our techniques are sound for the following reasons. The supermartingale V is required to be a supermartingale outside the exempt set T, on which it vanishes. This forces the trajectories to visit some sublevel set of V infinitely often almost surely. Criterion V2 gives, at each such visit, a non-zero lower bound on the probability of reaching Goal, with the bound depending only on the sublevel set. A zero-one law then yields the almost-sure reachability of Goal.
We will now detail the above argument in full. Let denote the state at the step of an execution of from a state , and let be the sigma-algebra on the space of trajectories generated by . We first show that, until the first visit to Goal, the trajectory remains in the invariant.
Lemma 1. For every , the event
satisfies . In particular, on the event , the trajectory lies in at every step almost surely.
PROOF. For , let . It is easy to see that each is -measurable. Additionally, holds because . On the event , the state lies in , so the invariant condition of Rule 4.1 gives . Thus, on this event, and on , the events and coincide. Hence , making every almost sure by induction. The event is the countable intersection of almost-sure events, and is therefore almost sure. This completes the proof.
We use the following notation for the level sets of the certificates. We let, for any function , denote the set for each . We also let for any set denote . These sets are measurable when is.
Recall that under Rule 4.1, the global supermartingale V is a supermartingale only outside the exempt set T, and on T (the vanishing in criterion ). Let be the first time the chain enters T; since Goal , . It is a random variable because T is measurable. We next show that, on the event , the trajectories almost surely visit some sublevel set of V infinitely often.
Lemma 2. For every ,
PROOF. Let us first note the possibilities when . In this case, there are three possibilities regarding the number of times the trajectory visits the exempt set . If there are infinitely many visits, then for infinitely many , and is visited infinitely often. If there are finitely many and , then the trajectory remains in for , and is visited infinitely often. It thus suffices to show that
To show this, we first demonstrate a supermartingale process. Consider the process . Each is a random variable because is measurable. Let be the -probability 1 event of Lemma 1 that the trajectory remains inside the invariant until Goal. On , we have , so the state lies in . The drift criterion then gives . Moreover, , and outside , . Hence almost surely, so is a supermartingale of finite non-negative random variables, and the Martingale Convergence Theorem (Thm D.6.2 in [51]) yields an almost surely finite random variable with almost surely.
On the event we have for every , so , and the convergent sequence is bounded in all but a -probability 0 set of trajectories. Thus, almost surely on . Because the analysis so far holds for any start state , we have
We now show (3). For , let be the event that the last visit to is at time . The event in (3) is the union over of the events , so it suffices to show that each of these countably many events occurs with
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
zero probability. Fix . On , the state lies in . On , the values are finitely many finite numbers, so holds there precisely when . Therefore
The event has -probability 0 by Lemma 1. For the second event, the Markov property at time and (4) give
This proves (3) and completes the proof.
We next show that, from every state of a sublevel set of V, criterion V2 yields a probability of reaching Goal that is bounded away from zero uniformly over the sublevel set.
Lemma 3. Let , and set
Then for every .
PROOF. Write , , and . Define the function on , so that implies , and precisely when . We show by induction on that
This proves the lemma. Take ; criterion V2 gives , hence . If , then and . Otherwise (5) at gives .
Base case: . Take with and , that is, ; in particular . The descent condition of criterion V2 at the level implies that in one step, the chain reaches with probability . Every state in this set has , hence . Thus .
Induction case. Suppose (5) holds for some , and take with and ; in particular and . As in the base case, in one step the chain reaches with probability ; since , this also gives . The set is measurable because is, so is defined. Every has and . Either , and , or , and the induction hypothesis gives . The Markov property at time 1 gives
This completes the induction and the proof.
The proof uses V2 at a single level R only: once , a descent from x reaches a state y with , so the condition applies at the same R from y.
We first recall a zero-one law of probabilistic processes.

Fig. 9. The symmetric random walk on N with the target g, which no transition enters and which the chain never leaves, with V and U below each state and . The dashed box is the sublevel set ; the descent it certifies from 2 (thick) leaves it.
Lemma 4 (Zero-One Law of Probabilistic Processes [47, Lemma 2.6.1]). Let be events with for every , and let satisfy for every . Then .
PROOF. The conditions of the lemma imply that for every . Thus, . Applying the Borel-Cantelli lemma [26] to the above gives for infinitely many . Since the events decrease, is contained in the event that occurs for infinitely many . This completes the proof.
In [47], is the event that a process has not left a set of states within steps, and the hypothesis holds when the probability of leaving in one step is at least from every state of .
We now complete the proof of soundness of Rule 4.1. For , let be the event that the trajectory visits infinitely often. By Lemma 2, the event occurs with zero probability. It thus suffices to show that for every : the event is then contained in a countable union of events of -probability 0.
Fix , and write and for the constants of Lemma 3. Let be the visit times to that are at least steps apart,
with . For , let and be the event that the -th visit occurs and Goal is not reached within steps of it. These events decrease, , because . Moreover, , because on every is finite. We show that for every . Lemma 4 then gives , and hence . On , the state lies in , so Lemma 3 gives . The strong Markov property (see [51, Section 3.4]) at therefore gives
where the last step holds because places inside .
Because the argument uses no property of beyond membership in , we have for every , completing the proof.
Why Majumdar et al. [44] is unsound. The rule of [44] is Rule 4.1 with the descent condition of criterion V2 with in place of . It certifies the symmetric random walk of
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
Fig. 9 on , which never reaches Goal = from : take , , , and
V vanishes exactly on and has zero drift at every ; vanishes exactly on Goal and is at most ; and from every with , the move to , of probability at least , lowers by .
The rule is unsound because a certified descent may leave the sublevel set of V that certified it. When this happens, the next sublevel set may certify a decrease of U only by a smaller d. The walk above leaves every ; the certified decreases of U shrink along the run and sum to at most , so U never reaches 0.
Note that this certificate does not meet criterion V2 of Rule 4.1: every has , and no lies below for all .
A.2 Completeness
Broadly, our proof of completeness uses techniques from the literature on Foster-Lyapunov criteria for recurrent Markov chains Meyn and Tweedie [51], Xu et al. [62]. To use such techniques however, we must first transform our chain such that these techniques can apply.
Let be a Markov chain. Let be the initial state of the chain, and let Goal be a measurable subset of . Suppose it is known that .
Lemma 5. The set
is measurable.
Proof. Define with
Since Goal is measurable and is a Markov kernel, the finite-horizon hitting probabilities defined with
are measurable for every . Moreover,
Therefore, is measurable as the pointwise limit of measurable functions, which makes a measurable set. This is due to being the inverse image of , which is a Borel subset of .
Set a new transition kernel for all and for all . Define with measured from the kernel .
Now, if for some , then , which contradicts . Thus, for all . This lets us define a Markov kernel for each and , giving us the restricted Markov chain , on which every state reaches Goal almost surely. This is the invariant, and the chain we work with for the rest of the proof.
We first show that
To this end, we invoke Lemma 5, which ensures that the set is measurable. Consequently, is also measurable. Moreover, the mapping is measurable, and . Therefore, if , then, by the positivity of the integral of a nonnegative measurable function,
We now introduce the notion of -irreducibility for the chain . A Markov chain is said to be -irreducible if there exists a nontrivial -finite measure on such that for every measurable set satisfying ,
Let denote the n-step transition kernel defined recursively by
Define the measure
It is easy to see that for all and with ,
Thus, is -irreducible with this measure .
We must now introduce the notion of the petite set. Towards this, we first introduce the sampled chains. A sampling distribution is a probability distribution over . For a Markov process , declare a transition kernel as . The process is the sampled chain of according to the sampling distribution . A measure over the measure space is said to non-trivial if it assigns a positive value to at least one set in . A set is called petite if there exists a sampling distribution and a non-trivial measure such that for all and .
We will now show that Goal is petite in the chain (Inv, ). Take the sampling distribution with and for , such that . Because every goal state moves to in one step, for all . Hence, with the non-trivial measure (the point mass at ),
so in particular . Thus, Goal is petite.
At this stage, we can show that the chain is recurrent. For , let
be the expected number of visits the chain makes to starting from , and write . -irreducible chain is recurrent if for every and every . Since every state in reaches the petite Goal almost surely (this is the defining property of ), we can invoke Meyn and Tweedie [51, Prop. 9.1.7] to conclude that the -irreducible chain is recurrent.
We now introduce three lemmas about petite sets from [62].
Lemma 6 (Petite Set Properties). Let be a -irreducible Markov process. Then:
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
(1) (Subset) Any measurable subset of a petite set is petite.
(2) (Union) The union of two petite sets is petite.
Lemma 7 (Uniform Hitting Probabilities). Let be a -irreducible Markov process on with satisfying . For any , there exists such that:
(1) , and
(2) For all , uniformly on ,
where is the hitting time.
Lemma 8 (Tail Behavior for Recurrent Processes). Let be a -irreducible recurrent Markov process and . For any , there exists such that:
(1) , and
(2) uniformly on .
Note that Xu et al. [62] use Egorov's theorem to demonstrate the uniform convergence in Lemma 7, thus eliminating the need for the Weak Feller property used in [44, 51].
We now present the proof of our main theorem. Our approach proceeds in three stages: first we construct the drift function V through an application of fundamental results from the literature, then we use V to build our variant function U. The function V so constructed is finite only outside a -null set, while Rule 4.1 asks for a finite-valued supermartingale. The third stage restricts the invariant to the states from which the infinite values of V are never reached. Both are built for the minimal exempt set vanishing exactly on Goal and satisfying , and U satisfying – which suffices for completeness, since Goal is itself a permissible exempt set of Rule 4.1.
The foundation of our argument relies on combining two important theoretical tools: the general framework from [51, Th. 9.4.2] and the specialized construction in [62, Th. 1] applied to our state space Inv. We produce the essential steps here to maintain self-containment and to establish the specific properties needed for our subsequent construction of U.
Our first step establishes the necessary foundations through Lemma 6 and Lemma 7. Rather than an arbitrary petite decomposition used by [62], we build V on the same exhaustion that underlies the variant U: an increasing sequence of sets defined inductively by and
We show below that each is petite and that , so is a nested sequence of petite sets with . Each is measurable, by induction on : is measurable, and if is measurable, then is measurable by the definition of a kernel, so is measurable. Since is impossible, ; hence is petite and satisfies the non-triviality condition , as reaches Goal almost surely. Building on this exhaustion is what will bound the variant on the sublevel sets of .
The petite exhaustion . We first verify the two properties of the exhaustion (6): each is petite, and the sequence covers Inv. Since is petite, Claim 1 together with the union property of Lemma 6 gives, by induction on , that every is petite.
Claim 1. If is a petite set, then for any real , the set
is also petite.
PROOF. Since is petite, by definition there exist a non-trivial measure and a probability distribution a on N such that
Define:
We will show that:
Let . Then:
Now observe that for ,
so we get:
By the definition of , , then
Hence, is petite.
Claim 2. .
Proof. Define the increasing sequence of sets where:
Note that . Since for all , we have .
We prove by induction that for all .
Base case : Trivially holds as .
Inductive step: Assume . Take any with . Then:
(1) From :
(2) From : for all
This implies for all , hence , contradicting since .
Therefore, , completing the induction.
□
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
Construction of the drift V. We construct V as a subsequence sum of hitting functions on the exhaustion . Fix the reference set (petite, with by the above), and for each let ((8) below) be the probability of leaving the shell before returning to ; each is a supermartingale off ((9)) and equals 1 outside . A sum therefore grows without bound as leaves every shell, making unbounded off petite sets — the coercivity criterion needs — provided the subsequence is chosen so the sum is also finite -almost everywhere. To make that choice we combine Lemma 7 (bounding the probability of escaping early) with Lemma 8 (via the recurrence shown above, bounding a late return to ), producing sets of -measure approaching 1 on which each is uniformly small.
To control the convergence behavior, we employ a precision parameter sequence with . Lemma 7 guarantees that for each precision level , there exists a control set with:
• Measure guarantee:
• Uniform convergence: as
where represents the hitting probability.
We then construct an optimized sequence of control domains through the telescoping intersection:
This construction ensures two critical properties:
(1) Monotonicity: for all
(2) Measure control: (by subadditivity)
Moreover, the uniform convergence property is preserved on each for all transition indices .
Let be the same precision sequence with . From Lemma 8, for each , there exists such that and
uniformly in . Assume .
Let
then
• (a) and .
• (b) For all , both
converge to zero uniformly in .
Using (a) and (b) the function can be constructed. Define
Each is measurable: is the limit as of and , which is measurable in by the argument of Lemma 5. Then
Since on , and , we have
We aim to demonstrate that, by appropriately selecting a subsequence , the function
satisfies the required properties. For every choice of the subsequence, V is measurable, as a pointwise limit of finite sums of the measurable functions . Specifically, V meets the drift criterion , owing to the linearity of the involved operations.
The leading term (recall ) is bounded and is itself an instance of (8), so it satisfies (9) and does not affect the drift property just noted; its purpose is to make vanish exactly on Goal: every summand vanishes on Goal, while for . Thus .
Let , then
Fix k, from (b) and choose such that
Then choose such that
So
From this:
From (a), hence,
This is weaker than the finite-valued V that Rule 4.1 asks for. We close the gap at the end of the proof, once U is available, because the restriction of the invariant must be shown to preserve criterion V2 as well as criterion V1.
By Fubini’s theorem and (9), satisfies criterion V1. To show V is unbounded off petite sets, note that for any m,
a petite set, which completes the construction of V: it satisfies the drift criterion V1 on Inv with values in , and is finite outside the -null set of (12).
Construction of the variant U. We can now define the variant explicitly:
U is measurable, being constant on Goal and on each of the measurable sets .
Claim 3. The variant U satisfies the variant criterion V2.
Proof. By construction exactly when , and, since on ,
Take the assistant functions , and .
Moussa Labbadi, Rupak Majumdar, V.R. Sathiyanarayana, and Sadegh Soudjani
Bound on the sublevel sets of V. Because V was built on the cover , the subsumption for every combines with (13) to give, for every real ,
that is, . As is increasing, is non-decreasing.
Descent. Let , such that (in particular ). By the definition (6) of we have , and forces by (13); hence
If in addition , then , and this probability exceeds . For there is no with , and the descent condition is vacuous. With , meets .
Making V finite. Rule 4.1 asks for a finite-valued V, while (12) guarantees finiteness only -almost everywhere. We extend the level-set notation to the value , so that and . We show that the set contains and Goal and satisfies the invariant condition, making it a suitable invariant under which V is finite.
Clearly, and Goal because . Every goal state moves to in one step, and reaches Goal almost surely, so the state at time is distributed as . Hence
where the inequality holds because is almost surely a finite index at least 1, and the final equality holds because every term of is non-negative and by (12).
Additionally, satisfies the invariant condition of Rule 4.1: at every , the kernels and coincide, , and (9) with Fubini's theorem gives , so ; hence .
It remains to restrict the certificates to . Take the invariant and the exempt set . The rule asks for certificates defined on all of , while the drift of (10) and the variant of Claim 3 are defined on only, and is infinite on . Take the functions that agree with and on and take the value 1 at every state outside , together with the assistant functions , and of Claim 3. and are measurable because , and are.
It is easy to see that these functions satisfy the conditions of Rule 4.1; we make this more explicit now. Outside the invariant, the rule constrains a certificate only through the two conditions and , and the value 1 meets both because . Writing and for and on , the set contains and Goal and satisfies the invariant condition of the rule. is finite-valued on , and there precisely when and precisely when , as on . The drift condition of criterion holds at every , because . The condition of criterion holds at every , because it holds at every . The descent condition of criterion holds at every with , because gives
This completes the proof of Theorem 2.