5

I am at my wits' end with my very basic statistics knowledge.

I roll $n$ dice with $k$ sides each (numbered $1$ thru $k$, laplace). I then add the numbers of the $m$ best dice (the higher the roll the better). This sum is the result.

What is the Expected Value of the result? (And how did you obtain it?)

What is the probability of getting the exact result of $x$ ($m \le x \le mk$)?

As you might have guessed, this question is about AD&D, and I got curious about the maths behind it.

EDIT: I think I found a partial solution, but this raises more questions. Please to check to see my answer.

5 Answers5

3

Answer:

The expected value for $n$ dice with $f$ faces, removing ("dropping") the $m$ lowest ones is:

$$ E(n,f,m)=\left(\frac{n+(n\cdot f)} {2}-m\right)-\frac{\displaystyle\sum_{d=1+n-m}^n(d-(n-m))\cdot\binom{n}{d}\cdot\left(\sum_{p=1}^{f-1}p^{n-d}\cdot (f-p)^d\right)}{f^n} $$

Note: The original question was for keeping $m$ highest dice, not removing $m$ lowest ones. For keeping the highest $m$, just put $n-m$ for $m$ into the formula.


Explanation:

Consider 2 3-sided dice ($n=2, f=3$): $$ \begin{array}{c|ccc} \text{Sum} & 1 & 2 & 3 \\ \hline 1 & 2 & 3 & 4 \\ 2 & 3 & 4 & 5 \\ 3 & 4 & 5 & 6 \\ \end{array}$$

$$\text{Average value: } (2+6)/2=4 \\ \text{Elements: }3^2 \\ \text{Sum of all Elements: }4\cdot 3^2=36$$

This approach reduces the $\text{Sum}$:

First, make it a tree. Consider it to start at $(0,0)$ and reach $(1,1)$ with a diagonal arrow. It allows you to treat the first element the same as the others, which makes this approach cleaner.

$$\begin{array}{ccccc} 2 & \rightarrow & 3 & \rightarrow & 4 \\ \downarrow & \searrow & & & \\ 3 & & 4 & \rightarrow & 5 \\ \downarrow & & \downarrow & \searrow & \\ 4 & & 5 & & 6 \\ \end{array}$$

Every arrow here represents a 'step' that increases the value by the dimension of the arrow (1D or 2D). It's the same as picking up the highest $1$ or $2$ dice from whatever you rolled, increase their value by one, and put them back on the table.

If you remove one (the lowest) die, the $2$D dimension will "collapse" into $1$D (because you will only have one die left). Explained by the dice: Going from $(1,1)$ to $(2,2)$ is $2$ more, but after removing $1$ die, it's still just $(1)$ to $(2)$ (which is exactly a $1$D step, doing $+1$).

So, we'll reduce every value that's attached to a diagonal arrow by $1$. This includes $(1,1)$, because we consider it to be attached to $(0,0)$. Therefore, we have to decrease $(1,1)$, $(2,2)$ and $(3,3)$ by $1$ each. Decreasing $(1,1)$ affects $9$ values (the entire tree), $(2,2)$ affects $4$, $(3,3)$ affects just itself.

The total decrease to be substracted from the $\text{Sum}$ is the following:

$$\left( \begin{array}{ccc} 1 & 1 & 1 \\ 1 & 1 & 1\\ 1 & 1 & 1\\ \end{array}\right) + \left( \begin{array}{ccc} 0 & 0 & 0 \\ 0 & 1 & 1\\ 0 & 1 & 1\\ \end{array}\right) + \left( \begin{array}{ccc} 0 & 0 & 0 \\ 0 & 0 & 0\\ 0 & 0 & 1\\ \end{array}\right)=3^2 + 2^2 + 1^2=14$$

And you end up with this tree:

$$\begin{array}{ccccc} 1 & \rightarrow & 2 & \rightarrow & 3 \\ \downarrow & \searrow & & & \\ 2 & & 2 & \rightarrow & 3 \\ \downarrow & & \downarrow & \searrow & \\ 3 & & 3 & & 3 \\ \end{array}$$

