arXiv:2610.36655cs.LGOct 2026

Manuscript Offprint

arXiv:2610.36655

Log-Derivative Trick for Parametric Markov Chains

Arthur Gall, Ichiro Hasuo, Thomas Seiller

Arthur Gall 1,2^{1,2}

Ichiro Hasuo 1,2,3^{1,2,3}

Thomas Seiller 4^{4}

1^{1}National Institute of Informatics, Tokyo, Japan

2^{2}SOKENDAI (The Graduate University for Advanced Studies), Kanagawa, Japan

3^{3}Imiron Co., Ltd., Tokyo, Japan

4^{4}CNRS, France

Abstract. Optimizing expected rewards and reachability probabilities in parametric Markov chains (pMCs) is central to the analysis and synthesis of probabilistic systems with loops. While traditional symbolic synthesis approaches—such as parameter lifting and rational function generation—suffer from scalability bottlenecks, gradient-based optimization emerges as an effective alternative. However, existing gradient-based techniques still rely on symbolic gradient computation—such as solving large linear systems—over the global state space, inheriting scalability limits. Finite-horizon approximation is possible but introduces uncontrollable bias.

In this paper, we introduce a scalable Monte Carlo gradient estimator based on a measure-theoretic generalization of the log-derivative trick. We prove that our estimator provides unbiased gradient estimates under almost-sure termination and standard regularity conditions. Crucially, our method avoids global state-space materialization and linear system solving entirely: it operates purely along sampled trajectories, requiring only black-box evaluations of local transition probabilities (or densities) and their derivatives. Unlike existing pMC techniques that are fundamentally restricted to finite discrete systems, our measure-theoretic framework naturally extends to continuous and general σ\sigma-finite state spaces. Empirical evaluations on synthetic discrete pMCs and continuous-state case studies demonstrate that our method scales to state spaces far beyond the reach of existing solvers, significantly reducing execution time without introducing bias.

1 INTRODUCTION

Solving verification and optimization problems over probabilistic programs is part of a growing research trend (Barthe et al., 2020; Baier & Katoen, 2008) with a wide range of applications, including security (Barthe et al., 2012; Roy et al., 2021), reliability (Carbin et al., 2013; Wang et al., 2021) and machine learning (Bingham et al., 2019; van de Meent et al., 2018; Lew et al., 2023). Parametric Markov chains (pMCs) provide a foundational model for probabilistic systems whose transition probabilities depend on a set of global parameters, capturing parameter dependencies across states. Since they naturally support loops, they represent a wide subclass of unconditioned probabilistic programs.

Figure

Figure 1: A finite MC T1T_{1}

Figure

Figure 2: A finite pMC T2T_{2}

Figure

Figure 3: A continuous pMC T3T_{3}

Figure 1 presents a finite Markov chain (MC); Figure 2 presents a finite pMC with a parameter pp; Figure 3 presents an infinite pMC with a continuum of states x∈R+x \in \mathbb{R}_+, with parameter pp. Here, −1-1 and +1+1 denote output states of the system, carrying designated terminal rewards.

Verification and optimization over pMCs have been extensively studied (Daws, 2005; Junges et al., 2024), with efficient algorithms and tools (Dehnert et al., 2015; Cubuktepe et al., 2022; Badings et al., 2023; Spel et al., 2021; Heck et al., 2025) applied to reliability analysis (Volk et al., 2016; Bartocci et al., 2011), planning under uncertainty (Junges et al., 2018; Polgreen et al., 2016), and systems biology (Česka et al., 2017).

Optimization over pMCs Given a real reward function defined over the output states of a parametric Markov chain ( {−1,+1}\{-1,+1\} in Figures 2–3), our goal is to synthesize a parameter valuation that maximizes the expected reward. Existing techniques broadly fall into two classes.

• Symbolic synthesis: Approaches based on parameter lifting, rational function generation, or feasibility region decomposition (Spel et al., 2021; Dehnert et al., 2015; Heck et al., 2025) offer rigorous global optimality guarantees by symbolically exploring the parameter space. However, their computational complexity scales poorly with the number of parameters; state-of-the-art tools rarely scale beyond dozens of parameters (Heck et al., 2025).

• Gradient descent: When systems involve higher-dimensional parameter spaces, gradient descent, while lacking global optimality guarantees, provides a practical and scalable optimization paradigm. Here, the central computational challenge lies in efficiently computing the gradient of the expected reward with respect to the parameters.

Linear Solver Method for Gradients, Exact and Approximate Recent work (Heck et al., 2022) presents what we call the linear solver method; it computes exact gradients in finite pMCs by solving a coupled linear system. Specifically, for an n-state pMC with transition matrix A and reward vector b, the expected reward vector x satisfies x=Ax+bx = Ax + b. Differentiating this relation with respect to a parameter yields ∂x=(∂A)x+A∂x+∂b\partial x = (\partial A)x + A\partial x + \partial b, which gives:

∂x=(I−A)−1((∂A)x+∂b)wherex=(I−A)−1b.(1)\partial x=(I-A)^{-1}\left((\partial A)x+\partial b\right)\quad\mathrm{w h e r e}\quad x=(I-A)^{-1}b. \tag{1}

Various numerical solvers enable the solution of such linear systems, ranging from direct sparse factorization methods (Davis, 2006) to iterative Krylov subspace algorithms (Saad, 2003), which are particularly well-suited for large sparse representations. These solvers provide exact gradient evaluations (up to numerical precision), yet this exactness incurs a substantial computational cost on large instances.

