## Introduction

As a rhythm game player, I often wonder what my max combo will be in my next play. This is a rather unpredictable outcome, and what I can do is to try to conclude a probability distribution of my max combo.

For those who are not familiar with rhythm games and also to make the question clearer, I state the problem in a more mathematical setting.

Consider a random bit string of length $n\in\mathbb N$, where each bit is independent and has probability $Y\in[0,1]$ of being $1$. Let $P_{n,k}(Y)$ be the probability that the length of the longest all-$1$ substring of the bit string is $k\in\mathbb N$ (where obviously $P_{n,k}(Y)$ is nonzero only when $k\le n$). What is the expression of $P_{n,k}(Y)$?

A more interesting problem to consider is what the probability distribution tends to be when $n\to\infty$. Define the random variable $\kappa\coloneqq k/n$ where $k$ is the length of the longest all-$1$ substring. Define a parameter $y\coloneqq Y^n$ (this parameter is held constant while $n\to\infty$). Define the probability distribution function of $\kappa$ as $f(y,\kappa)\coloneqq\lim_{n\to\infty}\left(n+1\right)P_{n,\kappa n}\!\left(y^{\frac1n}\right).$$\p{1}$ What is the expression of $f(y,\kappa)$?

## Notation

Notation for integer range: $a\ldots b$ denotes the integer range defined by the ends $a$ (inclusive) and $b$ (exclusive), or in other words $\left\{a,a+1,\ldots,b-1\right\}$. It is defined to be empty if $a\ge b$. The operator $\ldots$ has a lower precedence than $+$ and $-$ but a higher precedence than $\in$.

The notation $a\,..b$ denotes the inclusive integer range $\left\{a,a+1,\ldots,b\right\}$. It is defined to be empty if $a>b$.

## The case for finite $n$

A natural approach to find $P_{n,k}$ is to try to find a recurrence relation of $P_{n,k}$ for different $n$ and $k$, and then use a dynamic programming (DP) algorithm to compute $P_{n,k}$ for any given $n$ and $k$.

### The first DP approach

For a rhythm game player, the most straightforward way of finding $k$ for a given bit string is to track the current combo, and update the max combo when the current combo is greater than the previous max combo.

To give the current combo a formal definition, denote each bit in the bit string as $b_i$, where $i\in0\ldots n$. Define the current combo $r_i$ as the length of the longest all-$1$ substring of the bit string ending before (exclusive) $i$ (so $r_i=0$ if $b_{i-1}=0$, which is callled a combo break): $r_i\coloneqq\max\left\{r\in0\,..i\,\middle|\,\forall j\in i-r\ldots i:b_j=1\right\},$ where $i\in0\,..n$.

Now, use three numbers $(n,k,r)$ to define a DP state. Denote $P_{n,k,r}$ to be the probability that the max combo is $k$ and the final combo ($r_n$) is $r$. Then, consider a transition from state $(n,k,r)$ to state $(n+1,k',r')$ by adding a new bit $b_n$ to the bit string. There are two cases:

• If $b_n=0$ (has $1-Y$ probability), then this means a combo break, so we have $r'=0$ and $k'=k$.
• If $b_n=1$ (has $Y$ probability), then the combo continues, so we have $r'=r+1$. The max combo needs to be updated if needed, so we have $k'=\max(k,r')$.

However, in actual implementation of the DP algorithm, we need to reverse this transition by considering what state can lead to the current state $(n,k,r)$ (to use the bottom-up approach).

First, obviously in any possible case $r\in0\,..k$ (currently we only consider the cases where $n>k>0$). Divide all those cases into three groups:

1. If $r=0$, this is means a combo break, so the last bit is $0$, and the previous state can have any possible final combo $r'$. Therefore, it can be transitioned from any $(n-1,k,r')$ where $r'\in0\,..k$. For each possible previous state, the probability of the transition to this new state is $1-Y$.
2. If $r\in1\,..k-1$, this means the last bit is $1$, the previous final combo is $r-1$, and the previous max combo is already $k$. Therefore, the previous state is $(n-1,k,r-1)$, and the probability of the transition is $Y$.
3. If $r=k$, this means the max combo may (or may not) have been updated. In either case, the previous final combo is $r-1=k-1$.
• If the max combo is updated, the previous max combo must be $k-1$ because it must not be less than the previous final combo $k-1$ and must be less than the new max combo $k$. Therefore, the previous state is $(n-1,k-1,k-1)$, and the probability of the transition is $Y$.
• If the max combo is not updated, the previous max combo is the same as the new one, which is $k$. Therefore, the previous state is $(n-1,k,k-1)$, and the probability of the transition is $Y$.

Therefore, we can write a recurrence relation that is valid when $n>k>0$: $P_{n,k,r}=\begin{cases} \left(1-Y\right)\sum_{r'=0}^kP_{n-1,k,r'},&r=0\\ YP_{n-1,k,r-1},&r\in1\,..k-1\\ Y\left(P_{n-1,k-1,k-1}+P_{n-1,k,k-1}\right),&r=k. \end{cases}$

