Expected Shapley-Like Scores of Boolean Functions:
Complexity and Applications to Probabilistic Databases

PRATIK KARMAKAR, National University of Singapore, Singapore and CNRS@CREATE Ltd, Singapore

MIKAËL MONET, Inria, France and CRISTAL, Université de Lille, CNRS, France

PIERRE SENELLART*, DI ENS, ENS, PSL University, CNRS, France, Inria, France, and IUF, France

STÉPHANE BRESSAN*, National University of Singapore, Singapore

Shapley values, originating in game theory and increasingly prominent in explainable AI, have been proposed to assess the contribution of facts in query answering over databases, along with other similar power indices such as Banzhaf values. In this work we adapt these Shapley-like scores to probabilistic settings, the objective being to compute their expected value. We show that the computations of expected Shapley values and of the expected values of Boolean functions are interreducible in polynomial time, thus obtaining the same tractability landscape. We investigate the specific tractable case where Boolean functions are represented as deterministic decomposable circuits, designing a polynomial-time algorithm for this setting. We present applications to probabilistic databases through database provenance, and an effective implementation of this algorithm within the ProvSQL system, which experimentally validates its feasibility over a standard benchmark.

CCS Concepts: • Mathematics of computing → Probabilistic representations; • Information systems → Relational database model; • Theory of computation → Algorithmic game theory and mechanism design.

Additional Key Words and Phrases: Shapley value, Banzhaf value, probabilistic database, provenance, knowledge compilation, d-D circuit

# 1 INTRODUCTION

The *Shapley value* is a popular notion from cooperative game theory, introduced by Lloyd Shapley [37]. Its idea is to “fairly” distribute the rewards of a game among the players. The Banzhaf power index [8], another power distribution index with different weights, also plays an important role in voting theory. These are two instances of power indices for coalitions, which also include the Johnston [20, 21], Deegan-Packel [15], and Holler-Packel indices [18], see [27] for a survey. Shapley and Banzhaf values, in particular, have found recent applications in explainable machine learning [23, 40] and valuation of data inputs in data management [2, 17].

In this work, we revisit the computation of such values (which we call *Shapley-like* values or scores) in a setting where data is uncertain. A long line of work [11–13, 25, 28, 32, 41] has studied various ways in which scoring mechanisms can be incorporated in a probabilistic setting. More specifically, the authors of [11] propose the notion of *expected Shapley value* and show that this is the only scoring mechanism satisfying a certain set of axioms in a probabilistic setting. Motivated by this, we extend their notion to other scores (e.g., Banzhaf), and study the complexity of the associated computational problems.

Our objective is then to investigate the tractability of expected Shapley-like value computations for Boolean functions, having in mind the potential application of computation of expected Shapley-like values of facts for a query over probabilistic databases. In particular, some results have been obtained in the literature that reduces the complexity of (non-probabilistic) Shapley-value computation to and from the computation of the model count of a Boolean function (or to the computation

<footnote>*Also with CNRS@CREATE Ltd & IPAL, CNRS.</footnote>
of the probability of a query in probabilistic databases) under some technical conditions [17, 22]; we aim at understanding this connection better by investigating whether *expected Shapley*-(-like) value computation, which combines the computation of a power index and a probabilistic setting, is harder than each of these aspects taken in isolation.

We provide the following contributions. First (in Section 2), we formally introduce the notion of Shapley-like scores and of the expected value of such scores on Boolean functions whose variables are assigned independent probabilities. In Section 3, we investigate the connection between the computation of expected Shapley-like scores and the computation of the expected value of a Boolean function. In particular, we show a very general result (Corollary 3.7) that expected Shapley value computation is interreducible in polynomial time to the expected value computation problem over any class of Boolean functions for which it is possible to compute its value over the empty set in polynomial time; we also obtain a similar result (Corollary 3.12) for the computation of expected Banzhaf values. We then assume in Section 4 that we have a tractable representation of a Boolean function as a decomposable and deterministic circuit; in this case, we show a concrete polynomial-time algorithm for Shapley-like score computation (Algorithm 1) and some simplifications thereof for specific settings. We then apply in Section 5 these results to the case of probabilistic databases, showing (Corollary 5.3) that expected Shapley value computation is interreducible in polynomial time to probabilistic query evaluation. In Section 6 we show through an experimental evaluation that the algorithms proposed in this paper are indeed feasible in practical scenarios. Before concluding the paper, we discuss related work in Section 7.

For space reason, some proofs are relegated to the appendix.

## 2 PRELIMINARIES

For $n \in \mathbb{N}$ we write $[n] \stackrel{\text{def}}{=} \{0, \dots, n\}$. We denote by $\mathbf{P}$ the class of problems solvable in polynomial time. For a set $V$, we denote by $2^V$ its powerset.

*Boolean functions.* A Boolean function over a finite set of variables $V$ is a mapping $\varphi : 2^V \to \{0, 1\}$. To talk about the complexity of problems over a class of Boolean functions, one must first specify how functions are specified as input. By a class of Boolean functions, we then mean a class of representations of Boolean functions; for instance, truth tables, decision trees, Boolean circuits, and so on, with any sensible encoding. In particular, we consider that the size of $V$ is always provided in unary as part of the input. Let $\varphi : 2^V \to \{0, 1\}$ and $x \in V$. We denote by $\varphi_{+x}$ (resp., $\varphi_{-x}$) the Boolean function on $V \setminus \{x\}$ that maps $Z \subseteq V \setminus \{x\}$ to $\varphi(Z \cup \{x\})$ (resp., to $\varphi(Z)$).

*Expected value.* For each $x \in V$, let $p_x \in [0, 1]$ be a probability value. For $V' \subseteq V$ and $Z \subseteq V'$, define $\Pi_{V'}(Z)$ to be the probability of $Z$ being drawn from $V'$ under the assumption that every $x \in V'$ is chosen independently with probability $p_x$. Formally: $\Pi_{V'}(Z) \stackrel{\text{def}}{=} (\prod_{x \in Z} p_x) \times (\prod_{x \in V' \setminus Z} (1-p_x))$. The $p$-values do not appear in the notation $\Pi_{V'}(Z)$: this is to simplify notation. For $\varphi : 2^V \to \{0, 1\}$, define then the *expected value of $\varphi$* as $\text{EV}(\varphi) \stackrel{\text{def}}{=} \sum_{Z \subseteq V} \Pi_V(Z)\varphi(Z)$. Note that this is simply the probability of $\varphi$ being true. We then define the corresponding problem for a class of Boolean functions $\mathcal{F}$.

PROBLEM : $\text{EV}(\mathcal{F})$ (Expected Value)

INPUT : A Boolean function $\varphi \in \mathcal{F}$ over variables $V$ and probability values $p_x$ for each $x \in V$

OUTPUT : The quantity $\text{EV}(\varphi)$
<table><caption>Table 1. (Expected) Shapley values for $\phi_{ex} = (A \wedge a) \vee (C \wedge c)$</caption><thead><tr><th>x &isin; V</th><th>p<sub>x</sub></th><th>Score<sub>c<sub>Shapley</sub></sub>(&phi;<sub>ex</sub>, V, x)</th><th>EScore<sub>c<sub>Shapley</sub></sub>(&phi;<sub>ex</sub>, x)</th></tr></thead><tbody><tr><td>A</td><td>0.4</td><td>0.25</td><td>0.076</td></tr><tr><td>a</td><td>0.5</td><td>0.25</td><td>0.076</td></tr><tr><td>C</td><td>0.6</td><td>0.25</td><td>0.216</td></tr><tr><td>c</td><td>0.8</td><td>0.25</td><td>0.216</td></tr></tbody></table>

Here, we consider as usual that the probabilities values are rational numbers $\frac{p}{q}$ for $(p, q) \in \mathbb{N} \times (\mathbb{N} \setminus \{0\})$, provided as ordered pairs $(p, q)$ where $p$ and $q$ themselves are encoded in binary.

**EXAMPLE 2.1.** Consider the Boolean function in disjunctive normal form: $\phi_{ex} = (A \wedge a) \vee (C \wedge c)$ on variables $\{A, a, C, c\}$. Assume the probabilities for these variables given in the second column of Table 1. Then its expected value can be computed (since $\phi_{ex}$ is read-once as: $EV(\phi_{ex}) = 1 - (1 - 0.4 \times 0.5) \times (1 - 0.6 \times 0.8) = 1 - 0.8 \times 0.52 = 0.584$.

*Shapley-like scores.* Let $c: \mathbb{N} \times \mathbb{N} \to \mathcal{Q}$ be a function, that we call the coefficient function, and let $\phi: 2^V \to \{0, 1\}$ and $x \in V$. Define the *Shapley-like score* with coefficients $c$ of $x$ in $V$ with respect to $\phi$, or simply *score* when clear from context, by

$$ \text{Score}_c(\phi, V, x) \stackrel{\text{def}}{=} \sum_{E \subseteq V \setminus \{x\}} c(|V|, |E|) \times [\phi(E \cup \{x\}) - \phi(E)]. $$

**EXAMPLE 2.2.** Let $c_{\text{Shapley}}(k, \ell) \stackrel{\text{def}}{=} \frac{\ell!(k-1-\ell)!}{k!} = \binom{k-1}{\ell}^{-1}k^{-1}$ and $c_{\text{Banzhaf}}(k, \ell) \stackrel{\text{def}}{=} 1$. Then, by definition, $\text{Score}_{c_{\text{Shapley}}}(\phi, V, x)$ (resp., $\text{Score}_{c_{\text{Banzhaf}}}(\phi, V, x)$) is the usual Shapley (resp., Banzhaf) value, with set of players $V$ and wealth function $\phi$. The Penrose-Banzhaf power [24], a normalization of Banzhaf values, can also be defined by coefficients $(k, \ell) \mapsto 2^{-k+1}$.

For each fixed coefficient function $c$ and class of Boolean functions $\mathcal{F}$, we define the corresponding computational problem.

PROBLEM: $\text{Score}_c(\mathcal{F})$

INPUT: A Boolean function $\phi \in \mathcal{F}$ over variables $V$, a variable $x \in V$

OUTPUT: The quantity $\text{Score}_c(\phi, V, x)$

*Expected Shapley-like scores.* We now introduce the probabilistic variant of Shapley-like scores, which is our main object of study.

**DEFINITION 2.3.** Let $c$ be a coefficient function, $\phi: 2^V \to \{0, 1\}$ a Boolean function over variables $V$, probability values $p_y$ for $y \in V$, and $x \in V$. Define the expected score of $x$ for $\phi$ as:

$$ \text{EScore}_c(\phi, x) \stackrel{\text{def}}{=} \sum_{\substack{Z \subseteq V \\ x \in Z}} (\Pi_V(Z) \times \text{Score}_c(\phi, Z, x)), $$

where in $\text{Score}_c(\phi, Z, x)$ we see $\phi$ as a function from $2^Z$ to $\{0, 1\}$.

In words, this is the expected value of the corresponding score, when players are independently selected to be part of the cooperative game. Notice that subsets $Z \subseteq V$ not containing $x$ are not summed over: this is because in this case $x$ is not a player of the selected game and we thus declare its “contribution” to be null. We point out that the notion of expected Shapley value has been defined and studied in [11] in terms of the properties that it satisfies. The authors show that this
is the only value satisfying some natural sets of axioms, making it a natural candidate for score attribution in a probabilistic setting. This definition is also strongly motivated by its applications to probabilistic databases (cf. Section 5). We then define the corresponding computational problem, for a fixed $c$ and $\mathcal{F}$.

PROBLEM : $EScore_c(\mathcal{F})$ (Expected Score)

INPUT : A Boolean function $\varphi \in \mathcal{F}$ over variables $V$, probability values $p_y$ for each $y \in V$, a variable $x \in V$

OUTPUT : The quantity $EScore_c(\varphi, x)$

**EXAMPLE 2.4.** Continuing from Example 2.1, we can compute the Shapley value and the expected Shapley value of variables appearing in $\varphi_{ex}$. By symmetry, it is easy to see that all variables have the same Shapley value; on the other hand the expected Shapley values depend on the probability of each clause to be true. See Table 1 for all (expected) Shapley values. If other variables were in $V$, their Shapley and expected Shapley values w.r.t. $\varphi_{ex}$ would be 0, regardless of their probabilities, since they do not play a role in the satisfaction of $\varphi_{ex}$.

*Reductions.* For two computational problems $A$ and $B$, we write $A \le_P B$ to assert the existence of a polynomial-time Turing reduction from $A$ to $B$, i.e., a polynomial-time reduction that is allowed to use $B$ as an oracle. We write $A \equiv_P B$ when $A \le_P B$ and $B \le_P A$, meaning that the problems are equivalent under such reductions. Using this notation we can state a first trivial fact:

**FACT 2.5.** We have $Score_c(\mathcal{F}) \le_P EScore_c(\mathcal{F})$ for any coefficient function $c$ and class of Boolean functions $\mathcal{F}$.

This is simply because $EScore_c(\varphi, x) = Score_c(\varphi, V, x)$ when $p_y = 1$ for all $y \in V$, so that our probabilistic variants of such scores are proper generalizations of the non-probabilistic ones.

# 3 EQUIVALENCE WITH EXPECTED VALUES

In this section we link the complexity of computing expected Shapley-like scores with that of computing expected values. The point is that $EV(\mathcal{F})$ is a central problem that has already been studied in depth for most meaningful classes of Boolean functions, with classes for which that problem is in P while the general problem is #P-hard. In a sense then, if we can show for some problem $A$ that $A \equiv_P EV(\mathcal{F})$, this settles the complexity of $A$. We start in Section 3.1 by the direction most interesting for efficient algorithms: from expected scores to expected values. We show that this is always possible, under the assumption that the coefficient function is computable in polynomial time. We then give results for the other direction in Section 3.2, where the picture is more complex.

## 3.1 From Expected Scores to Expected Values

Let us call a coefficient function $c$ tractable if $c(k, \ell)$ can be computed in P when $k$ and $\ell$ are given in unary as input. It is easy to see that $c_{Banzhaf}$ and its normalized version are tractable. This is also the case of $c_{Shapley}$, using the fact that the $\binom{k}{\ell}$ binomial coefficient can be computed in time $O(k \times \ell)$ by dynamic programming (assuming arguments in unary). Under this assumption, we show that computing expected Shapley-like scores reduces in polynomial time to computing expected values.

**THEOREM 3.1.** We have $EScore_c(\mathcal{F}) \le_P EV(\mathcal{F})$ for any tractable coefficient function $c$ and any class $\mathcal{F}$ of Boolean functions.

We obtain for instance that $EScore_c(\mathcal{F})$ is in P for decision trees, ordered binary decision diagrams (OBDDs), deterministic and decomposable Boolean circuits, Boolean circuits of bounded treewidth [4], and so on, since $EV(\mathcal{F})$ is in P for these classes. By Fact 2.5, this also recovers the
results from [2, 17, 22] that (non-expected) Shapley and Banzhaf scores are in P for the tractable classes that they consider.

We prove Theorem 3.1 in the remaining of this section. To do so, we first define two intermediate problems.

**PROBLEM:** $\text{EV}_\star(\mathcal{F})$ (Expected Value of Fixed Size)

**INPUT:** A Boolean function $\varphi \in \mathcal{F}$ over variables $V$, probabilities $p_x$ for each $x \in V$, and $k \in [|V|]$

**OUTPUT:** The quantity $\text{EV}_k(\varphi) \stackrel{\text{def}}{=} \sum_{|Z|=k} \Pi_V(Z)\varphi(Z)$

**PROBLEM:** $\text{ENV}_{\star,\star}(\mathcal{F})$ (Expected Nested Value of Fixed Sizes)

**INPUT:** A Boolean function $\varphi \in \mathcal{F}$ over $V$, probabilities $p_x$ for each $x \in V$, and integers $k, \ell \in [|V|]$

**OUTPUT:** The quantity $\text{ENV}_{k,\ell}(\varphi) \stackrel{\text{def}}{=} \sum_{|Z|=k} \Pi_V(Z) \sum_{|E|=\ell} \varphi(E)$

Notice that $\text{ENV}_{k,\ell}(\varphi) = 0$ when $k < \ell$. Also, observe that $\text{EV}(\varphi) = \sum_{k=0}^{|V|} \text{EV}_k(\varphi)$ and that $\text{EV}_k(\varphi) = \text{ENV}_{k,k}(\varphi)$, so that $\text{EV}(\mathcal{F}) \leq_P \text{ENV}_\star(\mathcal{F}) \leq_P \text{ENV}_{\star,\star}(\mathcal{F})$ for any $\mathcal{F}$.

We now prove the chain of reductions $\text{EScore}_c(\mathcal{F}) \leq_P \text{ENV}_{\star,\star}(\mathcal{F})$ for any tractable coefficient function $c$ and any class of Boolean functions $\mathcal{F}$.

**LEMMA 3.2.** *We have $\text{EScore}_c(\mathcal{F}) \leq_P \text{ENV}_{\star,\star}(\mathcal{F})$ for any tractable coefficient function $c$ and any class of Boolean functions $\mathcal{F}$.*

**PROOF.** Let $\varphi: 2^V \to \{0,1\}$ in $\mathcal{F}$, probability values $p_y$ for $y \in V$, and $x \in V$. We wish to compute $\text{EScore}_c(\varphi, x)$. Observe that $\text{EScore}_c(\varphi, x) = A - B$, where

$$A = \sum_{Z \subseteq V} \Pi_V(Z) \sum_{x \in Z \setminus \{x\}} c(|Z|, |E|)\varphi(E \cup \{x\})$$

$$B = \sum_{Z \subseteq V} \Pi_V(Z) \sum_{x \in Z \setminus \{x\}} c(|Z|, |E|)\varphi(E).$$

Let us focus on A. Letting $V' \stackrel{\text{def}}{=} V \setminus \{x\}$, notice that these are the variables over which $\varphi_{+x}$ is defined. Letting $n \stackrel{\text{def}}{=} |V'|$, we have

$$A = \sum_{Z \subseteq V} \Pi_V(Z) \sum_{x \in Z \setminus \{x\}} c(|Z|, |E|)\varphi_{+x}(E) = p_x \sum_{Z \subseteq V'} \Pi_{V'}(Z) \sum_{x \in Z} c(|Z| + 1, |E|)\varphi_{+x}(E)$$

$$= p_x \sum_{Z \subseteq V'} \sum_{E \subseteq Z} c(|Z| + 1, |E|)\Pi_{V'}(Z)\varphi_{+x}(E) = p_x \sum_{k=0}^{n} \sum_{Z \subseteq V'} \sum_{|Z|=k}^{k} \sum_{|E|=\ell} c(k+1, \ell)\Pi_{V'}(Z)\varphi_{+x}(E)$$

$$= p_x \sum_{k=0}^{n} \sum_{\ell=0}^{k} c(k+1, \ell) \sum_{\substack{Z \subseteq V' \\ |Z|=k}} \sum_{\substack{E \subseteq Z \\ |E|=\ell}} \Pi_{V'}(Z)\varphi_{+x}(E) = p_x \sum_{k=0}^{n} \sum_{\ell=0}^{k} c(k+1, \ell)\text{ENV}_{k,\ell}(\varphi_{+x}).$$

We can do exactly the same for $B$ (replacing $\varphi_{+x}$ by $\varphi_{-x}$), after which we obtain:

$$\text{EScore}_c(\varphi, x) = p_x \sum_{k=0}^{n} \sum_{\ell=0}^{k} c(k+1, \ell) (\text{ENV}_{k,\ell}(\varphi_{+x}) - \text{ENV}_{k,\ell}(\varphi_{-x})). \quad (1)$$
We can compute the coefficients $c(k+1, \ell)$ in $P$ because $c$ is tractable. Therefore, all that is left to show is that we can compute in $P$ all the values $ENV_{k,l}(\varphi_{+x})$ and $ENV_{k,l}(\varphi_{-x})$ for $k, \ell \in [n]$. We point out that this is not obvious, because $\mathcal{F}$ might not be closed under conditioning, and unfortunately setting $p_x$ to 0 or 1 is not enough to directly give us the values we want. In [22], this annoying subtlety is handled by using the closure under OR-substitutions of the class $\mathcal{F}$ (see the proof of their Lemma 3.2). In our case, we will overcome this problem by using the fact that we can freely choose the probabilities.

Let $z \in [0, 1]$, and for $y \in V' = V \setminus \{x\}$ define $p_y^z \stackrel{\text{def}}{=} p_y$, and $p_x^z = z$. Define $\Pi^z$ and $ENV_{\star,\star}^z(\varphi)$ as expected. We claim that the following equation holds, for $i, j \in [n+1]$:

$$ \mathrm{ENV}_{i,j}^{z}(\varphi) = z[\mathrm{ENV}_{i-1,j}(\varphi_{-x}) + \mathrm{ENV}_{i-1,j-1}(\varphi_{+x})] + (1-z)\mathrm{ENV}_{i,j}(\varphi_{-x}), \quad (2) $$

where we extended the definition of $ENV_{\star,\star}(\varphi_{+x})$ and $ENV_{\star,\star}(\varphi_{-x})$ to have value zero for out-of-bound $(i, j)$-indices. Before proving this claim, let us explain why this allows us to conclude. Indeed, we can then use the oracle to $ENV_{\star,\star}(\mathcal{F})$ with $z=0$ to compute all the values $ENV_{k,l}(\varphi_{-x})$. Once these are known, we use the oracle again but this time with $z=1$, and thanks to Equation (2) again we can recover all the values $ENV_{k,l}(\varphi_{+x})$.

Therefore, all that is left to do is prove Equation (2). We have:

$$ \mathrm{ENV}_{i,j}^{z}(\varphi) \stackrel{\text{def}}{=} \sum_{\substack{Z \subseteq V \\ |Z|=i}} \Pi_{V}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi(E) = \underbrace{\sum_{\substack{Z \subseteq V \\ x \notin Z}} \Pi_{V}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi(E)}_{\alpha} + \underbrace{\sum_{\substack{Z \subseteq V \\ |Z|=i}} \Pi_{V}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi(E)}_{\beta} $$

With $\alpha$ and $\beta$ the two terms defined above, we have:

$$ \alpha = (1-z) \sum_{\substack{Z \subseteq V' \\ |Z|=i}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi(E) = (1-z) \sum_{\substack{Z \subseteq V' \\ |Z|=i}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi_{-x}(E) = (1-z) \mathrm{ENV}_{i,j}(\varphi_{-x}). $$

Let us now inspect $\beta$.

$$ \beta = z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \cup \{x\} \\ |E|=j}} \varphi(E) = z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \cup \{x\} \\ |E|=j \ x \notin E}} \varphi(E) + z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \cup \{x\} \\ |E|=j \ x \in E}} \varphi(E). $$