It gives $3$ for every combination of dice that contains a $3$, which is what we expect if we take away the lower die from that combination. Same for the lower values.

The maths look like this: $$\text{Substracting the matrices above from the Sum: } 36-(3^2+2^2+1^2)=22 \\ \text{Expected value: Corrected Sum}/\text{Elements in Sum table}=22/9=2.444$$


What if you remove both dice? That should result in a $\text{Sum}$ of $0$, of course. Let's see.

The same logic as above applies. Now both dimensions collapse to $0$D. Every arrow/step does a $+0$.

Generally, all dimensions/steps decrease by $dimension - (dices - m)$. If you have $37$ dice and remove $17$, the $33$th dimension will decrease by $33 - (37 - 17)=13$. This ties a decrease to every dimension, based on $m$. We only consider the dimensions where that is a positive value: $dimension - (dices - m) > 0$.

Above, the 2D step decreased by $2 - (2 - 1)=1$. We used this knowledge to correct the $\text{Sum}$ by $14$. This was done by counting the $2$D arrows - $3$ - and applying the decrease to every element that depended on the value the arrow pointed to.

For $m=2$, both dimensions become $0$D. We now need to take the $1$D dimension into account, as well.

This problem now becomes an arrow-counting problem. How many arrows are there and how much do they affect?

$$ \begin{array}{ccccc} 2 & \color{red}{\rightarrow} & 3 & \color{blue}{\rightarrow} & 4 \\ \color{red}{\downarrow} & \color{green}{\searrow} & & & \\ 3 & & 4 & \color{blue}{\rightarrow} & 5 \\ \color{blue}{\downarrow} & & \color{blue}{\downarrow} & \color{orange}{\searrow} & \\ 4 & & 5 & & 6 \\ \end{array} \implies \begin{array}{c|ccc} \text{Matrix Size} & 1 & 2 & 3\\ \hline \text{Dimension 1} & \color{blue}{4} & \color{red}{2} & 0\\ \text{Dimension 2} & \color{orange}{1} & \color{green}{1} & 1 \end{array}$$

This means that there is $1$ arrow affecting a matrix of dimension $2$ and side length $3$. That's the one from $(0,0)$ to $(1,1)$, of course. It affects the entire tree and therefore will reduce the $\text{Sum}$ by $2 \cdot 3^2$ (the $2$ is the decrease for that dimension). There are two $1$D arrows that affect $2$ values each: The ones from $(1,1)$ to $(1,2)$ and to $(2,1)$. The remaining $4$ $1$D arrows affect just one value each.

So what you now substract from the $\text{Sum}$ is this: $$\begin{align} & 1 \cdot (4 \cdot 1^1 + 2 \cdot 2^1) + \\ & 2 \cdot (1 \cdot 1^2 + 1 \cdot 2^2 + 1 \cdot 3^2) = 36\end{align}$$ which sums up to $36$, great. That means from the $\text{Sum}$ above, we remove all $36$, giving us a $0/9 = 0$, which is what we expected.

In an $n$-dimensional tree, the arrow counts get pretty big pretty fast. Here's an example of 4d6:

dimension 1:
500 256 108 32 4 0
dimension 2:
150 96 54 24 6 0
dimension 3:
20 16 12 8 4 0
dimension 4:
1 1 1 1 1 1

The values increase like so (right to left): $$\binom{dices}{dimension}\cdot step^{dices - dimension}$$ Where $step$ is zero-based, but starts at $1$. In other words, we'll skip the first step, which is $0$ for every dimension except the highest, and then give that highest dimension matrix a separate treatment.

Every such step decreases the total of the $\text{Sum}$ by $decrease\cdot(faces-step)^{dimension}$.

Lastly, to account for the $0$th index of the highest dimension, we can circle back to the very beginning and decrease the value of all elements in the $\text{Sum}$ table by m.

Putting it all together, you end up with:

$$ E(n,f,m)=\left(\frac{n+(n\cdot f)} {2}-m\right)-\frac{\displaystyle\sum_{d=1+n-m}^n(d-(n-m))\cdot\binom{n}{d}\cdot\left(\sum_{p=1}^{f-1}p^{n-d}\cdot (f-p)^d\right)}{f^n} $$

