---
title: Executable Counterfactuals
url: https://www.emergentmind.com/topics/executable-counterfactuals
type: topic
---

# Executable Counterfactuals

Executable counterfactuals are minimal, plausibly implementable modifications to inputs, policies, plans, or trajectories that are not just hypothetical but are guaranteed to be actionable, physically realizable, and causally coherent under either mechanistic, data-driven, or sequential decision-making models. Unlike classical counterfactual explanations—which may simply identify a nearby alternative input that produces a different prediction—executable counterfactuals rigorously incorporate constraints and dynamics to ensure that the prescribed changes correspond to feasible interventions in the real or modeled world.

## 1. Formalization Across Dynamical, Structural, and Decision-Theoretic Frameworks

Executable counterfactuals arise in multiple modeling paradigms:

| Paradigm          | Core Object Modified      | Executability Criterion                       |
|-------------------|------------------------- |-----------------------------------------------|
| Control/Dynamical | Trajectories, controls   | System dynamics $\dot{x} = f(x, u)$, endpoints $x(T) = x_{\rm cf}$ reach desired outcome via feasible $u(t)$ [2501.12914] |
| MDP/Sequential    | Policies/Strategies      | Modified policy $\pi_{\rm cf}$ respects Markov constraints, reachability bounds, and is close (in total variation) to original [2505.09412, 2107.02776] |
| ML/Recourse       | Feature-modification sequences | Changes $e-x$ align with plausible, observed transitions in longitudinal data [2403.00105]; stepwise recourse actions are feasible and pass through high-density regions [2309.04211] |
| Causal/SCM        | Variables, units         | Intervention and abduction over latent variables; realizability under fundamental physical and experimental constraints [2503.11870, 1206.5294] |
| Planning          | Action sequences         | The plan $\pi = [a_1, ..., a_k]$ is executable, minimal, and achieves specified goal fluents within the agent's knowledge/model [2502.09205] |

Executable counterfactuals are distinguished by three interlocking requirements:
- **Validity:** They achieve the specified target (e.g., outcome flip, risk reduction, or goal satisfaction).
- **Plausibility/Feasibility:** Prescribed changes must conform to physical laws, system constraints, or empirically observed capabilities (e.g., what users have changed in real longitudinal datasets or what actions are allowed for the system under control).
- **Minimality/Sparsity:** The modifications are as small or as localized as possible, measured by norms (e.g., $\ell_1$, $\ell_0$, total variation), support size, or deviation from original actions or strategies.

## 2. Optimization and Algorithmic Foundations

### a. Sequential Decision Processes (Markov Decision Processes)
In the context of MDPs, executable counterfactuals are operationalized by repairing policies. Given a policy $\pi_\text{old}$ with undesirable risk (e.g., excessive probability of reaching a target $t$), the task is to find $\pi_\text{cf}$ that reduces risk below a threshold $\delta$, while $\pi_\text{cf}$ remains minimally perturbed from $\pi_\text{old}$ in state-action distributions. The problem is encoded as a nonconvex MIQCQP:
\[
\min_{\pi \in \Sigma_M} d(\pi_\text{old}, \pi)\;\;\; \text{s.t.}\;\; \Pr_M^{\pi}(s_0 \to t) \le \delta
\]
where $d(\cdot,\cdot)$ combines statewise total variation via $d_0$, $d_1$, $d_\infty$ norms [2505.09412]. The global optimal $\pi_\text{cf}$ may change only a sparse subset of state policies (sometimes a single node in large transition graphs), yielding interpretable recourse strategies.

### b. Finite-Horizon Sequential Explanations
For fixed realization trajectories in finite-horizon MDPs, counterfactuals can be synthesized subject to a fixed budget $k$ of modifications. Embedding the MDP in a Gumbel–Max SCM, the optimal alternative policy maximizing expected reward is computed via dynamic programming, ensuring that every counterfactual trajectory differs in no more than $k$ actions from the factual sequence [2107.02776]. The solution yields both a policy $\pi^*_\tau$ and explicit, executable action sequences for intervention.

### c. Control-Theoretic Objectives
Under control system formulations, executable counterfactuals are synthesized as optimal control trajectories $(x(t), u(t))_{t \in [0, T]}$ that respect the full system dynamics $\dot{x}=f(x,u)$ and reach a classifier-flipping set (e.g., safe vs. unsafe region) in minimum effort or time, strictly obeying underlying physics [2501.12914]. The problem is relaxed and solved via occupation measure LPs and moment-SOS hierarchies, producing both endpoint counterfactuals and full intervention schedules suitable to be enacted in the real system.

### d. Counterfactuals in ML Algorithmic Recourse
Local, sequential recourse methods such as LocalFACE generate executable counterfactuals by sequentially constructing dense, feasible action paths from a factual instance to a counterfactual prediction, subject to density and actionability constraints at every step [2309.04211]. Genetically optimized counterfactuals can be additionally filtered for executability by comparing their change vectors to longitudinal data, using normalized Euclidean (or Mahalanobis-type) distances to observed human transitions [2403.00105].

