Manuscript Offprint
arXiv:2610.10792Bayes Rule for Conditioning Probabilistic Programs
FERAS A. SAAD, Carnegie Mellon University, USA
Probabilistic programs provide a rigorous programming-language foundation for expressing rich probabilistic models and offer language-level support for solving challenging statistical inference problems. A key theoretical challenge that probabilistic programs inherit from probability theory is conditioning a probability distribution on an observation that has probability zero. Many languages address this challenge by using computational rules for conditioning that may work well for some problems but are statistically unsound for others.
This article introduces a principled mathematical approach for conditioning probabilistic programs. We first show that existing techniques based on “soft conditioning” and “neighborhood limits” exhibit semantic issues from the perspective of measure theory and produce inference results that disagree with sound statistical reasoning. By leveraging tools from geometric measure theory, we construct a novel disintegration-based semantics for probabilistic program traces that enables sound conditioning. The theory delivers an explicit Bayes rule representation of the conditional distribution, which is directly compatible with widely used probabilistic inference algorithms that require access to unnormalized posterior densities. Our Bayes rule handles probabilistic models with loops, branches, discrete, continuous, and mixed-type distributions, observations on manifolds, differentiable structure, and additional modeling motifs that arise in practice.
1 Introduction
Probabilistic programs are standard computer programs augmented with a construct to sample random variables from probability distributions. These languages can be used to model and analyze complex probabilistic processes, and have been thoroughly studied by the programming languages community [Barthe et al. 2020]. Within this field is an important class of languages for statistical probabilistic programming, which enjoy broad adoption among the machine learning, statistics, and data science communities [van de Meent et al. 2021]. Statistical probabilistic programs include an additional construct to observe random variables taking on particular values, which conditions the probability distribution induced by the sample statements to agree with a set of constraints. These systems provide sophisticated probabilistic inference engines to solve statistical problems, such as generating samples from the conditional distribution or estimating conditional expectations.
The goal of this paper is to build a rigorous mathematical foundation for conditioning probabilistic programs that aligns with principled statistical theory. To illustrate the fundamental challenge, consider a hidden random variable X and an observable random variable Z. For discrete random variables, the conditional distribution of is given by the usual Bayes rule:
which is well-defined whenever . For discrete probability, this theory is complete: any semantics for discrete probabilistic programs can safely ignore probability-zero observations, because conditioning on for which is statistically undefined without controversy.
Real-world applications, however, demand the use of continuous random variables such as the normal, uniform, or gamma, which take on uncountably many outcomes. In this case, every observation z satisfies , which rules out the use of the standard Bayes rule. This challenge with conditioning on probability-zero events has a long history in probability theory.
Modern probabilistic programming languages use variants of the Bayes rules to condition on probability-zero events, which can be problematic. The first issue is semantic: while the computational behavior of the program is fully precise, the inference problem being solved may have no reasonable statistical interpretation. The second issue is practical: because inference algorithms such as importance sampling, variational inference, and Markov chain Monte Carlo all make use of unnormalized target distributions, using ad-hoc Bayes rules can give unsound statistical results.
Feras A. Saad
This formula combines probability mass functions for discrete variables and probability density functions for continuous variables, which is the standard approach adopted by probabilistic programming languages whose semantics treat observations as “soft conditions” [Borgström et al. 2016, Staton et al. 2016]. Many probabilistic programming users are surprised to find that soft conditioning cannot handle simple observation patterns, such as in the program shown in Figure 1.
x = sample normal(0,1) observe x*x == 4

