Massimo Nocentini

February 4, 2018: exponential P



Abstract
Exponential $\mathcal{P}$, according to Paul Barry's book.

In [1]:
from sympy import *
from sympy.abc import n, i, N, x, lamda, phi, z, j, r, k, a, alpha

from commons import *
from matrix_functions import *
from sequences import *
import functions_catalog

init_printing()


In [2]:
m = 10

In [3]:
eP = Matrix(m, m, lambda n,k: factorial(n)*binomial(n,k)/factorial(k))
eP


Out[3]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\6 & 18 & 9 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\24 & 96 & 72 & 16 & 1 & 0 & 0 & 0 & 0 & 0\\120 & 600 & 600 & 200 & 25 & 1 & 0 & 0 & 0 & 0\\720 & 4320 & 5400 & 2400 & 450 & 36 & 1 & 0 & 0 & 0\\5040 & 35280 & 52920 & 29400 & 7350 & 882 & 49 & 1 & 0 & 0\\40320 & 322560 & 564480 & 376320 & 117600 & 18816 & 1568 & 64 & 1 & 0\\362880 & 3265920 & 6531840 & 5080320 & 1905120 & 381024 & 42336 & 2592 & 81 & 1\end{matrix}\right]$$

In [6]:
inspect(eP)


Out[6]:
nature(is_ordinary=False, is_exponential=True)

In [7]:
eP_pm = production_matrix(eP)
eP_epm = production_matrix(eP, exp=True)

eP_pm, eP_epm


Out[7]:
$$\left ( \left[\begin{matrix}1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 4 & 5 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 9 & 7 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 16 & 9 & 1 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 25 & 11 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 36 & 13 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 49 & 15 & 1\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 64 & 17\end{matrix}\right], \quad \left[\begin{matrix}1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 2 & 5 & 3 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 3 & 7 & 4 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 4 & 9 & 5 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 5 & 11 & 6 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 6 & 13 & 7 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 7 & 15 & 8\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 8 & 17\end{matrix}\right]\right )$$

In [10]:
F = Matrix(m, m, diagonal_func_matrix(factorial))
F_inv = F**(-1)

F, F_inv


Out[10]:
$$\left ( \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 6 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 24 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 120 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 720 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 5040 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 40320 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 362880\end{matrix}\right], \quad \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & \frac{1}{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & \frac{1}{6} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & \frac{1}{24} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & \frac{1}{120} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{720} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{5040} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{40320} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{1}{362880}\end{matrix}\right]\right )$$

In order to factorize eP as F U F^{-1}, for some matrix U


In [11]:
B = F_inv * eP * F
B


Out[11]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 4 & 6 & 4 & 1 & 0 & 0 & 0 & 0 & 0\\1 & 5 & 10 & 10 & 5 & 1 & 0 & 0 & 0 & 0\\1 & 6 & 15 & 20 & 15 & 6 & 1 & 0 & 0 & 0\\1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 & 0 & 0\\1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1 & 0\\1 & 9 & 36 & 84 & 126 & 126 & 84 & 36 & 9 & 1\end{matrix}\right]$$

In [12]:
U = Matrix(m, m, rows_shift_matrix(by=1))
U


Out[12]:
$$\left[\begin{matrix}0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 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81 & 324 & 756 & 1134 & 1134 & 756 & 324 & 81 & 9\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$$

In [15]:
B**(-1) * F_inv * U * F * B


Out[15]:
$$\left[\begin{matrix}1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 2 & 5 & 3 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 3 & 7 & 4 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 4 & 9 & 5 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 5 & 11 & 6 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 6 & 13 & 7 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 7 & 15 & 8 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 8 & 17 & 9\\-10 & -100 & -450 & -1200 & -2100 & -2520 & -2100 & -1200 & -441 & -81\end{matrix}\right]$$

In [16]:
F * B**(-1) * F_inv * U * F * B * F_inv


Out[16]:
$$\left[\begin{matrix}1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 4 & 5 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 9 & 7 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 16 & 9 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 25 & 11 & 1 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 36 & 13 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 49 & 15 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 64 & 17 & 1\\-3628800 & -36288000 & -81648000 & -72576000 & -31752000 & -7620480 & -1058400 & -86400 & -3969 & -81\end{matrix}\right]$$


In [17]:
P = Matrix(m, m, binomial)

In [18]:
P_bar = Matrix(m, m, lambda i, j: binomial(i, j) if j < i else 0)
P_bar


Out[18]:
$$\left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 3 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 4 & 6 & 4 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 5 & 10 & 10 & 5 & 0 & 0 & 0 & 0 & 0\\1 & 6 & 15 & 20 & 15 & 6 & 0 & 0 & 0 & 0\\1 & 7 & 21 & 35 & 35 & 21 & 7 & 0 & 0 & 0\\1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 0 & 0\\1 & 9 & 36 & 84 & 126 & 126 & 84 & 36 & 9 & 0\end{matrix}\right]$$

In [20]:
production_matrix(P_bar[1:,:-1], exp=False), production_matrix(P_bar[1:,:-1], exp=True)


Out[20]:
$$\left ( \left[\begin{matrix}1 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\0 & \frac{1}{2} & \frac{3}{2} & 0 & 0 & 0 & 0 & 0\\0 & \frac{1}{6} & \frac{1}{2} & \frac{4}{3} & 0 & 0 & 0 & 0\\0 & 0 & \frac{1}{4} & \frac{1}{2} & \frac{5}{4} & 0 & 0 & 0\\0 & - \frac{1}{30} & 0 & \frac{1}{3} & \frac{1}{2} & \frac{6}{5} & 0 & 0\\0 & 0 & - \frac{1}{12} & 0 & \frac{5}{12} & \frac{1}{2} & \frac{7}{6} & 0\\0 & \frac{1}{42} & 0 & - \frac{1}{6} & 0 & \frac{1}{2} & \frac{1}{2} & \frac{8}{7}\\0 & 0 & \frac{1}{12} & 0 & - \frac{7}{24} & 0 & \frac{7}{12} & \frac{1}{2}\end{matrix}\right], \quad \left[\begin{matrix}1 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\0 & \frac{1}{2} & 3 & 0 & 0 & 0 & 0 & 0\\0 & \frac{1}{12} & \frac{1}{2} & 4 & 0 & 0 & 0 & 0\\0 & 0 & \frac{1}{12} & \frac{1}{2} & 5 & 0 & 0 & 0\\0 & - \frac{1}{720} & 0 & \frac{1}{12} & \frac{1}{2} & 6 & 0 & 0\\0 & 0 & - \frac{1}{720} & 0 & \frac{1}{12} & \frac{1}{2} & 7 & 0\\0 & \frac{1}{30240} & 0 & - \frac{1}{720} & 0 & \frac{1}{12} & \frac{1}{2} & 8\\0 & 0 & \frac{1}{30240} & 0 & - \frac{1}{720} & 0 & \frac{1}{12} & \frac{1}{2}\end{matrix}\right]\right )$$

In [21]:
j=3
(P_bar**j).applyfunc(lambda i: i/factorial(j))


Out[21]:
$$\left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\6 & 4 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\25 & 30 & 10 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\90 & 150 & 90 & 20 & 0 & 0 & 0 & 0 & 0 & 0\\301 & 630 & 525 & 210 & 35 & 0 & 0 & 0 & 0 & 0\\966 & 2408 & 2520 & 1400 & 420 & 56 & 0 & 0 & 0 & 0\\3025 & 8694 & 10836 & 7560 & 3150 & 756 & 84 & 0 & 0 & 0\end{matrix}\right]$$