Again with $\alpha'$ and $\beta'$ two terms above, we have:

$$ \alpha' = z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j}} \varphi_{-x}(E) = z \times \mathrm{ENV}_{i-1,j}(\varphi_{-x}), $$

and

$$ \beta' = z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j-1}} \varphi(E \cup \{x\}) = z \sum_{\substack{Z \subseteq V' \\ |Z|=i-1}} \Pi_{V'}(Z) \sum_{\substack{E \subseteq Z \\ |E|=j-1}} \varphi_{+x}(E) = z \times \mathrm{ENV}_{i-1,j-1}(\varphi_{+x}). $$

Putting it all together, we indeed obtain Equation (2), thus concluding the proof. $\square$

<figure><img src="image_1.png" /></figure>

The following lemma contains the most technical part of the proof of Theorem 3.1. It is proved using polynomial interpolation with carefully crafted probability values.

**LEMMA 3.3.** We have $ENV_{\star,\star}(\mathcal{F}) \le_P EV_{\star}(\mathcal{F})$ for any $\mathcal{F}$.
PROOF. Let $\varphi \in \mathcal{F}$ over variables $V$, probability values $p_x$ for each $x \in V$, and $k, \ell \in [|V|]$. Let $n \stackrel{\text{def}}{=} |V|$. Our goal is to compute $\text{ENV}_{k,\ell}(\varphi)$. We will in fact use polynomial interpolation to compute all the values $\text{ENV}_{j,\ell}(\varphi)$ for $j \in [n]$, and return $\text{ENV}_{k,\ell}(\varphi)$.

Let $z_0, \dots, z_n$ be $n+1$ distinct positive values in $\mathbb{Q}$. For $i \in [n]$ and $x \in V$, define $c_x^{z_i} \stackrel{\text{def}}{=} 2z_i p_x + 1 - p_x$ and $p_x^{z_i} \stackrel{\text{def}}{=} \frac{z_i p_x}{c_x^{z_i}}$, and define $\Pi^{z_i}$ and $\text{EV}^{z_i}(\varphi)$ as expected. Notice that these are all valid probability mappings, i.e., all values $p_x^{z_i}$ are well-defined and between 0 and 1, and observe that $1 - p_x^{z_i} = \frac{(z_i p_x) + (1 - p_x)}{c_x^{z_i}}$. Define further $C_{z_i} \stackrel{\text{def}}{=} \prod_{x \in V} c_x^{z_i}$. Then:

$$ 
\begin{aligned}
\text{EV}_{\ell}^{z_i}(\varphi) &= \sum_{\substack{E \subseteq V \\ |E| = \ell}} \Pi_{V}^{z_i}(E) \varphi(E) = \sum_{\substack{E \subseteq V \\ |E| = \ell}} \varphi(E) \prod_{x \in E} p_x^{z_i} \prod_{x \in V \setminus E} (1 - p_x^{z_i}) \\
&= \frac{1}{C_{z_i}} \sum_{\substack{E \subseteq V \\ |E| = \ell}} \varphi(E) \prod_{x \in E} z_i p_x \prod_{x \in V \setminus E} [(z_i p_x) + (1 - p_x)].
\end{aligned}
$$

Next we develop the innermost product as it is parenthesized and distribute the $\prod_{x \in E} z_i p_x$ term, obtaining:

$$ 
\begin{aligned}
\text{EV}_{\ell}^{z_i}(\varphi) &= \frac{1}{C_{z_i}} \sum_{\substack{E \subseteq V \\ |E| = \ell}} \varphi(E) \sum_{\substack{E \subseteq Z \subseteq V \\ |E| = \ell}} \prod_{x \in Z} z_i p_x \prod_{x \in V \setminus Z} (1 - p_x) \\
&= \frac{1}{C_{z_i}} \sum_{\substack{E \subseteq V \\ |E| = \ell}} \varphi(E) \sum_{j=0}^{n} \sum_{\substack{E \subseteq Z \subseteq V \\ |Z|=j}} \prod_{x \in Z} z_i p_x \prod_{x \in V \setminus Z} (1 - p_x) \\
&= \frac{1}{C_{z_i}} \sum_{\substack{E \subseteq V \\ |E| = \ell}} \varphi(E) \sum_{j=0}^{n} z_i^j \sum_{\substack{E \subseteq Z \subseteq V \\ |Z|=j}} \Pi_V(Z) \\
&= \frac{1}{C_{z_i}} \sum_{j=0}^{n} z_i^j \sum_{\substack{E \subseteq V \\ |E|=\ell}} \varphi(E) \sum_{\substack{E \subseteq Z \subseteq V \\ |Z|=j}} \Pi_V(Z). \\
&= \frac{1}{C_{z_i}} \sum_{j=0}^{n} z_i^j \text{ENV}_{j,\ell}(\varphi),
\end{aligned}
\quad (3) $$

where in the last equality we have inverted the two innermost sums. Using the oracle to $\text{EV}_\star(\mathcal{F})$, we compute $c_i \stackrel{\text{def}}{=} C_{z_i} \times \text{EV}_{\ell}^{z_i}(\varphi)$ for $i \in [n]$ in polynomial time. By Equation (3), this gives us a system of linear equations $AX = C$, with $C_i \stackrel{\text{def}}{=} c_i$, $X_j \stackrel{\text{def}}{=} \text{ENV}_{j,\ell}(\varphi)$ and $A_{ij} \stackrel{\text{def}}{=} z_i^j$. We see that $A$ is a non-singular Vandermonde matrix, so we can in polynomial time recover all the values $X_j$ and return $\text{ENV}_{k,\ell}(\varphi)$, as promised. This concludes the proof. $\square$

We can finally state the last step of the proof of Theorem 3.1, again proved using polynomial interpolation.

**LEMMA 3.4.** We have $\text{EV}_\star(\mathcal{F}) \le_P \text{EV}(\mathcal{F})$ for any $\mathcal{F}$.

PROOF. Let $\varphi \in \mathcal{F}$ over variables $V$, probability values $p_x$ for each $x \in V$, and $k \in [|V|]$. Let $n \stackrel{\text{def}}{=} |V|$. We wish to compute $\text{EV}_k(\varphi)$. We use again polynomial interpolation to compute all the values $\text{EV}_j(\varphi)$ for $j \in [n]$ and return $\text{EV}_k(\varphi)$.
Let $z_0, \dots, z_n$ be $n+1$ distinct positive values in $\mathbb{Q}$. For $i \in [n]$ and $x \in V$, define $c_x^{z_i} \stackrel{\text{def}}{=} 1 - p_x + z_i p_x$, define $p_x^{z_i} \stackrel{\text{def}}{=} \frac{z_i p_x}{c_x^{z_i}}$, and define $\Pi^{z_i}$ and $EV^{z_i}(\varphi)$ as expected. Again, these are all valid probability mappings, and observe that this time $1 - p_x^{z_i} = \frac{1-p_x}{c_x^{z_i}}$. Defining as before $C_{z_i} \stackrel{\text{def}}{=} \prod_{x \in V} c_x^{z_i}$, it is this time much easier to derive the equality $EV^{z_i}(\varphi) = \frac{1}{C_{z_i}} \sum_{j=0}^n z_i^j EV_j(\varphi)$:

$$
\begin{align*}
EV^{z_i}(\varphi) &\stackrel{\text{def}}{=} \sum_{Z \subseteq V} \Pi_V^{z_i}(Z)\varphi(Z) = \sum_{j=0}^{n} \sum_{\substack{Z \subseteq V \\ |Z|=j}} \Pi_V^{z_i}(Z)\varphi(Z) \\
&= \sum_{j=0}^{n} \sum_{\substack{Z \subseteq V \\ |Z|=j}} \varphi(Z) \prod_{x \in Z} p_x^{z_i} \prod_{x \in V \setminus Z} (1-p_x^{z_i}) = \frac{1}{C_{z_i}} \sum_{j=0}^{n} \sum_{\substack{Z \subseteq V \\ |Z|=j}} \varphi(Z) z_i^{|Z|} \prod_{x \in Z} p_x \prod_{x \in V \setminus Z} (1-p_x) \\
&= \frac{1}{C_{z_i}} \sum_{j=0}^{n} z_i^j \sum_{\substack{Z \subseteq V \\ |Z|=j}} \varphi(Z) \Pi_V(Z) = \frac{1}{C_{z_i}} \sum_{j=0}^{n} z_i^j EV_j(\varphi).
\end{align*}
$$

We can then conclude just like in the proof of Lemma 3.3. $\square$

<figure><img src="image_2.png" /></figure>

## 3.2 From Expected Values to Expected Scores

In this section we show reductions in the other direction for $c_{\text{Shapley}}$ and $c_{\text{Banzhaf}}$, under additional assumptions on the class $\mathcal{F}$.

*Shapley score.* Let us call a class of Boolean functions $\mathcal{F}$ *reasonable* if the following problem is in P: given as input (a representation of) $\varphi \in \mathcal{F}$, compute $\varphi(\emptyset)$. It is clear that all classes mentioned in this paper are reasonable in that sense. Then, under this assumption:

**PROPOSITION 3.5.** We have $EV(\mathcal{F}) \leq_P EScore_{c_{\text{Shapley}}}(\mathcal{F})$ for any reasonable class $\mathcal{F}$ of Boolean functions.

*PROOF.* For $\varphi: 2^Z \to \{0, 1\}$, it is well known that the efficiency property holds:

$\sum_{x \in Z} \text{Score}_{c_{\text{Shapley}}}(\varphi, Z, x) = \varphi(Z) - \varphi(\emptyset)$. Let then $\varphi \in \mathcal{F}$ over variables $V$ and probability values $p_x$ for each $x \in V$; our goal is to compute $EV(\varphi)$. We have:

$$
\begin{align}
\sum_{x \in V} \text{EScore}_{c_{\text{Shapley}}}(\varphi, x) &= \sum_{x \in V} \sum_{\substack{Z \subseteq V \\ x \in Z}} \Pi_V(Z) \times \text{Score}_{c_{\text{Shapley}}}(\varphi, Z, x) \nonumber \\
&= \sum_{Z \subseteq V} \sum_{x \in Z} \Pi_V(Z) \times \text{Score}_{c_{\text{Shapley}}}(\varphi, Z, x) \nonumber \\
&= \sum_{Z \subseteq V} \Pi_V(Z) [\varphi(Z) - \varphi(\emptyset)] \nonumber \\
&= EV(\varphi) - \varphi(\emptyset). \tag{4}
\end{align}
$$

We note this is what [11, Axiom 9] calls *expected efficiency*, with the slight difference that they only consider cases in which $\varphi(\emptyset) = 0$. We can compute the left-hand size in P using oracle calls, and we can compute $\varphi(\emptyset)$ in P as well because $\mathcal{F}$ is reasonable, therefore we can compute $EV(\varphi)$ in P indeed. This concludes the proof. $\square$

<figure><img src="image_3.png" /></figure>

**EXAMPLE 3.6.** The sum of all expected Shapley values in Table 1 is 0.584; as $\varphi_{\text{ex}}(\emptyset) = 0$, this is exactly $EV(\varphi_{\text{ex}})$ computed in Example 2.1.
This implies, for instance, that $EScore_{c_{\text{Shapley}}}(\mathcal{F})$ is intractable over arbitrary circuits, even monotone bipartite 2-DNF formulas [33]. Combining with Theorem 3.1, we obtain in particular:

**COROLLARY 3.7.** We have $EScore_{c_{\text{Shapley}}}(\mathcal{F}) \le_P \text{EV}(\mathcal{F})$ for any reasonable class $\mathcal{F}$ of Boolean functions.

Hence, at least with respect to polynomial-time computability, this settles the complexity of $EScore_{c_{\text{Shapley}}}(\mathcal{F})$ for such classes.

**Banzhaf score.** Next, we show a similar result for the Banzhaf value, under a different, though commonplace, assumption.

**DEFINITION 3.8.** A class $\mathcal{F}$ is said to be closed under conditioning if the following problem is in P: given $\varphi \in \mathcal{F}$ over variables $V$ and $x \in V$, compute a representation in $\mathcal{F}$ of $\varphi_{+x}$. We say $\mathcal{F}$ is closed under conjunctions (resp., disjunctions) with fresh variables if the following is in P: given $\varphi \in \mathcal{F}$ over variables $V$ and $x \notin V$, compute a representation in $\mathcal{F}$ of the Boolean function $\varphi \wedge x$ (resp., $\varphi \vee x$).

**PROPOSITION 3.9.** We have $\text{EV}(\mathcal{F}) \le_P \text{EScore}_{c_{\text{Banzhaf}}}(\mathcal{F})$ for any class $\mathcal{F}$ that is closed under conditioning and that is also closed under either conjunctions or disjunctions with fresh variables.

This implies that $EScore_{c_{\text{Banzhaf}}}$ is intractable, for instance, over monotone 2-CNFs or monotone 2-DNFs.

Proposition 3.9 requires more work than Proposition 3.5: we do it in two steps by introducing (yet) another intermediate problem.

**PROBLEM:** $\text{ENV}(\mathcal{F})$ (Expected Nested Value)

**INPUT:** A Boolean function $\varphi \in \mathcal{F}$ over variables $V$ and probability values $p_x$ for each $x \in V$

**OUTPUT:** The quantity $\text{ENV}(\varphi) \stackrel{\text{def}}{=} \sum_{Z \subseteq V} \Pi_V(Z) \sum_{E \subseteq Z} \varphi(E)$

The next two lemmas then imply Proposition 3.9.

**LEMMA 3.10.** We have $\text{ENV}(\mathcal{F}) \le_P \text{EScore}_{c_{\text{Banzhaf}}}(\mathcal{F})$ for any $\mathcal{F}$ closed under conjunctions (resp., disjunctions) with fresh variables.

**PROOF SKETCH.** First, for $\varphi' : 2^V \to \{0, 1\}$ and $x \in V'$, we prove the equation

$$ \mathrm{EScore}_{c_{\text{Banzhaf}}}(\varphi', x) = p_x[\mathrm{ENV}(\varphi'_{+x}) - \mathrm{ENV}(\varphi'_{-x})]. \quad (5) $$

Let then $\varphi : 2^V \to \{0, 1\}$ be the Boolean function for which we want to compute $\text{ENV}(\varphi)$, and let $x \notin V$ be a fresh variable. We use the closure property of $\mathcal{F}$ to compute a representation of $\varphi' \stackrel{\text{def}}{=} \varphi \odot x$, with $\odot$ being $\wedge$ or $\vee$ depending on the closure property. We then show using Equation (5) that $\text{ENV}(\varphi)$ can be recovered from the single oracle call $\text{EScore}_{c_{\text{Banzhaf}}}(\varphi', x)$, with $V' \stackrel{\text{def}}{=} V \cup \{x\}$, with same probability values for $y \in V$ and $p_x = 1$. $\square$

**LEMMA 3.11.** We have $\text{EV}(\mathcal{F}) \le_P \text{ENV}(\mathcal{F})$ for any class $\mathcal{F}$ that is closed under conditioning.

**PROOF SKETCH.** This is again a rather technical proof by polynomial interpolation, in which we curiously seem to need the assumption of closure under conditioning. $\square$

And thus, combining with Theorem 3.1, we obtain:

**COROLLARY 3.12.** We have $\text{EScore}_{c_{\text{Banzhaf}}}(\mathcal{F}) \equiv_P \text{EV}(\mathcal{F})$ for any class $\mathcal{F}$ that is closed under conditioning and that is also closed under either conjunctions or disjunctions with fresh variables.

We leave as future work a more systematic (tedious) study of when $\text{EV}(\mathcal{F}) \le_P \text{EScore}_c(\mathcal{F})$ holds for other coefficient functions.
# 4 DD CIRCUITS

We now present algorithms to compute expected Shapley-like scores in polynomial time over deterministic and decomposable Boolean circuits. Since computing expected values can be done in linear time over such circuits, the fact that computing expected Shapley-like scores over them is in P is already implied by our main result, Theorem 3.1. We nevertheless present more direct algorithms for these circuits as they are easier and more natural to implement than the convoluted chain of reductions with various oracle calls and matrix inversions from the previous section. We will moreover use these algorithms in our experimental evaluation in Section 6. We start by defining what are these circuits.

**Boolean circuits.** Let $C$ be a Boolean circuit over variables $V$, featuring $\land, \lor, \neg$, constant $0$- and $1$-gates, and variable gates (i.e., gates labeled by a variable in $V$), with $\land$- and $\lor$-gates having arbitrary fan-in greater than 1. We write $\text{Vars}(C) \subseteq V$ the set of variables that occur in the circuit. The size $|C|$ of $C$ is its number of wires. For a gate $g$ of $C$, we write $C_g$ the subcircuit rooted at $g$, and write $\text{Vars}(g)$ its set of variables. An $\land$-gate $g$ of $C$ is *decomposable* if for every two input gates $g_1 \neq g_2$ of $g$, $\text{Vars}(g_1) \cap \text{Vars}(g_2) = \emptyset$. We call $C$ *decomposable* if all $\land$-gates in it are. An $\lor$-gate $g$ of $C$ is *deterministic* if the Boolean functions captured by each pair of distinct input gates of $g$ are pairwise disjoint; i.e., there is no assignment that satisfies them both. We call $C$ *deterministic* if all $\lor$-gates in it are. A *deterministic and decomposable (d-D) Boolean circuit* [31] is a Boolean circuit that is both deterministic and decomposable. An $\lor$-gate $g$ is *smooth* if for any input $g'$ of $g$ we have $\text{Vars}(g) = \text{Vars}(g')$, and $C$ is smooth is all its $\lor$-gates are. We say that $C$ is *tight* if it satisfies the following three conditions: (1) $\text{Vars}(C) = V$; (2) $C$ is smooth; and (3) every $\land$ and every $\lor$ gate of $C$ has exactly two children.

