What is the probability of a multidimensional rectangle? Assume given a probability measure $P$ on $(\mathbb{R}^p,\mathcal{B}_p)$, where $\mathcal{B}_p$ denotes the $p$-dimensional Borel-$\sigma$-algebra. Let $F$ denote the $p$-dimensional CDF for $P$, given by $F:\mathbb{R}^p\to[0,1]$ with
$$
F(x_1,\ldots,x_p) = P((-\infty,x_1]\times\cdots\times(-\infty,x_p])
$$
I would like to know how to express a probability of the form
$$
P((x_1,y_1]\times\cdots\times(x_p,y_p])
$$
in terms of $F$. For example, in two dimensions, it holds that
$$
P((x_1,y_1]\times(x_2,y_2])
  =F(y_1,y_2) - F(x_1,y_2) - F(y_1,x_2) + F(x_1,x_2).
$$
I assume that the general formula is somehow related to the inclusion-exclusion principle, and I assume that the general formula is quite well-known as well, but it's not immediately obvious to me what the correct answer is...
 A: Let $\mathcal S$ be the set of sequences $s=n_1,\dots,n_p$ with $n_i\in\{1,2\}$ for every $i$.
Define intervals
$$\begin{array}{rl}
I_n(1) &= (-\infty, x_n] \\
I_n(2) &= (-\infty, y_n]
\end{array}$$
And for $s=n_1,\dots,n_p$ set $$
\begin{array}{rl}
R(s) &= I_1(n_1)\times\dots\times I_p(n_p) \\
K(s) &= n_1+\dots+n_p
\end{array}$$
Then we can express 
$$P\left((x_1,y_1]\times\dots\times(x_p,y_p]\right) = \sum_{s\in S}(-1)^{K(s)} P(R(s)).$$
To see this, choose a point $v=(v_1,\dots,v_p)\in (-\infty,y_1]\times\dots\times(-\infty,y_p]$ and
let $S(v)\subset S$ be the set of sequences such that $v\in R(s)$ for every $s\in S(v)$.
It is enough to check
$$\delta_v\left((x_1,y_1]\times\dots\times(x_p,y_p]\right) = \sum_{s\in S(v)}(-1)^{K(s)}.$$
where $\delta_v$ is the Kronecker delta measure. 
Now, if $v\in(x_1,y_1]\times\dots\times(x_p,y_p]$ then $S(v)$ contains only a single element $(2,2,\dots,2)$ and $ \sum_{s\in S(v)}(-1)^{K(s)}=1$.
if not there are $m$ values of $i$ such that $n_i=2$ for every $s\in S(v)$ and  the value of $n_i$ is allowed to vary freely is allowed to vary freely on the other $p-m$ values of $i$. 
Therefore there is some value of $i$ such that for every $s\in S(v)$ there exists $s'\in S(v)$ such that $n_j = n'j$ for every $j\neq i$ but $n_i \neq n'_i$. notice we must have $(-1)^{K(s)} + (-1)^{K(s') }= 0$.
Therefore by partitioning $S(v)$ into pairs we must have
$ \sum_{s\in S(v)}(-1)^{K(s)}=1$.
So each point $v$ is counted the correct number of times and our expression for  $P\left((x_1,y_1]\times\dots\times(x_p,y_p]\right) $ is correct.
A: Let $x$ and $y$ be two elements of $\Bbb R^p$ such that $x_i< y_j$ for all $i$. If $I$ is a subset of $[p]$ then $v_I$ is the element of $\Bbb R^p$ such that the coordinated $i\in I$ are $x_i$ and $j\in I^c$ are $y_j$. For example, with $p=3$, $v_{\{1,3\}}=(x_1,y_2,x_3)$. Then 
$$\mathbb P\left(\prod_{j=1}^p(-x_j,y_j]\right)=\sum_{I\subset [p]}(-1)^{|I|}F(v_I).$$
This can be proved by induction on $p$.
