Refuting Equivalence in Probabilistic Programs with Conditioning

Krishnendu Chatterjee, Ehsan Kafshdar Goharshady, Petr Novotný, Đorđe Žikelić

TL;DR

This paper introduces "weighted restarting," a novel program transformation technique that converts probabilistic programs with conditioning (observe and score statements) into output-equivalent, conditioning-free programs. By pairing this transformation with martingale-based analysis, the authors deliver the first fully automated, provably correct method to refute equivalence (i.e., prove that two programs produce different output distributions) in conditional probabilistic programs.

What Problem Does This Paper Address?

Probabilistic programs (PPs) describe complex statistical models by mixing standard code with random sampling. Unlike deterministic programs, a PP defines a probability distribution over its outputs. Verifying whether two PPs are equivalent—meaning they produce the exact same output distribution—is vital for tasks like verifying compiler optimizations or checking if a sampler behaves correctly. However, this problem is generally undecidable.

The challenge intensifies with conditioning via observe and score statements, which are fundamental to Bayesian inference. observe statements discard execution paths that violate specific constraints, while score statements dynamically scale the probability weights of specific paths. Prior automated techniques for refuting equivalence (proving two programs are different) only worked on conditioning-free programs. This paper bridges that gap, tackling the highly complex domain of conditional PPs.

Methods

The authors introduce a two-step framework to automate equivalence refutation:

  1. Weighted Restarting Transformation: This is the core innovation. The algorithm eliminates conditioning instructions by introducing a fresh weight variable, $W$, initialized to 1.
  2. observe(\phi) is replaced by code that sets $W := 0$ if $\phi$ is violated.
  3. score(e) multiplies $W$ by the expression $e$.
  4. At the end of the program, a "restarting block" is added. With a probability proportional to the accumulated weight ($W/M$, where $M$ is a known upper bound), the program terminates normally. Otherwise, the program resets all variables to their initial states and restarts from the beginning. The authors mathematically prove that this loop transformation yields a conditioning-free program with an identical output distribution.
  5. Martingale-Based Refutation & LP Solving: Once the program is conditioning-free, the method applies a template-based synthesis approach using Upper and Lower Expectation Supermartingales (U/LESMs). The algorithm searches for a "witness function" $f$ over the outputs such that the expected value of $f$ is provably different between the two programs. This search is encoded into polynomial constraints and solved efficiently in polynomial time using Linear Programming (LP) via Handelman’s theorem.

Crucially, the authors prove that their underlying proof rule is both sound and complete, meaning a witness always exists if the programs are non-equivalent.

Datasets

The authors evaluated their prototype tool on three distinct benchmark sets:

  • PSI Inference Suite: 12 discrete probabilistic programs frequently used to test exact inference tools (e.g., bertrand, burglarAlarm, gossip).
  • Loopy Programs: 18 programs featuring complex loop structures drawn from termination analysis literature, modified to include an observe statement at the end.
  • Symbolic Inference Benchmarks: 11 program pairs from recent literature specifically designed to test PPs containing score statements (e.g., random walk variants like rdwalk).

Key Insights and Ideas

  • Simulating Conditioning via Resets: Instead of tracking complex, normalized conditional density functions through loops symbolically, "weighted restarting" physically mimics the conditioning mechanism by discarding or repeating paths. This elegantly reduces a conditional analysis problem to an unconditional one.
  • Static Analysis Beats Exact Inference: Traditional exact inference tools try to compute the exact symbolic output distribution, which hits a massive computational bottleneck when loops are involved. By looking for a witness function via supermartingales, this method bypasses the need to compute the exact distribution entirely.
  • Completeness in an Undecidable Domain: While checking program equivalence is undecidable, the authors prove their refutation system is semi-complete. If a polynomial witness of degree $D$ exists to prove two programs differ, their algorithm is guaranteed to find it.

Key Results

The method was evaluated against a baseline pipeline consisting of the state-of-the-art exact inference tool PSI combined with Mathematica.

  • Higher Success Rate: The new method successfully refuted 34 out of 41 non-equivalent program pairs, whereas the PSI+Mathematica baseline only managed 12 out of 41.
  • Loop Mastery: On the loopy benchmark set, the baseline failed completely (0/18) due to timeouts from symbolic execution bottlenecks. The new method successfully refuted 12 out of 18.
  • Handling Scores: The baseline could not handle the third dataset because PSI does not natively support score statements. The new method successfully refuted 10 out of 11 pairs.
  • Efficiency: The average runtime for successful refutations was a swift 11.8 seconds.

Limitations and Future Work

  • Dependency on Invariant Generators: The framework relies on external tools (like STING and ASPIC) to generate supporting linear invariants. If these tools fail or take too long (e.g., taking over 2 minutes on the coupon4 benchmark), the entire pipeline slows down.
  • Polynomial Constraints: The current automation requires all program arithmetic and synthesized martingales to be polynomial. It cannot currently handle programs requiring non-polynomial witnesses (such as the Species Fight benchmark, which timed out).
  • Future Directions: The authors suggest extending the automation to non-polynomial programs and exploring how the "weighted restarting" transformation can be applied to other types of static analyses for conditional PPs.

Summary updated

Abstract

We consider the problem of refuting equivalence of probabilistic programs, i.e., the problem of proving that two probabilistic programs induce different output distributions. We study this problem in the context of programs with conditioning (i.e., with observe and score statements), where the output distribution is conditioned by the event that all the observe statements along a run evaluate to true, and where the probability densities of different runs may be updated via the score statements. Building on a recent work on programs without conditioning, we present a new equivalence refutation method for programs with conditioning. Our method is based on weighted restarting, a novel transformation of probabilistic programs with conditioning to the output equivalent probabilistic programs without conditioning that we introduce in this work. Our method is the first to be both a) fully automated, and b) providing provably correct answers. We demonstrate the applicability of our method on a set of programs from the probabilistic inference literature.
BibTeX
@inproceedings{chatterjee2025refuting,
  author = {Krishnendu Chatterjee and Ehsan Kafshdar Goharshady and Petr Novotný and Đorđe Žikelić},
  title = {{Refuting Equivalence in Probabilistic Programs with Conditioning}},
  booktitle = {TACAS},
  year = {2025},
  doi = {10.1007/978-3-031-90653-4\_14},
}
Figure