However, there are also other cases (mostly edge cases) because we assumed $n>k>0$. Actually, in the meaningfulness condition $n\ge k\ge r\ge0$ (necessary condition for $P_{n,k,r}$ to be nonzero), there are three inequality that can be altered between a less-than sign or an equal sign, so there are totally $2^3=8$ cases. Considering all those cases (omitted in this article because of the triviality), we can write a recurrence relation that is valid for all $n,k,r$, covering all the edge cases: $P_{n,k,r}=\begin{cases} 1,& n=k=r=0,\\ YP_{n-1,n-1,n-1},& n=k=r>0,\\ 0,& n=k>r>0,\\ 0,& n=k>r=0,\\ Y\left(P_{n-1,k-1,k-1}+P_{n-1,k,k-1}\right),& n>k=r>0,\\ YP_{n-1,k,r-1},& n>k>r>0,\\ \left(1-Y\right)\sum_{r'=0}^kP_{n-1,k,r'},& n>k>r=0,\\ \left(1-Y\right)P_{n-1,0,0},& n>k=r=0. \end{cases}$$\p{2}$

Note that the probabilities related to note count $n$ only depend on those related to note count $n-1$ and that the probabilities related to max combo $k$ and final combo $r$ only depend on those related to either less max combo than $k$ or less final combo than $r$ (except for the case $n>k>r=0$, which can be specially treated before the current iteration of $k$ actually starts), so for the bottom-up DP we can reduce the spatial complexity from $O\!\left(n^3\right)$ to $O\!\left(n^2\right)$ by reducing the 3-dimensional DP to a 2-dimensional one. What needs to be taken care of is that the DP table needs to be updated from larger $k$ and $r$ to smaller $k$ and $r$ instead of the other way so that the numbers in the last iteration in $n$ are left untouched while we need to use them in the current iteration.

After the final iteration in $n$ finishes, we need to sum over the index $r$ to get the final answer: $P_{n,k}=\sum_{r=0}^kP_{n,k,r}.$

Writing the code for the DP algorithm is then straightforward. Here is an implementation in Ruby. In the code, dp[k][r] means $P_{n,k,r}$ in the $n$th iteration.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14  ## Returns an array of size m+1, ## with the k-th element being the probability P_{m,k}. def combo m (1..m).each_with_object [[1]] do |n, dp| dp[n] = [0]*n + [Y * dp[n-1][n-1]] # n = k > 0 (n-1).downto 1 do |k| # n > k > 0 dpk0 = (1-Y) * dp[k].sum dp[k][k] = Y * (dp[k-1][k-1] + dp[k][k-1]) # n > k = r > 0 (k-1).downto(1) { |r| dp[k][r] = Y * dp[k][r-1] } # n > k > r > 0 dp[k][0] = dpk0 # n > k > r = 0 end dp[0][0] *= 1-Y # n > k = r = 0 end.map &:sum end 

Because of the three nested loops, the time complexity of the DP algorithm is $O\!\left(n^3\right)$.

### The second DP approach

Here is an alternative way to use DP to solve the problem. Instead of building a DP table with the $k,r$ indices, we can build a DP table with the $n,k$ indices.

First, we need to rewrite the recurrence relation of $P_{n,k}$ instead of that of $P_{n,k,r}$. We then need to try to express $P_{n,k,r}$ in terms of $P_{n,k}$ terms. The easiest part is the case where $n\ge k=r=0$. By recursively applying Equation 2 to $P_{n,0,0}$, we have \begin{align*} P_{n,0,0}&=\left(1-Y\right)P_{n-1,0,0}\\ &=\left(1-Y\right)^2P_{n-2,0,0}\\ &=\cdots\\ &=\left(1-Y\right)^nP_{0,0,0}. \end{align*} Because $P_{0,0,0}=1$, we have $P_{n,0,0}=\left(1-Y\right)^n.$$\p{3}$

For $n>k>r>0$, we can recursively apply Equation 2 to get \begin{align*} P_{n,k,r}&=YP_{n-1,k,r-1}\\ &=Y^2P_{n-2,k,r-2}\\ &=\cdots \end{align*} This will finally either decend the note count to $k$ or decend the final combo to $0$, determined by which comes first.

• If $n-r\le k$, we will decend to the term $P_{k,k,r-(n-k)}$, which must be zero according to the case $n=k>r=0$ and the case $n=k>r>0$ in Equation 2, so $P_{n,k,r}=0$.
• If $n-r>k$, then we will decend to the term $P_{n-r,k,0}$, which is equal to $\left(1-Y\right)P_{n-r-1,k}$ according to the case $n>k>r=0$ in Equation 2.

Therefore, for $n>k>r>0$, we have $P_{n,k,r}=\begin{cases} 0,&n-r\le k,\\ Y^r\left(1-Y\right)P_{n-r-1,k},&n-r>k. \end{cases}$$\p{4}$