## 3. Causal, Realizability, and SCM Frameworks

From a structural causal model (SCM) perspective, executable counterfactuals require explicit abduction (inferring latents given observations), performing interventions on the chosen variables, and predicting under the altered model. The framework of executable counterfactuals for LLMs—anchored in SCM formalism—operationalizes abduction–action–prediction via code, requiring models to infer hidden variables, apply controlled interventions, and produce candidate outputs [2510.01539]. Evaluation, training, and code-based benchmarking enforce that generation traces truly correspond to this three-step process, not mere interventional or associative reasoning.

Realizability, as formalized in recent causal literature, codifies whether a given counterfactual distribution $P(\mathcal{W}_\star)$ is not only identifiable but "physically constructible" from experimental actions in the real world. The realization algorithm (CTF-REALIZE) checks, under the constraint of no time-travel and unit-consistency, when unit-level counterfactuals can be sampled directly under given experimental designs [2503.11870].

## 4. Diversity, Minimality, and Interpretability

Many frameworks explicitly optimize for diverse, sparse, and interpretable executable counterfactuals:
- **Policy diversity:** In sequential settings, diversity-promoting determinants are introduced into the objective to generate multiple, maximally "spread" strategies differing from the original policy and from each other [2505.09412].
- **Minimality guarantees:** Optimization objectives enforce $\ell_0$ (support-size), average ($d_1$), or maximum ($d_\infty$) total-variation distances to ensure counterfactuals change as few individual decisions as possible.
- **Trajectory coherence:** Explanations generated as plans or recourse sequences are only accepted if all intermediate steps are executable in the modeled system, leveraging feasibility checks at every planning or optimization stage [2502.09205, 2309.04211].

Sample scenario (loan-application MDP): Original policy yields high rejection risk; the counterfactual policy alters only the action distribution at the "Rework" state, switching "Submit" from $0.3$ to $0.86$ probability, cutting rejection risk from $0.411$ to $0.20$—with minimal, highly interpretable intervention [2505.09412].

## 5. Practical Implications, Empirical Findings, and Limitations

Empirical studies across domains confirm the benefits and nuances of executable counterfactuals:
- **Sequential domains:** In loan approval, music streaming, or service interaction logs, counterfactual strategy repair rapidly lowers undesirable outcome probabilities with extremely localized changes [2505.09412].
- **Clinical decision-making:** In cognitive behavioral therapy, optimal $k$-action-close counterfactual policies yield modest but actionable depression reduction improvements, with explanations remaining interpretable for small $k$ [2107.02776].
- **Control and physiological systems:** In glucose–insulin regulation, executable trajectories computed via SDPs achieve safe regimens minimizing intervention effort while strictly adhering to biological dynamics; further, endpoint counterfactuals concentrate near clinically relevant boundaries [2501.12914].
- **Algorithmic recourse:** Integration of longitudinal constraints guarantees recommendations never propose changes unobserved in the target population. However, stricter executability often narrows the set of valid counterfactuals and exposes populations for whom recourse is effectively unavailable under the model [2403.00105].

Principal limitations noted include reliance on exact transition probabilities, model knowledge, low-dimensional or discrete state/action spaces, and the intractability of extension to adversarial or partially observable settings in most current frameworks [2505.09412, 2107.02776, 2501.12914].

## 6. Generalizations and Theoretical Limits

Executable counterfactuals span all layers of the Pearl Causal Hierarchy, but realizability constraints impose strict boundaries:
- Certain counterfactual queries (e.g., $P(Y_x, Y_{x'})$ for two conflicting regimes) are proven non-realizable for a single unit under physical constraints and no time-reversal [2503.11870].
- In interventional versus counterfactual reasoning benchmarks for LLMs, there is a consistent $25$–$40$ percentage point accuracy drop, confirming that "execution"—full abduction plus intervention plus prediction—is significantly harder and more discriminating than mere intervention [2510.01539].
- In plan-based models, executability is guaranteed by construction in the returned action sequence; reconciliation between user and agent models is handled via explicit modal updates, refining the search space for feasible explanations [2502.09205].

## 7. Future Directions

Open research directions include:
- Extending frameworks to high-dimensional, continuous control, and adversarial or partially observable decision-making.
- Tight coupling of executable counterfactuals with learned or hybrid mechanistic–statistical models to bridge physics, data, and logical feasibilities.
- Enabling scalable, interactive generation—and verification—of counterfactual explanations in large, real-world systems, from robotics controllers to AI-assisted recourse for policy and medical interventions.
- Studying the integration of global constraints (fairness, safety, regulatory) and their enforcement through realizability-aware counterfactual planning [2503.11870, 2306.15328].

In sum, executable counterfactuals provide the mathematically principled bridge between hypothetical counterfactual reasoning and actionably grounded, intervention-compliant recommendations in dynamic, causal, and multi-step environments. These constructs unify control theory, causal inference, decision processes, and recourse under a rigorous executability criterion, enabling minimally invasive yet fully realizable intervention strategies across science and engineering domains.

Source: https://www.emergentmind.com/topics/executable-counterfactuals