Why are $\lceil 1/\operatorname{entropy-per-bit} \rceil$ number of bits not sufficient to generate an unbiased bit?
Because the question is formulated for just one (nearly) unbiased bit to produce. For a large number of (nearly) unbiased bits to produce, that would be enough.
Assume $n$ independent input bits $b_j$, each set with known probability exactly $\alpha$, thus $\operatorname{entropy-per-bit}=\alpha\log_2(\alpha)-(1-\alpha)\log_2(1-\alpha)$. The question is for $\alpha=0.9$, thus $\operatorname{entropy-per-bit}\approx0.468996$, and $\lceil 1/\operatorname{entropy-per-bit} \rceil=3$.
We can make an explicit algorithm generating $m$ bits from $n=\lceil(m+\ell)/\operatorname{entropy-per-bit}\rceil$ bits of the biased source, with advantage $\mathcal O(2^{-\ell})$ (including vanishing individual bit bias) for an adversary trying to distinguish the output from $m$ uniform random bits.
One of the simplest such algorithm, generating $m$ bits from $n$ goes:
- $x\gets0$ and $y\gets1$ (these a real values, or rationals when $\alpha$ is rational)
- for each of the $n$ input bits $b_j$
- if $b_j=0$, then $y\gets\alpha\,x+(1-\alpha)\,y$, else $x\gets\alpha\,x+(1-\alpha)\,y$
- output the $m$ bits of the binary expression of $\lfloor x\,2^m\rfloor$.
This is a so-called arithmetic coder. There are slightly more complex variants that most of the time output some bits before the end. There are other variants that use bounded memory (here, we need storage proportional to $m$), at the expense of a small bias.
Back to the problem of generating a single output bit, as unbiased as possible, from a fixed number $n\ge1$ input bits.
There are $2^n$ possible values of $n$ input bits. For any such $n$-bit bitstring, note $i$ the corresponding integer per big-endian binary convention (thus $0\le i<2^n$) and $\mathcal\|i\mathcal\|=k$ the number of ones in $i$, with thus $0\le k\le n$. Value $i$ has probability $p_i=(1-\alpha)^{n-k}\,\alpha^k$. There are $n\choose k$ values $i$ with the same probability $q_k$, and correspondingly $1=\sum{n\choose k}q_k$. Recall $n\choose k$ is given by Pascal's triangle.
For each of the $2^n$ possible values $i$, we can decide if it will output a $0$ or a $1$. The probability of a $1$ at the output is the sum of the $p_i$ for the $i$ we decide will output a $1$. That's $2^{(2^n)}$ assignments, which quickly becomes too much to explore. However we can make simplifications:
- The only thing that matters to the final probability is how many $i$ with a given $\mathcal\|i\mathcal\|=k$ output a $1$. That's an integer $m_k\in[0,{n\choose k}]$, and the final probability of a $1$ is $\sum{m_k\,q_k}$.
- In the search of the $m_k$ leading to $p$ closest to $1/2$, we can force $m_n=1$ (meaning that if all the input bits are set, that is $i=2^-1$, the output will be $1$). That's because changing all the $m_k$ to $m'_k={n\choose k}-m_k$ will change the probability of a $1$ from $p$ to $p'=1-p$, leaving the bias from $1/2$ unchanged in absolute value.
For example, with $n=2$, we can have $m_0\in\{0,1\}$, $m_1\in\{0,1,2\}$, for a total of only $2\times3=6$ possibilities of the outcome as a function of the two input bits $b_0$ and $b_1$. We show the corresponding probability $p$ that the output is $1$, and the value of $\alpha$ for $p=1/2$, if any.
$$\begin{array}{cc|cccc|c|l}
&&0&0&1&1&b_0\\
&&0&1&0&1&b_1\\
\hline
m_0&m_1&&&&&p&\alpha\text{ for }p=1/2\\
\hline
0&0&0&0&0&1&\alpha^2&1/\sqrt2\\
0&1&0&0&1&1&\alpha&1/2\\
0&2&0&1&1&1&2\alpha-\alpha^2&1-1/\sqrt2\\
1&0&1&0&0&1&1-2\alpha+2\alpha^2&1/2\\
1&1&1&0&1&1&1-\alpha+\alpha^2\\
1&2&1&1&1&1&1\\
\hline
&&0&1&1&2&k\\
\end{array}$$
I don't know where the question's $n=849$ bit for $2^{-64}$ bias and $\alpha=0.9$ exactly comes from, but it's much too high. With $n=6$ we can't get better than $p=0.469\ldots$, but with $n=7$, $m_0=1$, $m_1=3$, $m_2=6$, $m_3=0$, $m_4=6$, $m_5=3$, $m_6=0$, $m_7=1$ gets $p=0.499996$, and I think we get one extra decimal (over 3 bits) for each increment of $n$.
Pseudocode implementing this strategy goes
- $i\gets0$ and $k\gets0$
- for each in $n=7$ input bits $b_j$
- $i\gets2i+b_j$
- $k\gets k+b_j$
- if $k=7$, return $1$;
- if $k=5$ and $i\le\mathtt{0110111_b}$, return $1$;
- if $k=4$ and $i\le\mathtt{0100111_b}$, return $1$;
- if $k=2$ and $i\le\mathtt{0001100_b}$, return $1$;
- if $k=1$ and $i\le\mathtt{0000100_b}$, return $1$;
- if $k=0$, return $1$;
- return $0$.
Note: the binary constant for $k$ is the ${m_k}^\text{th}$ integer with exactly $k$ bit(s) set.
A use case of this algorithm is to generate one almost unbiased bit from $n=7$ throws of a dice 10 with only one of the 10 sides marked. This is not a common setup, and correspondingly this algorithm is seldom used. That's because in practice, we seldom know exactly the $\alpha$ of a biased source. In that case, the applied cryptographer feeds the input to a CSPRNG.