For the case $n>k=r>0$, we can also recursively apply Equation 2 to get \begin{align*} P_{n,k,k}&=Y\left(P_{n-1,k-1,k-1}+P_{n-1,k,k-1}\right)\\ &=Y\left(Y\left(P_{n-2,k-2,k-2}+P_{n-2,k-1,k-2}\right)+P_{n-1,k,k-1}\right)\\ &=\cdots\\ &=Y\left(Y\left(\cdots Y\left(P_{n-k,0,0}+P_{n-k,1,0}\right)+\cdots\right)+P_{n-1,k,k-1}\right)\\ &=Y^kP_{n-k,0,0}+\sum_{j=1}^kY^jP_{n-j,k-j+1,k-j}. \end{align*} We can then substitute Equation 3 and 4 into the above equation. The substitution of Equation 3 can be done without a problem, but the substitution of Equation 4 requires some care because of the different cases.

• If $n-k>k$, then only the case $n-r>k$ in Equation 4 will be involved in the summation.
• If $n-k\le k$, then both cases in Equation 4 will be involved in the summation. To be specific, for $j\in1\,..\,2k-n+1$, we need the case $n-r\le k$ in Equation 4 (where the summed terms are just zero and can be omitted); for other terms in the summation, we need the other case.

Considering both cases, we may realize that we can just modify the range of the summation to $j\in\max(1,2k-n+1)\,..k$ and adopt the case $n-r>k$ in Equation 4 for all terms in the summation. Therefore, we have \begin{align*} P_{n,k,k}&=Y^k\left(1-Y\right)^{n-k}+\sum_{j=\max(1,2k-n+1)}^{k}Y^jY^{k-j}\left(1-Y\right)P_{n-j-(k-j)-1,k-j+1}\\ &=Y^k\left(1-Y\right)^{n-k}+Y^k\left(1-Y\right)\sum_{k'=1}^{\min(k,n-k-1)}P_{n-k-1,k'}, \end{align*} where in the last line we changed the summation index to $k'\coloneqq k-j+1$ to simplify it. Because $P_{n-k-1,0}=P_{n-k-1,0,0}=\left(1-Y\right)^{n-k-1}$ according to Equation 3, we can combine the two terms into one summation to get the final result for $n>k=r>0$: $P_{n,k,k}=Y^k\left(1-Y\right)\sum_{k'=0}^{\min(k,n-k-1)}P_{n-k-1,k'}.$$\p{5}$ Noticing the obvious fact that $\sum_{k=0}^nP_{n,k}=1$, the above equation can be simplified, when $k\ge n-k-1$, to $P_{n,k,k}=Y^k\left(1-Y\right).$$\p{6}$ This simplification is not specially useful, but it can be used to simplify the calculation in the program.

Then, for $n>k>0$, express $P_{n,k}$ in terms of $P_{n,k,r}$ by summing over $r$, and substitute previous results: \begin{align*} P_{n,k}&=\sum_{r=0}^kP_{n,k,r}\\ &=P_{n,k,0}+P_{n,k,k}+\sum_{r=1}^{k-1}P_{n,k,r}\\ &=\left(1-Y\right)P_{n-1,k}+Y^k\left(1-Y\right)\sum_{k'=0}^{\min(k,n-k-1)}P_{n-k-1,k'}\\ &\phantom{=~}{}+\sum_{r=1}^{\min(k-1,n-k-1)}Y^r\left(1-Y\right)P_{n-r-1,k}\\ &=\left(1-Y\right)\left( Y^k\sum_{k'=0}^{\min(k,n-k-1)}P_{n-k-1,k'} +\sum_{r=0}^{\min(k-1,n-k-1)}Y^rP_{n-r-1,k} \right) \end{align*} where in the last term $r$ is summed to $\min(k-1,n-k-1)$ instead of $k-1$ because of the different cases in Equation 4.

Finally, consider the edge cases where $n=k\ge0$ and $n\ge k=0$ (trivial), we have the complete resursive relation for $P_{n,k}$: $P_{n,k}=\begin{cases} Y^n,&n=k\ge0,\\ \left(1-Y\right)^n,&n\ge k=0,\\ \displaystyle{\begin{split} \left(1-Y\right)&\,\left( Y^k\sum_{k'=0}^{\min(k,n-k-1)}P_{n-k-1,k'} \right.\\&\left. +\sum_{r=0}^{\min(k-1,n-k-1)}Y^rP_{n-r-1,k} \right), \end{split}}&n>k>0. \end{cases}$$\p{7}$

Then, we can write the program to calculate $P_{n,k}$:

 1 2 3 4 5 6 7 8 9 10  ## Returns an array of size m+1, ## with the k-th element being the probability P_{m,k}. def combo m (1..m).each_with_object [[1]] do |n, dp| dp[n] = (1..n-1).each_with_object [(1-Y)**n] do |k, dpn| dpn[k] = (1-Y) * (Y**k * (0..[k, n-k-1].min).sum { dp[n-k-1][_1] } + (0..[k-1, n-k-1].min).sum { Y**_1 * dp[n-_1-1][k] }) end dp[n][n] = Y**n end.last end 

This algorithm has the same (asymptotic) space and time complexity as the previous one.

### Polynomial coefficients

We have wrote programmes to calculate probabilities $P_{n,k}(Y)$ based on given $Y$, which we assumed to be a float number. However, float numbers have limited precision, and the calculation may be inaccurate. Actually, the calculation can be done symbolically.

The probability $P_{n,k}$ is a polynomial of degree (at most) $n$ in $Y$, and the coefficients of the polynomial are integers. This can be easily proven by using mathematical induction and utilizing Equation 7. Therefore, we can calculate the coefficients of the polynomial $P_{n,k}(Y)$ instead of calculate the value directly so that we get a symbolic but accurate result.

Both the two DP algorithms above can be modified to calculate the coefficients of the polynomial. Actually, we can define Y to be a polynomial object that can do arithmetic operations with other polynomials or numbers, and then the programmes can run without any modification. Here, I will modify the second DP algorithm to calculate the coefficients of the polynomial.

We can also utilize Equation 6 to simplify the calculation. Considering the edge cases involved in $\min(k,n-k-1)$ and $\min(k-1,n-k-1)$, there are three cases we need to consider:

1. Case $k>n-k-1$: Equation 6 can be applied, and $r$ is summed to $n-k-1$.
2. Case $k=n-k-1$ (can only happen when $n$ is odd): Equation 6 can be applied, and $r$ is summed to $k-1$.
3. Case $k: Equation 6 cannot be applied, and $r$ is summed to $k-1$.

Then, use arrays to store the coefficients of the polynomial $P_{n,k}(Y)$, and we can write the program to calculate the coefficients:

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  ## Returns a nested array of size m+1 times m+1, ## with the j-th element of the k-th element being the coefficient of Y^j in P_{m,k}(Y). def combo_pc m (1..m).each_with_object [[[1]]] do |n, dp| dp[n] = Array.new(n+1) { Array.new n+1, 0 } # dp[n][0] = (1-Y)**n 0.upto(n-1) { dp[n][0][_1] = dp[n-1][0][_1] } # will be multiplied by 1-Y later 1.upto n/2-1 do |k| # dp[n][k] = (1-Y) * (Y**k * (0..k).sum { |j| dp[n-k-1][j] } + (0..k-1).sum { |r| Y**r * dp[n-r-1][k] }) 0.upto(k) { |j| 0.upto(n-k-1) { dp[n][k][_1+k] += dp[n-k-1][j][_1] } } 0.upto(k-1) { |r| 0.upto(n-r-1) { dp[n][k][_1+r] += dp[n-r-1][k][_1] } } end if n % 2 == 1 k = n/2 # dp[n][k] = (1-Y) * (Y**k + (0..k-1).sum { |r| Y**r * dp[n-r-1][k] }) dp[n][k][k] = 1 0.upto(k-1) { |r| 0.upto(n-r-1) { dp[n][k][_1+r] += dp[n-r-1][k][_1] } } end ((n+1)/2).upto n-1 do |k| # dp[n][k] = (1-Y) * (Y**k + (0..n-k-1).sum { |r| Y**r * dp[n-r-1][k] }) dp[n][k][k] = 1 0.upto(n-k-1) { |r| 0.upto(n-r-1) { dp[n][k][_1+r] += dp[n-r-1][k][_1] } } end 0.upto(n-1) { |k| n.downto(1) { dp[n][k][_1] -= dp[n][k][_1-1] } } # multiply by 1-Y # dp[n][n] = Y**n dp[n][n][n] = 1 end.last end 

Here I list first few polynomials $P_{n,k}(Y)$ calculated by the above program: $\begin{array}{r|llllc} & k=0 & 1 & 2 & 3 & \cdots\\ \hline n=0 & 1\\ 1 & 1-Y & Y\\ 2 & 1-2Y+Y^2 & 2Y-Y^2 & Y^2\\ 3 & 1-3Y+3Y^2-Y^3 & 3Y-5Y^2+2Y^3 & 2Y^2-2Y^3 & Y^3\\ \vdots \end{array}$

When evaluating the polynomials for large $n$, the result is inaccurate for $Y$ that is not close to $0$ because of the limited precision of floating numbers. If $Y$ is closer to $1$, we can first find the coefficients of $P_{n,k}(1-X)$ and then substitute $X\coloneqq1-Y$.

### Plots of the probability distributions

Here are some plots of the probability distribution of max combo $k$ when $n=50$:

The plots are intuitive as they show that one has higher probability to get a higher max combo when they have a higher success rate.

There is a suspicious jump in $P_{n,k}(Y)$ near $k=n/2$ when $Y$ is close to $1$. We can look at it closer:

In the zoomed-in plot, we can also see a jump in first derivative (w.r.t. $k$) of $P_{n,k}(Y)$ near $k=n/3$. Actually, the jumps can be modeled in later sections when we talk about the case when $n\to\infty$.

## The case when $n\to\infty$

A natural approach is to try substituting Equation 7 into Equation 1 to get a function w.r.t. the unknown function $f(y,\kappa)$. First, we can easily write the case when $y=0$ because it means zero success rate, and the only possible max combo is zero: $f(y=0,\kappa)=\delta(\kappa).$$\p{8}$ Similarly, we can easily write the case when $y=1$: $f(y=1,\kappa)=\delta(\kappa-1).$$\p{9}$

From now on, we only consider the case when $0. First, for the case $\kappa=0$, according to Equation 7, \begin{align*} f(y,\kappa=0)&=\lim_{n\to\infty}\left(n+1\right)\left(1-y^{\frac1n}\right)^n\\ &=\begin{cases}0,&0 The $\infty$ means that there is a Dirac $\delta$ function (shown in Equation 8).

Then, for the case $\kappa=1$, according to Equation 7, $f(y,\kappa=1)=\lim_{n\to\infty}\left(n+1\right)y=\infty.$ The $\infty$ means that there is a Dirac $\delta$ function. Actually, it is easy to see that there must be a $y\delta(\kappa-1)$ term in the expression of $f(y,\kappa)$ because the probability of getting a max combo ($\kappa=1$) is $y$.

Define $h(y,\kappa)\coloneqq f(y,\kappa)-y\delta(\kappa-1),$$\p{10}$ and then we can get rid of the infinity here.

From now on, we only consider the case when $0 and $0<\kappa<1$. According to Equation 7, \begin{align*} &\phantom{=~}f\!\left(y\in\left(0,1\right),\kappa\in\left(0,1\right)\right)\\ &=\lim_{n\to\infty}\left(n+1\right)\left(1-y^{\frac1n}\right)\left( y^\kappa\sum_{k'=0}^{\min(\kappa n,n-\kappa n-1)}P_{n-\kappa n-1,k'}\!\left(y^{\frac1n}\right) \right.\\&\phantom{=\lim_{n\to\infty}\left(n+1\right)\left(1-y^{\frac1n}\right)}\left. +\sum_{r=0}^{\min(\kappa n-1,n-\kappa n-1)}y^{\frac rn}P_{n-r-1,\kappa n}\!\left(y^{\frac1n}\right) \right)\\ &=\lim_{n\to\infty}n\left(1-y^{\frac1n}\right)\cdot\lim_{n\to\infty}\left( y^\kappa\sum_{t=0,\Delta t=\frac1n}^{\min(\kappa,1-\kappa)}P_{(1-\kappa)n,tn}\!\left(y^{\frac1n}\right) +\sum_{t=0,\Delta t=\frac1n}^{\min(\kappa,1-\kappa)}y^tP_{(1-t)n,\kappa n}\!\left(y^{\frac1n}\right) \right)\\ &=-\ln y\lim_{n\to\infty}\left( y^\kappa\sum_{t=0,\Delta t=\frac1n}^{\min(\kappa,1-\kappa)} \frac1{\left(1-\kappa\right)n}f\!\left(y^{1-\kappa},\frac t{1-\kappa}\right) \right.\\&\phantom{=-\ln y\lim_{n\to\infty}}\left. +\sum_{t=0,\Delta t=\frac1n}^{\min(\kappa,1-\kappa)}y^t \frac1{\left(1-t\right)n}f\!\left(y^{1-t},\frac{\kappa}{1-t}\right) \right)\\ &=-\ln y\lim_{n\to\infty}\sum_{t=0,\Delta t=\frac 1n}^{\min(\kappa,1-\kappa)}\left( \frac{y^\kappa}{1-\kappa}f\!\left(y^{1-\kappa},\frac t{1-\kappa}\right) +\frac{y^t}{1-t}f\!\left(y^{1-t},\frac\kappa{1-t}\right) \right)\Delta t\\ &=-\ln y\int_{t=0}^{\min(\kappa,1-\kappa)}\left( \frac{y^\kappa}{1-\kappa}f\!\left(y^{1-\kappa},\frac t{1-\kappa}\right) +\frac{y^t}{1-t}f\!\left(y^{1-t},\frac\kappa{1-t}\right) \right)\mathrm dt. \end{align*} Add back the delta function at $\kappa=1$, and we have the integral equation $\begin{split} f\!\left(y\in\left(0,1\right),\kappa\right)=-\ln y\int_{t=0}^{\min(\kappa,1-\kappa)}&\,\left( \frac{y^\kappa}{1-\kappa}f\!\left(y^{1-\kappa},\frac t{1-\kappa}\right) \right.\\&\left. +\frac{y^t}{1-t}f\!\left(y^{1-t},\frac\kappa{1-t}\right) \right)\mathrm dt+y\delta(\kappa-1). \end{split}$

There are two terms in the integral. Substitute $u\coloneqq\frac t{1-\kappa}$ in the first term, and we have \begin{align*} \int_{t=0}^{\min\left(\kappa,1-\kappa\right)}\frac{y^\kappa}{1-\kappa}f\!\left(y^{1-\kappa},\frac t{1-\kappa}\right)\mathrm dt &=\int_0^{\min(\frac\kappa{1-\kappa},1)}y^\kappa f\!\left(y^{1-\kappa},u\right)\mathrm du\\ &=\int_0^{\min(\frac\kappa{1-\kappa},1)}\left(y^\kappa h\!\left(y^{1-\kappa},u\right)+y\delta(u-1)\right)\mathrm du. \end{align*} Substitute $v\coloneqq\frac\kappa{1-t}$ in the second term, and we have \begin{align*} \int_{t=0}^{\min(\kappa,1-\kappa)}\frac{y^t}{1-t}f\!\left(y^{1-t},\frac\kappa{1-t}\right)\mathrm dt &=\int_\kappa^{\min\left(\frac\kappa{1-\kappa},1\right)}y^{1-\frac\kappa v}f\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v\\ &=\int_\kappa^{\min\left(\frac\kappa{1-\kappa},1\right)}\left(y^{1-\frac\kappa v}h\!\left(y^{\frac\kappa v},v\right)+y\delta(v-1)\right)\frac{\mathrm dv}v. \end{align*}

Further, let (we only consider $y\in\left(0,1\right)$ from now on) $g(y,\kappa)\coloneqq\frac{h(y,\kappa)}{y},$$\p{11}$ then the integral equation becomes $\begin{split} g(y,\kappa)=-\ln y&\,\left( \int_0^{\min\left(\frac\kappa{1-\kappa},1\right)}\left(g\!\left(y^{1-\kappa},u\right)+\delta(u-1)\right)\mathrm du \right.\\&\left. +\int_\kappa^{\min\left(\frac\kappa{1-\kappa},1\right)}\left(g\!\left(y^{\frac\kappa v},v\right)+\delta(v-1)\right)\frac{\mathrm dv}v \right). \end{split}$$\p{12}$

There is another integral equation for $g$. Because $\int_0^1f\!\left(y,\kappa\right)\mathrm d\kappa=1$, we have $\int_0^1g\!\left(y,\kappa\right)\mathrm d\kappa=\frac1y-1.$$\p{13}$

Equation 12 and 13 are the equations that we are going to utilize to get the expression for $g(y,\kappa)$.

### The case $\kappa\in\left(\frac12,1\right)$

In this case, we have $\min\!\left(\frac\kappa{1-\kappa},1\right)=1,$ so the Dirac delta functions in Equation 12 should be considered. In this case, it simplifies to $g_1(y,\kappa)\coloneqq g\!\left(y,\kappa\in\left(\frac12,1\right)\right)= -\ln y\left(y^{\kappa-1}+\int_\kappa^1g\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v+1\right),$$\p{14}$ where Equation 13 is utilized when finding the first term.

We can try to solve Equation 14 by using Adomian decomposition method (ADM). Suppose $g_1$ can be written in a series $g_1=g_1^{(0)}+g_1^{(1)}+\cdots,$ and substitute it into Equation 14, and we have $g_1^{(0)}(y,\kappa)+\cdots =-\ln y\left(y^{\kappa-1}+1+\int_\kappa^1\left( g^{(0)}\!\left(y^{\frac\kappa v},v\right)+\cdots \right)\frac{\mathrm dv}v\right).$ Assume we may interchange integration and summation (which is OK here because we can verify the solution after we find it using ADM). Then, \begin{align*} &\phantom{=~}g_1^{(0)}(y,\kappa)+g_1^{(1)}(y,\kappa)+\cdots\\ &=-\ln y\left(y^{\kappa-1}+1\right) -\ln y\int_\kappa^1g^{(0)}\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v-\cdots. \end{align*} If we let $\begin{split} g_1^{(0)}(y,\kappa)&\coloneqq-\ln y\left(y^{\kappa-1}+1\right),\\ g_1^{(i+1)}(y,\kappa)&\coloneqq-\ln y\int_\kappa^1g^{(i)}\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v,\quad i\in\mathbb N, \end{split}$$\p{15}$ then we can equate each term in the two series. If the sum $g_1=\sum_{i=0}^\infty g_1^{(i)}$ converges, then this is a guess of the solution to Equation 14, which we can verify whether it is correct or not.

Using Equation 15, we can find first few terms in the series by directly integrating. The first few terms are $\begin{split} g_1^{(0)}(y,\kappa)&=-\ln y\left(y^{\kappa-1}+1\right),\\ g_1^{(1)}(y,\kappa)&=-\ln y\left(y^{\kappa-1}-1+\ln y^{\kappa-1}\right),\\ g_1^{(2)}(y,\kappa)&=-\ln y\left(y^{\kappa-1}-1-\ln y^{\kappa-1}+\frac12\left(\ln y^{\kappa-1}\right)^2\right),\\ g_1^{(3)}(y,\kappa)&=-\ln y\left(y^{\kappa-1}-1-\ln y^{\kappa-1}-\frac12\left(\ln y^{\kappa-1}\right)^2+\frac16\left(\ln y^{\kappa-1}\right)^3\right),\\ \vdots& \end{split}$ We may then guess that the terms have general formula $g_1^{(i)}(y,\kappa)=-\ln y\left(y^{\kappa-1}+\frac1{i!}\left(\ln y^{\kappa-1}\right)^i -\sum_{j=0}^{i-1}\frac1{j!}\left(\ln y^{\kappa-1}\right)^j\right).$ Sum up the terms, and we have \begin{align*} g_1(y,\kappa)&=\sum_{i=0}^\infty g_1^{(i)}(y,\kappa)\\ &=\lim_{q\to\infty}\sum_{i=0}^q-\ln y\left( y^{\kappa-1}+\frac1{i!}\left(\ln y^{\kappa-1}\right)^i -\sum_{j=0}^{i-1}\frac1{j!}\left(\ln y^{\kappa-1}\right)^j \right)\\ &=-\ln y\left(\exp\ln y^{\kappa-1}+\lim_{q\to\infty}\left( \left(q+1\right)y^{\kappa-1} -\sum_{j=0}^q\sum_{i=j+1}^q\frac1{j!}\left(\ln y^{\kappa-1}\right)^j \right)\right)\\ &=-\ln y\left(y^{\kappa-1}+\lim_{q\to\infty}\left( \left(q+1\right)y^{\kappa-1} -\sum_{j=0}^q\frac{q-j}{j!}\left(\ln y^{\kappa-1}\right)^j \right)\right)\\ &=-\ln y\left( y^{\kappa-1}+\lim_{q\to\infty}\left( qy^{\kappa-1}-q\sum_{j=0}^q\frac1{j!}\left(\ln y^{\kappa-1}\right)^j \right) \right.\\&\phantom{=-\ln y}\left.\vphantom{\sum_j^q} +y^{\kappa-1} +\ln y^{\kappa-1}\exp\ln y^{\kappa-1} \right)\\ &=-\ln y\left(2+\ln y^{\kappa-1}\right)y^{\kappa-1}. \end{align*}

Therefore, we have the final guess of solution $g_1(y,\kappa)=-\ln y\left(2+\ln y^{\kappa-1}\right)y^{\kappa-1}.$$\p{16}$ We can substitute it into Equation 14 to verify that it is indeed the solution.

### The case $\kappa\in\left(\frac13,\frac12\right)$

In this case, we have $\min\!\left(\frac\kappa{1-\kappa},1\right)=\frac\kappa{1-\kappa}\in\left(\frac12,1\right).$ We can then use the same method as in the previous case to find the solution.

First, by Equation 14, \begin{align*} g_2(y,\kappa)&\coloneqq g\!\left(y,\kappa\in\left(\frac13,\frac12\right)\right)\\ &=-\ln y\left( \int_0^{\frac\kappa{1-\kappa}}g\!\left(y^{1-\kappa},u\right)\mathrm du +\int_\kappa^{\frac\kappa{1-\kappa}}g\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v \right)\\ &=-\ln y\left( \int_0^1g\!\left(y^{1-\kappa},u\right)\mathrm du -\int_{\frac\kappa{1-\kappa}}^1g_1\!\left(y^{1-\kappa},u\right)\mathrm du \right.\\&\phantom{=-\ln y}\left. +\int_\kappa^{\frac12}g_2\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v +\int_{\frac12}^{\frac\kappa{1-\kappa}}g_1\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v \right). \end{align*} Substitute Equation 13 and 16 into the above equation, and we have $\begin{split} g_2(y,\kappa)&=-\ln y\left( y^{\kappa-1} +y^{-\kappa}\left(1+\ln y^{-\kappa}\right) -2y^{2\kappa-1}\left(1+\ln y^{2\kappa-1}\right) \vphantom{\int_\kappa^{\frac12}}\right.\\&\phantom{=-\ln y}\left. +\int_\kappa^{\frac12}g_2\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v \right). \end{split}$$\p{17}$

Equation 17 can again be solved by ADM though the calculation is much more complicated than the previous case. We may guess $g_2=\sum_{i=0}^\infty g_2^{(i)}$ is the solution if the series converges, where $\begin{split} g_2^{(0)}(y,\kappa)&\coloneqq-\ln y\left( y^{\kappa-1} +y^{-\kappa}\left(1+\ln y^{-\kappa}\right) -2y^{2\kappa-1}\left(1+\ln y^{2\kappa-1}\right) \right),\\ g_1^{(i+1)}(y,\kappa)&\coloneqq-\ln y\int_\kappa^{\frac12}g^{(i)}\!\left(y^{\frac\kappa v},v\right)\frac{\mathrm dv}v, \quad i\in\mathbb N. \end{split}$ The first few terms go too long to be written here before one may find the pattern, so they are omitted here. If you want to see them, use a mathematical software to help you, and you should be able to find the pattern after calculating first six (or so) terms. After looking at first few terms, the guessed general term is \begin{align*} g_2^{(i)}=-\ln y&\,\left( y^{\kappa-1}+2y^{2\kappa-1}\left(i-1-\ln y^{2\kappa-1}\right) -2\sum_{j=0}^{i-1}\frac{i-j-1}{j!}\left(\ln y^{2\kappa-1}\right)^j \right.\\&\left. {}-y^{-\kappa}\sum_{j=0}^{i-1}\frac1{j!}\left(\ln y^{2\kappa-1}\right)^j +\frac1{i!}y^{-\kappa}\left(1+\ln y^{-\kappa}\right)\left(\ln y^{2\kappa-1}\right)^i \right). \end{align*} Then we can sum it to get a guess of $g_2$.

After some tedious calculation, we have $g_2(y,\kappa)=-\ln y\left( \left(2+\ln y^{\kappa-1}\right)y^{\kappa-1} -\left(2+4\ln y^{2\kappa-1}+\left(\ln y^{2\kappa-1}\right)^2\right)y^{2\kappa-1} \right).$$\p{18}$ On may verify that this is indeed the solution by substituting it into Equation 17.

### The case $\kappa\in\left(\frac14,\frac13\right)$

By using very similar methods but after very tedious calculation, the solution is $\begin{split} g_3(y,\kappa)&\coloneqq g\!\left(y,\kappa\in\left(\frac14,\frac13\right)\right)\\ &=-\ln y\left( \left(2+\ln y^{\kappa-1}\right)y^{\kappa-1} -\left(2+4\ln y^{2\kappa-1}+\left(\ln y^{2\kappa-1}\right)^2\right)y^{2\kappa-1}\vphantom{\frac12} \right.\\&\phantom{=-\ln y}\left. {}+\left(3\ln y^{3\kappa-1}+3\left(\ln y^{3\kappa-1}\right)^2+\frac12\left(\ln y^{3\kappa-1}\right)^3\right)y^{3\kappa-1} \right). \end{split}$$\p{19}$

### Other cases

After seeing Equation 16, 18, and 19, one may guess the form of solution for other cases.

Guess the form of solution for $\kappa\in\left(\frac1{q+1},\frac1q\right)$, where $q\in1\ldots\infty$, is $g_q(y,\kappa)\coloneqq g\!\left(y,\kappa\in\left(\frac1q,\frac1{q+1}\right)\right)=\sum_{s=1}^q\Delta g_s(y,\kappa),$ where $\Delta g_s(y,\kappa)\coloneqq\left(-1\right)^sy^{s\kappa-1}\ln y\sum_{j=0}^s\frac{A_{s,j}}{j!}\left(\ln y^{s\kappa-1}\right)^j,$ where $A_{s,j}$ are coefficients to be determined.

Now, consider the cases $q\in2\ldots\infty$. Because $\kappa\in\left(\frac1{q+1},\frac1q\right)$, $\min\!\left(\frac\kappa{1-\kappa},1\right)=\frac\kappa{1-\kappa}\in\left(\frac1q,\frac1{q-1}\right).$ Therefore, \begin{align*} &\phantom{=~}\int_0^{\min\left(\frac\kappa{1-\kappa},1\right)}\left(g\!\left(y^{1-\kappa},u\right)+\delta(u-1)\right)\mathrm du\\ &=\int_0^1g\!\left(y^{1-\kappa},u\right)\mathrm du -\sum_{p=1}^{q-2}\int_{\frac1{p+1}}^{\frac1p}g_p\!\left(y^{1-\kappa},u\right)\mathrm du -\int_{\frac\kappa{1-\kappa}}^\frac1{q-1}g_{q-1}\!\left(y^{1-\kappa},u\right)\mathrm du\\ &=y^{\kappa-1}-1 -\sum_{p=1}^{q-2}\int_{\frac1{p+1}}^{\frac1p}\sum_{s=1}^p\Delta g_s\!\left(y^{1-\kappa},u\right)\mathrm du -\int_{\frac\kappa{1-\kappa}}^\frac1{q-1}\sum_{s=1}^{q-1}\Delta g_s\!\left(y^{1-\kappa},u\right)\mathrm du\\ &=y^{\kappa-1}-1 -\sum_{s=1}^{q-1}\left( \sum_{p=s}^{q-2}\int_{\frac1{p+1}}^{\frac1p}+\int_{\frac\kappa{1-\kappa}}^\frac1{q-1} \right)\Delta g_s\!\left(y^{1-\kappa},u\right)\mathrm du\\ &=y^{\kappa-1}-1 -\sum_{s=1}^{q-1}\int_{\frac\kappa{1-\kappa}}^{\frac1s}\Delta g_s\!\left(y^{1-\kappa},u\right)\mathrm du, \end{align*}