where $d$ denotes the dimension and $p$ the step. $p$ only goes to $f-1$, because the indices are zero-based. The decrease and the $\binom{n}{d}$ have been factored out. $m$ is the amount of the lowest dice you remove. So if $m = n$, the result will be $0$. If you want to use this with the amount of the highest dice you want to keep, then just put $n-m$ instead of $m$ into this formula.


Special cases:

In the case of $m=1$, which means 'roll $n$ dice, take away the lowest one', this collapses to: $$ \begin{align} E(n,f,1)&=\left(\frac{n+(n\cdot f)} {2}-1\right)-\frac{\sum_{d=1+n-1}^n(d-(n-1))\cdot\binom{n}{d}\cdot\left(\sum_{p=1}^{f-1}p^{n-d}\cdot (f-p)^d\right)}{f^n}\\ &=\left(\frac{n+(n\cdot f)} {2}-1\right)-\frac{(n-(n-1))\cdot\binom{n}{n}\cdot\left(\sum_{p=1}^{f-1}p^{n-n}\cdot (f-p)^n\right)}{f^n}\\ &=\left(\frac{n+(n\cdot f)} {2}-1\right)-\frac{\sum_{p=1}^{f-1}(f-p)^n}{f^n}\\ &=\left(\frac{(f+1)\cdot n} {2}-\frac{f^n}{f^n}\right)-\frac{\sum_{p=1}^{f-1}p^n}{f^n}\\ &=\frac{(f+1)\cdot n} {2}-\left(\frac{\sum_{p=1}^{f-1}p^n}{f^n}+\frac{f^n}{f^n}\right)\\ &=\frac{(f+1)\cdot n} {2}-\frac{\sum_{p=1}^{f}p^n}{f^n}\\ &=\frac{(f+1)\cdot n} {2}-\frac{H_{f}^{(-n)}}{f^n} \end{align} $$

where $H$ is the generalized harmonic number. In the further case of $n=2, m=1$, which means 'roll two dice, take the higher one/roll two dice, remove the lower one/roll with advantage', we get: $$ E(2,f,1)=\frac{(f+1)\cdot 2} {2}-\frac{H_{f}^{(-2)}}{f^2} =f+1-\frac{\frac{f^3}{3}+\frac{f^2}{2}+\frac{f}{6}}{f^2} =\frac{(4f-1)(f+1)}{6f} $$

which, divided by $f$, approaches $\frac{2}{3}$ as $f\to\infty$, giving the somewhat well-known result that rolling with advantage is, on average, approximately $\frac{2}{3}$ times highest face on the die.

Finally, for $n=2, f=3, m=1$, as above: $$ E(2, 3, 1)=\frac{(4\cdot3 -1)(3+1)}{6\cdot3}=\frac{11\cdot4}{18}=\frac{22}{9}=2.444 $$

Some examples:

$E(2,6,1) = 161 / 36 = 4.47222$
$E(2,20,1)=5530/400=13.825$
$E(4,6,1)=15869/1296=12.2446$
$E(4,6,3)=6797 / 1296 = 5.2446$
$E(33,22,11)=410237042226924051890969990312773679921645 / 1238753918671327566481737454139790589952 = 331.169$

Thomas B.
  • 187
1

This is only the case $n=4,k=6,m=3$:

 X    Count     Probability
 3        1     0.0008
 4        4     0.0031
 5       10     0.0077
 6       21     0.0162
 7       38     0.0293
 8       62     0.0478
 9       91     0.0702
10      122     0.0941
11      148     0.1142
12      167     0.1289
13      172     0.1327
14      160     0.1235
15      131     0.1011
16       94     0.0725
17       54     0.0417
18       21     0.0162

Simple Perl program.

Thomas Andrews
  • 177,126
  • Thank you. Is there also a closed expression for $E(n,k,m)$ or $P(n,k,m,x)$ without the need of actually summing up all the possible combinations? – Hyperboreus Jul 15 '13 at 19:11
1