Fig. 1. Probabilistic program conditioning on a function of a random variable.
In this program, we have and . Statistical theory tells us that, by symmetry of the normal distribution, the conditional distribution of must be an equally weighted mixture of atoms at . Also, as is fixed given , it is conditionally a discrete random variable with mass . With this setup, applying the modified Bayes rule fails for every value of , because the denominator is zero:
For an alternative approach, we recognize that is marginally a continuous ChiSq(1) random variable, so it does have a well-defined probability density function . Applying the mantra of "masses for discrete variables" and "densities for continuous variables", we can use this continuous density in the denominator of the Bayes rule and set the conditional mass in the numerator to be a discrete distribution on . In this case, we have
The result is clearly not a valid discrete distribution for X, as the probabilities of the two atoms sum up to 4. Standard probabilistic programming inference engines exhibit this failure in different ways. Some systems will silently fail, by sampling traces from the prior distribution and assigning them a likelihood weight of zero. Other systems force the user to wrap the observation around artificial noise, e.g., ; , which fundamentally changes the original model desired by the user and in turn alters the resulting statistical inferences.
The limitations of soft conditioning are not restricted to the situation just demonstrated above (known as exact conditioning [Stein and Staton 2024]). Inferences using soft conditioning fail to comport with statistical theory in the presence of mixed-type random variables—which are discrete in one branch and continuous in another—or in the presence of observe statements within conditionally executed program branches. More generally, as we argue in §2, language semantics based on probability densities are largely inadequate for developing a coherent theory for statistical probabilistic programs. They are best understood as languages for defining unnormalized measures, which carry a meaningful statistical interpretation in only a restricted fragment in the language.
1.2 Conditioning Probabilistic Programs via Neighborhood Limits
To address the limitations of soft conditioning, Jacobs [2021] introduces an alternative approach based on arguments from Jaynes [2003]. The key idea is to formalize conditioning on a probability zero set E in terms of a limiting process, such that for any event ,
where is a family of positive probability events that descend to E. An unavoidable consequence of the Borel–Kolmogorov paradox is that the limit can and will depend on the chosen family of limiting events, so Jacobs provides a language construct for users to specify the neighborhoods within the observe statements. Jacobs demonstrates that this approach can resolve certain “paradoxes” with the standard soft conditioning semantics, such as unit errors, handling mixed-type distributions, and observe statements in conditional branches. The language also supports observations of transformations of random variables (but these functions are assumed to be injective, and so the observation pattern with from Figure 1 is not handled directly).
In §3, we study the viability of neighborhood limits as a semantic foundation for statistical probabilistic programs. By analyzing the measure-theoretic structure of limiting arguments, we find that this approach exhibits similar limitations to soft conditioning using probability densities.
In essence, the language of Jacobs can be understood as enabling a user to condition a probabilistic program on a parametric family of measure-zero events, say for observations . We show that null sets in the language do not necessarily arise from observing a unified random variable , i.e., it is not the case that for every . This high degree of flexibility puts the formalism of Jacobs in tension with the standard setting of statistical inference procedures, which fundamentally revolve around a fixed measurable function of the data:
A statistic is virtually any measurable function of the data, X.
—Schervish [1995; p. 83].
For the fragment of the language where the null sets arise from a unified statistic , then conditioning by limits can be given a rigorous statistical interpretation ( ). In the general case, however, neighborhood limits only provide a computational rule for defining specific conditional probabilities at fixed events : these individual numbers do not unify into a coherent conditional probability distribution in the standard statistical sense (cf. Proposition 3.1).
1.3 Conditioning Probabilistic Programs via Disintegration
The approach to conditioning advocated for this article is based on disintegration, a probabilistic concept that generalizes the elementary law of total probability. In the discrete setting, a conditional distribution of is any function . that factorizes the prior distribution:
This factorization gives an inversion of the generative model. To generate a trace X from the law , we may first sample Z from its marginal distribution and then sample an X such that from the conditional distribution . The marginal distribution of Z is
For each with , any conditional distribution . agrees with the usual Bayes rule (1). Otherwise if , the identity (5) shows that the conditional distribution is undetermined, exactly as in the usual Bayes rule for discrete probabilities.
Feras A. Saad
Disintegration generalizes this theory from discrete probability spaces to general spaces. For example, a disintegration of the probabilistic program from Figure 1 is given by
b = sample bernoulli(0.5) if b == 0 sample dirac(sqrt(z)) else sample dirac(-sqrt(z))
In general, a disintegration is a family of probability measures for such that
This identity shows that is undetermined for every such that , precisely as in the discrete case. Instead what matters is the expected behavior of the program, over random observations drawn from the data generating process. The statistical issues with the soft-conditioning approach from §1.1 and the neighborhood-limit approach from §1.2 arise from defining the entire semantics of a probabilistic program in terms of quantities that are arbitrary on a measure-zero set. Indeed, it is impossible to assign good statistical meaning when conditioning a generative model on a specific null set, as famously stated by Kolmogorov:
The concept of a conditional probability with regard to an isolated hypothesis whose probability equals 0 is inadmissible.
—Kolmogorov [1933; p. 51]
This fact is reinforced by decades of attempts by various researchers to resolve the Borel–Kolmogorov paradox: if are jointly continuous in , there is simply no canonical way to condition on the null event (see Bungert and Wacker [2022] for a recent formidable attempt). On the other hand, for statistical inference procedures with statistic , the disintegration formula furnishes a fully coherent semantics for the conditional law .
1.4 This Work: A Measure-Theoretic Foundation for Conditioning by Disintegration
Equipped with this background, we establish a principled measure-theoretic foundation for conditioning statistical probabilistic programs by disintegration. For a flexible class of probabilistic programs (essentially Turing complete, equipped with exact real computation), we seek to identify conditions on the prior distribution over traces and the observation map that guarantee the existence of a disintegration . Using techniques from geometric measure theory [Federer 1996], we develop a disintegration for a large class of probabilistic programs that include loops, branches, discrete, continuous, and mixed-type random variables, manifold-supported and mixed-dimensional variables, differentiable structure, and other constructs used in practice.
Beyond existence of the disintegration, we identify an explicit representation in terms of a Bayes rule that addresses the limitations from using the formulas for soft conditioning (2) and neighborhood limits (4). The Bayes rule form of the disintegration can be used for a variety of approximate probabilistic inference algorithms—such as importance sampling, Markov chain Monte Carlo, variational inference, and sequential Monte Carlo—that require access to the target density only up to an (unknown) normalizing constant. As a proof-of-concept, we prove the consistency of likelihood weighting in a probabilistic language with unbounded while loops and trace addresses.
Scope. The scope of this article is firmly on the mathematical side. We do not seek to build a language implementation that reifies the key ideas of our construction, and focus primarily on measure-theoretic rather than language-design aspects. Our objective is to establish a rigorous foundation for statistical probabilistic programs that (i) gives insight into existing disintegration-based systems that are formalized using operational rules; and (ii) enables the development of new probabilistic languages that include more flexible constructs supported by our theory. While the theoretical development behind the soundness arguments is relatively involved, our Bayes rule for conditional distributions is readily interpretable: it can be used by language designers and practitioners as an operational device, without reference to its measure-theoretic justification.
Contributions. In summary, the main contributions of this article are as follows.
(C1) We systematically review the ways in which “soft conditioning” semantics using densities lead to ill-behaved programs and produce incorrect statistical inference results ( ).
(C2) We analyze the measure-theoretic structure behind conditioning via neighborhood limits. While this procedure provides a workable computational rule, we prove that it does not guarantee a coherent posterior distribution over the probability space and does not comport with the semantic soundness properties of conditioning used in the statistics literature ( ).
(C3) We construct a measure-theoretic foundation for inference over probabilistic program traces. We prove a novel disintegration theorem for a large family of statistical models and show that it carries an explicit Bayes rule that can be used by inference algorithms ( ).
Language design considerations are discussed in §8 and related work in §9.
2 Conditioning Probabilistic Programs using Probability Densities
The dominant paradigm in probabilistic programming—adopted by major languages such as Gen [Cusumano-Towner et al. 2019], Pyro [Bingham et al. 2019], Stan [Carpenter et al. 2017], and PyMC [Abril-Pla et al. 2023]—uses soft conditioning [Borgström et al. 2016, Huot et al. 2023, Staton et al. 2016] to express statistical inference problems. Our goal in this section is to highlight how soft conditioning with probability density functions produces ill-defined programs and inference results that disagree with statistical theory. These case studies serve to motivate the alternative theory of conditioning that we develop in §§5–7 to resolve the limitations of soft conditioning.
Listing 1. Language for generative probabilistic programs with observe statements.
Listing 1 shows a standard probabilistic language with soft conditioning, which includes a sample expression and an observe statement. A sample expression generates a random variable from a probability distribution whose parameters are ; for example for a continuous variable and for a discrete variable. Similarly, observe z statement records a “measurement” of a random draw from to take value z. Typing rules for expressions are entirely standard (e.g., in sample e, the expression e must evaluate to a distribution name applied to valid parameters, etc.) and are omitted. To highlight the essential statistical issues, which is the focus of this paper, we restrict attention to programs that halt almost surely. Such programs still contain an infinite number of control-flow paths, e.g., using a while loop to sample a geometric random variable, or sampling a Poisson number N of loop iterations.
2.1 Semantics of Straight-Line Programs
A straight-line probabilistic program denotes a target probability density over sampled variables, weighted by the observations. In particular, let be a straight-line program that dynamically
Feras A. Saad
encounters sample statements over the course of its execution, say for . The parameters may depend on all previously generated samples in the execution, as well as other constants in the current environment. Further, suppose there are observe statements, say for , where again the distributional parameters and observed values depend on all previous samples.
With this notation, the probabilistic program denotes a probability density function
whenever , where the densities of the sample and observe statement are defined by
Therefore, (8) is taken as a “posterior density” over the set of traces, with respect to the product of base measures (here is the Lebesgue measure if is a continuous distribution and is the counting measure if is a discrete distribution).
2.2 Inference with Densities
Exact sampling from the distribution (8) is generally intractable. Many algorithms for approximate inference bypass this challenge by working with the unnormalized density , which is available by running the probabilistic program on a fixed trace and aggregating probability densities.
A standard example is sampling via “likelihood weighting”, i.e., importance sampling using the prior as the proposal distribution. We run the program to produce random samples from the sample statements, while carrying a weight from evaluating the probability densities from the observe statements at their realized parameters and measurements. Given importance samples, we approximate the expectation of a test function under the target density (8) using ratio estimation (which is typically biased but consistent as ):
The unnormalized density can also be used for other inference algorithms available in probabilistic programming libraries, such as Markov chain Monte Carlo (MCMC), sequential Monte Carlo, or variational inference, which do not require knowledge of the intractable normalizing constant .
2.3 Soft Conditioning and Statistical Inference in Generative Models
The sample and observe keywords are constructs that suggestively define a distribution by conditioning a generative model. We would like to think of the sample statements as defining “hidden” variables and the observe statements as conditioning on the values of “observable” variables. Eq. (8) resembles the Bayes rule, where the numerator is the joint probability density of the hidden and observed variables and the denominator is the marginal likelihood of the observed variables.
Despite these apparent parallels, the target density (8) in general carries no intrinsic meaning as conditioning in the statistical sense. A program with sample and observe is best understood as defining an unnormalized target density: the statistical interpretation fails in two places.
-
First, the soft conditioning semantics depend on values of quantities at specific null sets where measure-theory tells us that their values are allowed to be arbitrarily defined. As a result, a specific program may fail to denote a meaningful conditional distribution, even when the underlying statistical inference problem is perfectly well defined.
-
Second, under a statistical interpretation of programs with soft conditioning, inference results computed using Eq. (8) do not cohere with inference results from statistical theory.
2.4 Failure to Denote a Conditional Distribution
2.4.1 Infinite Marginal Likelihood. Consider the following probabilistic program.
u = sample uniform(0, 1) x = sample gamma(u, 1) observe normal(0, x) 0
The program encodes an inference problem for the posterior distribution of a Gaussian random variable at , where the variance has a Gamma prior whose shape has a uniform hyperprior. The issue with this program is that its normalizing constant is infinite:
The inner integral is infinite for every , which has positive measure under the uniform prior for . The same pathology arises if is replaced with any constant in (see Figure 2).