**EXAMPLE 4.1.** The formula $\varphi_{\text{ex}} = (A \land a) \lor (C \land c)$ from our running example is not a d-D when interpreted as a circuit, since the $\lor$ gate is not deterministic. An equivalent d-D is for example $\neg[\neg(A \land a) \land \neg(C \land c)]$, interpreted as a circuit in the natural way.

The following is folklore.

**LEMMA 4.2.** *Given as input a d-D circuit $C$ over variables $V$, we can compute in $O(|C| \times |V|)$ a d-D circuit $C'$ over $V$ that is equivalent to $C$ and that is tight.*

*General polynomial-time algorithm.* It is thus enough to explain how to compute expected Shapley-like scores for tight d-Ds; let $C$ be such a circuit on variables $V$. We start from Equation (1), restated here for convenience:

$$ \text{EScore}_c(C, x) = p_x \sum_{k=0}^{|V|-1} \sum_{\ell=0}^{k} c(k+1, \ell) (\text{ENV}_{k,\ell}(C_1) - \text{ENV}_{k,\ell}(C_0)). $$

Here, $C_1$ (resp., $C_0$) is the circuit $C$ in which we have replaced every variable gate labeled by $x$ by a constant 1-gate (resp., a constant 0-gate). It can easily be checked that $C_0$ and $C_1$ are tight d-Ds over $V \setminus \{x\}$. Therefore, it suffices to compute, for an arbitrary tight d-D circuit $C'$, the $\text{ENV}_{\star,\star}$ quantities. To do this, we crucially need the determinism and decomposability properties. The idea is to compute corresponding quantities for each gate of the circuit, in a bottom-up fashion. This is similar to what is done in [6, Theorem 2] and [17, Proposition 4.4], but the expressions we obtain are more involved because we have a quadratic number of parameters for each gate of the circuit, as opposed to a linear number of such parameters in these earlier works. The resulting algorithm for the whole procedure is shown in Algorithm 1. Intuitively, the values $\beta_{k,\ell}^g$ correspond to the $\text{ENV}_{k,\ell}$-values for the subcircuit of $C_1$ rooted at gate $g$, the values $\gamma_{k,\ell}^g$ correspond to those for $C_0$, and $\delta$ values are intermediate quantities that we have to compute. Thus:
**THEOREM 4.3.** Let $c$ be a tractable coefficient function. Given a d-D circuit $C$ on variables $V$, probability values $p_y$ for $y \in V$, and $x \in V$, Algorithm 1 correctly computes $EScore_c(C, x)$ in polynomial time. Moreover, if we ignore the cost of arithmetic operations, it is in time $O(|C| \times |V|^5 + T_c(|V|) \times |V|^2)$ where $T_c(\alpha)$ is the cost of computing the coefficient function on inputs $\le \alpha$.