$\def\eqdef{\stackrel{\text{def}}{=}}$ The $\ S\ $ you're interested in is that of the last $\ m\ $ order statistics of the values shown on the dice's faces. The order statistics are those values $\ V_1\le$$\,V_2\le\dots\le V_n\ $ arranged in increasing order, and so $$ S=\sum_{t=1}^mV_{n+1-t}\ , $$ or, putting $\ B_t\eqdef V_{n+1-t}\ $, $$ S=\sum_{t=1}^mB_t\ . $$ The expectation $\ E(n,k,m)\eqdef\Bbb{E}(S)\ $ can be evaluated using the linearity of expectation: \begin{align} \Bbb{E}(S)&=\sum_{t=1}^m\Bbb{E}\big(B_t\big)\\ &=\sum_{t=1}^m\sum_{r=1}^kr\,\Bbb{P}\big(B_t=r\big)\tag{1}\label{exp1} \end{align} and the probability mass functions $\ \Bbb{P}\big(B_t=r\big)\ $ of the random variables $\ B_t\ $. In a separate section below, I derive an expression for the probability mass functions of $\ B_t\ $ and provide a Magma script for evaluating $\ E(n,k,m)\ $ using the expression \eqref{exp1}.

Since the order statistics aren't independent, it's not possible to obtain the probability mass function $\ P(n,k,m,x)\eqdef$$\,\Bbb{P}(S=x)\ $ of $\ S\ $ by convolving those of $\ B_m,$$\,B_{m-1},$$\,\dots,B_1\ $. It is possible, however, to express $\ P(n,k,m,x)\ $ in terms of the joint probability mass function of $\ B_m,B_{m-1},\dots,B_1\ $. While there's no simple closed form expression for it, it can nevertheless be expressed as a sum of products of powers, binomial coefficients and restricted composition numbers. The work necessary to evaluate this sum is a polynomial function of $\ n\ $ and so, when $\ n\ $ is large, it requires much less work than that needed to exhaust over all possible combinations, which grows exponentially with $\ n\ $.

The expression for $\ P(n,k,m,x)\ $ is $$ \sum_{a=1}^{m-1}{n\choose a}\sum_{r=\max\left(1,\left\lceil\frac{x-ka}{m-a}\right\rceil\right)}^{\min\left(k,\left\lfloor\frac{x-a}{m-a}\right\rfloor\right)}p_{x-(m-a)r,a,r+1,k}\ \ \sum_{b=m-a}^{n-a}{n-a\choose b}\left(\frac{1}{k}\right)^{a+b}\left(\frac{r-1}{k}\right)^{n-a-b} $$ if $\ x\ $ is not evenly divisible by $\ m\ $, where $\ p_{z,a,\ell,u}\ $ is the number of restricted compositions of length $\ a\ $ of the number $\ z\ $ into parts of sizes between $\ \ell\ $ and $\ u\ $ (inclusive), or \begin{align} \sum_{b=m}^n&{n\choose b}\left(\frac{1}{k}\right)^b\left(\frac{x-m}{mk}\right)^{n-b}+\\ &\sum_{a=1}^{m-1}{n\choose a}\sum_{r=\max\left(1,\left\lceil\frac{x-ka}{m-a}\right\rceil\right)}^{\min\left(k,\left\lfloor\frac{x-a}{m-a}\right\rfloor\right)}p_{x-(m-a)r,a,r+1,k}\ \ \sum_{b=m-a}^{n-a}{n-a\choose b}\left(\frac{1}{k}\right)^{a+b}\left(\frac{r-1}{k}\right)^{n-a-b} \end{align} if $\ x\ $ is evenly divisible by $\ m\ $.

The following Magma script evaluates $\ P(n,k,m,x)\ $ using the above expressions. You can run it by copying and pasting it into the online Magma calculator. For $\ n=4,k=6,m=3\ $ it agrees with the results obtained by Thomas Andrews in his answer. It also contains code to evaluate $\ E(n,k,m)\ $ using the definition $$ E(n,k,m)=\sum_{x=m}^{km}xP(n,k,m,x) $$ and obtains the same values for $\ E(n,k,m)$ Thomas B. does with the method he describes in his answer, except for the case $\ n=33, k=22\ $. When $\ n\ $ and $\ k\ $ are both that large, the computation of the restricted composition numbers $\ p\ $ exceeds the time limit imposed by the online Magma calculator.

