Skip to content

Commit 44408e5

Browse files
committed
k_ -> r_
1 parent 7720d4b commit 44408e5

20 files changed

Lines changed: 220 additions & 220 deletions

File tree

content/post/three-var-recursive.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ $$\frac{1}{1-\rho} = \sum_{i \geq 0} \rho^i$$
6666

6767
and the multinomial expansion
6868

69-
$$(x_1+x_2+x_3+x_4)^N = \sum_{k_1+k_2+k_3+k_4=N} \binom{N}{k_1,k_2,k_3,k_4} x_1^{k_1} x_2^{k_2} x_3^{k_3} x_4^{k_4}$$
69+
$$(x_1+x_2+x_3+x_4)^N = \sum_{r_1+r_2+r_3+r_4=N} \binom{N}{r_1,r_2,r_3,r_4} x_1^{r_1} x_2^{r_2} x_3^{r_3} x_4^{r_4}$$
7070

7171
with
7272

73-
$$\binom{N}{k_1,k_2,k_3,k_4} = \frac{N!}{k_1!\cdot k_2!\cdot k_3!\cdot k_4!}$$
73+
$$\binom{N}{r_1,r_2,r_3,r_4} = \frac{N!}{r_1!\cdot r_2!\cdot r_3!\cdot r_4!}$$
7474

7575
we expand the denominator of $\Phi$. Let $\rho = 2xyz + xy + xz + yz$. Then
7676

7777
$$\Phi = \frac{1+x+y+z}{1-\rho} = (1+x+y+z) \sum_{N \geq 0} \rho^N$$
7878

79-
Expanding $\rho^N$ with the multinomial theorem (and writing $k_4 = N - k_1 - k_2 - k_3$):
79+
Expanding $\rho^N$ with the multinomial theorem (and writing $r_4 = N - r_1 - r_2 - r_3$):
8080

8181
$\sum_{N \geq 0} \rho^N = \sum_{N}(2 x y z + x y + x z + y z)^N $
82-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} (2 x y z)^{k_1} \cdot (x y)^{k_2} \cdot (x z)^{k_3} \cdot (y z)^{k_4}$
83-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} 2^{k_1} x^{k_1+k_2+k_3} y^{k_1+k_2+k_4} z^{k_1+k_3+k_4}$
84-
$ = \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$
82+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} (2 x y z)^{r_1} \cdot (x y)^{r_2} \cdot (x z)^{r_3} \cdot (y z)^{r_4}$
83+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} 2^{r_1} x^{r_1+r_2+r_3} y^{r_1+r_2+r_4} z^{r_1+r_3+r_4}$
84+
$ = \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$
8585

8686
So we have
8787

88-
$$ \Phi = (1 + x + y + z) \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$$
88+
$$ \Phi = (1 + x + y + z) \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$$
8989

9090
Extracting the coefficient of $x^n y^m z^k$ gives the closed form. The full expression has four sums (from the numerator $1+x+y+z$):
9191

@@ -141,12 +141,12 @@ def a_rec(n: int, m: int, k: int) -> int:
141141

