This is a subproblem that arose from a programming exercise that I'm doing (which is not a homework).
I have a hyperrectangle in $\mathbb{R}^d$ with dimensions $l_1\times l_2\times l_3\cdots \times l_d$, which is placed so that the $i$ coordinate of a point inside the rectangle lies between $0$ and $l_i$. My rectangle was ate by the part that satisfies $x_1+x_2+\cdots+x_d\leq s$. I need to find the volume $V$ that is gone.
I will get inputs for all $d, s, l_1, l_2, \cdots l_d$, so I need to keep the algorithm for finding $V$ as general as possible. We can also assume that $s\leq \sum_{i=1} ^dl_i$ so that the hyperplane always intersects with the hyperrectangle.
I think I need to use the inclusion-exclusion principle. For each coordinate, we need to consider whether $l_i\leq s$ or $l_i>s$. Let $T$ be the volume of the set $\{(x_1, x_2, \cdots, x_d) | x_1+x_2+\cdots+x_d\leq s, x_i\geq 0 \; \text{for} \; i=1, 2, \cdots d\}$. Then, I think $T=\frac{s^d}{d!}$ since it matches for both $d=2, 3$(I haven't done the exact integral). Here is where I got stuck, I'm not sure how to use the inclusion-exclusion principle here. If $l_i>s$ for some $i$, the similarity ratio is $l_i-s:s$ so the volume ratio is $\frac{(l_i-s)^d}{s^d}$ and I suppose I can subtract $\frac{(l_i-s)^d}{s^d}T$ from $T$. But I'm not sure how to handle cases where $l_i>s$ and $l_{i+1}>s$ or $l_i>s$ and $l_{i+1}<s$.