Fig. 2. Normalizing constant of the gamma-normal probabilistic program as a function of the variable u.
The density semantics thus cannot produce a well-defined distribution and fails to assign good meaning to the program as a representation of the “posterior distribution” .
This pathology has a sound resolution under a statistical interpretation of the program. It turns out that the problematic term is not u, but rather the program constant 0 in the observe statement. The density of a continuous distribution can be arbitrarily defined on a set of measure zero, so the behavior of at , as well as the entire posterior distribution , are not uniquely defined mathematical objects. Second, whatever representative of we choose, any inference algorithm for the posterior has zero probability of encountering an observation z in a “bad” set A of points whose marginal likelihoods are invalid:
But this resolution is incompatible with soft conditioning. For example, the above program does not contain an explicit variable called Z, which is represented only implicitly by an observe statement that adds a likelihood factor to an unnormalized target density. Any convention about a generative story for this observe statement is an external modeling choice that lives outside the program’s intrinsic semantics. Moreover, the target density over variables from the sample statements is parameterized by the specific numerical constants (in this case, ) written in the text of the program. Such semantics are inadmissible from the statistical viewpoint. The values of the probability density functions and in Eq. (9) are underdetermined at the program constants that appear in observe statements. As the semantics of the program depend on a specific , we can set to be any value by selecting another representative of the density at . There is no statistical basis on which to prioritize or refute any particular choice.
Feras A. Saad
2.4.2 Scoring with Arbitrary Values. Many languages feature a special construct called , which allows users to introduce an arbitrary multiplicative factor to the unnormalized density. While appears more flexible than on the surface, they are equivalent:
The first expression holds by definition. The second expression holds because
Eq. (12) gives us insight into the misbehavior of additional nondenoting programs. Consider the following program , whose normalizing constant .
This program does not include a numerical constant on which probability densities are evaluated. However, if we transform the into an equivalent and interpret the program as a generative model , , we find that its denotation is equivalent to the posterior at (using the Bayes rule (2) with canonical densities). As in the previous case, the posterior is undetermined at . The statistical interpretation of this semantically equivalent program is again tied to the behavior of a probability density at a null set.
More generally, there are many semantics-preserving transformations from to besides (12). For example, the fact for any mean and variance
In general, there could be many different generative stories behind the observe statements in a given probabilistic program, which all have the same density semantics. It is therefore impossible to extract a statistical inference problem from the text of the probabilistic program alone.
2.4.3 Exact Conditions. A statistical motif that sample and observe cannot express is an “exact” condition. For example, consider and . For every observation outside a null set, the posterior distribution is uniform over the line segment . Many users attempt to express this problem as follows.
With soft conditioning, the Bernoulli flip has weight 0 with probability 1. The weight of the observation is also 0 with probability 1 and the normalizer is . The sample and observe constructs are not flexible enough to handle exact conditions, which are statistically well-defined but poorly defined under the density semantics: the joint distribution of lives in but is singular with respect to , even though every pair of variables is absolutely continuous with respect to . The naïve choice of product base measures used to dominate the density cannot reason about such distributions, forcing a.e. The elementary Bayes rule (1) assumes that the posterior distribution is dominated by the prior, which is not the case with exact conditioning.
The issue here is dual to the issue from the previous two examples. With exact conditions, the theoretical posterior distribution is supported on a measure-zero set for almost every observation z. However, the program encodes observation as a Bernoulli variable—whose probability mass is never an arbitrary choice—that disagrees with its observed value with prior probability one.
x = sample bernoulli(0.5) if x == 0 observe uniform(0,1) 1 else observe bernoulli(0.5) 1
(a) Mixed-Type Distribution
x = sample bernoulli(0.5) if x == 0 observe uniform(0,1) 1 observe uniform(0,1) 0.5 else observe uniform(0,1) 0.25
(b) Control Flow with Different Observes
Listing 2. Programs where scoring semantics disagree with probabilistic conditioning.
2.5 Incorrect Statistical Inferences
The previous section focused on semantic issues with probabilistic programs when their denotations are sensitive to arbitrary choices at null sets. We now focus on a well-behaved fragment where the target density does denote a probability measure, but where interpreting (8) as a Bayes rule produces incorrect statistical inference results. These issues are best highlighted for probabilistic programs that exhibit control flow (i.e., branching statements), whose semantics we briefly recount.
2.5.1 Semantics of Programs with Control Flow. For a probabilistic program with control flow, enumerating all possible execution paths yields a collection whose elements are straight-line programs . Suppose that each straight-line program contains sample statements and observe statements. Let be the set of sample traces whose realized control flow is exactly equal to , i.e., by satisfying all the corresponding guard constraints in the if and while statements. The trace space is and the target probability density function is
which is taken with respect to the coproduct of base measures. The notation denotes an atomic measure on a set located at , often abbreviated as .
2.5.2 Mixed-Type Distributions. Consider a pair of random variables where is a fair coin flip and if and otherwise. Given an observation , the posterior contains no measure-theoretic difficulties as , and so the posterior is not arbitrarily defined at this observation. Listing 2a encodes this statistical inference problem using a sample statement for and two observe statements for in different program branches. The semantics (15) for probabilistic programs with control flow gives
i.e., the else-branch is less likely than the if-branch. However, statistical theory tells us that the posterior distribution must assign probability one to the else-branch, because a probability mass is infinitely more likely than a probability density. An ad-hoc computation confirms this intuition: in order to compare the likelihood of the observation under each branch as bona-fide probabilities on equal footing, we take the limit of conditional probabilities that
Feras A. Saad
The disagreement between (16) and (17) is known in the literature, often as the “Indian GPA Problem” [Wu et al. 2018]. To clarify the issue, let denote the two straight-line programs in Listing 2a corresponding to and respectively. The probability densities for the observe statements used in path densities and are defined with respect to different base measures. In particular, is dominated by in path but by in path . Eq. (15) is therefore not a valid Bayes’ rule, which requires that the densities for hidden and observed variables are defined with respect to a single unified base measure. For the observable variable , a natural unified base measure to use in the semantics of the overall program is , which gives
On the other hand, the implicit base measures used by the density semantics of observe are L for the path and for :
For path , the correct base measure (18) forces the uniform density to exclude 0 and 1, while the incorrect base measure (20) allows the density to be arbitrary at 0 and 1. From a language perspective, this example shows that the choice of correct base measure is not local: it requires knowledge of the distribution of the observable variables across all program paths in . In §§4–7, we develop a method to construct correct base measures for general probabilistic programs that can be used to soundly compare probability densities of observations across control flow paths.
2.5.3 Continuous Observations Along Different Paths. Listing 2b shows a related issue to the mixed-type distribution problem. Under a statistical interpretation of this program, there is a branching variable X. If X = 0 then we observe the uniform variables , otherwise we observe the uniform variable . Repeating the calculation from (16) gives the “posterior” probability
On the other hand, using a limit-based computation analogous to (17) with neighborhoods
shows that accumulates probability whereas accumulates . Only the branch survives in the limit and has posterior probability one:
In general, under the statistical interpretation of the observe statements, only those program paths with the fewest continuous observations survive the limit using these neighborhoods. Under the density semantics (where observe is just a score with an arbitrary number), probabilities are defined computationally using (15) and result in unsound inferences such as (16) and (22).
The examples from §2.4 and §2.5 emphasize that the most coherent interpretation of the density semantics of a straight-line probabilistic program is an unnormalized measure. Its total mass is the expectation of the scores defined by the observe statements under the probability distribution defined by the sample statements. Control flow gives a sum of pathwise unnormalized measures, whose total mass is the sum, over program paths, of the prior path probability times the expected score conditional on taking that path. Many users and language developers interpret (8) and (15) as conditional probability densities, which gives inference results that disagree with statistical theory.
3 Conditioning Probabilistic Programs Using Neighborhood Limits
To address the limitations of soft conditions—in particular those in §2.5 where density calculations produce incorrect results—Jacobs [2021] uses a neighborhood-based approach to conditioning on measure-zero events. According to Jacobs, the issue with the density semantics is that they are not expressive enough to handle the inescapable ambiguity that arises from conditioning on null sets. To resolve these issues, Jacobs introduces the construct
which encodes an observation for some random variable , analogously to the approach we used in (17) and (23). While the language does not include random variable names for the observe statements, Jacobs still interprets these statements in the statistical modeling sense (i.e., not unnormalized measures), as is evident in the discussion from Jacobs [2021; §3.2].
Our goal in this section is to study neighborhood-limit semantics as a candidate foundation for statistical probabilistic programming. Indeed, §2.5 showed that a carefully chosen limit construction can result in plausible posterior inferences for the programs in Listing 2. We will show that this approach—when used in its full generality—exhibits analogous issues to soft conditioning.
3.1 Theory of Conditional Probability via Neighborhood Limits
The following principle, adapted from Jaynes [2003], forms the basis of Jacobs's semantics.
A general method for conditioning on measure-zero events is to define a sequence of events parameterized by a number such that in some sense converges to in the limit , but for all . We then define the conditional distribution to be the limit of :
—Jacobs [2021; p. 58:2]
The value of this limit will necessarily depend on the sequence of events , a consequence of the Borel–Kolmogorov paradox. Any statistician who is truly concerned with conditional probabilities given a bare null event E must also specify the neighborhoods that converge to E.
3.1.1 Limits Do Not Give Conditional Probability Distributions. In Conditional Measures and Applications, Rao [2005; p. 68] argues that the limit (26) can be used to obtain a conditional distribution on the probability space of a probabilistic experiment. By appealing to the Vitali-Hahn-Saks theorem [Rényi 1970; Theorem 4.3.11], Rao argues that if is a sequence of decreasing events such that , with and for each , then (26) defines a probability distribution if the limit exists for all . If such a result holds, then the limit definition serves as a rigorous approach to conditioning in probabilistic programs.
The flaw in Rao’s reasoning (also in Rao [1988; §4b]) is that the hypothesis needed to invoke Vitali-Hahn-Saks is impossible to satisfy using (26): the limit does not exist for all . The next result proves that the limit definition of does not give a conditional distribution.
PROPOSITION 3.1. Let be a probability space and let be a sequence of events converging to , with for every and . There is no measure on such that
Feras A. Saad
PROOF. Assume that exists. Clearly is finite, as . Also
because for every . But computing using continuity from above gives
where the penultimate equality follows from the fact that whenever .
Proposition 3.1 implies, after specifying a limiting neighborhood, the rule (26) does not deliver a coherent conditional distribution. Rather, it delivers a collection of isolated numbers that in general have no relationship with one another as the event changes.
3.1.2 Conditional Probability Given a Sigma-Algebra. As Proposition 3.1 rules out the possibility that a neighborhood limit defines a conditional distribution, we will analyze the mathematical object (26) from the lens of modern probability theory [Kolmogorov 1933; §5]. Let be a probability space. Given events with , the conditional probability is defined in the usual way. Given event and a sub-sigma algebra , we define the conditional probability to be any -measurable random variable such that
As usual, the random variable is unique up to -null sets. For example, if is a null event, then can be defined arbitrarily for , because which leaves the integrand unconstrained. There is no mathematical basis on which to favor any particular version over another, and program semantics must not be sensitive to the chosen version.
Multiple individual conditional probabilities can be coherently combined together using the idea of a “regular” conditional probability. For a sub-sigma algebra , a regular conditional probability on given is a function such that
• For every , the map is a conditional probability of given ;
• For -almost every , the map is a probability measure on .
3.1.3 The Sigma-Algebra Structure of a Neighborhood. Let us now analyze neighborhood limits using conditional probabilities. Following Rao [2005; p. 68], we identify as the underlying sigma-algebra that is being conditioned on when the practitioner specifies a neighborhood-limit (26) with descending sets . This sigma-algebra is generated by the following disjoint events, which are all atoms of :
It is readily verified that any conditional distribution (regular or otherwise) given is of the form
where and are arbitrary constants that cannot be determined by the sets alone.
This representation exposes the nature of neighborhood-limit probabilities: they pin down only the underdetermined constant in a given version of . The program’s meaning under (26) rests entirely on an arbitrary choice of ; from the statistical perspective, however, we can only depend on the behavior of the -a.s. unique object under an integral sign. This semantic issue with neighborhood limit mirrors the one for density semantics from §2.4, which depend on values of probability density functions at specific points.
3.2 Revisiting the “Type 1” Paradox
The neighborhood-limit approach aims to solve the problem of conditioning on null sets. We wish to demonstrate that a bare null set is too informal to encode a meaningful statistical inference problem. Toward this end, we review the “Paradox of Type 1” example [Jacobs 2021; §3], where different variables are observed in different control flow paths (see also Listing 2b).
h = sample normal(1.7, 0.5) # sample height w = sample normal(70, 30) # sample weight b = sample bernoulli(0.5) if b == 0 observe normal(h, 0.1) 2 # noisy measurement of height else observe normal(w, 5) 90 # noisy measurement of weight bmi = w / h^2
As Jacobs interprets observe in the sense of statistical conditioning, the statements on lines 5 and 7 should not be understood using the equivalent score semantics (12). Rather, Jacobs' discussion states that the program conditions the joint distribution of on the null event
where and are the implicit random variables used in the two observe statements. Jacobs shows that using soft conditioning to analyze this program exhibits unit anomalies, in the sense that the posterior distribution of changes if we measure height using centimeters instead of meters. While acknowledging that some readers may object about conditionally executed observe, Jacobs argues by analogy that because they have a rigorous interpretation in the discrete case, they should also carry good probabilistic meaning in the continuous case. We study this assertion from the perspective of statistical inference, and find that unit anomaly problems actually mask a more significant issue that is caused by interpreting observe as conditioning on a bare null set.
3.2.1 Bare Null Events as Observations. Recall from Proposition 3.1 that does not define a probability distribution, so we require an alternative mathematical explanation of this limit. By considering repeated trials of the statistical experiment in the program above, the null event (33) must be understood as a member of a family of events indexed by observable values of the noisy height and weight from a given realization of the underlying experiment:
so that . As statistics are by definition measurable functions of the data (cf. Page 3), we seek to construct a random variable in the probability space such that for all . Such a construction, if possible, would lead to a principled statistical inference problem. Even though the posterior is arbitrary at any fixed (e.g., the constants 2 and 90 hard-coded in the program), it is perfectly well-defined as a regular conditional distribution defined earlier.
For events of the form shown in (33), such a construction is generally impossible. Indeed, there are infinitely many different random variables that encode at a specific z, for example,
But and are of the form , i.e., the definition of each random variable depends on the specific observation z. Therefore, each event in the family arises from conditioning a different random variable on a different value. The individual encodings do not provide a unified encoding using a fixed observable statistic on the underlying probability space.
Feras A. Saad
PROPOSITION 3.2. Consider the parameterized families of conditioning events in (34). There does not exist a random variable and mapping such that , for every
PROOF. For and , the events but . If then , contradiction. If , then , so , contradiction.
As a result, we cannot state any consistency property for our statistical inferences as we change the program constants to other values that represent different noisy “observations” of the height and weight. Given only a bare null event , we cannot formulate a Bayes rule such that for every setting of program constants in the observe statements. As Listing 2b also conditions on a bare null set, the possibility of statistical inference in this program is similarly ruled out. For Listing 2a, this program is admissible, provided that the observe measures the same statistic in both branches. In this case, using the generative semantics of observe, we can write a semantically equivalent program that randomizes over the distribution while holding the observation fixed, as in a standard statistical mixture model:
x = sample bernoulli(0.5) if x == 0 D = uniform(0,1) else D = bernoulli(0.5) observe D 1
3.2.2 Ambiguity of Null Set Conditioning. The argument for neighborhood limits in Jaynes [2003] is an attempt to resolve Borel's paradox: to make the question of conditioning on a bare null set E meaningful, the user also must specify additional mathematical structure, such as a limiting process , a sigma-algebra of events , or a random variable encoding Z. But this resolution assumes that conditioning on a bare null set is a statistically sensible problem to begin with.
The representation of using underscores the issue. Since , is almost surely equal to 0. The regular conditional distribution given is therefore the prior. But the event of interest is the probability-zero observation , for which the defining equation for conditional probability imposes no constraint whatsoever:
Version issues are not pathologies of regular conditional distributions, because their semantic property is stated by integration against the marginal law of the observation. Neighborhood limits, on the other hand, do not define conditional distributions (Proposition 3.1) and exhibit more significant difficulties. As we showed in (32), they use an unconstrained value at the null fiber as the semantic property of the entire program. This choice is external structure that is undetermined by the generative process, and different equally admissible neighborhoods select different posteriors. To fix the “unit anomaly” problem, the method of Jacobs requires arbitrary constants that specify the rate at which the neighborhoods shrink in each program path:
Let and be the marginal likelihoods of the noisy observations and , respectively. In the limit , the posterior branch probabilities depend not only on and (as expected), but also on the arbitrary constants and selected by the user:
Pushforward
Trace Space
Observation Space
Disintegration
Trace Space
Observation Space