We can show that the number of bits of numerators and denominators of the $\beta$, $\gamma$ and $\delta$ values is roughly $O(b \times |V|)$, for $b$ the bound on the number of bits of numerators and denominators of all $p_y$ values. Therefore to obtain the exact complexity, without ignoring the time to perform additions and multiplications over such numbers, one has to add an $O(b \times |V|)$ multiplicative factor.

In the case where all probabilities are identical, we can obtain a lower complexity by reusing techniques from [17]:

**PROPOSITION 4.4.** Let $c$ be a tractable coefficient function. Given a d-D circuit $C$ on variables $V$, a unique probability value $p = p_y$ for all $y \in V$, and $x \in V$, $EScore_c(C, x)$ can be computed in time $O(|V|^2 \times (|C| |V| + |V|^2 + T_c(|V|)))$ assuming unit-cost arithmetic.

**Quadratic-time algorithm for expected Banzhaf score.** For the expected Shapley value, instantiating Algorithm 1 with $c = c_{\text{Shapley}}$ seems to be the best that we can do. For the expected Banzhaf value however, we can design a more efficient algorithm. We start from Equation (5), restated here in terms of circuits:

$$EScore_{c_{\text{Banzhaf}}}(C, x) = p_x[\text{ENV}(C_1) - \text{ENV}(C_0)]. \quad (6)$$

We can show that $\text{ENV}$ can be computed in linear time over tight d-D circuits, thus obtaining a $O(|C| \times |V|)$ complexity for $EScore_{c_{\text{Banzhaf}}}$ over arbitrary d-D circuits by Lemma 4.2:

**THEOREM 4.5.** Given a d-DC on variables $V$, probability values $p_y$ for $y \in V$, and $x \in V$, we can compute in time $O(|C| \times |V|)$ (ignoring the cost of arithmetic operations) the quantity $EScore_{c_{\text{Banzhaf}}}(C, x)$.

*Comparing to and recovering the algorithms of [17] and [2].* We end this section by discussing how this relates to the algorithms proposed in [17] and [2], respectively for Shapley and Banzhaf value computation in a deterministic (non-probabilistic) setting.

First, we note that we can specialize Algorithm 1 to the computation of Shapley values by setting all $p_y$ to 1, which means that, when computing $\text{ENV}_{k,l}$-values, we only need to consider the case where $k = n$ as all $Z \subseteq V$ with $|Z| < n$ have $\Pi_V(Z) = 0$. This leads to the following simplifications: $\delta_k^g$ values need not be computed as they are all 0's except for $\delta_{|\text{Vars}(g)|}^g = 1$; similarly, $\beta_{k,l}^g$ and $\gamma_{k,l}^g$ values need only be computed when $k = |\text{Vars}(g)|$, all other being set to 0. This simplifies the computation to remove a factor of $|V|^2$, and we essentially recover the algorithm described in [17]. Note that the final complexity obtained is $O(|C| \times |V|^3)$, which is better than the complexity from Proposition 4.4.

Second, we observe that the algorithm underlying Theorem 4.5 has the same complexity as the exact algorithm in [2] for computing (non-expected) Banzhaf values. We note that [2] considers decomposition trees instead of d-D circuits, but any decomposition tree is in fact a d-D circuit in disguise, since a decomposable OR of the form $A \lor B$ can be rewritten as $\neg(\neg A \land \neg B)$, with the AND being decomposable. Their algorithm works in linear time on decomposition trees that are tight (see their Section 3.1), hence we obtain the same complexity while solving a seemingly more general problem: we study the *expected* Banzhaf values (which degenerates to the non-expected setting when all probabilities are 1), and d-D circuits are more general than decomposition trees as they allow sharing of subexpressions (i.e., the circuit is a DAG instead of a tree).

# 5 PROBABILISTIC DATABASES

(Probabilistic) databases and queries. Let $\Sigma = \{R_1, \dots, R_n\}$ be a signature, consisting of relation names each with their associated *arity* $\text{ar}(R_i) \in \mathbb{N}$, and Const be a set of constants. A *fact* over
**Algorithm 1:** Expected Shapley-like scores for deterministic and decomposable Boolean circuits

**Input:** A d-D C on variables V, probability values $p_y$ for $y \in V$, and $x \in V$.

**Output:** The value $EScore_c(C, x)$

1. Let $n' = |V| - 1$ and let $g_{out}$ be the output gate of C;

2. Make C tight using Lemma 4.2, and call it C again;