restcomp:=function(x,n,l,u)
   rcold:=ZeroMatrix(Integers(),1,Min(x,u*(n-1)));
   rcnew:=ZeroMatrix(Integers(),1,Min(x,u*(n-1)));
   if (x lt n*l) or (x gt n*u) then
      return(0);
   end if;
   if n eq 1 then      
       return(1);
   else
       for xi in [l..Min(x,u)] do     
         rcold[1,xi]:=1;
       end for;
       for ni in [2..n-1] do
          for xi in [ni*l..Min(x,ni*u)] do
             for v in [Max(l,xi-(ni-1)*u)..Min(xi-1,u)] do
                rcnew[1,xi]:=rcnew[1,xi]+rcold[1,xi-v];
             end for;
          end for;
          rcold:=rcnew;
          rcnew:=ZeroMatrix(Integers(),1,Min(x,u*(n-1)));              
       end for;
       tot:=0;
       for v in [Max(l,x-(n-1)*u)..Min(x-1,u)] do
          tot:=tot+rcold[1,x-v];
       end for;
       return(tot);
   end if;
end function;
P:=function(n,k,m,x)   
   pr:=0;
   for a in [1..m-1] do
     g1:=Max(1,Ceiling(Rationals()!(x-k*a)/Rationals()!(m-a)));
     g2:=Min(k,Floor(Rationals()!(x-a)/Rationals()!(m-a)));
     sc:=0;
     for r in [g1..g2] do
         s:=0;
         for b in [m-a..n-a] do
            s:=s+Binomial(n-a,b)*Binomial(n,a)*(r-1)^(n-a-b)/k^n;
         end for;
         sc:=sc+s*restcomp(x-(m-a)*r,a,r+1,k);
     end for;
     pr:=pr+sc;
   end for;
   if IsDivisibleBy(x, m) then
      for  b in [m..n] do
          pr := pr+Binomial(n,b)*(x-m)^(n-b)/(m^(n-b)*k^n);
      end for;
   end if;
   return( pr );
 end function;

E:= function(n,k,m) expv:=0; for x in [m..k*m] do expv:=expv+x*P(n,k,m,x); end for; return(expv); end function;

for x in [3..18] do print x, P(4,6,3,x), RealField(7)!P(4,6,3,x); end for;

print E(2,6,1), E(2,20,1), E(4,6,3), E(4,6,1);

Probability mass function of $\ B_t $

The event $\ \big\{B_t=r\big\}\ $ occurs if and only if the uppermost faces of some number $\ a\ $ between $\ 0\ $ and $\ t-1\ $ of dice bear numbers strictly greater than $\ r\ $, the uppermost faces of some number $\ b\ $ between $\ t-a\ $ and $\ n-a\ $ of the remaining dice show exactly $\ r\ $, and the uppermost faces of the remaining $\ n-a-b\ $ dice bear numbers strictly less than $\ r\ $. The probability of this event is $$ \sum_{a=0}^{t-1}{n\choose a}\sum_{b=t-a}^{n-a}\left(\frac{k-r}{k}\right)^a{n-a\choose b}\left(\frac{1}{k}\right)^b\left(\frac{r-1}{k}\right)^{n-a-b}\ , $$ which is therefore the value of $\ \Bbb{P}\big(B_t=r\big)\ $. In the above expression, $\ {n-a\choose b}\ $ is the number ways the $\ a\ $ dice to show numbers strictly larger than $\ r\ $ can be chosen, and $\ \left(\frac{k-r}{k}\right)^a\ $ is the probability that they will all in fact show numbers strictly larger than $\ r\ $, $\ {n-a\choose b}\ $ is the number of ways $\ b\ $ of the remaining $\ n-a\ $ dice to show exactly the number $\ r\ $ can be chosen, and $\ \left(\frac{1}{k}\right)^b\ $ is the probability that those $\ b\ $ dice will in fact all show the number $\ r\ $. Finally, $\ \left(\frac{r-1}{k}\right)^{n-a-b}\ $ is the probability that the remaining $\ n-a-b\ $, designated as showing numbers strictly less than $\ r\ $ will in fact all show numbers strictly less than $\ r\ $.