142142
```python
143143
@functools.lru_cache(maxsize=None)
144-
def binom4(N: int, k1: int, k2: int, k3: int) -> int:
145-
k4 = N - k1 - k2 - k3
144+
def binom4(N: int, r1: int, r2: int, r3: int) -> int:
145+
r4 = N - r1 - r2 - r3
146146

147147
return math.factorial(N) // (
148-
math.factorial(k1) * math.factorial(k2)
149-
* math.factorial(k3) * math.factorial(k4)
148+
math.factorial(r1) * math.factorial(r2)
149+
* math.factorial(r3) * math.factorial(r4)
150150
)
151151

152152

index.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ $ = \Phi \cdot ( 2 x y z + x y + x z + y z ) + 1 + x + y + z$</p>
5353
<p>Using</p>
5454
<p>$$\frac{1}{1-\rho} = \sum_{i \geq 0} \rho^i$$</p>
5555
<p>and the multinomial expansion</p>
56-
<p>$$(x_1+x_2+x_3+x_4)^N = \sum_{k_1+k_2+k_3+k_4=N} \binom{N}{k_1,k_2,k_3,k_4} x_1^{k_1} x_2^{k_2} x_3^{k_3} x_4^{k_4}$$</p>
56+
<p>$$(x_1+x_2+x_3+x_4)^N = \sum_{r_1+r_2+r_3+r_4=N} \binom{N}{r_1,r_2,r_3,r_4} x_1^{r_1} x_2^{r_2} x_3^{r_3} x_4^{r_4}$$</p>
5757
<p>with</p>
58-
<p>$$\binom{N}{k_1,k_2,k_3,k_4} = \frac{N!}{k_1!\cdot k_2!\cdot k_3!\cdot k_4!}$$</p>
58+
<p>$$\binom{N}{r_1,r_2,r_3,r_4} = \frac{N!}{r_1!\cdot r_2!\cdot r_3!\cdot r_4!}$$</p>
5959
<p>we expand the denominator of $\Phi$. Let $\rho = 2xyz + xy + xz + yz$. Then</p>
6060
<p>$$\Phi = \frac{1+x+y+z}{1-\rho} = (1+x+y+z) \sum_{N \geq 0} \rho^N$$</p>
61-
<p>Expanding $\rho^N$ with the multinomial theorem (and writing $k_4 = N - k_1 - k_2 - k_3$):</p>
61+
<p>Expanding $\rho^N$ with the multinomial theorem (and writing $r_4 = N - r_1 - r_2 - r_3$):</p>
6262
<p>$\sum_{N \geq 0} \rho^N = \sum_{N}(2 x y z + x y + x z + y z)^N $
63-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} (2 x y z)^{k_1} \cdot (x y)^{k_2} \cdot (x z)^{k_3} \cdot (y z)^{k_4}$
64-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} 2^{k_1} x^{k_1+k_2+k_3} y^{k_1+k_2+k_4} z^{k_1+k_3+k_4}$
65-
$ = \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$</p>
63+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} (2 x y z)^{r_1} \cdot (x y)^{r_2} \cdot (x z)^{r_3} \cdot (y z)^{r_4}$
64+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} 2^{r_1} x^{r_1+r_2+r_3} y^{r_1+r_2+r_4} z^{r_1+r_3+r_4}$
65+
$ = \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$</p>
6666
<p>So we have</p>
67-
<p>$$ \Phi = (1 + x + y + z) \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$$</p>
67+
<p>$$ \Phi = (1 + x + y + z) \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$$</p>
6868
<p>Extracting the coefficient of $x^n y^m z^k$ gives the closed form. The full expression has four sums (from the numerator $1+x+y+z$):</p>
6969
<p>$$a_{n,m,k} = \sum_{N=\max(n,m,k)}^{ (n+m+k)/2 } \binom{N}{n+m+k-2N, N-n, N-m, N-k} 2^{n+m+k-2N}$$
7070
$$ + \sum_{N=\max(n,m-1,k)}^{ (n+m+k-1)/2 } \binom{N}{n+m+k-2N-1, N-n, N-m+1, N-k} 2^{n+m+k-2N-1}$$
@@ -108,12 +108,12 @@ $$ + \sum_{N=\max(n,m,k-1)}^{ (n+m+k-1)/2 } \binom{N}{n+m+k-2N-1, N-n, N-m, N-k+
108108
</span></span><span style="display:flex;"><span> <span style="color:#f92672">+</span> a_rec(n, m <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>, k <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>)
109109
</span></span><span style="display:flex;"><span> )
110110
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#a6e22e">@functools.lru_cache</span>(maxsize<span style="color:#f92672">=</span><span style="color:#66d9ef">None</span>)
111-
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">binom4</span>(N: int, k1: int, k2: int, k3: int) <span style="color:#f92672">-></span> int:
112-
</span></span><span style="display:flex;"><span> k4 <span style="color:#f92672">=</span> N <span style="color:#f92672">-</span> k1 <span style="color:#f92672">-</span> k2 <span style="color:#f92672">-</span> k3
111+
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">binom4</span>(N: int, r1: int, r2: int, r3: int) <span style="color:#f92672">-></span> int:
112+
</span></span><span style="display:flex;"><span> r4 <span style="color:#f92672">=</span> N <span style="color:#f92672">-</span> r1 <span style="color:#f92672">-</span> r2 <span style="color:#f92672">-</span> r3
113113
</span></span><span style="display:flex;"><span>
114114
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> math<span style="color:#f92672">.</span>factorial(N) <span style="color:#f92672">//</span> (
115-
</span></span><span style="display:flex;"><span> math<span style="color:#f92672">.</span>factorial(k1) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k2)
116-
</span></span><span style="display:flex;"><span> <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k3) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k4)
115+
</span></span><span style="display:flex;"><span> math<span style="color:#f92672">.</span>factorial(r1) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r2)
116+
</span></span><span style="display:flex;"><span> <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r3) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r4)
117117
</span></span><span style="display:flex;"><span> )
118118
</span></span><span style="display:flex;"><span>
119119
</span></span><span style="display:flex;"><span>

post/index.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ $ = \Phi \cdot ( 2 x y z + x y + x z + y z ) + 1 + x + y + z$</p>
5353
<p>Using</p>
5454
<p>$$\frac{1}{1-\rho} = \sum_{i \geq 0} \rho^i$$</p>
5555
<p>and the multinomial expansion</p>
56-
<p>$$(x_1+x_2+x_3+x_4)^N = \sum_{k_1+k_2+k_3+k_4=N} \binom{N}{k_1,k_2,k_3,k_4} x_1^{k_1} x_2^{k_2} x_3^{k_3} x_4^{k_4}$$</p>
56+
<p>$$(x_1+x_2+x_3+x_4)^N = \sum_{r_1+r_2+r_3+r_4=N} \binom{N}{r_1,r_2,r_3,r_4} x_1^{r_1} x_2^{r_2} x_3^{r_3} x_4^{r_4}$$</p>
5757
<p>with</p>
58-
<p>$$\binom{N}{k_1,k_2,k_3,k_4} = \frac{N!}{k_1!\cdot k_2!\cdot k_3!\cdot k_4!}$$</p>
58+
<p>$$\binom{N}{r_1,r_2,r_3,r_4} = \frac{N!}{r_1!\cdot r_2!\cdot r_3!\cdot r_4!}$$</p>
5959
<p>we expand the denominator of $\Phi$. Let $\rho = 2xyz + xy + xz + yz$. Then</p>
6060
<p>$$\Phi = \frac{1+x+y+z}{1-\rho} = (1+x+y+z) \sum_{N \geq 0} \rho^N$$</p>
61-
<p>Expanding $\rho^N$ with the multinomial theorem (and writing $k_4 = N - k_1 - k_2 - k_3$):</p>
61+
<p>Expanding $\rho^N$ with the multinomial theorem (and writing $r_4 = N - r_1 - r_2 - r_3$):</p>
6262
<p>$\sum_{N \geq 0} \rho^N = \sum_{N}(2 x y z + x y + x z + y z)^N $
63-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} (2 x y z)^{k_1} \cdot (x y)^{k_2} \cdot (x z)^{k_3} \cdot (y z)^{k_4}$
64-
$ = \sum_{k_1+k_2+k_3+k_4=N} \binom{N} {k_1,k_2,k_3,k_4} 2^{k_1} x^{k_1+k_2+k_3} y^{k_1+k_2+k_4} z^{k_1+k_3+k_4}$
65-
$ = \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$</p>
63+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} (2 x y z)^{r_1} \cdot (x y)^{r_2} \cdot (x z)^{r_3} \cdot (y z)^{r_4}$
64+
$ = \sum_{r_1+r_2+r_3+r_4=N} \binom{N} {r_1,r_2,r_3,r_4} 2^{r_1} x^{r_1+r_2+r_3} y^{r_1+r_2+r_4} z^{r_1+r_3+r_4}$
65+
$ = \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$</p>
6666
<p>So we have</p>
67-
<p>$$ \Phi = (1 + x + y + z) \sum_{k_1+k_2+k_3 \leq N} \binom{N} {k_1,k_2,k_3, N-k_1-k_2-k_3} 2^{k_1} x^{k_1+k_2+k_3} y^{N-k_3} z^{N-k_2}$$</p>
67+
<p>$$ \Phi = (1 + x + y + z) \sum_{r_1+r_2+r_3 \leq N} \binom{N} {r_1,r_2,r_3, N-r_1-r_2-r_3} 2^{r_1} x^{r_1+r_2+r_3} y^{N-r_3} z^{N-r_2}$$</p>
6868
<p>Extracting the coefficient of $x^n y^m z^k$ gives the closed form. The full expression has four sums (from the numerator $1+x+y+z$):</p>
6969
<p>$$a_{n,m,k} = \sum_{N=\max(n,m,k)}^{ (n+m+k)/2 } \binom{N}{n+m+k-2N, N-n, N-m, N-k} 2^{n+m+k-2N}$$
7070
$$ + \sum_{N=\max(n,m-1,k)}^{ (n+m+k-1)/2 } \binom{N}{n+m+k-2N-1, N-n, N-m+1, N-k} 2^{n+m+k-2N-1}$$
@@ -108,12 +108,12 @@ $$ + \sum_{N=\max(n,m,k-1)}^{ (n+m+k-1)/2 } \binom{N}{n+m+k-2N-1, N-n, N-m, N-k+
108108
</span></span><span style="display:flex;"><span> <span style="color:#f92672">+</span> a_rec(n, m <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>, k <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>)
109109
</span></span><span style="display:flex;"><span> )
110110
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#a6e22e">@functools.lru_cache</span>(maxsize<span style="color:#f92672">=</span><span style="color:#66d9ef">None</span>)
111-
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">binom4</span>(N: int, k1: int, k2: int, k3: int) <span style="color:#f92672">-></span> int:
112-
</span></span><span style="display:flex;"><span> k4 <span style="color:#f92672">=</span> N <span style="color:#f92672">-</span> k1 <span style="color:#f92672">-</span> k2 <span style="color:#f92672">-</span> k3
111+
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">binom4</span>(N: int, r1: int, r2: int, r3: int) <span style="color:#f92672">-></span> int:
112+
</span></span><span style="display:flex;"><span> r4 <span style="color:#f92672">=</span> N <span style="color:#f92672">-</span> r1 <span style="color:#f92672">-</span> r2 <span style="color:#f92672">-</span> r3
113113
</span></span><span style="display:flex;"><span>
114114
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> math<span style="color:#f92672">.</span>factorial(N) <span style="color:#f92672">//</span> (
115-
</span></span><span style="display:flex;"><span> math<span style="color:#f92672">.</span>factorial(k1) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k2)
116-
</span></span><span style="display:flex;"><span> <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k3) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(k4)
115+
</span></span><span style="display:flex;"><span> math<span style="color:#f92672">.</span>factorial(r1) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r2)
116+
</span></span><span style="display:flex;"><span> <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r3) <span style="color:#f92672">*</span> math<span style="color:#f92672">.</span>factorial(r4)
117117
</span></span><span style="display:flex;"><span> )
118118
</span></span><span style="display:flex;"><span>
119119
</span></span><span style="display:flex;"><span>

0 commit comments

Comments
 (0)