One can imagine a natural approximation of the linear solver method, namely the Jacobi method applied to (1). It approximates the gradient by unrolling the linear system for a fixed budget of K steps. However, this finite-horizon truncation introduces uncontrollable bias and fails to capture long-horizon behaviors.

The linear solver method, both exact and approximate, comes with two fundamental limitations:

• Global state-space materialization: They require explicitly constructing and storing the full transition matrix A (and its derivative ∂A\partial A), which quickly exhausts memory on large models.

• Restriction to finite discrete systems: They fundamentally operate on discrete adjacency matrices, rendering them inapplicable to continuous or general state spaces such as Figure 3.

Our Method: Sampling Gradients via the Log-Derivative Trick In this paper, we present a new algorithm that samples the gradient via the log-derivative trick (Williams, 1992), operating entirely along sampled trajectories without state-space materialization and naturally extending to infinite and continuous state spaces. Note first that the expected reward E[r]\mathbb{E}[r] over paths π\pi is given by the formula

E[r]=∑π∈Pathpπrπ=∑π∈Pathpπ1⋯pπ∣π∣rπ,\mathbb{E}[r]=\sum_{\pi\in\mathrm{Path}}\mathsf{p}_{\pi}r_{\pi}=\sum_{\pi\in\mathrm{Path}}\mathsf{p}_{\pi_{1}}\cdots\mathsf{p}_{\pi_{|\pi|}}r_{\pi},

where pπip_{\pi_i} is the probability of taking the branch πi\pi_i, and pπp_{\pi} is that for the path π\pi. We assume that the reward function does not depend on the parameters, i.e. ∂rπ=0\partial r_{\pi} = 0 (for simplicity; lifting this is easy). Then differentiation ∂\partial (with respect to parameters) yields

∂E[r]=∑π∈Path∂(pπ1⋯pπ∣π∣)rπ=∑π∈Pathpπ1⋯pπ∣π∣∂log⁡(pπ1⋯pπ∣π∣)rπ=E[∂log⁡pπ⋅r],\partial\mathbb{E}[r]=\sum_{\pi\in\mathrm{Path}}\partial\left(\mathsf{p}_{\pi_{1}}\cdots\mathsf{p}_{\pi_{|\pi|}}\right)r_{\pi}=\sum_{\pi\in\mathrm{Path}}\mathsf{p}_{\pi_{1}}\cdots\mathsf{p}_{\pi_{|\pi|}}\partial\log\left(\mathsf{p}_{\pi_{1}}\cdots\mathsf{p}_{\pi_{|\pi|}}\right)r_{\pi}=\mathbb{E}[\partial\log\mathsf{p}_{\pi}\cdot r],

where the second equality used the log-derivative trick ( ∂log⁡f=∂f/f\partial \log f = \partial f/f). The last expression E[∂log⁡pπ⋅r]\mathbb{E}[\partial \log p_{\pi} \cdot r] implies that the gradient can be estimated by sampling paths π\pi directly from the parametric Markov chain and, by the product rule of logarithm, accumulating the sum of the log-derivatives of the transition probabilities scaled by the reward of the path. Indeed,

∂log⁡(pπ1⋯pπ∣π∣)=∂log⁡pπ1+⋯+∂log⁡pπ∣π∣.\partial\log\left(\mathsf{p}_{\pi_{1}}\cdots\mathsf{p}_{\pi_{|\pi|}}\right)=\partial\log\mathsf{p}_{\pi_{1}}+\cdots+\partial\log\mathsf{p}_{\pi_{|\pi|}}.

Our algorithm operates as a Monte Carlo gradient estimator (Mohamed et al., 2020), reducing computational cost at the price of increased variance. As a theoretical result, we prove that our sampling algorithm provides unbiased gradient estimates under almost-sure termination and standard regularity conditions. We also demonstrate experimentally that, despite the potentially unbounded path lengths arising from cycles, our algorithm remains scalable and effective in practice for computing an approximation of the gradient. We show that our algorithm is suitable for gradient descent in pMCs and outperforms other methods such as the linear solver method of Heck et al. (2022).

Beyond finite systems, our framework naturally generalizes to infinite and continuous state spaces (such as the model in Figure 3), which lie entirely outside the scope of methods that require explicit state spaces (such as symbolic synthesis and the linear solver methods). As another theoretical contribution, we generalize the log-derivative trick via the Radon–Nikodym derivative, and show that our estimator remains unbiased for any σ\sigma-finite transition structure under almost-sure termination and standard regularity conditions.

Summarizing, the main contribution of this paper is a trajectory-based gradient estimator algorithm for parametric Markov chains. It features the following theoretical and practical characteristics:

• Unbiasedness: Under almost-sure termination and standard regularity conditions, our estimator yields unbiased gradient estimates. This is unlike the approximate linear solver (see above).

• No state-space materialization needed: The estimator operates purely along sampled paths. It requires only local evaluations of transition probabilities (or densities) and their derivatives, completely bypassing the need to store entire transition matrices or solve global linear systems.

• General state spaces: Formulated in general measure-theoretic terms, our framework handles discrete, continuous, and hybrid σ\sigma-finite state spaces within a unified mathematical foundation.

• Empirical scalability and effective synthesis: We show that our estimator pairs naturally with constrained gradient-descent optimizers. In end-to-end parameter synthesis under fixed time budgets, it quickly boosts rewards by trading exact gradient computations for faster, approximate steps. It scales to models orders of magnitude larger than linear solvers (and thus than symbolic synthesis). It also optimizes continuous-state pMCs where other methods cannot directly apply.

References (28)