The following Magma script to evaluate $\ E(n,k,m)\ $ for arbitrary values of $\ n,k\ $ and $\ m\ $ using the expression \eqref{exp1}. It obtains the same values for $\ E(n,k,m)$ as the procedure given above using the probability mass function of $\ S\ $. Thanks to Thomas B. for picking up the fact that my $\ m\ $ is his $\ n-m\ $, and thus resolving an apparent discrepancy I had been concerned about earlier.

expv:=function(n,k,m)
   ev:=0;
   for t in [1..m] do
     evbt:=0;
     for r in [1..k] do
       pbter:=0;
       for a in [0..t-1] do
         s:=0;
         for b in [t-a..n-a] do
            s:=s+Binomial(n-a,b)*Binomial(n,a)*(r-1)^(n-a-b);
         end for;
         pbter:=pbter+s*(k-r)^a/k^n;
       end for;
       evbt:=evbt+r*pbter;
     end for;
     ev:=ev+evbt;
   end for;
   return( ev );
 end function;

print expv(2,6,1), expv(2,20,1), expv(4,6,3), expv(4,6,1); print expv(33,22,22), RealField(10)!expv(33,22,22);

print expv(2,6,1), expv(2,20,1), expv(4,6,3), expv(4,6,1); print expv(33,22,22), RealField(10)!expv(33,22,22);

Addendum

I agree with the expression you derive for $\ E(n,k)\eqdef$$\,E(n,k,n-1)\ $ in your answer. I believe it's possible to derive your expression by substituting the one I give above for $\ \Bbb{P}\big(B_t=r\big)\ $ into the sum $\ \sum_\limits{t=1}^{n-1}\sum_\limits{r=1}^kr\,\Bbb{P}\big(B_t=r\big)\ $. The only way I can see of proving the identity algebraically, however, is to transfer the sum over $\ t\ $ across the other three sums in the expression so that it becomes the inner sum instead of the outer sum. The algebraic manipulations necessary to do this are rather cumbersome and error-prone, and since I'm satisfied your expression is correct, I eventually gave up trying to prove it by this unnecessarily convoluted procedure. I did however write a Magma function to evaluate your expression for $\ E(n,k)\ $ and compare its output with that of $\ E(n,k,n-1)\ $ as produced by the above Magma script. For every pair $\ n,k\ $ I tried, the results were identical. Here they are: \begin{align} E(2,6)&=\frac{161}{36}=E(2,6,1)\\ E(2,20)&=\frac{553}{40}=E(2,20,1)\\ E(4,6)&=\frac{15869}{1296}=E(4,6,3)\\ E(33,22)&=\frac{ 56692906323757439755684138687075800338253661}{149889224159230635544290231950914661384192}\\ &=E(33,22,32)\ . \end{align}

lonza leggiera
  • 28,646
  • 2
  • 12
  • 33
  • The values you're getting are correct. The difference is that your solution gives the result for keeping $m$ dice, mine is for removing $m$ dice. Keeping 11 dice (from 33d22) gives 204.669. – Thomas B. May 08 '23 at 17:43
  • Fair point actually, I failed to make that clear. I've edited my answer. Your Magma links don't seem to work for me...? – Thomas B. May 08 '23 at 17:50
  • @Thomas B. Thank you for resolving the apparent discrepancy. In an earlier edit of mine, I inadvertently overwrote the Magma script I had originally included in the answer. I've now restored it. Hopefully it was the absence of the script that was causing you problems, rather than the links not actually working. – lonza leggiera May 08 '23 at 23:56
0

I think I have come to a solution for $m=n-1$, but it would be great if someone could check it.

We roll $n$ $k$-sided dice, ignore the least roll ($m=n-1$) and sum the rest.

Let $P_\ge(x)$ denote the probability that every single roll of the $n$ rolls is greater or equal to $x$.