3. Compute values $\delta_k^g$ for every gate $g$ in C and $k \in [n']$ by bottom-up induction on C as follows:

4. **if** $g$ is a constant gate or a variable gate with $Vars(g) = \{x\}$ **then**

5. $\delta_0^g \leftarrow 1$ and $\delta_k^g \leftarrow 0$ for $k \ge 1$;

6. **else if** $g$ is a variable gate with $Vars(g) = \{y\}$ and $y \ne x$ **then**

7. $\delta_0^g \leftarrow 1 - p_y$, $\delta_1^g \leftarrow p_y$, and $\delta_k^g \leftarrow 0$ for $k \ge 2$;

8. **else if** $g$ is a $\neg$-gate with input gate $g'$ **then**

9. $\delta_k^g \leftarrow \delta_k^{g'}$ for $k \in [n']$;

10. **else if** $g$ is an $\vee$-gate with input gates $g_1, g_2$ **then**

11. $\delta_k^g \leftarrow \delta_k^{g_1}$ for $k \in [n']$;

12. **else if** $g$ is an $\wedge$-gate with input gates $g_1, g_2$ **then**

13. $\delta_k^g \leftarrow \sum_{k_1=0}^k \delta_{k_1}^{g_1} \delta_{k-k_1}^{g_2}$ for $k \in [n']$;

14. **end**

15. Compute values $\beta_{k,l}^g$ and $\gamma_{k,l}^g$ for every gate $g$ in C and $k, l \in [n']$ by bottom-up induction on C:

16. **if** $g$ is a constant $a$-gate ($a \in \{0, 1\}$) **then**

17. $\beta_{0,0}^g, \gamma_{0,0}^g \leftarrow a$, and $\beta_{k,l}^g, \gamma_{k,l}^g \leftarrow 0$ for $(k, l) \ne (0, 0)$;

18. **else if** $g$ is a variable gate with $Vars(g) = \{x\}$ **then**

19. $\beta_{0,0}^g \leftarrow 1, \gamma_{0,0}^g \leftarrow 0$, and $\beta_{k,l}^g, \gamma_{k,l}^g \leftarrow 0$ for $(k, l) \ne (0, 0)$;

20. **else if** $g$ is a variable gate with $Vars(g) = \{y\}$ and $y \ne x$ **then**

21. $\beta_{0,0}^g, \beta_{1,0}^g, \gamma_{0,0}^g, \gamma_{1,0}^g \leftarrow 0, \beta_{1,1}^g, \gamma_{1,1}^g \leftarrow p_x$, and $\beta_{k,l}^g, \gamma_{k,l}^g \leftarrow 0$ for all other values of $k, l$;

22. **else if** $g$ is a $\neg$-gate with input gate $g'$ **then**

23. $\beta_{k,l}^g \leftarrow (k) \delta_k^g - \beta_{k,l}^{g'}$ for $k, l \in [n']$;

24. $\gamma_{k,l}^g \leftarrow (k) \delta_k^g - \gamma_{k,l}^{g'}$ for $k, l \in [n']$;

25. **else if** $g$ is an $\vee$-gate with input gates $g_1, g_2$ **then**

26. $\beta_{k,l}^g \leftarrow \beta_{k,l}^{g_1} + \beta_{k,l}^{g_2}$ for $k, l \in [n']$;

27. $\gamma_{k,l}^g \leftarrow \gamma_{k,l}^{g_1} + \gamma_{k,l}^{g_2}$ for $k, l \in [n']$;

28. **else if** $g$ is an $\wedge$-gate with input gates $g_1, g_2$ **then**

29. $\beta_{k,l}^g \leftarrow \sum_{k_1=0}^k \sum_{\ell_1=0}^{k_1} \beta_{k_1,\ell_1}^{g_1} \times \beta_{k-k_1,\ell-\ell_1}^{g_2}$ for $k, l \in [n']$;

30. $\gamma_{k,l}^g \leftarrow \sum_{k_1=0}^k \sum_{\ell_1=0}^{k_1} \gamma_{k_1,\ell_1}^{g_1} \times \gamma_{k-k_1,\ell-\ell_1}^{g_2}$ for $k, l \in [n']$;

31. **end**

32. **return** $p_x \sum_{k=0}^{n'} \sum_{\ell=0}^{k} c(k+1, \ell) (\beta_{k,\ell}^{g_{out}} - \gamma_{k,\ell}^{g_{out}})$;
<table><caption>Table 2. A TID with two relations Students and Grades</caption><thead><tr><th colspan="5">Students</th><th colspan="4">Grades</th></tr><tr><th>ID</th><th>Name</th><th>Age</th><th>Prob.</th><th>Prov.</th><th>ID</th><th>Grade</th><th>Prob.</th><th>Prov.</th></tr></thead><tbody><tr><td>01</td><td>Alice</td><td>20</td><td>0.4</td><td>A</td><td>01</td><td>86</td><td>0.5</td><td>a</td></tr><tr><td>02</td><td>Bob</td><td>21</td><td>0.3</td><td>B</td><td>02</td><td>80</td><td>0.2</td><td>b</td></tr><tr><td>03</td><td>Charlie</td><td>22</td><td>0.6</td><td>C</td><td>03</td><td>92</td><td>0.8</td><td>c</td></tr><tr><td>04</td><td>Danny</td><td>25</td><td>0.8</td><td>D</td><td>04</td><td>99</td><td>0.9</td><td>d</td></tr></tbody></table>

(Σ, Const) is a term of the form $R(a_1, ..., a_{ar(R)})$, for $R \in \Sigma$ and $a_i \in \text{Const}$. A $(\Sigma, \text{Const})$-database D (or simply a *database D*) is a finite set of facts over $(\Sigma, \text{Const})$. We assume familiarity with the most common classes of query languages and refer the reader to [1, 7] for the basic definitions. A Boolean query is a query $q$ that takes as input a database D and outputs $q(D) \in \{0, 1\}$. If $q(\bar{x})$ is a query with free variables $\bar{x}$ and $\bar{t}$ is a tuple of constants of appropriate length, we denote by $q[\bar{x}/\bar{t}]$ the Boolean query defined by $q[\bar{x}/\bar{t}](D) = 1$ if and only if $\bar{t}$ is in the output of $q(\bar{x})$ on D. A *tuple-independent probabilistic database*, or TID for short, consists of a database D together with probability values $p_f$ for every fact $f \in D$. For a Boolean query $q$ and TID D = (D, ($p_f$)$_{f \in D}$), the probability that D satisfies $q$, written $\text{Pr}(D \models q)$, is defined as $\text{Pr}(D \models q) \stackrel{\text{def}}{=} \sum_{D' \subseteq D \text{ s.t. } q(D')=1} \text{Pr}(D')$, where $\text{Pr}(D')$ is $\prod_{f \in D'} p_f \times \prod_{f \in D \setminus D'} (1-p_f)$. For a fixed Boolean query $q$, we denote by PQE($q$) the computational problem that takes as input a TID D and outputs $\text{Pr}(D \models q)$.

(Expected) Shapley-like scores. Let $c: \mathbb{N} \times \mathbb{N} \rightarrow \mathbb{Q}$ be a coefficient function, $q$ a Boolean query, $D$ a database and $f \in D$ a fact. Following the literature [17, 29, 30], we define the Shapley-like score with coefficients $c$ of $f$ in $D$ with respect to $q$, or simply score when clear, by<fnref n="1" /> $\text{Score}_c(q, D, f) \stackrel{\text{def}}{=} \sum_{E \subseteq D \setminus \{f\}} c(|D|, |E|) \times [q(E \cup \{f\}) - q(E)]$. We denote by $\text{Score}_c(q)$ the corresponding computational problem. Let now $\mathbf{D} = (D, (p_f)_{f \in D})$ be a TID and $f \in D$, and define the *expected score of $f$ for $q$ in $\mathbf{D}$* as:

$$ \text{EScore}_c(q, D, f) \stackrel{\text{def}}{=} \sum_{Z \subseteq D, f \in Z} (\text{Pr}(Z) \times \text{Score}_c(q, Z, f)), $$

where in $\text{Score}_c(q, Z, f)$ we see $q$ as a function from $2^Z$ to $\{0, 1\}$. Define the problem $\text{EScore}_c(q)$ as expected. Note that all of this matches our definitions of expected values, Shapley-like and expected Shapley-like scores for Boolean functions.

**EXAMPLE 5.1.** Consider the TID shown in Table 2. The probability of each tuple is shown in the next-to-last column of each table, and a tuple identifier used as a provenance token in the last one. Consider the Boolean query $q_{\text{ex}}$ over these tables expressed in SQL as: "SELECT DISTINCT 1 FROM Students s JOIN Grades g ON s.ID = g.ID WHERE Age < 23 AND Grade >= 85". Its Boolean provenance [35] can be computed to be exactly the DNF formula $\varphi_{\text{ex}} = (A \land a) \lor (C \land c)$ from the running example. Its probability is thus 0.584, as computed in Example 2.1. The expected Shapley value of every tuple contributing to making $q_{\text{ex}}$ true is given in Table 1.

As usual, if the query $q(\bar{x})$ has free variables, for a tuple $\bar{t}$ of appropriate length we can define similarly, for $f \in D$, the expected score of $f$ by using the Boolean query $q[\bar{x}/\bar{t}]$ in the above definition. This score then represents the contribution of $f$ to $\bar{t}$ potentially being in the query result (one might in particular be interested in explaining why a tuple is *not* in the query result).

<footnote n="1">¹We point out that the facts of D are traditionally partitioned between *endogenous* and *exogenous* facts, but we do not make this distinction in our work. This is to simplify the presentation, as usual definitions would extend in a straightforward manner.</footnote>
Then Theorem 3.1 directly translates into this setting of Shapley-like scores of facts over probabilistic databases:

**THEOREM 5.2.** We have $EScore_c(q) \le_P PQE(q)$ for any tractable coefficient function $c$ and any Boolean query $q$.

**PROOF.** It suffices to instantiate Theorem 3.1 with the set of Boolean functions $\mathcal{F}_q \stackrel{\text{def}}{=} \{\varphi_{q,D} \mid D \text{ is a database}\}$, where $\varphi_{q,D} : 2^D \to \{0,1\}$, the Boolean provenance [35] of query $q$ over $D$, is defined by $\varphi_{q,D}(D') \stackrel{\text{def}}{=} q(D')$ for $D' \subseteq D$. Here, it is implicit that the Boolean function $\varphi_{q,D}$ is represented by $D$ itself. $\square$

In the case of the Shapley value, we can even get a full equivalence from Corollary 3.7:

**COROLLARY 5.3.** We have $EScore_{c_{\text{Shapley}}}(q) \equiv_P PQE(q)$ for any Boolean query $q$.

**PROOF.** One direction is Theorem 5.2. The other direction comes from Corollary 3.7, using the same $\mathcal{F}_q$ as in the proof of Theorem 5.2, and noticing that $\mathcal{F}_q$ is reasonable because the query is fixed. $\square$

In particular, this gives a dichotomy on $EScore_{c_{\text{Shapley}}}(q)$ between P and #P-hard for unions of conjunctive queries (UCQs), or more generally for queries that are closed under homomorphisms [3, 14]. This should be compared with the corresponding result for (non-expected) $Score_{c_{\text{Shapley}}}(q)$, where a dichotomy is currently only known for self-join-free conjunctive queries [22, 29].

For Banzhaf values, even though $EScore_{c_{\text{Banzhaf}}}(q) \le_P PQE(q)$ is true for any Boolean query by Theorem 5.2, it is not clear how to obtain the other direction from Proposition 3.9: indeed, the class $\mathcal{F}_q$ from above has in general no reason to be closed under conditioning nor under taking conjunctions or disjunctions with fresh variables. Yet, we mention that [29, Proposition 5.6] shows a dichotomy for (non-expected) $Score_{c_{\text{Banzhaf}}}(q)$ for self-join-free CQs: the tractable queries are the hierarchical queries, while for non-hierarchical queries the problem is #P-hard. This dichotomy then directly extends to $EScore_{c_{\text{Banzhaf}}}(q)$: the tractable side follows from our Theorem 5.2 because $PQE(q)$ is in P for hierarchical queries, while the hardness result is inherited by Fact 2.5 from the hardness of $Score_{c_{\text{Banzhaf}}}(q)$ shown in [29].

*Provenance computation and compilation.* Unfortunately, not all queries are tractable for probabilistic query evaluation. When faced with an intractable query, another approach is to use the *intensional method* [38], which is to compute and compile the Boolean provenance of the query on the database in a formalism from knowledge compilation that enjoys tractable computation of expected values, such as d-D circuits. When the provenance has been computed as a d-D circuit, we can use the results from Section 4 to compute the expected Shapley-like scores. This is the route that we take in the next section to compute these scores in practice.

# 6 IMPLEMENTATION AND EXPERIMENTS

In this section, we experimentally show that the computation of expected Shapley-like scores is feasible in practice on some realistic queries over probabilistic databases, despite the #P-hardness of the problem in general and the high $O(|C| \times |V|^5)$ upper bound (see Theorem 4.3) on the complexity of Algorithm 1 for d-Ds. The objective is not to provide a comprehensive experimental evaluation but to simply validate that algorithms presented in this work have reasonable complexity for practical applications.
<table><caption>Table 3. Provenance computation time, knowledge compilation time and method, and total Shapley/Banzhaf computation time for all output tuples and all facts, in the deterministic case and for expected values in the probabilistic case. The queries are the same TPC-H queries used in [17] (without the LIMIT operator used in [17]). All times reported are in seconds.</caption><thead><tr><th>TPC-H query</th><th># Output tuples</th><th>Provenance time</th><th>Compilation time</th><th>Compilation method</th><th>Avg d-D #gates</th><th>Shapley time Determ.</th><th>Shapley time Expect.</th><th>Banzhaf time Expect.</th></tr></thead><tbody><tr><td>3</td><td>11620</td><td>2.125 ± 0.029</td><td>1.226 ± 0.008</td><td>33% dec., 67% tree dec.</td><td>22</td><td>0.762 ± 0.005</td><td>1.758 ± 0.011</td><td>0.468 ± 0.002</td></tr><tr><td>5</td><td>5</td><td>1.117 ± 0.022</td><td>0.044 ± 0.000</td><td>100% tree dec.</td><td>1115</td><td>0.766 ± 0.001</td><td>40.910 ± 0.447</td><td>0.191 ± 0.000</td></tr><tr><td>7</td><td>4</td><td>1.215 ± 0.053</td><td>0.017 ± 0.000</td><td>100% tree dec.</td><td>750</td><td>0.269 ± 0.001</td><td>9.381 ± 0.020</td><td>0.085 ± 0.000</td></tr><tr><td>10</td><td>1783</td><td>1.229 ± 0.023</td><td>0.018 ± 0.000</td><td>98% dec., 2% tree dec.</td><td>5</td><td>0.023 ± 0.000</td><td>0.037 ± 0.000</td><td>0.015 ± 0.000</td></tr><tr><td>11</td><td>61</td><td>0.174 ± 0.023</td><td>0.001 ± 0.000</td><td>87% dec., 13% tree dec.</td><td>7</td><td>0.001 ± 0.000</td><td>0.002 ± 0.000</td><td>0.001 ± 0.000</td></tr><tr><td>16</td><td>466</td><td>0.247 ± 0.027</td><td>0.084 ± 0.000</td><td>100% tree dec.</td><td>65</td><td>0.159 ± 0.001</td><td>0.455 ± 0.005</td><td>0.094 ± 0.001</td></tr><tr><td>18</td><td>91159</td><td>2.711 ± 0.298</td><td>0.749 ± 0.005</td><td>97% dec., 3% tree dec.</td><td>4</td><td>0.655 ± 0.002</td><td>1.008 ± 0.007</td><td>0.490 ± 0.003</td></tr><tr><td>19</td><td>56</td><td>1.223 ± 0.239</td><td>0.000 ± 0.000</td><td>100% dec.</td><td>3</td><td>0.000 ± 0.000</td><td>0.000 ± 0.000</td><td>0.000 ± 0.000</td></tr></tbody></table>

*Implementation.* We rely on, and have extended, ProvSQL [36]<fnref n="2" />, an open-source PostgreSQL extension that computes (between other things) the Boolean provenance of a query over a database. We let ProvSQL compute the Boolean provenance of SQL queries over relational databases as a Boolean circuit, and have extended this system to add the following features: (1) We compile Boolean provenance into a d-D in the simple but common decomposable case where every ∧- or ∨-gate *g* is decomposable, i.e., for every two inputs *g*₁ and *g*₂ to *g*, Vars(*g*₁) ∩ Vars(*g*₂) = ∅. Note that, as we have already observed in Section 4, a decomposable ∨-gate of the form A ∨ B can be rewritten, using De Morgan's laws, into a decomposable ∧-gate. (2) For cases where this is not possible, we attempt to compile Boolean provenance into a d-D by computing, if possible, a tree decomposition of the circuit of treewidth ≤ 10, and by then following the construction detailed in [4, Section 5.1] to turn any Boolean circuit into a d-D in linear time when the treewidth is fixed. (3) Otherwise, we default to ProvSQL's default compilation of circuits into d-Ds, which amounts to coding the circuit as a CNF using the Tseitin transformation [39] and then calling an external knowledge compiler, d4 [26]. (4) We have implemented directly within ProvSQL Algorithm 1 to compute expected Shapley values on d-Ds, its simplification when all *p*<sub>y</sub> are set to 1 detailed at the end of Section 4, as well as the algorithm to compute expected Banzhaf values in the proof of Theorem 4.5. They are all implemented with floating-point numbers.

In particular, this approach is not restricted to queries on the tractable side of the dichotomy of [14]. In addition, we benefit from the fact that, since late 2021, ProvSQL stores the provenance circuit in main memory, which speeds provenance computation up (earlier versions stored the provenance circuit within the database, on disk).

*Experiment setup.* Following [2, 17], we used the TPC-H 1 GB benchmark, with standard generated data and 8 standard TPC-H queries adapted to remove nesting and aggregation, as provided by the authors of [17]<fnref n="3" />. We use the exact same queries as in [17], except that the LIMIT operator used for the experiments of that paper was removed, to obtain a larger and more realistic benchmark (we end up with 105 154 output tuples for these 8 queries). Probabilities were drawn uniformly at random for all facts.

Experiments were run on a desktop Linux PC with Xeon W3550 2.80GHz CPU, 64 GB RAM (8 GB of which were made available for PostgreSQL's shared buffers), running version 14.9 of

<footnote n="2">²https://github.com/PierreSenellart/provsql</footnote>

<footnote n="3">³https://github.com/navefr/ShapleyForDbFacts, archived as swh:1:rev:7a46a9fa381194097b81a7aae705d396872b26e3</footnote>
PostgreSQL; our code has been incorporated in ProvSQL, and we ran the latest version of ProvSQL as of December 2023⁴. Data for PostgreSQL is stored on standard magnetic hard drives in RAID 1.

*Results.* We show in Table 3 results of these experiments. For each query, we report: the number of output tuples; the total time required by ProvSQL to evaluate the query and compute the provenance representation of every output tuple; the total time required by the compilation of the Boolean provenance circuits of all query results to d-Ds; the method used to produce these d-Ds<fnref n="5" />; the average number of gates of the resulting d-Ds; the total time needed to compute (expected) Shapley values of all query outputs for all relevant facts<fnref n="6" /> in the deterministic case (where all probabilities are set to 1) and in the probabilistic case; the same for expected Banzhaf values in the probabilistic case<fnref n="7" />. All times are in seconds, repeated over 20 runs of each query, with the mean and standard deviation shown. To avoid caching provenance across multiple runs or multiple queries, the ProvSQL circuit was reset each time and PostgreSQL restarted.

We have the following observations regarding the experimental results (also compare with the results from Table 1 of [17]).

(1) ProvSQL is able to compute in a reasonable amount of time (at most a couple of seconds) the output of all queries, along with their Boolean provenance as a circuit; this contrasts with the results of [17] where provenance computation time could take up to 6 hours for query 3, even when limited to output only 100 tuples; we assume this is the result of recent ProvSQL optimizations and in-memory storage of the Boolean provenance circuit.

(2) Compilation to a d-D takes a time that is comparable to provenance computation, and uses a combination of interpreting the circuit as a decomposable one and the tree decomposition algorithm of [4]; using an external knowledge compiler, which was what was done in [17], is never required. Note that compilation is much faster than reported in [17] (remember that the times in [17] need to be multiplied by the number of output tuples, whereas we report the sum of all compilation times); the provenance circuits for queries 5 and 7 could not even be compiled to a d-D in [17].

(3) The total time required for deterministic Shapley value computation is of similar magnitude as query evaluation as well and comparable to those reported in [17] (except in one case, for query 19, where numbers reported in [17] are abnormally high).

(4) Computing expected Shapley values in a probabilistic setting using Algorithm 1 incurs a higher cost, but remains more practical in practice than the high theoretical complexity of this algorithm may suggest – the maximum time required is for query 5, with 41 seconds to compute the expected Shapley values over five d-Ds whose average size is over a thousand of gates.

(5) The total time required for Banzhaf value computation is significantly lower than that of deterministic Shapley value computation, especially for circuits with large numbers of gates or variables, as consistent with the established complexities.

(6) Though query evaluation and provenance computation can be marred with significant performance differences from one run to the next (due to disk caching, interaction with PostgreSQL, etc.), there is little variation of the performance of knowledge compilation and expected Shapley-like value computation.

To summarize, the experiments validate the practicality of the algorithms presented in this paper for computation of expected Shapley-like scores over probabilistic databases.

<footnote n="4">⁴Archived on Software Heritage as swh:1:rev:bba98e1d96af4c5a25ac672a2f67ea44ed869f8f</footnote>

<footnote n="5">⁵A different method might be used for each output tuple; we report the proportion of “dec.” when the obtained circuit was already decomposable; and of “tree dec.” when we used the tree decomposition approach; none of the circuits produced required using an external knowledge compiler.</footnote>

<footnote n="6">⁶By relevant facts, we mean here the facts that appear in the provenance circuits. Indeed, the other facts have a score of zero.</footnote>

<footnote n="7">⁷There is of course virtually no difference between computing deterministic and expected Banzhaf values, since the algorithm we use (that of Theorem 4.5), is the same.</footnote>
# 7 RELATED WORK

Probabilistic scores from Game Theory. While Shapley value [37] is one of the most popular measures of player contribution in a game, it does not take into account the probabilistic aspect of some of these games. To address this issue, a long line of work [11–13, 25, 28, 32, 41] defines and studies various ways in which scoring mechanisms can be incorporated in the setting of probabilistic games. For instance, the expected Shapley value that we study in this paper has been defined in [11] (see Definition 9), where it is shown that, just like the non-probabilistic Shapley value, it is the only scoring mechanism that satisfies a natural set of axioms over probabilistic games (see Theorems 3 and 4 of [11]). In these works, authors mainly focus on analysing the characteristics of such scoring mechanisms, in particular in terms of axioms they verify. To the best of our knowledge, no complexity results or algorithms are proposed, whereas this is precisely what we study in this paper.

Shapley-like scores. The authors of [17, 29, 30, 34] study the complexity of the problems Score<sub>cShapley</sub> and Score<sub>cBanzhaf</sub>, over Boolean functions or, most often, instantiated in the setting of relational databases. See [9] for a survey for databases. In particular, [17] shows that, for any query, the problem Score<sub>cShapley</sub> can be reduced in polynomial time to probabilistic query evaluation for the same query. The authors of [22] show an analogous result for Boolean functions, also obtaining the other direction of the reduction (under some assumptions). Formally, define the *model counting problem* for class *F* of Boolean functions as follows: given as input *φ* ∈ *F* over variables *V*, compute #φ ≜<sub>def</sub> {Z ∈ 2<sup>V</sup> | φ(Z) = 1}. They then show (we refer to their article for the definition of closure under OR-substitutions):

**THEOREM 7.1 ([22, COROLLARY 7]).** We have Score<sub>cShapley</sub>(F) ≡<sub>P</sub> MC(F) for any class F that is closed under OR-substitutions.

Notice the resemblance between, on the one side, these last two results that we mention, and on the other side our Corollaries 3.7 and 5.3. The difference is that we study the *expected Shapley* values. There is a priori no reason for the tractable cases to be the same as the non-expected variant: indeed, the counting (or probabilistic) version of a problem is often much harder than the decision one — for instance probabilistic query evaluation is often intractable for queries for which regular evaluation is easy.<fnref n="8" /> By our results, this phenomenon does not occur for EScore<sub>cShapley</sub>. Since EScore<sub>cShapley</sub> strictly generalizes Score<sub>cShapley</sub> (by Fact 2.5), the reduction from EScore<sub>cShapley</sub> to EV is more challenging, and indeed one can check that our polynomial interpolation proofs are more involved than, say, [17, Proposition 3.1]. On the other hand, our life is made easier to prove the other direction of these equivalences. This explains why we do not need the assumption of closure under OR-substitutions in Corollary 3.7, and this is also what allows us to obtain a *complete* equivalence to probabilistic query evaluation in Corollary 5.3, *no matter the Boolean query*, whereas in the case of non-expected Shapley values this is only known for self-join-free CQs (see also [10] which makes progress on this problem, but does not solve it completely yet). As for algorithms for d-D circuits [2, 17], we refer to the end of Section 4.

**SHAP-score.** The authors of [5, 6, 16, 40] study the complexity of computing the SHAP-score. In particular [16, 40] show that it is equivalent to computing expected values, and [5, 6] propose polynomial-time algorithms for d-D circuits. Thus, the landscape is similar to what we obtain here. However, there is to the best of our knowledge no formal connection between the SHAP-score and the expected scores that we study here: in a nutshell, we compute the expected Shapley value

<footnote n="8">⁸So one could say that expected Shapley scores are to Shapley scores what probabilistic query evaluation is to non-probabilistic query evaluation.</footnote>
where the game function is the Boolean function $\varphi$, whereas the SHAP score is computing the Shapley value where the game function is a conditional expectation of $\varphi$. Hence, the two sets of results seem to be independent.

# 8 CONCLUSION

We proposed the new notion of expected Shapley-like scores for Boolean functions, proved that computing these scores can always be reduced in polynomial-time to the well-studied problem of computing expected values, and that these two problems are often even equivalent (under commonplace assumptions). We designed algorithms for deterministic and decomposable Boolean circuits and implemented them in the setting of probabilistic databases, where our preliminary experimental results show that these scoring mechanisms could actually be used in practice. We leave as future work the study of approximation algorithms for this new notion. In particular, it is known that $\text{Score}_{c_{\text{Shapley}}}(q)$ has a *fully polynomial-time randomized scheme* [19] whenever $q$ is a UCQ [9], and one could study whether this stays true for the probabilistic variant. Still we note that, since the reduction from Fact 2.5 is parsimonious, we inherit the few hardness results of the non-probabilistic setting, such as those of [34] for conjunctive queries with negations.

# ACKNOWLEDGMENTS

This research is part of the program DesCartes (https://descartes.cnrsatcreate.cnrs.fr/) and is supported by the National Research Foundation, Prime Minister's Office, Singapore under its Campus for Research Excellence and Technological Enterprise (CREATE) program. This work was done in part while Mikaël Monet and Pierre Senellart were visiting the Simons Institute for the Theory of Computing.
REFERENCES

[1] Serge Abiteboul, Richard Hull, and Victor Vianu. 1995. *Foundations of Databases*. Addison-Wesley.

[2] Omer Abramovich, Daniel Deutch, Nave Frost, Ahmet Kara, and Dan Olteanu. 2023. Banzhaf Values for Facts in Query Answering. arXiv preprint arXiv:2308.05588.

[3] Antoine Amarilli. 2023. Uniform Reliability for Unbounded Homomorphism-Closed Graph Queries. In *ICDT (LIPIcs, Vol. 255)*. 14:1–14:17.

[4] Antoine Amarilli, Florent Capelli, Mikaël Monet, and Pierre Senellart. 2020. Connecting knowledge compilation classes and width parameters. *Theory of Computing Systems* 64 (2020), 861–914.

[5] Marcelo Arenas, Pablo Barceló, Leopoldo E. Bertossi, and Mikaël Monet. 2021. The Tractability of SHAP-Score-Based Explanations for Classification over Deterministic and Decomposable Boolean Circuits. In *AAAI. 6670–6678*.

[6] Marcelo Arenas, Pablo Barceló, Leopoldo E Bertossi, and Mikaël Monet. 2023. *J. Mach. Learn. Res.* 24, 63 (2023), 1–58.

[7] Marcelo Arenas, Pablo Barceló, Leonid Libkin, Wim Martens, and Andreas Pieris. 2022. Database Theory. Work in progress, latest version at https://github.com/pdm-book/community.

[8] John F Banzhaf III. 1964. Weighted voting doesn't work: A mathematical analysis. *Rutgers L. Rev.* 19 (1964), 317.

[9] Leopoldo Bertossi, Benny Kimelfeld, Ester Livshits, and Mikaël Monet. 2023. The Shapley value in database management. *SIGMOD Record* 52, 2 (2023), 6–17.

[10] Meghyn Bienvenu, Diego Figueira, and Pierre Lafourcade. 2024. When is Shapley Value Computation a Matter of Counting?. In *PODS*.

[11] Surajit Borkotokey, Sujata Gowala, and Rajnish Kumar. 2023. The Expected Shapley value on a class of probabilistic games. arXiv preprint arXiv:2308.03489.

[12] Francesc Carreras and Maria Albina Puente. 2015. Coalitional multinomial probabilistic values. *European Journal of Operational Research* 245, 1 (2015), 236–246.

[13] Francesc Carreras and Maria Albina Puente. 2015. Multinomial probabilistic values. *Group decision and negotiation* 24, 6 (2015), 981–991.

[14] Nilesh Dalvi and Dan Suciu. 2013. The dichotomy of probabilistic inference for unions of conjunctive queries. *Journal of the ACM (JACM)* 59, 6 (2013), 1–87.

[15] John Deegan and Edward W Packel. 1978. A new index of power for simple n-person games. *International Journal of Game Theory* 7 (1978), 113–123.

[16] Guy Van den Broeck, Anton Lykov, Maximilian Schleich, and Dan Suciu. 2021. On the Tractability of SHAP Explanations. In *AAAI. 6505–6513*.

[17] Daniel Deutch, Nave Frost, Benny Kimelfeld, and Mikaël Monet. 2022. Computing the Shapley Value of Facts in Query Answering. In *SIGMOD Conference*. 1570–1583.

[18] Manfred J Holler and Edward W Packel. 1983. Power, luck and the right index. *Zeitschrift für Nationalökonomie* 43 (1983), 21–29.

[19] Mark R Jerrum, Leslie G Valiant, and Vijay V Vazirani. 1986. Random generation of combinatorial structures from a uniform distribution. *Theoretical Computer Science* 43 (1986), 169–188.

[20] Ron J Johnston. 1977. National sovereignty and national power in European institutions. *Environment and Planning A* 9, 5 (1977), 569–577.

[21] Ronald John Johnston. 1978. On the measurement of power: Some reactions to Laver. *Environment and Planning A* 10, 8 (1978), 907–914.

[22] Ahmet Kara, Dan Olteanu, and Dan Suciu. 2024. From Shapley Value to Model Counting and Back. In *PODS*.

[23] Adam Karczmarz, Tomasz P. Michalak, Anish Mukherjee, Piotr Sankowski, and Piotr Wygocki. 2022. Improved feature importance computation for tree models based on the Banzhaf value. In *UAI*.

[24] Werner Kirsch and Jessica Langner. 2010. Power indices and minimal winning coalitions. *Social Choice and Welfare* 34, 1 (2010), 33–46.

[25] Maurice Koster, Sascha Kurz, Ines Lindner, and Stefan Napel. 2017. The prediction value. *Social Choice and Welfare* 48 (2017), 433–460.

[26] Jean-Marie Lagniez and Pierre Marquis. 2017. An Improved Decision-DNNF Compiler. In *IJCAI. 667–673*.

[27] Annick Laruelle. 1999. *On the choice of a power index*. Technical Report. Instituto Valenciano de Investigaciones Económicas.

[28] Annick Laruelle and Federico Valenciano. 2008. Potential, value, and coalition formation. *Transactions in Operations Research* 16 (2008), 73–89.

[29] Ester Livshits, Leopoldo Bertossi, Benny Kimelfeld, and Moshe Sebag. 2021. The Shapley value of tuples in query answering. *Logical Methods in Computer Science* 17 (2021).

[30] Ester Livshits, Leopoldo E. Bertossi, Benny Kimelfeld, and Moshe Sebag. 2020. The Shapley value of tuples in query answering. In *ICDT*, Vol. 155. 20:1–20:19.
[31] Mikaël Monet. 2020. Solving a Special Case of the Intensional vs Extensional Conjecture in Probabilistic Databases. In *PODS*. 149–163.

[32] Guillermo Owen. 1972. Multilinear extensions of games. *Management Science* 18, 5-part-2 (1972), 64–79.

[33] J Scott Provan and Michael O Ball. 1983. The complexity of counting cuts and of computing the probability that a graph is connected. *SIAM J. Comput.* 12, 4 (1983), 777–788.

[34] Alon Reshef, Benny Kimelfeld, and Ester Livshits. 2020. The impact of negation on the complexity of the Shapley value in conjunctive queries. In *PODS*. 285–297.

[35] Pierre Senellart. 2017. Provenance and Probabilities in Relational Databases: From Theory to Practice. *SIGMOD Record* 46, 4 (2017).

[36] Pierre Senellart, Louis Jachiet, Silviu Maniu, and Yann Ramusat. 2018. ProvSQL: Provenance and Probability Management in PostgreSQL. *Proc. VLDB Endow.* 11, 12 (2018), 2034–2037.

[37] Lloyd S. Shapley et al. 1953. A value for n-person games. (1953).

[38] Dan Suciu, Dan Olteanu, Christopher Ré, and Christoph Koch. 2011. *Probabilistic Databases*. Morgan & Claypool.

[39] G Tseitin. 1968. On the complexity of derivation in propositional calculus. *Studies in Constrained Mathematics and Mathematical Logic* (1968).

[40] Guy Van den Broeck, Anton Lykov, Maximilian Schleich, and Dan Suciu. 2022. On the tractability of SHAP explanations. *Journal of Artificial Intelligence Research* 74 (2022), 851–886.

[41] Robert J Weber. 1988. Probabilistic values for games. *The Shapley Value. Essays in Honor of Lloyd S. Shapley* (1988), 101–119.
A PROOFS FOR SECTION 3 (EQUIVALENCE WITH EXPECTED VALUES)

LEMMA 3.10. We have ENV(的大于号) ≤_P EScore<sub>cBanzhaf</sub> (的大于号) for any F closed under conjunctions (resp., disjunctions) with fresh variables.

PROOF. Let us first show that for φ' : 2V' → {0, 1} and probability values p_y for y ∈ V' and x ∈ V' we have the equation claimed in the proof sketch, restated here:

$$
EScore_{c_{Banzhaf}} (\varphi', x) = p_x [\mathrm{ENV}(\varphi'_{+x}) - \mathrm{ENV}(\varphi'_{-x})].
$$

The derivation is similar to that of Lemma 3.2, but simpler. Observe that EScore<sub>cBanzhaf</sub>(φ, x) = A-B,
where

$$
A = \sum_{Z \subseteq V'} \prod_{x \in Z} (Z) \sum_{E \subseteq Z \setminus \{x\}} \varphi'(E \cup \{x\})
$$

$$
B = \sum_{Z \subseteq V'} \prod_{x \in Z} (Z) \sum_{E \subseteq Z \setminus \{x\}} \varphi'(E).
$$

Let us focus on A. Letting $V'' \stackrel{\text{def}}{=} V' \setminus \{x\}$, notice that these are the variables over which $\varphi'_{+x}$ is defined. Letting $n \stackrel{\text{def}}{=} |V''|$, we have

$$
A = \sum_{Z \subseteq V'} \prod_{x \in Z} (Z) \sum_{E \subseteq Z \setminus \{x\}} \varphi'_{+x}(E) = p_x \sum_{Z \subseteq V''} \prod_{x \in Z} (Z) \sum_{E \subseteq Z} \varphi'_{+x}(E) = p_x \mathrm{ENV}(\varphi'_{+x}).
$$

We can do the same for B to obtain $B = p_x \mathrm{ENV}(\varphi'_{-x})$, hence the equation.

We now prove Lemma 3.10 in the case that $\mathcal{F}$ is closed under conjunctions with fresh variables. Let then $\varphi : 2^V \to \{0, 1\}$, and probabilities $p_y$ for $y \in V$. We want to compute $\mathrm{ENV}(\varphi)$. Since $\mathcal{F}$ is closed under conjunctions with fresh variables, let $x \notin V$ and compute a representation of $\varphi' \stackrel{\mathrm{def}}{=} \varphi \wedge x$ in $\mathcal{F}$. We call the oracle to $\mathrm{EScore}_{c\mathrm{Banzhaf}}$ on $\varphi'$ with same probabilities for $y \in V$ and with $p_x \stackrel{\mathrm{def}}{=} 1$. By the above equation (with $V' = V \cup \{x\}$) this immediately gives us $\mathrm{ENV}(\varphi)$ and concludes.

For the case when $\mathcal{F}$ is closed under disjunctions with fresh variables we do the same but with
$\varphi' \stackrel{\text{def}}{=} \varphi \lor x$: now by Equation (5) the oracle call returns $[\sum_{Z \subseteq V} \Pi_V(Z) \sum_{E \subseteq Z} 1] - \mathrm{ENV}(\varphi)$, which
is equal to $[\sum_{Z \subseteq V} \Pi_V(Z) 2^{|Z|}] - \mathrm{ENV}(\varphi)$. We conclude the proof by showing that the first term is
equal to $\prod_{y \in V} (1 + p_y)$, which can be computed in polynomial time, hence we can indeed recover
$\mathrm{ENV}(\varphi)$. Indeed, let $n \stackrel{\text{def}}{=} |V|$, and order the variables of $V$ arbitrarily as $y_1, \dots, y_n$. For $i \in [n]$,
define $V_i \stackrel{\text{def}}{=} \{y_j \mid 1 \le j \le i \in [n]\}$ (note that $V_0 = \emptyset$), and $d_i \stackrel{\text{def}}{=} \sum_{Z \subseteq V_i} \Pi_{V_i}(Z) 2^{|Z|}$.
Observe that the quantity that we want is $d_n$. But it is clear that $d_0 = 1$ and that $d_i = \sum_{y_i \notin Z} \Pi_{V_i}(Z) 2^{|Z|} + \sum_{y_i \in Z} \Pi_{V_i}(Z) 2^{|Z|} = (1-p_{y_i})d_{n-1} + p_{y_i} \times d_{n-1} \times 2 = (1+p_{y_i})d_{n-1}$ for $1 \le i \le n$, which concludes. $\square$

LEMMA 3.11. We have ENV(的大于号) ≤_P ENV(的大于号) for any class F that is closed under conditioning.

PROOF. Let $\varphi \in \mathcal{F}$ over variables $V$ with $n \stackrel{\text{def}}{=} |V|$ and probability values $p_x$ for each $x \in V$; we want to compute $\mathrm{EV}(\varphi)$. We use polynomial interpolation to compute all the values $\mathrm{EV}_j(\varphi)$ for $j \in [n]$, after which we can simply return $\sum_{j=0}^n \mathrm{EV}_j(\varphi) = \mathrm{EV}(\varphi)$.

Without loss of generality, we can assume that $p_x < 1$ for all $x \in V$. Indeed, if there is $x$ such that $p_x = 1$, we consider $V' = V \setminus \{x\}$ and $\varphi' = \varphi_{+x}$. Then $\mathrm{EV}_j(\varphi) = \mathrm{EV}_{j-1}(\varphi')$ for any $j \ge 1$ and $\mathrm{EV}_0(\varphi) = 0$. This is indeed without loss of generality because $\mathcal{F}$ is closed under conditioning, so that $\varphi_{+x}$ is in $\mathcal{F}$.
Let $M \stackrel{\text{def}}{=} \max_{x \in V} p_x < 1$. Let $z_0, \dots, z_n$ be $n+1$ distinct rational values in $(0, 1-M)$. For $i \in [n]$ and $x \in V$, we define this time $p_x^{z_i} \stackrel{\text{def}}{=} \frac{z_i p_x}{1-p_x}$, and define $\Pi^{z_i}$ and $\text{EV}^{z_i}(\varphi)$ as expected. Again, these are all valid probability mappings. Define $C \stackrel{\text{def}}{=} \prod_{x \in V} (1-p_x)$. We will show that we have $\text{ENV}^{z_i}(\varphi) = \frac{1}{C} \sum_{j=0}^n z_i^j \text{EV}_j(\varphi)$, which allows us to conclude as in the proof of Lemma 3.3. Indeed:

$$
\begin{align*}
\text{ENV}^{z_i}(\varphi) &= \sum_{Z \subseteq V} \Pi_V^{z_i}(Z) \sum_{E \subseteq Z} \varphi(E) \\
&= \sum_{E \subseteq V} \varphi(E) \sum_{E \subseteq Z \subseteq V} \Pi_V^{z_i}(Z) = \sum_{E \subseteq V} \varphi(E) \sum_{E \subseteq Z \subseteq V} \prod_{x \in Z} p_x^{z_i} \prod_{x \in V \setminus Z} (1-p_x^{z_i}) \\
&= \frac{1}{C} \sum_{E \subseteq V} \varphi(E) \sum_{E \subseteq Z \subseteq V} \prod_{x \in Z} z_i p_x \prod_{x \in V \setminus Z} (1-p_x - z_i p_x) \\
&= \frac{1}{C} \sum_{E \subseteq V} \varphi(E) \prod_{x \in E} z_i p_x \prod_{x \in V \setminus E} [(z_i p_x) + (1-p_x - z_i p_x)] \\
&= \frac{1}{C} \sum_{E \subseteq V} \varphi(E) \prod_{x \in E} z_i p_x \prod_{x \in V \setminus E} (1-p_x) = \frac{1}{C} \sum_{j=0}^n \sum_{\substack{E \subseteq V \\ |E|=j}} z_i^j \Pi_V(E) \varphi(E) = \frac{1}{C} \sum_{j=0}^n z_i^j \text{EV}_j(\varphi). \quad \Box
\end{align*}
$$

B PROOFS FOR SECTION 4 (DD CIRCUITS)

B.1 Proof of Theorem 4.3

THEOREM 4.3. Let $c$ be a tractable coefficient function. Given a $d$-D circuit $C$ on variables $V$, probability values $p_y$ for $y \in V$, and $x \in V$, Algorithm 1 correctly computes $\text{EScore}_c(C, x)$ in polynomial time. Moreover, if we ignore the cost of arithmetic operations, it is in time $O(|C| \times |V|^5 + T_c(|V|) \times |V|^2)$ where $T_c(\alpha)$ is the cost of computing the coefficient function on inputs $\le \alpha$.

Proving Theorem 4.3, as explained in Section 4, boils down to showing how we can compute,
given a tight d-D circuit, the ENV$_{★,★}$ quantities. We then show:

PROPOSITION B.1. Given as input a tight d-D circuit $C'$ on variables $V'$ and probability values $p_y$ for $y \in V'$ we can compute all the values $\text{ENV}_{k,l}(C)$ for $k, l \in [|V'|]$ in $O(|C'| \times |V'|^4)$, ignoring the cost of arithmetic operations.

Recall that this will be instantiated with $C' = C_0$ and $C' = C_1$ for the circuits $C_0$ and $C_1$ from Section 4 (which should not be confused with circuit $C$ of that section). Also note that, even though by Equation (1) we only need to compute the values for $k \ge l$ (since they are zero when $k > l$), we still do as if we wanted to naively compute them all. This allows us to obtain cleaner expressions, in which the ranges for the sums are easier to read. Let us define $n' \stackrel{\text{def}}{=} |V'|$.

We first explain how to compute an intermediate quantity that will be needed later.

DEFINITION B.2. For a gate $g \in C'$ and integer $k \in [n']$, define $\delta_k^g \stackrel{\text{def}}{=} \sum_{Z \subseteq \text{Vars}(g)} \Pi_{\text{Vars}(g)}(Z)$. (Note that $\delta_k^g = 0$ when $k > \text{Vars}(g)$.)

Notice that $\delta_k^g$ only depends on the “structure” of the circuit, but not on its semantics.

LEMMA B.3. We can compute in $O(|C'| \times n'^2)$ all quantities $\delta_k^g$, ignoring the cost of arithmetic operations.

PROOF. We compute them by bottom-up induction on $C'$.
**Constant gates.** Let $g$ be a constant gate. Then $\text{Vars}(g) = \emptyset$, so $\delta_k^g = 0$ for $k \ge 1$, and $\delta_0^g = 1$ (indeed $\Pi_\emptyset(\emptyset) = 1$ since this is the neutral element of multiplication).

**Input gates.** Let $g$ be an input gate, with variable $y$. Then $\text{Vars}(g) = \{y\}$, so $\delta_k^g = 0$ for $k \ge 2$, while $\delta_0^g = \Pi_{\text{Vars}(g)}(\emptyset) = 1 - p_y$ and $\delta_1^g = \Pi_{\text{Vars}(g)}(\{y\}) = p_y$.

**Negation gates.** Let $g$ be a $\neg$-gate with input $g'$. Notice that $\text{Vars}(g) = \text{Vars}(g')$. So we have $\delta_k^g = \delta_k^{g'}$ for all $k \in [n']$ and we are done since the values $\delta_k^{g'}$ have already been computed inductively.

**Deterministic smooth $\vee$-gates.** Let $g$ be a smooth deterministic $\vee$-gate with inputs $g_1, g_2$. Since $g$ is smooth we have $\text{Vars}(g) = \text{Vars}(g_1) = \text{Vars}(g_2)$. In particular we have $\delta_k^g = \delta_k^{g_1}$ for all $k \in [n']$ and we are done.

**Decomposable $\wedge$-gates.** Let $g$ be a decomposable $\wedge$-gate with inputs $g_1, g_2$. Notice that $\text{Vars}(g) = \text{Vars}(g_1) \cup \text{Vars}(g_2)$ with the union being disjoint. We can then decompose $Z$ into a "left" part $Z_1 \subseteq \text{Vars}(g_1)$ of size $k_1 \in \{0, \dots, k\}$ and a "right" part $Z_2 \subseteq \text{Vars}(g_2)$ of size $k - k_1$. We then have:

$$ 
\begin{align*}
\delta_k^g &= \sum_{\substack{Z \subseteq \text{Vars}(g) \\ |Z|=k}} \Pi_{\text{Vars}(g)}(Z) = \sum_{k_1=0}^k \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \Pi_{\text{Vars}(g_1)}(Z_1) \Pi_{\text{Vars}(g_2)}(Z_2) \\
&= \sum_{k_1=0}^k \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \Pi_{\text{Vars}(g_1)}(Z_1) \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \Pi_{\text{Vars}(g_2)}(Z_2) = \sum_{k_1=0}^k \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \Pi_{\text{Vars}(g_1)}(Z_1) \delta_{k-k_1}^{g_2} \\
&= \sum_{k_1=0}^k \delta_{k-k_1}^{g_2} \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \Pi_{\text{Vars}(g_1)}(Z_1) = \sum_{k_1=0}^k \delta_{k_1}^{g_1} \delta_{k-k_1}^{g_2},
\end{align*}
$$

and we are done.

The complexity of every step is $O(n')$ except for $\wedge$-gates where the complexity is $O(n'^2)$; each step needs to be repeated for every gate of $C'$, which gives the stated complexity. This concludes the proof of Lemma B.3. $\square$

We next define $\text{ENV}_{\star,\star}$-quantities for all gates of the circuit $C'$.

**DEFINITION B.4.** For a gate $g \in C'$ and $k, \ell \in [n']$, define

$$ \alpha_{k, \ell}^g \stackrel{\text{def}}{=} \sum_{Z \subseteq \text{Vars}(g)} \sum_{|Z|=k} \Pi_{\text{Vars}(g)}(Z) C_g^r(E). $$

If we can show that we can compute all quantities $\alpha_{k,\ell}^g$ in the required complexity then we are done: indeed, we can then take $g$ to be the output gate of $C'$, which gives us the quantities $\text{ENV}_{k,\ell}(C')$ that we wanted. We show just that in the next lemma.

**LEMMA B.5.** We can compute in $O(|C'| \times n'^4)$ all the quantities $\alpha_{k,\ell}^g$.

**PROOF.** This is again done by bottom-up induction on $C'$.

**Constant gates.** Let $g$ be a constant gate. Then $\text{Vars}(g) = \emptyset$, so $\alpha_{k,\ell}^g = 0$ when $(k, \ell) \ne (0, 0)$, and $\alpha_{0,0}^g = 1$ if $g$ is a constant 1-gate and $\alpha_{0,0}^g = 0$ if it is a constant 0-gate.

**Input gates.** Let $g$ be an input gate, with variable $y$. Then $\text{Vars}(g) = \{y\}$, so all values other than $\alpha_{0,0}^g, \alpha_{1,0}^g$ and $\alpha_{1,1}^g$ are null, and one can easily check that $\alpha_{0,0}^g = \alpha_{1,0}^g = 0$ and $\alpha_{1,1}^g = p_y$.
**Negation gates.** Let $g$ be a $
eg$-gate with input $g'$. Notice that $\text{Vars}(g) = \text{Vars}(g')$ and that $C'_g(E) = 1 - C'_g(E)$ for any $E \subseteq \text{Vars}(g)$. We have

$$ 
\begin{aligned}
\alpha_{k, \ell}^g &= \sum_{Z \subseteq \text{Vars}(g) \atop |Z|=k} \sum_{\substack{E \subseteq Z \\ |E|=\ell}} \Pi_{\text{Vars}(g)}(Z) (1 - C'_{g'}(E)) = \left[ \binom{k}{\ell} \sum_{Z \subseteq \text{Vars}(g) \atop |Z|=k} \Pi_{\text{Vars}(g)}(Z) \right] - \alpha_{k, \ell}^{g'} \\
&= \binom{k}{\ell} \delta_k^g - \alpha_{k, \ell}^{g'}
\end{aligned}
$$

and we are done thanks to Lemma B.3.

**Deterministic smooth $\vee$-gates.** Let $g$ be a smooth deterministic $\vee$-gate with inputs $g_1, g_2$. Since $g$ is smooth we have $\text{Vars}(g) = \text{Vars}(g_1) = \text{Vars}(g_2)$, and since it is deterministic we have $C'_g(E) = C'_{g_1}(E) + C'_{g_2}(E)$ for any $E \subseteq \text{Vars}(g)$. Therefore we obtain $\alpha_{k, \ell}^g = \alpha_{k, \ell}^{g_1} + \alpha_{k, \ell}^{g_2}$ and we are done.

**Decomposable $\wedge$-gates.** Let $g$ be a decomposable $\wedge$-gate with inputs $g_1, g_2$. Notice that $\text{Vars}(g) = \text{Vars}(g_1) \cup \text{Vars}(g_2)$ with the union being disjoint, and that $C'_g(E) = C'_{g_1}(E \cap \text{Vars}(g_1)) \times C'_{g_2}(E \cap \text{Vars}(g_2))$ and $\Pi_{\text{Vars}(g)}(Z) = \Pi_{\text{Vars}(g_1)}(Z \cap \text{Vars}(g_1)) \times \Pi_{\text{Vars}(g_2)}(Z \cap \text{Vars}(g_2))$ for any $Z, E \subseteq \text{Vars}(g)$. We decompose the summations over $Z$ and $E$ as we did in the proof of Lemma B.3 for $\wedge$-gates. For readability we use colors to point out which parts of the expressions are modified or moved around.

$$ 
\begin{aligned}
\alpha_{k, \ell}^g &= \sum_{Z \subseteq \text{Vars}(g) \atop |Z|=k} \sum_{\substack{E \subseteq Z \\ |E|=\ell}} \Pi_{\text{Vars}(g)}(Z) C'_g(E) \\
&= \sum_{k_1=0}^k \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{E \subseteq Z_1 \cup Z_2 \\ |E|=\ell}} \Pi_{\text{Vars}(g_1)}(Z_1) \Pi_{\text{Vars}(g_2)}(Z_2) C'_g(E) \\
&= \sum_{k_1=0}^k \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{\ell_1=0 \\ E_1 \subseteq Z_1 \\ |E_1|=\ell_1}} \sum_{\substack{E_2 \subseteq Z_2 \\ |E_2|=\ell-\ell_1}} \Pi_{\text{Vars}(g_1)}(Z_1) \Pi_{\text{Vars}(g_2)}(Z_2) C'_{g_1}(E_1) C'_{g_2}(E_2) \\
&= \sum_{k_1=0}^k \sum_{\substack{\ell_1=0 \\ Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{E_1 \subseteq Z_1 \\ |E_1|=\ell_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{E_2 \subseteq Z_2 \\ |E_2|=\ell-\ell_1}} \Pi_{\text{Vars}(g_1)}(Z_1) \Pi_{\text{Vars}(g_2)}(Z_2) C'_{g_1}(E_1) C'_{g_2}(E_2) \\
&= \sum_{k_1=0}^k \sum_{\substack{\ell_1=0 \\ Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{E_1 \subseteq Z_1 \\ |E_1|=\ell_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{E_2 \subseteq Z_2 \\ |E_2|=\ell-\ell_1}} \Pi_{\text{Vars}(g_1)}(Z_1) C'_{g_1}(E_1) \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{E_2 \subseteq Z_2 \\ |E_2|=\ell-\ell_1}} \Pi_{\text{Vars}(g_2)}(Z_2) C'_{g_2}(E_2) \\
&= \sum_{k_1=0}^k \sum_{\substack{\ell_1=0 \\ Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{E_1 \subseteq Z_1 \\ |E_1|=\ell_1}} \sum_{\substack{Z_2 \subseteq \text{Vars}(g_2) \\ |Z_2|=k-k_1}} \sum_{\substack{E_2 \subseteq Z_2 \\ |E_2|=\ell-\ell_1}} \Pi_{\text{Vars}(g_1)}(Z_1) C'_{g_1}(E_1) \alpha_{k-k_1, \ell-\ell_1}^{g_2}
\end{aligned}
$$
$$
\begin{align*}
&= \sum_{k_1=0}^{k} \sum_{\ell_1=0}^{k_1} \alpha_{k-k_1, \ell-\ell_1}^{g_2} \sum_{\substack{Z_1 \subseteq \text{Vars}(g_1) \\ |Z_1|=k_1}} \sum_{\substack{E_1 \subseteq Z_1 \\ |E_1|=\ell_1}} \Pi_{\text{Vars}(g_1)}(Z_1) C'_{g_1}(E_1) \\
&= \sum_{k_1=0}^{k} \sum_{\ell_1=0}^{k_1} \alpha_{k_1, \ell_1}^{g_1} \times \alpha_{k-k_1, \ell-\ell_1}^{g_2}.
\end{align*}
$$

and we are done.

The complexity is given by that of the step for $\neg$- and $\wedge$-gates, which are the most costly at $O(n'^4)$ (recall that computing $\binom{k}{\ell}$ is in $O(k \times \ell)$), which we need to multiply by the size of the circuit. This concludes the proof of Lemma B.5. $\square$

In Algorithm 1, the $\beta$ values are the $\alpha$ values for $C_1$ and the $\gamma$ values are the $\alpha$ values for $C_0$, and they are computed in a single pass over the circuit $C$ instead of first computing $C_1$ and $C_0$ and making passes over these two circuits. Therefore, Algorithm 1 is correct. To obtain the final complexity, we need to add the cost of line 32, which is in $O(n'^2 \times T(n'))$ ignoring the cost of arithmetic operations, and remember that $|C_1|$ and $|C_0|$ are in $O(|C| \times |V|)$ by Lemma 4.2.

What remains to argue is that the number of bits (numerator and denominator) of all the $\alpha$ and $\delta$ values stays polynomial. But for $\alpha_{k,\ell}^g$ for instance we have

$$ \alpha_{k, \ell}^{g} \stackrel{\text{def}}{=} \sum_{Z \subseteq \text{Vars}(g)} \sum_{\substack{E \subseteq Z \\ |E| = \ell}} \Pi_{\text{Vars}(g)}(Z) C'_{g}(E) \le 2^{2^{|V|}} \max_{Z \subseteq \text{Vars}(g)} \Pi_{\text{Vars}(g)}(Z). $$

If the number of bits of all numerators and denominators of all $p_x$ is bounded by $b$, then the numerator of $\alpha_{k,\ell}^g$ is bounded by $2^{2^{|V|}} 2^{|E|} = 2^{(b+2)|V|}$, so indeed have a polynomial number of bits for the numerators, and similar reasoning works for denominators and for the $\delta$ values.

## B.2 Proof of Proposition 4.4

**PROPOSITION 4.4.** Let $c$ be a tractable coefficient function. Given a d-D $C$ on variables $V$, a unique probability value $p = p_y$ for all $y \in V$, and $x \in V$, $EScore_c(C, x)$ can be computed in time $O(|V|^2 \times (|C||V| + |V|^2 + T_c(|V|))$ assuming unit-cost arithmetic.

**PROOF.** To prove Proposition 4.4 we consider a d-D circuit $C$ over variables $V$ with $n = |V|$. For a variable $x \in V$,

$$
\begin{align*}
\text{EScore}_c(C, x) &= \sum_{\substack{Z \subseteq V \\ x \in Z}} \Pi_V(Z) \times \text{Score}_c(C, Z, x) \\
&= \sum_{\substack{Z \subseteq V \\ x \in Z}} \Pi_V(Z) \sum_{E \subseteq Z \setminus \{x\}} c(|Z|, |E|) \times [C(E \cup \{x\}) - C(E)] \\
&= \sum_{E \subseteq V \setminus \{x\}} \left[ \sum_{E \subseteq Z \subseteq V \setminus \{x\}} c(|Z| + 1, |E|) \times p_x \times \Pi_V(Z) \right] [C(E \cup \{x\}) - C(E)] \\
&= \sum_{\ell=0}^{|V|-1} \sum_{\substack{E \subseteq V \setminus \{x\} \\ |E|=\ell}} \sum_{k=\ell}^{|V|-1} \left[ \sum_{\substack{E \subseteq Z \subseteq V \setminus \{x\} \\ |Z|=k}} c(k+1, \ell) \times p^{k+1} (1-p)^{n-k-1} \right] [C(E \cup \{x\}) - C(E)]
\end{align*}
$$
$$
\begin{align*}
&= \sum_{\ell=0}^{|V|-1} \sum_{k=\ell}^{|V|-1} \left[ \binom{n-1-\ell}{k-\ell} \times c(k+1, \ell) \times p^{k+1} (1-p)^{n-k-1} \right] \sum_{\substack{E \subseteq V \setminus \{x\} \\ |E|=\ell}} [C(E \cup \{x\}) - C(E)] \\
&= \sum_{\ell=0}^{|V|-1} [\#\mathrm{SAT}_{\ell}(C_1) - \#\mathrm{SAT}_{\ell}(C_0)] \sum_{k=\ell}^{|V|-1} \left[ \binom{n-1-\ell}{k-\ell} \times c(k+1, \ell) \times p^{k+1} (1-p)^{n-k-1} \right]
\end{align*}
$$

where we set $C_1$ and $C_0$ as usual and $\#\mathrm{SAT}_\ell(C')$ is the number of satisfying valuations of size $\ell$ of the circuit $C'$. Using the techniques of [17] (in particular, Lemma 4.5 of this paper), we can show that all the $\#\mathrm{SAT}_\ell(C')$ values for a tight circuit $C'$ over variables $|V'|$ can be computed in $O(|C'| \times |V'|^2)$. So, to compute all $\#\mathrm{SAT}_\ell(C_0)$, we first need to make it tight (in $O(|C| \times |V|)$) and then we have a cost of $O(|C| \times |V|^3)$.

Now, to compute the rest of the sum, we need to compute for every $\ell$ and $k$ a binomial coefficient in $O(n^2)$, a value of the coefficient function in $O(T_c(n))$ and perform the other multiplications in $O(1)$ assuming unit cost arithmetic. We obtain thus an algorithm in $O(|C| \times |V|^3 + |V|^2 \times (|V|^2 + T_c(|V|)))$.

□

## B.3 Proof of Theorem 4.5

**THEOREM 4.5.** Given a d-DC on variables $V$, probability values $p_y$ for $y \in V$, and $x \in V$, we can compute in time $O(|C| \times |V|)$ (ignoring the cost of arithmetic operations) the quantity $EScore_{cBanzhaf}(C, x)$.

**PROOF.** As argued in Section 4, we need only to prove, thanks to Equation (6), that ENV can be computed in linear time for tight d-D circuits. Let $C'$ be a tight d-D over variables $V'$ and $p_x$ probability values for all $x \in V'$. We want to compute ENV($\varphi$) $\stackrel{\text{def}}{=} \sum_{Z \subseteq V'} \Pi_{V'}(Z) \sum_{E \subseteq Z} C'(E)$. (Recall that this will be instantiated with $C' = C_1$ and $C' = C_0$) from Equation (6).) We do this again by bottom-up induction on the circuit, computing the corresponding quantities for very gate. Formally, for a gate $g$ of $C'$, define: $\alpha^g \stackrel{\text{def}}{=} \sum_{Z \subseteq \mathrm{Vars}(g)} \Pi_{\mathrm{Vars}(g)}(Z) \sum_{E \subseteq Z} C'_g(E)$. Notice that we want $\alpha^g$ for $g$ the output gate of $C'$. We show next how this can be done.

**Constant gates.** Let $g$ be a constant gate. Then $\mathrm{Vars}(g) = \emptyset$, so $\alpha^g$ equals 1 if $g$ is a constant 1-gate and 0 if it is a constant 0-gate.

**Input gates.** Let $g$ be an input gate, with variable $y$. Then $\mathrm{Vars}(g) = \{y\}$, so $\alpha^g = p_y$.

**Negation gates.** Let $g$ be a $\neg$-gate with input $g'$.

Then $C'_g(E) = 1 - C'_{g_1}(E)$, therefore $\alpha^g = [\sum_{Z \subseteq \mathrm{Vars}(g)} \Pi_{\mathrm{Vars}(g)}(Z) \sum_{E \subseteq Z} 1] - \alpha^{g'}$. We have already observed in the proof of Lemma 3.10 that the first term is equal to $\prod_{y \in \mathrm{Vars}(g)} (1+p_y)$, therefore we obtain $\alpha^g = [\prod_{y \in \mathrm{Vars}(g)} (1+p_y)] - \alpha^{g'}$.

**Deterministic smooth $\vee$-gates.** Let $g$ be a smooth deterministic $\vee$-gate with inputs $g_1, g_2$. Since $g$ is smooth we have $\mathrm{Vars}(g) = \mathrm{Vars}(g_1) = \mathrm{Vars}(g_2)$, and since it is deterministic we have $C'_g(E) = C'_{g_1}(E) + C'_{g_2}(E)$. Therefore $\alpha^g = \alpha^{g_1} + \alpha^{g_2}$.

**Decomposable $\wedge$-gates.** Let $g$ be a decomposable $\wedge$-gate with inputs $g_1, g_2$. We decompose the sum similarly to what we did in the proof of Theorem 4.3:

$$
\begin{align*}
\alpha^g &= \sum_{Z \subseteq \mathrm{Vars}(g)} \Pi_{\mathrm{Vars}(g)}(Z) \sum_{E \subseteq Z} C'_g(E) \\
&= \sum_{Z_1 \subseteq \mathrm{Vars}(g_1)} \sum_{Z_2 \subseteq \mathrm{Vars}(g_2)} \Pi_{\mathrm{Vars}(g)}(Z_1 \cup Z_2) \sum_{E_1 \subseteq Z_1} \sum_{E_2 \subseteq Z_2} C'_g(E_2 \cup E_2) \\
&= \sum_{Z_1 \subseteq \mathrm{Vars}(g_1)} \sum_{Z_2 \subseteq \mathrm{Vars}(g_2)} \Pi_{\mathrm{Vars}(g_1)}(Z_1) \Pi_{\mathrm{Vars}(g_2)}(Z_2) \sum_{E_1 \subseteq Z_1} \sum_{E_2 \subseteq Z_2} C'_{g_1}(E_1) C'_{g_2}(E_2)
\end{align*}
$$
$$
\begin{align*}
&= \sum_{Z_1 \subseteq \text{Vars}(g_1)} \Pi_{\text{Vars}(g_1)}(Z_1) \sum_{E_1 \subseteq Z_1} C'_{g_1}(E_1) \sum_{Z_2 \subseteq \text{Vars}(g_2)} \Pi_{\text{Vars}(g_2)}(Z_2) \sum_{E_2 \subseteq Z_2} C'_{g_2}(E_2) \\
&= \sum_{Z_1 \subseteq \text{Vars}(g_1)} \Pi_{\text{Vars}(g_1)}(Z_1) \sum_{E_1 \subseteq Z_1} C'_{g_1}(E_1) \alpha^{g_2} \\
&= \alpha^{g_2} \sum_{Z_1 \subseteq \text{Vars}(g_1)} \Pi_{\text{Vars}(g_1)}(Z_1) \sum_{E_1 \subseteq Z_1} C'_{g_1}(E_1) \\
&= \alpha^{g_2} \alpha^{g_1}.
\end{align*}
$$

This concludes the proof, as all of this can be done in $O(|C'|)$, ignoring the cost of arithmetic operations (and, in any case, the number of bits stays polynomial). For it to be true for negation gates, we need to compute $\prod_{y \in \text{Vars}(g)} (1 + p_y)$ for every gate, which can also be done during the bottom-up processing of the circuit. $\square$

## B.4 Complexity in the Case where All Probabilities are 1

As discussed at the end of Section 4, when all probabilities are set to 1, we recover the algorithm of [17] for non-probabilistic Shapley value computation. We briefly discuss its precise complexity.

In that setting, as discussed, we do not need to compute $\delta_k^g$ values (line 3–14) so we only need to discuss the cost of computing $\beta_{k,l}^g$ and $\gamma_{k,l}^g$ (lines 15–31) on the one hand, and of line 32 on the other hand. Further, recall that only the setting where $k = |\text{Vars}(g)|$ is relevant. This means that the main loop to compute $\beta$ and $\gamma$ values is run $|\text{Vars}(g)|$ times instead of $|\text{Vars}(g)|^2$ times, and furthermore, that in the case where $g$ is an $\wedge$-gate, its computation involves a single sum, as we can set $k_1$ to be $|\text{Vars}(g_1)|$ (and thus $k_2$ to be $|\text{Vars}(g_2)|$) on lines 29 and 30. Finally, on line 32, similarly, we only have one sum operator as $\beta_{k,l}^{g_{\text{out}}}$ and $\gamma_{k,l}^{g_{\text{out}}}$ are zero when $k \neq |\text{Vars}(g_{\text{out}})|$.

Remember that since the circuit needs to be made tight, its size is $O(|C| \times |V|)$. We therefore have for complexity: $O(|C| \times |V| \times |V|^2 + |V| \times T_{c_{\text{Shapley}}}(|V|)) = O(|C| \times |V|^3 + |V| \times |V|^2) = O(|C| \times |V|^3)$.