Fig. 3. Illustration of pushforward and disintegration of a probability measure through a map . The pushforward operation induces a measure on , where the measure of a set is the measure of its preimage . Informally, disintegration decomposes the measure of as the weighted sum of measures of slices that partition , where is weighted by . These operations give a precise semantics for observations and conditional distributions in probabilistic programs.
4 Disintegration Theory
Our approach to conditioning is based on disintegration, which is introduced informally in §1.3. More formally, a probabilistic program operates over a measurable space of traces with probability measure and a random trace. The observation process is modeled using a measure space and a measurable observation map . We define to be the observable random variable, with marginal distribution . For example, in a standard parametric statistical inference problem, is a pair of random variables where is a latent parameter and observable data, with a projection of the second coordinate. Given a specific observation , the inference problem is to infer the conditional distribution .
A disintegration of X through t is a probability kernel such that
where is supported on the fiber for -a.e. z, i.e., (cf. Figure 3).
PROPOSITION 4.1. A disintegration induces a regular conditional distribution on the probability space given the sigma algebra , by setting .
(Appendices A and B contain all the proofs from here on.) Disintegrations exist under a variety of settings [Bogachev 2007; §10.4]. For our purposes, and are standard Borel spaces, which guarantees a disintegration [Bogachev 2007; Proposition 10.4.12]; [Chang and Pollard 1997; Theorem 1]. Following the usual setting in statistics, where the observable data we condition is assumed to be drawn from the specified model, version differences are immaterial because disintegrations are canonical up to null sets (i.e., any two versions agree -a.s.).
4.1 Generalized Bayes Rule
In our setup, we cannot represent the disintegration using the elementary Bayes rule (2), because has a degenerate distribution . Therefore, the density of the “likelihood” term is not yet well specified. We will construct an explicit representation of the disintegration as a probability density , by way of a more general Bayes rule.
Feras A. Saad
Suppose we have a -finite base measure on the observation space that can be used to disintegrate the base measure on , that is, there exists a transition kernel such that
where assigns zero measure outside the fiber . This assumption is sufficient to obtain a generalized Bayes rule representation of the disintegration.
THEOREM 4.2. Let be a probability space with for a sigma-finite base measure . Let be measurable, , and a sigma-finite measure on . If is a disintegration of as in (41), then
4.2.1 The transition kernel is uniformly -finite, for -a.e. z.
4.2.2 The marginal distribution of Z satisfies , with density
4.2.3 The conditional distribution of X given Z satisfies , with density
It is essential to select a sigma-finite base measure that satisfies the hypotheses of Theorem 4.2. For example, the obvious choice as the pushforward of the trace base measure through is invalid, as it may not be sigma-finite. For example, put with . Then for every with . Instead, a valid choice in this example is setting with .
5 A Probabilistic Language with Observation Maps
Listing 3 shows a probabilistic language that facilitates conditioning by disintegration. Inline observe statements have been eliminated and a return statement followed by a single observe statement is introduced. The idea here is that return e represents the observation map and observe fixes the observation , where . The program semantics will not be tied to any specific values of observe z, but rather the disintegration property that establishes correctness for almost-every random data vector Z in the prior support.
Listing 3. Language for statistical probabilistic programs with return value.
We formulate a disintegration semantics for this language in stages. In §6, we first consider a fixed program path and identify a local disintegration
This base measure will furnish a Bayes rule according to Theorem 4.2 for an observation map corresponding to the return statement associated with that path.
In §7, we construct a global disintegration for a probabilistic program with multiple paths . This step requires combining the family of local objects from §6 into a global disintegration:
such that
A key challenge is identifying measure-theoretic structure that satisfies the hypotheses of Theorem 4.2, to obtain a Bayes rule for the overall program with observation map .
Notation 5.1. The symbol denotes the -dimensional Hausdorff measure on . For any measure and event , we write to denote the restriction of to . If regarded as a measure on , it is given by , where .
5.1 Primitive Probability Distributions
We first formalize the primitive probability distributions in our calculus. We fix a countable set Dist of primitive distribution names. For each there is a distribution family
where indicates whether the distribution is discrete or continuous.
-
In the discrete case , the carrier is a countable set equipped with the powerset sigma-algebra and counting base measure .
-
In the continuous case , the carrier is Euclidean space equipped with the Borel sigma-algebra and Lebesgue base measure .
In both cases, is a measurable parameter space, and the probability density function is jointly measurable, such that for . The induced primitive probability distribution is therefore for .
Note that our semantics omit continuous primitive distributions that are singular with respect to the Lebesgue measure. Samples from such distributions can be implemented in the language by sampling from a lower-dimensional coordinate parametrization of the support. For example, the uniform distribution over the circle in centered at with radius is given by
rather than a standalone primitive x = sample uniform_circle(theta). This assumption is needed to retain a practical language semantics, refer to Appendix C for a detailed discussion.
6 Disintegration within a Single Probabilistic Program Path
Equipped with the primitives, we construct the disintegration (44) for a single program path .
6.1 Measure Structure
Path Distributions. A finite program path contains dynamic occurrences of sample statements, which determines an ordered sequence of primitive distribution names . For compactness, we omit the subscript so that and similarly for remaining quantities in (47), where . The path encounters measurable maps that determine the distributional parameters of each , so that for any trace prefix the concrete distribution used by the ith encountered sample statement is , whose density with respect to is denoted .
Feras A. Saad
Unconstrained Trace Space. We first model the traces of ignoring any guard conditions. The ambient (unconstrained) trace space is given by the product . We partition the sample sites into discrete and continuous indexes
These indexes identify the discrete and continuous (differentiable) structure in the ambient trace space. In particular, letting
we identify the congruences
With this representation, we let denote a generic trace for , where contains variables from the discrete sample statements and the variables from the continuous sample statements. We let extract the ith coordinate in the trace in chronological order, i.e., the sample from . The ambient path density with respect to is thus
6.2 Incorporating Path Guards
We now refine the measure space to account for guards that appear in the if and while statements of the program path . Suppose that encounters guard occurrences. For each guard occurrence , let be the number of encountered sample statements executed before guard is evaluated. Each guard expression denotes a measurable Boolean function . The program path fixes a specific Boolean guard value , indicating whether the guard evaluates to false or true. The resulting measure space for is
Using the congruences in (50), the base measure—which is evidently sigma-finite using standard counting arguments—is congruent to
We have thus identified the prior over traces within the program path as subprobability distribution. We assume without loss of generality that is nonzero, because any path whose guards carve out a -measure zero subset of can be semantically ignored.
6.3 Observation Map
From Listing 3, each path ends with return , where is a well-formed expression in the current path environment that evaluates to a list of reals. Expression gives a measurable observation map . Note here that a given program always returns a list of fixed length , while other paths may be used to return lists with a different length.
Continuous Structure. As operates on discrete and continuous coordinates, we let denote the observation maps on the continuous part, with . Here, the sets partition the domain according to the continuous sections of the trace, holding fixed the discrete values . A generic path-compatible trace is written in terms of discrete and continuous coordinates as .
To enforce geometric regularity on the observation maps, we assume each is the restriction to of a (continuously differentiable) constant-rank map on an open domain:
where is open and . This assumption is mathematically mild, as many observation maps that are not globally nor constant rank can be handled by stratifying the domain (although the syntactic implementation requires careful consideration, cf. §8). We define
Jacobian Matrix. Transforming a random variable through an observation map requires a correction for the volume change between the domain and range. For , let denote the Fréchet derivative of the map . In coordinates, we have
The constant-rank assumption means there exists nonnegative integer such that for all and . The Jacobian of the matrix (57) is defined as
where extract the nonzero singular values, with the convention if . These partial derivatives are often available by standard automatic differentiation on the return expression of the probabilistic program. There are two familiar cases for the Jacobian:
6.4 Local Disintegration
We now have the ingredients to state the main disintegration theorem for our setup.
THEOREM 6.1. For every and , the Lebesgue measure disintegrates as
This result is based on the coarea formula from [Federer 1996; Theorem 3.2.22], adapted specifically to our topological assumptions on the trace space and observation map. The disintegration of the Lebesgue measure suggests using the restricted Hausdorff measure as the observation base measure . The next results show that this measure is sigma-finite, as needed in Theorem 4.2.
Feras A. Saad
THEOREM 6.2. The measure is sigma-finite.
Taking the sum over the discrete variables and applying Tonelli's theorem to interchange the integral and summation gives the overall disintegration within the program path .
THEOREM 6.3. The prior base measure over disintegrates through as follows:
Posterior Density. We next apply Theorem 4.2 to represent the disintegration of using the posterior density . It is more convenient to use an unweighted geometric reference measure that dominates the canonical measure identified in Eq. (63). For , we set
Applying the chain rule of Radon–Nikodym derivatives to Eq. (43) gives
This expression gives a unified density representation relative to an unweighted base measure, by moving the Jacobian factor from the base measure (63) into the density (65). It can therefore be used to directly compare the densities of different points and on the fiber making it directly compatible with algorithms such as importance sampling and MCMC.
7 Disintegration of Full Probabilistic Programs
We now construct a disintegration for a probabilistic program with multiple paths , by combining the local objects (45) to obtain a global disintegration (46).
The global measure space over traces is defined as the countable coproduct
where the prior density and distribution over traces satisfy
Note that superscripts have been omitted for clarity. As the return statement in each path produces an output in , the global observation measurable space is also the coproduct:
The global observation map is given by . The final step is constructing the global base measure on , which must dominate all the local path base measures .
7.1 Observation Base Measure
There are two natural candidates for the observation base measure to consider: (i) the sum ; and (ii) the coproduct . The former, however, may not be sigma-finite. The latter is unsuitable because it lives on tagged observations which defeats the purpose of posterior inference over the unknown program path that generated the observation.
We will construct a global base measure that avoids both failures. It is defined on raw observation values and measures each value only once to ensure sigma-finiteness. Toward this end, we stratify the observation space Z according to the output dimension and observation rank associated with each path . For each and , we define
The set contains observations that lie in the image of an observation map whose rank is at most . The set contains observations for which is the lowest such rank.
With these constructions, the observation base measure is defined as the restriction of the Hausdorff measure to these rank-stratified sets:
THEOREM 7.1. The measure over is sigma-finite.
7.2 Unifying the Pathwise Base Measures
We next express all the local base measures for program paths in terms of the global base . This change-of-measure step is necessary to soundly compare densities that arise from different program paths with respect to a unified base measure (recall Eqs. (18)–(21) from §2.5.2).
PROPOSITION 7.2. For each , let be the extension of the local base measure defined in Eq. (63) to the global measure space . Then and has density
where , with the convention .
This result shows that only those program paths for which the observation lies in and has minimal rank contribute to the density . Informally, a path whose observation map has rank assigns a mass of order to an -neighborhood of a regular observation value, so only the smallest exponents survive in the infinitesimal limit. The global base measure captures this asymptotic comparison. It measures only on its minimal rank stratum, while the density of the local path measures with respect to retains paths whose observation rank is minimal.
The change-of-measure (71) now lets us identify the global disintegration.
THEOREM 7.3. The prior base measure over disintegrates through as follows:
for each , where .
Posterior Density. Theorems 4.2 and 7.3 together furnish the required densities and . As in the case for disintegrating a single path, it is more convenient for probabilistic inference algorithms to use a conditional density with respect to an unweighted geometric measure that excludes the z-specific term and x-specific term :
Feras A. Saad
Analogously to (65), applying Theorem 4.2 to the disintegration in Theorem 7.3 and then changing the base measure from to gives the overall conditional density:
for any program path and trace .
7.3 Relationship to Neighborhood Limits
The disintegration that we have constructed admits a neighborhood-limit interpretation. Pfanzagl [1979] shows that under standard topological assumptions (satisfied by our construction), for a fixed observation map , a conditional distribution can be obtained as a derivative of measures on Z. For a neighborhood C of z such that , define the measure
Informally, Pfanzagl proves that converges to a regular conditional distribution as , for -almost every . The object is unique up to -null sets. Different admissible neighborhood bases for the same map only change the resulting version of the regular conditional distribution. This result does not contradict Proposition 3.1, because Pfanzagl takes the weak limits of probability measures , not the setwise limits that Jaynes advocates for.
Neighborhood limits are therefore sound when they arise from a coherent observation map. The neighborhood-limit approach of Jacobs [2021] from §2 does not guarantee this condition, because it uses branch-dependent neighborhood approximations such as , which may not be the preimage of a single neighborhood under a fixed observation map. The limiting branch probabilities can therefore contain arbitrary scale factors from the chosen neighborhoods, as shown in Eq. (39). Our global observation map and base measure rule out extra choices exogenous to the statistical model, because all program paths are compared through the same observation-space derivative. Our construction of explicitly represents the weak limit of the measure-theoretic derivative (75) for probabilistic program traces as a posterior density (74).
7.4 Projection Observations and Likelihood Weighting
The factor in the posterior density is a global program property that requires knowing (i) whether z lies in the path image; and (ii) whether the path has minimal rank among all paths that can generate z. In the special case of projection observations, this factor can be soundly estimated by sampling, and we can prove that inference via likelihood weighting is strongly consistent.
Suppose the language in Listing 3 is equipped with a deterministic addressing scheme for sample statements. Each execution along a program path produces an addressed trace , where is the set of encountered addresses. The observation maps are coordinate projections:
With the identification of addressed traces as Euclidean vectors, the Jacobian and the path rank is the number of continuous coordinates in . The nonlocal term in is :
Let be the usual likelihood-weighting proposal over X for an observation z, which generates a trace x by sampling all unobserved coordinates from their prior conditionals and fixing observed coordinates to z. The likelihood weight L is the product of the probability densities (or masses) of the fixed coordinates and . Draw i.i.d. importance-weighted samples
As is unknown, it is estimated empirically from samples as follows:
Finally, for a measurable function , define the likelihood-weighting ratio estimator
which is set arbitrarily when the denominator is zero.
THEOREM 7.4. Let be bounded and measurable, and be an observation with . Likelihood weighting is strongly consistent for , that is,
The key idea is that with projection observations, likelihood weighting does not need to know the global rank statically. The event has positive -probability, so by Borel–Cantelli it occurs infinitely often with -probability one. The empirical estimator will therefore eventually equal , after which the likelihood-weighting ratio estimator reduces to ordinary self-normalized importance sampling within the program paths of minimal-rank. A similar argument can be used for general proposal importance-sampling distributions (not necessarily the prior) and for randomized addressing schemes from a countable set.
8 Language Design Considerations
To our knowledge, no existing probabilistic programming language supports in full generality the geometric semantics for conditioning developed in this paper. We expect implementations to specialize our framework in different ways, depending on the desired tradeoff between expressiveness, runtime performance, and static verification. We briefly discuss implementation considerations that arise when designing systems whose inference algorithms leverage our Bayes rule:
The easy terms are , which is available by executing the program on a fixed trace, and , which can be ignored by inference algorithms that do not depend on normalizing constants.
Guards. Theorem 6.1 allows the path domain to be an arbitrary positive-measure subset of the ambient Euclidean trace space carved out by program guards ( ). Even exotic domains such as a fat Cantor set, which has positive Lebesgue measure but empty interior, are admissible in the mathematical theory. In practice, however, language implementations are likely to restrict guards to more structured classes, such as expressions built from piecewise-analytic-under-analytic-partition (PAP) functions [Lee et al. 2020], in order to make path analysis and inference tractable.
Observation Map. Enforcing that each path-specific observation map is constant-rank may require explicit stratification using program branches. For example, the map has rank 0 at and rank 1 at ; if is a mixed-type random variable (e.g., a normal-Bernoulli mixture), then explicit paths are needed for the , , and cases. Stratification is theoretically straightforward but may be nontrivial to expose in program syntax, and may require support from the host language to detect and construct valid constant-rank observation maps.
Feras A. Saad
Jacobian. Because the observation maps in the main theory are restrictions of maps on Euclidean domains, the Jacobian is computed from ordinary Euclidean partial derivatives. These derivatives can often be obtained by automatic differentiation of the return expression, once the trace is typed into discrete and continuous coordinates. A practical AD implementation requires enough type information to distinguish the discrete and continuous coordinates, so that is held constant and differentiation is performed with respect to .
Fiber Support. The posterior distribution is always supported on the fiber , so the density term implicitly includes an indicator . Generating samples on this fiber—such as for proposal distributions in importance sampling or Markov chain Monte Carlo—is a key challenge. If observation maps are projections of sampled variables, the fiber is a coordinate slice, so importance sampling using the prior works as a default proposal ( ). In general, however, the fiber may be a complex set, and there is no default proposal strategy. Practical language implementations will likely require user guidance, specialized constraint solvers, reparameterizations of the fiber, or programmable inference kernels that can effectively explore the posterior geometry.
Rank. Section 7.4 showed a special case where the global rank information can be consistently estimated via importance sampling. In restricted languages, observation ranks may be obtained by exploiting known structure of the probabilistic model. In more flexible languages, a combination of program analysis and statistical estimation methods may be required to compute the ranks.
9 Related Work
9.1 Geometric Densities and Base Measures
Diaconis et al. [2013] leverage geometric techniques to solve statistical problems that involve probability distributions on Euclidean submanifolds. This perspective is closely related to our construction in §6, where the coarea formula disintegrates the Lebesgue measure along the fibers of a path-specific observation map. Our contribution differs in scope, however. Rather than sampling from a fixed manifold, we construct in §7 disintegration semantics for entire probabilistic program traces. Our theory supports constructs beyond those in Diaconis et al. [2013], such as countably many execution paths, discrete-continuous mixtures, overlapping path images, and a global sigma-finite observation base measure that gives a Bayes rule over probabilistic program traces.
Radul and Alexeev [2021] develop a powerful calculus for computing densities of probability distributions on manifolds. Using our notation, their construction can be understood as a principled representation of the marginal density over the observation space . The essential difference between our developments lies in the semantic objects of interest and resulting geometric machinery. Our task goes further, where a probabilistic program denotes a prior measure over traces together with an observation map , and conditioning is defined by disintegration:
As we aim to construct a conditional law and density over path-indexed traces , the observation density falls out only as the normalizing constant. This distinction requires us to develop alternative measure-theoretic constructions to the ones in Radul and Alexeev that enable a disintegration theorem and Bayes rule. These differences are most visible in three places.
• Countably Infinite Path Supports. Radul and Alexeev [2021; §4.2] work with a finite union of manifolds and take the sum of Hausdorff measures as the common base. Probabilistic programs may involve countably many manifolds where the sum of base measures is not appropriate (cf. §7.1). We construct an alternative base measure that lets us apply Theorem 4.2 to derive a Bayes rule.
-
Positive Measure Overlaps. For two manifolds and in Z with dimensions and , Radul and Alexeev assume that the intersection has a lower dimension than . This assumption is fine for representing a standalone measure or density on Z, but is not compatible with path-based disintegration. Observation maps from different program paths can overlap on a positive-measure subset of the same rank, and this overlap is precisely where posterior uncertainty about the branching structure of the program lives. In our theory, these overlaps contribute additively because the global kernel retains every minimal-rank path that can produce z. Each observation value is therefore measured once by , while posterior uncertainty over the generating path is represented on the trace side by the density .
-
Observation Maps. The change-of-variables result in Radul and Alexeev [2021; Theorem 1] applies to a diffeomorphic map on manifolds, where each point has a unique preimage. Our theory handles noninjective maps, whose images are not necessarily single embedded manifolds but countably rectifiable (Definition A.2). Noninjective constant-rank maps include immersions, which can have multiple zero-dimensional preimages, and submersions, which can have a positive-dimensional fiber. To handle such observation maps we derive a coarea formula (Theorem 6.1) to disintegrate the trace base measure over , with a Jacobian correction for the volume change.
9.2 Probabilistic Programming Systems with Disintegration
On the implementation side, Narayanan et al. [2016], Narayanan and Shan [2020], Shan and Ramsey [2017] develop sophisticated inference techniques in Hakaru that produce disintegrations symbolically via semantics-preserving program transformations. These systems are largely formalized using operational rewrite rules, whereas our contribution provides a mathematical foundation for disintegrating probabilistic program traces at the measure-theoretic level. In addition, several modeling constructs handled by our theory are not handled by existing solver-based implementations.
Certain systems implement the restricted form of disintegration from §7.4, where the observation map is a projection. Lew et al. [2020] adopt this formalism and build a type system that rules out mixed-type distributions and other constructs where density semantics fail. Wu et al. [2018] and Saad et al. [2021] develop generalized density semantics and probabilistic inference algorithms that avoid pitfalls of soft conditioning and correctly handle mixed-type distributions for restricted probabilistic languages that specify Bayesian networks and sum-product networks, respectively.
9.3 Language Semantics and Disintegration
Quasi-Borel spaces [Heunen et al. 2017] provide a categorical foundation for higher-order probability, replacing measurable spaces with a Cartesian closed setting that supports function types. This direction is complementary to our work. We operate in a standard Borel space of trace and observation spaces, and construct an explicit geometric disintegration of the measure on traces.
Dahlqvist and Kozen [2020] give a denotational semantics for probabilistic programs using linear operators on Banach spaces, where conditioning is modeled as the adjoint of the forward generative operator. [Dahlqvist and Kozen 2020; Remark 25]. In contrast to this work, we construct explicit posterior kernels and densities for exact observations in a space of path-indexed traces, which can be used directly by probabilistic inference algorithms such as importance sampling and MCMC.
Vákár and Ong [2026] study s-finite kernels as a semantic domain for probabilistic programs and prove s-finite analogues of Radon–Nikodym and disintegration theorems. For our goal of an explicit Bayes rule, an s-finite observation base measure is not sufficient. As we have shown, the sum of local pathwise base measures can be s-finite but not sigma-finite, which makes it challenging to compute densities. Therefore, our construction specifically uses a sigma-finite base measure, giving standard Radon–Nikodym densities and a Bayes rule representation of the disintegration.
Feras A. Saad
Acknowledgements
This material is based upon work supported by the National Science Foundation under Award No. 2311983. Any opinions, findings and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.
The author gratefully acknowledges Jesse M. Michel, whose request for a coherent mathematical account of conditioning in probabilistic programs served as an impetus for the present work.
References
Oriol Abril-Pla et al. 2023. PyMC: A Modern, and Comprehensive Probabilistic Programming Framework in Python. PeerJ Computer Science 9, Article e1516 (2023), 35 pages. doi:10.7717/peerj-cs.1516
Giles Barthe, Joost-Pieter Katoen, and Alexandra Silva. 2020. Foundations of Probabilistic Programming. Cambridge University Press, Cambridge, UK. doi:10.1017/9781108770750
Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul Szerlip, Paul Horsfall, and Noah D. Goodman. 2019. Pyro: Deep Universal Probabilistic Programming. Journal of Machine Learning Research 20, 28 (2019), 1–6.
Vladimir I. Bogachev. 2007. Measure Theory. Springer, Berlin. doi:10.1007/978-3-540-34514-5
Johannes Borgström, Ugo Dal Lago, Andrew D. Gordon, and Marcin Szymczak. 2016. A Lambda-Calculus Foundation for Universal Probabilistic Programming. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, New York, NY, USA, 33–46. doi:10.1145/2951913.2951942
Leon Bungert and Philipp Wacker. 2022. The Lion in the Attic – A Resolution of the Borel–Kolmogorov Paradox. arXiv:2009.04778v2 [math.PR]
Bob Carpenter, Andrew Gelman, Matthew D. Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker, Jiqiang Guo, Peter Li, and Allen Riddell. 2017. Stan: A Probabilistic Programming Language. Journal of Statistical Software 76, 1 (2017), 1–32. doi:10.18637/jss.v076.i01
Joseph T. Chang and David Pollard. 1997. Conditioning as Disintegration. Statistica Neerlandica 51, 3 (1997), 287–317. doi:10.1111/1467-9574.00056
Marco F. Cusumano-Towner, Feras A. Saad, Alexander K. Lew, and Vikash K. Mansinghka. 2019. Gen: A General-Purpose Probabilistic Programming System with Programmable Inference. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery, New York, NY, USA, 221–236. doi:10.1145/3314221.3314642
Fredrik Dahlqvist and Dexter Kozen. 2020. Semantics of Higher-Order Probabilistic Programs with Conditioning. Proceedings of the ACM on Programming Languages 4, POPL, Article 57 (Jan. 2020), 29 pages. doi:10.1145/3371125
Persi Diaconis, Susan Holmes, and Mehrdad Shahshahani. 2013. Sampling from a Manifold. In Advances in Modern Statistical Theory and Applications: A Festschrift in Honor of Morris L. Eaton, Galin Jones and Xiaotong Shen (Eds.). Institute of Mathematical Statistics Collections, Vol. 10. Institute of Mathematical Statistics, Beachwood, OH, 102–125. doi:10.1214/12-IMSCOLL1006
Herbert Federer. 1996. Geometric Measure Theory. Grundlehren der mathematischen Wissenschaften, Vol. 153. Springer-Verlag, Berlin. doi:10.1007/978-3-642-62010-2
David H. Fremlin. 2010. Measure Theory, Volume 2: Broad Foundations (2nd ed.). Fremlin Torres, Colchester, UK.
Chris Heunen, Ohad Kammar, Sam Staton, and Hongseok Yang. 2017. A Convenient Category for Higher-Order Probability Theory. In Proceedings of the 32nd Annual ACM/IEEE Symposium on Logic in Computer Science. IEEE Press, Piscataway, NJ, USA, 1–12. doi:10.1109/LICS.2017.8005137
Mathieu Huot, Alexander K. Lew, Vikash K. Mansinghka, and Sam Staton. 2023. -PAP Spaces: Reasoning Denotationally About Higher-Order, Recursive Probabilistic and Differentiable Programs. In Proceedings of the 38th Annual ACM/IEEE Symposium on Logic in Computer Science. IEEE Press, Piscataway, NJ, USA, 14 pages. doi:10.1109/LICS56636.2023.10175739
Jules Jacobs. 2021. Paradoxes of Probabilistic Programming: And How to Condition on Events of Measure Zero with Infinitesimal Probabilities. Proceedings of the ACM on Programming Languages 5, POPL, Article 58 (Jan. 2021), 26 pages. doi:10.1145/3434339
Edwin T. Jaynes. 2003. Probability Theory: The Logic of Science. Cambridge University Press, Cambridge, UK. doi:10.1017/CBO9780511790423
Andrey Kolmogorov. 1933. Grundbegriffe der Wahrscheinlichkeitsrechnung. Ergebnisse der Mathematik und Ihrer Grenzgebiete. 1. Folge, Vol. 2. Springer, Berlin. doi:10.1007/978-3-642-49888-6
Wonyeol Lee, Hangyeol Yu, Xavier Rival, and Hongseok Yang. 2020. On Correctness of Automatic Differentiation for Non-Differentiable Functions. In Proceedings of the 34th International Conference on Neural Information Processing Systems (Advances in Neural Information Processing Systems, Vol. 33). Curran Associates Inc., Red Hook, NY, USA, Article 564,
12 pages.
Alexander K. Lew, Marco F. Cusumano-Towner, Benjamin Sherman, Michael Carbin, and Vikash K. Mansinghka. 2020. Trace Types and Denotational Semantics for Sound Programmable Inference in Probabilistic Languages. Proceedings of the ACM on Programming Languages 4, POPL, Article 19 (Jan. 2020), 31 pages. doi:10.1145/3371087
Pertti Mattila and R. Daniel Mauldin. 1997. Measure and Dimension Functions: Measurability and Densities. Mathematical Proceedings of the Cambridge Philosophical Society 121, 1 (1997), 81–100. doi:10.1017/S0305004196001089
Praveen Narayanan, Jacques Carette, Wren Romano, Chung-chieh Shan, and Robert Zinkov. 2016. Probabilistic Inference by Program Transformation in Hakaru (System Description). In Proceedings of the 13th International Symposium on Functional and Logic Programming. Springer International Publishing, Cham, 62–79. doi:10.1007/978-3-319-29604-3_5
Praveen Narayanan and Chung-chieh Shan. 2020. Symbolic Disintegration with a Variety of Base Measures. ACM Transactions on Programming Languages and Systems 42, 2, Article 9 (May 2020), 60 pages. doi:10.1145/3374208
Johann Pfanzagl. 1979. Conditional Distributions as Derivatives. The Annals of Probability 7, 6 (1979), 1046–1050. doi:10.1214/aop/1176994897
Alexey Radul and Boris Alexeev. 2021. The Base Measure Problem and its Solution. In Proceedings of the 24th International Conference on Artificial Intelligence and Statistics (Proceedings of Machine Learning Research, Vol. 130). PMLR, Norfolk, MA, 3583–3591.
Malempati M. Rao. 1988. Paradoxes in Conditional Probability. Journal of Multivariate Analysis 27, 2 (1988), 434–446. doi:10.1016/0047-259X(88)90140-6
Malempati M. Rao. 2005. Conditional Measures and Applications (2nd ed.). Chapman & Hall/CRC, Boca Raton, FL. doi:10.1201/9781420027433
Alfred Rényi. 1970. Foundations of Probability. Holden-Day, Inc., San Francisco, CA.
Feras A. Saad, Martin C. Rinard, and Vikash K. Mansinghka. 2021. SPPL: Probabilistic Programming with Fast Exact Symbolic Inference. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation. Association for Computing Machinery, New York, NY, USA, 804–819. doi:10.1145/3453483.3454078
Mark J. Schervish. 1995. Theory of Statistics. Springer-Verlag, New York. doi:10.1007/978-1-4612-4250-5
Chung-chieh Shan and Norman Ramsey. 2017. Exact Bayesian Inference by Symbolic Disintegration. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, NY, USA, 130–144. doi:10.1145/3009837.3009852
Sam Staton, Hongseok Yang, Frank Wood, Chris Heunen, and Ohad Kammar. 2016. Semantics for Probabilistic Programming: Higher-Order Functions, Continuous Distributions, and Soft Constraints. In Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science. Association for Computing Machinery, New York, NY, USA, 525–534. doi:10.1145/2933575.2935313
Dario Stein and Sam Staton. 2024. Probabilistic Programming with Exact Conditions. J. ACM 71, 1, Article 2 (Feb. 2024), 53 pages. doi:10.1145/3632170
Matthijs Vákár and Luke Ong. 2026. On S-Finite Measures and Kernels. arXiv:1810.01837v2 [math.PR]
Jan-Willem van de Meent, Brooks Paige, Hongseok Yang, and Frank Wood. 2021. An Introduction to Probabilistic Programming. arXiv:1809.10756v2 [stat.ML]
Yi Wu, Siddharth Srivastava, Nicholas Hay, Simon Du, and Stuart Russell. 2018. Discrete-Continuous Mixtures in Probabilistic Programming: Generalized Semantics and Inference Algorithms. In Proceedings of the 35th International Conference on Machine Learning (Proceedings of Machine Learning Research, Vol. 80). PMLR, Norfolk, MA, 5343–5352.
Feras A. Saad
A Technical Lemmas
Notation A.1. Let be a countable index set and be a family of measure spaces. The product measure space is defined by
In the product construction, if is infinite then the construction assumes . The coproduct (disjoint union) measure space is defined by
In the coproduct construction, if the sets are disjoint, we may implicitly take the disjoint union symbol to mean the regular (untagged) union of sets, otherwise it denotes the tagged union. «
Definition A.2. A set is called countably -rectifiable if there exists a family
of Lipschitz functions and a set such that
In particular, (almost) all of M can be traced out by only d parameters.
Remark A.3. If is a embedded manifold of dimension , then is countably -rectifiable with .
LEMMA A.4. If is countably -rectifiable, then is -finite.
PROOF. Decompose each set from (86) into bounded subsets for . As is Borel and is continuous, the image is analytic, and thus Hausdorff measurable. It also has finite measure from the Lipschitz bound
Let be the Lipschitz constant for . The Hausdorff-measure bound for Lipschitz maps [Federer 1996; Corollary 2.10.11] gives
As , by Borel regularity of we may enlarge and each to Borel supersets of the same measure. Intersecting these sets with gives a countable Borel cover of by sets of finite measure.
LEMMA A.5. If is countably -rectifiable, then for all .
PROOF. By Lemma A.4, is sigma-finite, so there exists a cover such that for each and . Therefore, for all [Federer 1996; 2.10.2(1)]. By countable additivity, we have .
LEMMA A.6. Let be open and be a function. If there exists such that for all , then is Borel and countably -rectifiable.
PROOF. By the constant-rank theorem, for each there exists an open neighborhood such that is a embedded -dimensional submanifold of , in particular it is Borel and countably -rectifiable. As has a countable base, choose points , such that covers . Then . As the union is countable, the conclusion follows.
LEMMA A.7. Let be measurable, let be open with , and let be . Suppose there is such that for all . Let , and . Define the Jacobian as the product of the first nonzero singular values of , with the convention when . Then for every ,
PROOF. This result follows from the coarea formula in Federer [1996; Theorem 3.2.22]. As the coarea formula is stated for Lipschitz maps, we establish the result for our assumption that is .
By Lemma A.6, is Borel and countably -rectifiable. Choose compact convex sets , , with , and define the Borel partition
Since is , its derivative is bounded on each . Thus is Lipschitz.
Each is Borel, hence countably -rectifiable and -measurable. Therefore the coarea formula from Federer [1996; Theorem 3.2.22] applies to . In particular, by the measurability assertion in the coarea formula, for every nonnegative Borel function , the map
is Borel measurable. Indeed, for every compact set , the map is Borel [Mattila and Mauldin 1997; Theorem 6.1]. These measures are finite on compact subsets of by the constant-rank assumption. A standard monotone-class argument on each extends the conclusion to every nonnegative Borel integrand.
In our setting, the approximate Jacobian in Federer agrees with the ordinary Jacobian . Applying coarea on with the function
gives
Summing over j and applying Tonelli's theorem yields
The Hausdorff measure agrees with the Lebesgue on by the standard normalization. ☐
Feras A. Saad
B Deferred Proofs
PROPOSITION 4.1 (RESTATED). A disintegration induces a regular conditional distribution on the probability space given the sigma algebra , by setting .
Proof. For , write for some . Then, for any , we have
The first equality follows by definition and the second by the fact that . The equality follows from the fiber-support condition , which implies that for fixed ,
Whence
THEOREM 4.2 (RESTATED). Let be a probability space with for a sigma-finite base measure . Let be measurable, , and a sigma-finite measure on . If is a disintegration of as in (41), then
4.2.1 The transition kernel is uniformly -finite, for -a.e. z.
4.2.2 The marginal distribution of Z satisfies , with density
4.2.3 The conditional distribution of X given Z satisfies , with density
Proof. To establish 4.2.1, we show there exists a countable cover of events , independent of , such that
(for -a.e.z and all ).
(99)
Since is -finite, let be a covering of such that for all . Define . Then
so for -a.e. . That is, for . Put , with . For any and every ,
which shows that is -finite for every .
To establish 4.2.2, for
where the second-to-last equality follows from the fact that lives on the fiber , so that the domain of integration in (103) is precisely
To show that , -almost surely, assume for contradiction that there exists a positive probability event , so that . As , it follows that , and so
which cannot hold, as is a probability measure. That has probability zero is immediate:
To establish 4.2.3, for
where the division by is secure, as we have shown that , -almost surely.
THEOREM 6.2 (RESTATED). The measure is sigma-finite.
PROOF. By Lemma A.6, the set is countably -rectifiable for each . Because is countable, is also countably -rectifiable. The result follows from Lemma A.4.
THEOREM 6.1 (RESTATED). For every and , the Lebesgue measure disintegrates as
Proof. Apply Lemma A.7 with , , , , , and .
THEOREM 6.3 (RESTATED). The prior base measure over disintegrates through as follows:
Feras A. Saad
Proof. Using Theorem 6.1, we have
For each , the coarea formula integrates over . Since , and the inner integral is zero for , we may extend each outer integral to . Thus, by Tonelli,
where is the inner fiber integral. The last equality holds by the definitions of and .
THEOREM 7.1 (RESTATED). The measure over is sigma-finite.
Proof. Observe the base measure is equal to a sum of restricted Hausdorff measures:
We show that each summand is sigma-finite. By Lemma A.6, each is countably -rectifiable, which implies the same for . Therefore and are both countably m-rectifiable. By Lemma A.4, the restricted measures are each sigma-finite.
We now construct a countable cover of Z by sets of finite -measure. The collection
is countable and pairwise disjoint. For each fix a countable cover such that . As the strata are disjoint, we have . Together with the complement of —which has -measure zero—the sets form a countable cover of . The conclusion follows.
PROPOSITION 7.2 (RESTATED). For each , let be the extension of the local base measure defined in Eq. (63) to the global measure space . Then and has density
where , with the convention .
Proof. Fix a path and event . As , it is sufficient to consider the strata inside the -summand. Consider the decomposition
Consider the following two cases on m.
(Case 1) For , as the are disjoint for each we have
(Case 2) For , the set is countably m-rectifiable by Lemma A.6. Therefore
because is countably m-rectifiable, which by Lemma A.5 has zero measure.
It follows that the only member in the decomposition of in (117) that has nonzero measure is the minimal stratum . Therefore
But on , the global base measure is precisely . Therefore
THEOREM 7.3 (RESTATED). The prior base measure over disintegrates through as follows:
for each , where .
Proof. The result follows from Theorem 6.3 and Proposition 7.2 and Tonelli's theorem:
(Theorem 6.3)
(123)
(Proposition 7.2)
(124)
(Tonelli's Theorem).
(125)
THEOREM 7.4 (RESTATED). Let be bounded and measurable, and be an observation with . Likelihood weighting is strongly consistent for , that is,
PROOF OF THEOREM 7.4. To fix notation, we are importance sampling the posterior distribution using a proposal distribution that performs ancestral sampling. For any pair of a path and addressed trace, let denote the product of the primitive densities of the constrained variables along the path. Let denote the fiber supporting the posterior distribution, and let be the restriction of the proposal to this fiber, so that . By the ancestral sampling property, we have
Therefore, and the importance weight
Feras A. Saad
is proportional to the usual likelihood weight from ancestral sampling, multiplied by the rank-selection indicator. Because is supported on , we can extend this density by 0 off to obtain the density with respect to the full proposal:
Let . We write the unnormalized weight as
noting that as only if , the factor in may be omitted.
We seek to estimate
The standard importance-sampling identity gives
Thus, the event
has positive -probability.
For the i.i.d. sequence of importance samples, define the events
The events are independent and identically distributed, so
By the second Borel–Cantelli lemma, occurs i.o., -a.s. In particular, the hitting time is finite:
Moreover, if , then , so by definition of , we must have . Therefore, for every , so for all sufficiently large , we have
As is bounded and , the strong law of large numbers gives
in the limit as , -a.s.
Because the limit in the denominator is positive, the ratio converges:
Finally, using the importance-sampling identity once more, the right-hand side is
C Singular Primitive Distributions
In our formalism from §5.1, the primitive distributions are by assumption either discrete or absolutely continuous with respect to Lebesgue measure. A more flexible approach would be to allow primitive distributions that are supported on parametrized lower dimension manifolds, for example the boundary of a circle with radius in . Our semantics avoids this additional generality because singular primitive distributions introduce significant complexities.
• A singular primitive distribution may not be dominated by any fixed -finite base measure.
- A singular primitive distribution must carry tangent-space data for its support in order to compute the appropriate Jacobian corrections.
Resolving these challenges requires adding significant geometric structure to the semantics that is not canonically part of the program text. We elaborate on these two issues.
Base Measure. A primitive distribution on a lower-dimensional manifold may not admit a unified base measure on which to define its densities. For example, suppose is a primitive such that is the uniform distribution on the circle . Suppose is a measure on such that for every . Then for uncountably many pairwise disjoint circles , so is not sigma-finite [Fremlin 2010; Proposition 215B].
As there is no sigma-finite global base measure , we may instead consider a parameterized family of sigma-finite measures for . In this case, the resulting parametrized densities no longer serve as meaningful likelihoods, because they are not defined with respect to a fixed base measure that is independent of . If the base measure depends on , then the densities are not comparable across different parameter values. For example, the rescaling
for some positive function leaves every distribution unchanged, but changes all the likelihood calculations involving . Therefore, handling primitives on lower-dimensional manifolds must either fix the support manifold and let parameters change only the density on that support, or provide a different representation such as sampling in intrinsic coordinates followed by a deterministic embedding (which may as well be performed in the probabilistic program itself).
In our semantics, the assumption that is either continuous or discrete (with counting or Lebesgue base measure) avoids these complexities, because the counting measure on every countable set is sigma-finite and is sigma-finite. Even if the support of varies with , all the distributions remain dominated by . For example, if is uniform over , then , and this density is valid with respect to the fixed base measure .
Coarea Jacobian. In a language with primitives over lower-dimensional manifolds, the domain of the observation maps for each and is not guaranteed to be a positive measure set. This generalization is compatible in principle with Federer [1996; Theorem 3.2.22], which only requires the domain of the function to be countably rectifiable.
In this setting, however, the coarea Jacobian in Eq. (58) is not a straightforward function of the standard derivative matrix in Eq. (57); it must measure volume change along .
Feras A. Saad
- If is a d-dimensional embedded manifold, then the ordinary derivative must be restricted to the tangent space . Equivalently, if is an orthonormal matrix whose columns form a basis for , then the relevant coarea Jacobian is the tangential Jacobian
where is the rank of the restricted derivative . With a non-orthonormal tangent basis, this same correction can be written using the Gram-determinant ratio, similarly to the manifold change-of-variables formula of Radul and Alexeev [2021; Theorem 1, Eq. (3)].
- If is not a manifold but only countably d-rectifiable, then the tangent space must be replaced by the approximate tangent space and the derivative by the approximate differential [Federer 1996; 3.2.16–3.2.19]. The corresponding Jacobian is that of the approximate differential, which appears in the coarea formulas for rectifiable sets [Federer 1996; 3.2.20, 3.2.22].
Our semantics avoids these complexities. By assuming that has nonzero Lebesgue measure, we ensure that the standard derivative matrix contains all the information needed to compute the coarea Jacobian (58). The underlying partial derivatives in (57) can be obtained by applying AD to the return expression. In the general setting, however, computing the coarea Jacobian requires not only added structure about the (approximate) tangent spaces, but also a “tangent-aware” AD method that propagates tangent bases through deterministic program expressions.