$P_\ge(x) = \dfrac {(k - x + 1) ^ n} {k^n}$

Let $P_{\ge2}(x)$ denote the probability that every single roll of the $n$ rolls is greater or equal to $x$ and at least one roll equals $x$.

$$P_{\ge2}(x) = \dfrac {(k - x + 1) ^ n} {k^n} - \sum_{\nu=x + 1}^kP_\ge(\nu) \\ = \dfrac {(k - x + 1) ^ n - (k - x)^n} {k^n} $$ This $P_{\ge2}(x)$ is actually the probability that I have to rest $x$ from the sum of my rolls.

Its expected value is $E(P_{\ge2})$. $$ E(P_{\ge2}) = \sum_{\nu=1}^k \nu P_{\ge2}(\nu) \\ = \sum_{\nu=1}^k \nu \dfrac {(k - \nu + 1) ^ n - (k - \nu)^n} {k^n} $$

So I expect to subtract $E(P_{\ge2})$ from every $n$ rolls I do. The expected value of rolling $n$ $k$-sided dice without ignoring any rolls is $E_0 (n,k)=\dfrac{k+1}{2}n$.

Hence the expected value for rolling $n$ dice and ignoring one is: $$E (n,k) = E_0 (n,k)- E(P_{\ge2}) \\ = \dfrac{k+1}{2}n - \sum_{\nu=1}^k \nu \dfrac {(k - \nu + 1) ^ n - (k - \nu)^n} {k^n} $$

Comparing the result of this formula with real results (little program doing the rolls) shows that it seems to hold.

Is my thinking correct or is this just an approximation (I am not sure about simply subtracting both expected values)?

How can this be expanded for $m \ne n-1$?

0

This class of question was also asked about here.

Multiset enumeration

I would be remiss not to mention AnyDice, which can conveniently compute many problems of this type and is the currently the most popular resource of its type in the tabletop RPG area. However, it does enumerate all $\binom{n + k - 1}{n}$ possible multisets that can come out of a pool, so

output [highest 11 of 22d33]

would attempt to evaluate over 781 trillion possibilities, far beyond its 5-second limit.

Fast Fourier Transform

That the sum of a set of dice can be computed via convolution is a classical result in discrete statistics. Convolution (sometimes also framed in terms of generating functions) allows us to use the fantastically efficient fast Fourier transform (FFT). With some more work, FFTs can also be used the case where only some of the dice are kept. Approaches of this type have been proposed on StackExchange, with examples including:

Dynamic programming

However, my preferred approach is dynamic programming (sometimes also framed in terms of recurrence relations). Examples include:

The short of it is that we compute the answer to the problem to "roll $n$ d10, keep $m$" by considering how many dice $k = 0 \ldots n$ might possibly roll a 10, and then use the solutions to "roll $n - k$ d9, keep $m - k$" -- namely, the remaining pool after the $k$ dice that rolled a 10 are removed -- to complete the solution. In turn, the solutions for d9s use the solutions for d8s, and so forth until we reach d1s and all of the remaining dice must roll 1. While not as fast as FFTs, the dynamic programming approach is much more flexible, covering general "single-pass" functions over order statistics: in addition to summing the dice, it can also be used to produce efficient solutions for matching sets, straights, RISK-like mechanics, and so forth.

I've implemented this in my Icepool Python package. Here is an example script for keeping the highest 11 out of 33d22:

from icepool import d

output(d(22).highest(33, 11))

You can try it online here.

If you are interested in learning more, you can read my paper on the subject.

@inproceedings{liu2022icepool,
    title={Icepool: Efficient Computation of Dice Pool Probabilities},
    author={Albert Julius Liu},
    booktitle={Eighteenth AAAI Conference on Artificial Intelligence and Interactive Digital Entertainment},
    volume={18},
    number={1},
    pages={258-265},
    year={2022},
    month={Oct.},
    eventdate={2022-10-24/2022-10-28},
    venue={Pomona, California},
    url={https://ojs.aaai.org/index.php/AIIDE/article/view/21971},
    doi={10.1609/aiide.v18i1.21971}
}