Massimo Nocentini

April 20, 2018: cleanup, `sin` and `cos` $g$ poly
November 16 and 18, 2016: `expt` and `log` $g$ poly
November 9, 2016: splitting from "big" notebook



Abstract
Theory of matrix functions, with applications to Catalan array $\mathcal{C}$.

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()

Catalan array $\mathcal{C}$


In [2]:
m=8

In [3]:
C = define(let=Symbol(r'\mathcal{{C}}_{{ {} }}'.format(m)), 
           be=Matrix(m, m, lambda n,k: (k+1)*binomial(2*n-k, n-k)/(n+1) if n > 0 else int(not k)))
C


Out[3]:
$$\mathcal{C}_{ 8 } = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\5 & 5 & 3 & 1 & 0 & 0 & 0 & 0\\14 & 14 & 9 & 4 & 1 & 0 & 0 & 0\\42 & 42 & 28 & 14 & 5 & 1 & 0 & 0\\132 & 132 & 90 & 48 & 20 & 6 & 1 & 0\\429 & 429 & 297 & 165 & 75 & 27 & 7 & 1\end{matrix}\right]$$

In [4]:
eigendata = spectrum(C)
eigendata


Out[4]:
$$\sigma{\left (\mathcal{C}_{ 8 } \right )} = \left ( \left \{ 1 : \left ( \lambda_{1}, \quad m_{1}\right )\right \}, \quad \left \{ \lambda_{1} : 1\right \}, \quad \left \{ m_{1} : 8\right \}\right )$$

In [5]:
data, eigenvals, multiplicities = eigendata.rhs

In [6]:
Phi_poly = Phi_poly_ctor(deg=m-1)
Phi_poly


Out[6]:
$$\Phi{\left (z,i,j \right )} = z^{7} \phi_{i,j,0} + z^{6} \phi_{i,j,1} + z^{5} \phi_{i,j,2} + z^{4} \phi_{i,j,3} + z^{3} \phi_{i,j,4} + z^{2} \phi_{i,j,5} + z \phi_{i,j,6} + \phi_{i,j,7}$$

In [7]:
Phi_polynomials = component_polynomials(eigendata, early_eigenvals_subs=True)
Phi_polynomials


Out[7]:
$$\left \{ \left ( 1, \quad 1\right ) : \Phi_{ 1, 1 }{\left (z \right )} = 1, \quad \left ( 1, \quad 2\right ) : \Phi_{ 1, 2 }{\left (z \right )} = z - 1, \quad \left ( 1, \quad 3\right ) : \Phi_{ 1, 3 }{\left (z \right )} = \frac{z^{2}}{2} - z + \frac{1}{2}, \quad \left ( 1, \quad 4\right ) : \Phi_{ 1, 4 }{\left (z \right )} = \frac{z^{3}}{6} - \frac{z^{2}}{2} + \frac{z}{2} - \frac{1}{6}, \quad \left ( 1, \quad 5\right ) : \Phi_{ 1, 5 }{\left (z \right )} = \frac{z^{4}}{24} - \frac{z^{3}}{6} + \frac{z^{2}}{4} - \frac{z}{6} + \frac{1}{24}, \quad \left ( 1, \quad 6\right ) : \Phi_{ 1, 6 }{\left (z \right )} = \frac{z^{5}}{120} - \frac{z^{4}}{24} + \frac{z^{3}}{12} - \frac{z^{2}}{12} + \frac{z}{24} - \frac{1}{120}, \quad \left ( 1, \quad 7\right ) : \Phi_{ 1, 7 }{\left (z \right )} = \frac{z^{6}}{720} - \frac{z^{5}}{120} + \frac{z^{4}}{48} - \frac{z^{3}}{36} + \frac{z^{2}}{48} - \frac{z}{120} + \frac{1}{720}, \quad \left ( 1, \quad 8\right ) : \Phi_{ 1, 8 }{\left (z \right )} = \frac{z^{7}}{5040} - \frac{z^{6}}{720} + \frac{z^{5}}{240} - \frac{z^{4}}{144} + \frac{z^{3}}{144} - \frac{z^{2}}{240} + \frac{z}{720} - \frac{1}{5040}\right \}$$

In [8]:
cmatrices = component_matrices(C, Phi_polynomials)
list(cmatrices.values())


Out[8]:
$$\left [ Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,1} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,2} = \left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\5 & 5 & 3 & 0 & 0 & 0 & 0 & 0\\14 & 14 & 9 & 4 & 0 & 0 & 0 & 0\\42 & 42 & 28 & 14 & 5 & 0 & 0 & 0\\132 & 132 & 90 & 48 & 20 & 6 & 0 & 0\\429 & 429 & 297 & 165 & 75 & 27 & 7 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,3} = \left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{11}{2} & 3 & 0 & 0 & 0 & 0 & 0 & 0\\26 & 19 & 6 & 0 & 0 & 0 & 0 & 0\\119 & 98 & \frac{87}{2} & 10 & 0 & 0 & 0 & 0\\542 & 476 & 246 & 82 & 15 & 0 & 0 & 0\\2478 & \frac{4527}{2} & 1278 & 507 & \frac{275}{2} & 21 & 0 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,4} = \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\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{31}{3} & 4 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{235}{3} & \frac{137}{3} & 10 & 0 & 0 & 0 & 0 & 0\\\frac{1588}{3} & \frac{1112}{3} & 127 & 20 & 0 & 0 & 0 & 0\\\frac{20323}{6} & \frac{7898}{3} & \frac{2231}{2} & \frac{844}{3} & 35 & 0 & 0 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,5} = \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 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{197}{12} & 5 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1087}{6} & \frac{177}{2} & 15 & 0 & 0 & 0 & 0 & 0\\\frac{20281}{12} & \frac{12383}{12} & \frac{1159}{4} & 35 & 0 & 0 & 0 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,6} = \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 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{237}{10} & 6 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{21437}{60} & \frac{1509}{10} & 21 & 0 & 0 & 0 & 0 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,7} = \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 & 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\\\frac{643}{20} & 7 & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right], \quad Z^{\left[ \mathcal{C}_{ 8 } \right]}_{1,8} = \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 & 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\end{matrix}\right]\right ]$$

power function


In [9]:
f_power, g_power, G_power = functions_catalog.power(eigendata, Phi_polynomials)

In [13]:
C_power = G_power(C)
C_power


Out[13]:
$$\operatorname{P_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\r & 1 & 0 & 0 & 0 & 0 & 0 & 0\\r \left(r + 1\right) & 2 r & 1 & 0 & 0 & 0 & 0 & 0\\\frac{r}{2} \left(2 r^{2} + 5 r + 3\right) & r \left(3 r + 2\right) & 3 r & 1 & 0 & 0 & 0 & 0\\\frac{r}{3} \left(3 r^{3} + 13 r^{2} + 18 r + 8\right) & r \left(4 r^{2} + 7 r + 3\right) & 3 r \left(2 r + 1\right) & 4 r & 1 & 0 & 0 & 0\\\frac{r}{12} \left(12 r^{4} + 77 r^{3} + 178 r^{2} + 175 r + 62\right) & \frac{r}{3} \left(15 r^{3} + 47 r^{2} + 48 r + 16\right) & \frac{r}{2} \left(20 r^{2} + 27 r + 9\right) & 2 r \left(5 r + 2\right) & 5 r & 1 & 0 & 0\\\frac{r}{30} \left(30 r^{5} + 261 r^{4} + 875 r^{3} + 1405 r^{2} + 1075 r + 314\right) & \frac{r}{6} \left(36 r^{4} + 171 r^{3} + 298 r^{2} + 225 r + 62\right) & r \left(15 r^{3} + 37 r^{2} + 30 r + 8\right) & 2 r \left(10 r^{2} + 11 r + 3\right) & 5 r \left(3 r + 1\right) & 6 r & 1 & 0\\\frac{r}{60} \left(60 r^{6} + 669 r^{5} + 3002 r^{4} + 6900 r^{3} + 8510 r^{2} + 5301 r + 1298\right) & \frac{r}{60} \left(420 r^{5} + 2754 r^{4} + 7075 r^{3} + 8860 r^{2} + 5375 r + 1256\right) & \frac{r}{4} \left(84 r^{4} + 319 r^{3} + 448 r^{2} + 275 r + 62\right) & \frac{r}{3} \left(105 r^{3} + 214 r^{2} + 144 r + 32\right) & \frac{5 r}{2} \left(14 r^{2} + 13 r + 3\right) & 3 r \left(7 r + 2\right) & 7 r & 1\end{matrix}\right]$$

In [15]:
define(C_power.lhs, C_power.rhs.applyfunc(factor)) # factored


Out[15]:
$$\operatorname{P_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\r & 1 & 0 & 0 & 0 & 0 & 0 & 0\\r \left(r + 1\right) & 2 r & 1 & 0 & 0 & 0 & 0 & 0\\\frac{r}{2} \left(r + 1\right) \left(2 r + 3\right) & r \left(3 r + 2\right) & 3 r & 1 & 0 & 0 & 0 & 0\\\frac{r}{3} \left(r + 1\right) \left(r + 2\right) \left(3 r + 4\right) & r \left(r + 1\right) \left(4 r + 3\right) & 3 r \left(2 r + 1\right) & 4 r & 1 & 0 & 0 & 0\\\frac{r}{12} \left(r + 1\right) \left(r + 2\right) \left(12 r^{2} + 41 r + 31\right) & \frac{r}{3} \left(r + 1\right) \left(3 r + 4\right) \left(5 r + 4\right) & \frac{r}{2} \left(4 r + 3\right) \left(5 r + 3\right) & 2 r \left(5 r + 2\right) & 5 r & 1 & 0 & 0\\\frac{r}{30} \left(r + 1\right) \left(r + 2\right) \left(30 r^{3} + 171 r^{2} + 302 r + 157\right) & \frac{r}{6} \left(r + 1\right) \left(36 r^{3} + 135 r^{2} + 163 r + 62\right) & r \left(r + 1\right) \left(3 r + 2\right) \left(5 r + 4\right) & 2 r \left(2 r + 1\right) \left(5 r + 3\right) & 5 r \left(3 r + 1\right) & 6 r & 1 & 0\\\frac{r}{60} \left(r + 1\right) \left(r + 2\right) \left(4 r + 11\right) \left(15 r^{3} + 81 r^{2} + 131 r + 59\right) & \frac{r}{60} \left(r + 1\right) \left(420 r^{4} + 2334 r^{3} + 4741 r^{2} + 4119 r + 1256\right) & \frac{r}{4} \left(r + 1\right)^{2} \left(84 r^{2} + 151 r + 62\right) & \frac{r}{3} \left(3 r + 2\right) \left(5 r + 4\right) \left(7 r + 4\right) & \frac{5 r}{2} \left(2 r + 1\right) \left(7 r + 3\right) & 3 r \left(7 r + 2\right) & 7 r & 1\end{matrix}\right]$$

In [16]:
assert C_power.rhs == (C.rhs**r).applyfunc(simplify)

In [17]:
inspect(C_power.rhs)


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

In [18]:
production_matrix(C_power.rhs).applyfunc(factor)


Out[18]:
$$\left[\begin{matrix}r & 1 & 0 & 0 & 0 & 0 & 0\\r & r & 1 & 0 & 0 & 0 & 0\\- \frac{r}{2} \left(r - 3\right) & r & r & 1 & 0 & 0 & 0\\\frac{r}{3} \left(r - 4\right) \left(r - 2\right) & - \frac{r}{2} \left(r - 3\right) & r & r & 1 & 0 & 0\\- \frac{r}{12} \left(r - 2\right) \left(3 r^{2} - 22 r + 31\right) & \frac{r}{3} \left(r - 4\right) \left(r - 2\right) & - \frac{r}{2} \left(r - 3\right) & r & r & 1 & 0\\\frac{r}{60} \left(12 r^{4} - 155 r^{3} + 650 r^{2} - 1075 r + 628\right) & - \frac{r}{12} \left(r - 2\right) \left(3 r^{2} - 22 r + 31\right) & \frac{r}{3} \left(r - 4\right) \left(r - 2\right) & - \frac{r}{2} \left(r - 3\right) & r & r & 1\\- \frac{r}{60} \left(10 r^{5} - 167 r^{4} + 975 r^{3} - 2525 r^{2} + 2945 r - 1298\right) & \frac{r}{60} \left(12 r^{4} - 155 r^{3} + 650 r^{2} - 1075 r + 628\right) & - \frac{r}{12} \left(r - 2\right) \left(3 r^{2} - 22 r + 31\right) & \frac{r}{3} \left(r - 4\right) \left(r - 2\right) & - \frac{r}{2} \left(r - 3\right) & r & r\end{matrix}\right]$$

inverse function


In [19]:
f_inverse, g_inverse, G_inverse = functions_catalog.inverse(eigendata, Phi_polynomials)

In [20]:
C_inverse = G_inverse(C)
C_inverse, G_inverse(C_inverse)


Out[20]:
$$\left ( \operatorname{I_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & -2 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 1 & -3 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 3 & -4 & 1 & 0 & 0 & 0\\0 & 0 & -1 & 6 & -5 & 1 & 0 & 0\\0 & 0 & 0 & -4 & 10 & -6 & 1 & 0\\0 & 0 & 0 & 1 & -10 & 15 & -7 & 1\end{matrix}\right], \quad \operatorname{I_{ 8 }}{\left (\operatorname{I_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\5 & 5 & 3 & 1 & 0 & 0 & 0 & 0\\14 & 14 & 9 & 4 & 1 & 0 & 0 & 0\\42 & 42 & 28 & 14 & 5 & 1 & 0 & 0\\132 & 132 & 90 & 48 & 20 & 6 & 1 & 0\\429 & 429 & 297 & 165 & 75 & 27 & 7 & 1\end{matrix}\right]\right )$$

In [21]:
inspect(C_inverse.rhs)


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

In [22]:
production_matrix(C_inverse.rhs)


Out[22]:
$$\left[\begin{matrix}-1 & 1 & 0 & 0 & 0 & 0 & 0\\-1 & -1 & 1 & 0 & 0 & 0 & 0\\-2 & -1 & -1 & 1 & 0 & 0 & 0\\-5 & -2 & -1 & -1 & 1 & 0 & 0\\-14 & -5 & -2 & -1 & -1 & 1 & 0\\-42 & -14 & -5 & -2 & -1 & -1 & 1\\-132 & -42 & -14 & -5 & -2 & -1 & -1\end{matrix}\right]$$

In [23]:
assert C_inverse.rhs*C.rhs == Matrix(m, m, identity_matrix())
assert C_inverse.rhs == C_power.rhs.subs({r:-1})

sqrt function


In [24]:
f_sqrt, g_sqrt, G_sqrt = functions_catalog.square_root(eigendata, Phi_polynomials)

In [25]:
C_sqrt = G_sqrt(C)
C_sqrt


Out[25]:
$$\operatorname{R_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{2} & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{3}{4} & 1 & 1 & 0 & 0 & 0 & 0 & 0\\\frac{3}{2} & \frac{7}{4} & \frac{3}{2} & 1 & 0 & 0 & 0 & 0\\\frac{55}{16} & \frac{15}{4} & 3 & 2 & 1 & 0 & 0 & 0\\\frac{545}{64} & \frac{143}{16} & \frac{55}{8} & \frac{9}{2} & \frac{5}{2} & 1 & 0 & 0\\\frac{709}{32} & \frac{727}{32} & \frac{273}{16} & 11 & \frac{25}{4} & 3 & 1 & 0\\\frac{15249}{256} & \frac{3855}{64} & \frac{2853}{64} & \frac{455}{16} & \frac{65}{4} & \frac{33}{4} & \frac{7}{2} & 1\end{matrix}\right]$$

In [26]:
inspect(C_sqrt.rhs)


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

In [27]:
production_matrix(C_sqrt.rhs)


Out[27]:
$$\left[\begin{matrix}\frac{1}{2} & 1 & 0 & 0 & 0 & 0 & 0\\\frac{1}{2} & \frac{1}{2} & 1 & 0 & 0 & 0 & 0\\\frac{5}{8} & \frac{1}{2} & \frac{1}{2} & 1 & 0 & 0 & 0\\\frac{7}{8} & \frac{5}{8} & \frac{1}{2} & \frac{1}{2} & 1 & 0 & 0\\\frac{83}{64} & \frac{7}{8} & \frac{5}{8} & \frac{1}{2} & \frac{1}{2} & 1 & 0\\\frac{125}{64} & \frac{83}{64} & \frac{7}{8} & \frac{5}{8} & \frac{1}{2} & \frac{1}{2} & 1\\\frac{23}{8} & \frac{125}{64} & \frac{83}{64} & \frac{7}{8} & \frac{5}{8} & \frac{1}{2} & \frac{1}{2}\end{matrix}\right]$$

In [28]:
assert C.rhs**(S(1)/2) == C_sqrt.rhs
assert C_sqrt.rhs == C_power.rhs.subs({r:S(1)/2})

expt function


In [29]:
f_exp, g_exp, G_exp = functions_catalog.exp(eigendata, Phi_polynomials)

In [30]:
C_exp = G_exp(C)
C_exp


Out[30]:
$$\operatorname{E_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}e^{\alpha} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0 & 0 & 0\\\alpha \left(\alpha + 2\right) e^{\alpha} & 2 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{2} \left(2 \alpha^{2} + 11 \alpha + 10\right) & \alpha \left(3 \alpha + 5\right) e^{\alpha} & 3 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{3} \left(3 \alpha^{3} + 31 \alpha^{2} + 78 \alpha + 42\right) & \alpha \left(4 \alpha^{2} + 19 \alpha + 14\right) e^{\alpha} & 3 \alpha \left(2 \alpha + 3\right) e^{\alpha} & 4 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{12} \left(12 \alpha^{4} + 197 \alpha^{3} + 940 \alpha^{2} + 1428 \alpha + 504\right) & \frac{\alpha e^{\alpha}}{3} \left(15 \alpha^{3} + 137 \alpha^{2} + 294 \alpha + 126\right) & \frac{\alpha e^{\alpha}}{2} \left(20 \alpha^{2} + 87 \alpha + 56\right) & 2 \alpha \left(5 \alpha + 7\right) e^{\alpha} & 5 \alpha e^{\alpha} & e^{\alpha} & 0 & 0\\\frac{\alpha e^{\alpha}}{30} \left(30 \alpha^{5} + 711 \alpha^{4} + 5435 \alpha^{3} + 15880 \alpha^{2} + 16260 \alpha + 3960\right) & \frac{\alpha e^{\alpha}}{6} \left(36 \alpha^{4} + 531 \alpha^{3} + 2224 \alpha^{2} + 2856 \alpha + 792\right) & \alpha \left(15 \alpha^{3} + 127 \alpha^{2} + 246 \alpha + 90\right) e^{\alpha} & 2 \alpha \left(10 \alpha^{2} + 41 \alpha + 24\right) e^{\alpha} & 5 \alpha \left(3 \alpha + 4\right) e^{\alpha} & 6 \alpha e^{\alpha} & e^{\alpha} & 0\\\frac{\alpha e^{\alpha}}{60} \left(60 \alpha^{6} + 1929 \alpha^{5} + 21437 \alpha^{4} + 101405 \alpha^{3} + 203230 \alpha^{2} + 148680 \alpha + 25740\right) & \frac{\alpha e^{\alpha}}{60} \left(420 \alpha^{5} + 9054 \alpha^{4} + 61915 \alpha^{3} + 157960 \alpha^{2} + 135810 \alpha + 25740\right) & \frac{\alpha e^{\alpha}}{4} \left(84 \alpha^{4} + 1159 \alpha^{3} + 4462 \alpha^{2} + 5112 \alpha + 1188\right) & \frac{\alpha e^{\alpha}}{3} \left(105 \alpha^{3} + 844 \alpha^{2} + 1521 \alpha + 495\right) & \frac{5 \alpha}{2} \left(14 \alpha^{2} + 55 \alpha + 30\right) e^{\alpha} & 3 \alpha \left(7 \alpha + 9\right) e^{\alpha} & 7 \alpha e^{\alpha} & e^{\alpha}\end{matrix}\right]$$

In [35]:
define(C_exp.lhs, C_exp.rhs.applyfunc(factor))


Out[35]:
$$\operatorname{E_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}e^{\alpha} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0 & 0 & 0\\\alpha \left(\alpha + 2\right) e^{\alpha} & 2 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{2} \left(2 \alpha^{2} + 11 \alpha + 10\right) & \alpha \left(3 \alpha + 5\right) e^{\alpha} & 3 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{3} \left(3 \alpha^{3} + 31 \alpha^{2} + 78 \alpha + 42\right) & \alpha \left(4 \alpha^{2} + 19 \alpha + 14\right) e^{\alpha} & 3 \alpha \left(2 \alpha + 3\right) e^{\alpha} & 4 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0\\\frac{\alpha e^{\alpha}}{12} \left(12 \alpha^{4} + 197 \alpha^{3} + 940 \alpha^{2} + 1428 \alpha + 504\right) & \frac{\alpha e^{\alpha}}{3} \left(15 \alpha^{3} + 137 \alpha^{2} + 294 \alpha + 126\right) & \frac{\alpha e^{\alpha}}{2} \left(20 \alpha^{2} + 87 \alpha + 56\right) & 2 \alpha \left(5 \alpha + 7\right) e^{\alpha} & 5 \alpha e^{\alpha} & e^{\alpha} & 0 & 0\\\frac{\alpha e^{\alpha}}{30} \left(30 \alpha^{5} + 711 \alpha^{4} + 5435 \alpha^{3} + 15880 \alpha^{2} + 16260 \alpha + 3960\right) & \frac{\alpha e^{\alpha}}{6} \left(36 \alpha^{4} + 531 \alpha^{3} + 2224 \alpha^{2} + 2856 \alpha + 792\right) & \alpha \left(15 \alpha^{3} + 127 \alpha^{2} + 246 \alpha + 90\right) e^{\alpha} & 2 \alpha \left(10 \alpha^{2} + 41 \alpha + 24\right) e^{\alpha} & 5 \alpha \left(3 \alpha + 4\right) e^{\alpha} & 6 \alpha e^{\alpha} & e^{\alpha} & 0\\\frac{\alpha e^{\alpha}}{60} \left(60 \alpha^{6} + 1929 \alpha^{5} + 21437 \alpha^{4} + 101405 \alpha^{3} + 203230 \alpha^{2} + 148680 \alpha + 25740\right) & \frac{\alpha e^{\alpha}}{60} \left(420 \alpha^{5} + 9054 \alpha^{4} + 61915 \alpha^{3} + 157960 \alpha^{2} + 135810 \alpha + 25740\right) & \frac{\alpha e^{\alpha}}{4} \left(84 \alpha^{4} + 1159 \alpha^{3} + 4462 \alpha^{2} + 5112 \alpha + 1188\right) & \frac{\alpha e^{\alpha}}{3} \left(105 \alpha^{3} + 844 \alpha^{2} + 1521 \alpha + 495\right) & \frac{5 \alpha}{2} \left(14 \alpha^{2} + 55 \alpha + 30\right) e^{\alpha} & 3 \alpha \left(7 \alpha + 9\right) e^{\alpha} & 7 \alpha e^{\alpha} & e^{\alpha}\end{matrix}\right]$$

In [37]:
C_exp1 = define(let=Subs(C_exp.lhs, alpha, 1), be=C_exp.rhs.subs({alpha:1}))
C_exp1


Out[37]:
$$\left. \operatorname{E_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} \right|_{\substack{ \alpha=1 }} = \left[\begin{matrix}e & 0 & 0 & 0 & 0 & 0 & 0 & 0\\e & e & 0 & 0 & 0 & 0 & 0 & 0\\3 e & 2 e & e & 0 & 0 & 0 & 0 & 0\\\frac{23 e}{2} & 8 e & 3 e & e & 0 & 0 & 0 & 0\\\frac{154 e}{3} & 37 e & 15 e & 4 e & e & 0 & 0 & 0\\\frac{1027 e}{4} & \frac{572 e}{3} & \frac{163 e}{2} & 24 e & 5 e & e & 0 & 0\\\frac{7046 e}{5} & \frac{6439 e}{6} & 478 e & 150 e & 35 e & 6 e & e & 0\\\frac{502481 e}{60} & \frac{390899 e}{60} & \frac{12005 e}{4} & \frac{2965 e}{3} & \frac{495 e}{2} & 48 e & 7 e & e\end{matrix}\right]$$

In [38]:
inspect(C_exp.rhs)


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

In [58]:
inspect(C_exp1.rhs)


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

In [42]:
eigendata_Cexpt = spectrum(C_exp1)
eigendata_Cexpt


Out[42]:
$$\sigma{\left (\left. \operatorname{E_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} \right|_{\substack{ \alpha=1 }} \right )} = \left ( \left \{ 1 : \left ( \lambda_{1}, \quad m_{1}\right )\right \}, \quad \left \{ \lambda_{1} : e\right \}, \quad \left \{ m_{1} : 8\right \}\right )$$

In [43]:
Phi_polynomials_Cexpt = component_polynomials(eigendata_Cexpt, early_eigenvals_subs=True)
Phi_polynomials_Cexpt


Out[43]:
$$\left \{ \left ( 1, \quad 1\right ) : \Phi_{ 1, 1 }{\left (z \right )} = 1, \quad \left ( 1, \quad 2\right ) : \Phi_{ 1, 2 }{\left (z \right )} = z - e, \quad \left ( 1, \quad 3\right ) : \Phi_{ 1, 3 }{\left (z \right )} = \frac{z^{2}}{2} - e z + \frac{e^{2}}{2}, \quad \left ( 1, \quad 4\right ) : \Phi_{ 1, 4 }{\left (z \right )} = \frac{z^{3}}{6} - \frac{e z^{2}}{2} + \frac{z e^{2}}{2} - \frac{e^{3}}{6}, \quad \left ( 1, \quad 5\right ) : \Phi_{ 1, 5 }{\left (z \right )} = \frac{z^{4}}{24} - \frac{e z^{3}}{6} + \frac{z^{2} e^{2}}{4} - \frac{z e^{3}}{6} + \frac{e^{4}}{24}, \quad \left ( 1, \quad 6\right ) : \Phi_{ 1, 6 }{\left (z \right )} = \frac{z^{5}}{120} - \frac{e z^{4}}{24} + \frac{z^{3} e^{2}}{12} - \frac{z^{2} e^{3}}{12} + \frac{z e^{4}}{24} - \frac{e^{5}}{120}, \quad \left ( 1, \quad 7\right ) : \Phi_{ 1, 7 }{\left (z \right )} = \frac{z^{6}}{720} - \frac{e z^{5}}{120} + \frac{z^{4} e^{2}}{48} - \frac{z^{3} e^{3}}{36} + \frac{z^{2} e^{4}}{48} - \frac{z e^{5}}{120} + \frac{e^{6}}{720}, \quad \left ( 1, \quad 8\right ) : \Phi_{ 1, 8 }{\left (z \right )} = \frac{z^{7}}{5040} - \frac{e z^{6}}{720} + \frac{z^{5} e^{2}}{240} - \frac{z^{4} e^{3}}{144} + \frac{z^{3} e^{4}}{144} - \frac{z^{2} e^{5}}{240} + \frac{z e^{6}}{720} - \frac{e^{7}}{5040}\right \}$$

log function


In [44]:
f_log, g_log, G_log = functions_catalog.log(eigendata, Phi_polynomials)

In [45]:
C_log = G_log(C)
C_log


Out[45]:
$$\operatorname{L_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{3}{2} & 2 & 3 & 0 & 0 & 0 & 0 & 0\\\frac{8}{3} & 3 & 3 & 4 & 0 & 0 & 0 & 0\\\frac{31}{6} & \frac{16}{3} & \frac{9}{2} & 4 & 5 & 0 & 0 & 0\\\frac{157}{15} & \frac{31}{3} & 8 & 6 & 5 & 6 & 0 & 0\\\frac{649}{30} & \frac{314}{15} & \frac{31}{2} & \frac{32}{3} & \frac{15}{2} & 6 & 7 & 0\end{matrix}\right]$$

In [46]:
inspect(C_log.rhs[1:,:-1])


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

In [48]:
production_matrix(C_log.rhs[1:,:-1])


Out[48]:
$$\left[\begin{matrix}1 & 2 & 0 & 0 & 0 & 0\\\frac{1}{4} & 0 & \frac{3}{2} & 0 & 0 & 0\\\frac{2}{9} & 0 & 0 & \frac{4}{3} & 0 & 0\\\frac{13}{48} & 0 & 0 & 0 & \frac{5}{4} & 0\\\frac{113}{300} & 0 & 0 & 0 & 0 & \frac{6}{5}\\\frac{1187}{2160} & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$$

In [49]:
g_log_Cexpt = Hermite_interpolation_polynomial(f_log, eigendata_Cexpt, Phi_polynomials_Cexpt)
g_log_Cexpt


Out[49]:
$$\operatorname{L_{ 8 }}{\left (z \right )} = \frac{z^{7}}{7 \lambda_{1}^{7}} + z^{6} \left(- \frac{1}{6 \lambda_{1}^{6}} - \frac{e}{\lambda_{1}^{7}}\right) + z^{5} \left(\frac{1}{5 \lambda_{1}^{5}} + \frac{e}{\lambda_{1}^{6}} + \frac{3 e^{2}}{\lambda_{1}^{7}}\right) + z^{4} \left(- \frac{1}{4 \lambda_{1}^{4}} - \frac{e}{\lambda_{1}^{5}} - \frac{5 e^{2}}{2 \lambda_{1}^{6}} - \frac{5 e^{3}}{\lambda_{1}^{7}}\right) + z^{3} \left(\frac{1}{3 \lambda_{1}^{3}} + \frac{e}{\lambda_{1}^{4}} + \frac{2 e^{2}}{\lambda_{1}^{5}} + \frac{10 e^{3}}{3 \lambda_{1}^{6}} + \frac{5 e^{4}}{\lambda_{1}^{7}}\right) + z^{2} \left(- \frac{1}{2 \lambda_{1}^{2}} - \frac{e}{\lambda_{1}^{3}} - \frac{3 e^{2}}{2 \lambda_{1}^{4}} - \frac{2 e^{3}}{\lambda_{1}^{5}} - \frac{5 e^{4}}{2 \lambda_{1}^{6}} - \frac{3 e^{5}}{\lambda_{1}^{7}}\right) + z \left(\frac{1}{\lambda_{1}} + \frac{e}{\lambda_{1}^{2}} + \frac{e^{2}}{\lambda_{1}^{3}} + \frac{e^{3}}{\lambda_{1}^{4}} + \frac{e^{4}}{\lambda_{1}^{5}} + \frac{e^{5}}{\lambda_{1}^{6}} + \frac{e^{6}}{\lambda_{1}^{7}}\right) + \log{\left (\lambda_{1} \right )} - \frac{e}{\lambda_{1}} - \frac{e^{2}}{2 \lambda_{1}^{2}} - \frac{e^{3}}{3 \lambda_{1}^{3}} - \frac{e^{4}}{4 \lambda_{1}^{4}} - \frac{e^{5}}{5 \lambda_{1}^{5}} - \frac{e^{6}}{6 \lambda_{1}^{6}} - \frac{e^{7}}{7 \lambda_{1}^{7}}$$

In [50]:
g_log_Cexpt = g_log_Cexpt.subs(eigendata_Cexpt.rhs[1])
g_log_Cexpt


Out[50]:
$$\operatorname{L_{ 8 }}{\left (z \right )} = \frac{z^{7}}{7 e^{7}} - \frac{7 z^{6}}{6 e^{6}} + \frac{21 z^{5}}{5 e^{5}} - \frac{35 z^{4}}{4 e^{4}} + \frac{35 z^{3}}{3 e^{3}} - \frac{21 z^{2}}{2 e^{2}} + \frac{7 z}{e} - \frac{223}{140}$$

In [52]:
with lift_to_matrix_function(g_log_Cexpt) as G_log_Cexpt:
    CC = G_log_Cexpt(C_exp1)
CC


Out[52]:
$$\operatorname{L_{ 8 }}{\left (\left. \operatorname{E_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} \right|_{\substack{ \alpha=1 }} \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\5 & 5 & 3 & 1 & 0 & 0 & 0 & 0\\14 & 14 & 9 & 4 & 1 & 0 & 0 & 0\\42 & 42 & 28 & 14 & 5 & 1 & 0 & 0\\132 & 132 & 90 & 48 & 20 & 6 & 1 & 0\\429 & 429 & 297 & 165 & 75 & 27 & 7 & 1\end{matrix}\right]$$

sin function


In [53]:
f_sin, g_sin, G_sin = functions_catalog.sin(eigendata, Phi_polynomials)

In [54]:
C_sin = G_sin(C)    
C_sin


Out[54]:
$$\operatorname{S_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}\sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\cos{\left (1 \right )} & \sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0\\- \sin{\left (1 \right )} + 2 \cos{\left (1 \right )} & 2 \cos{\left (1 \right )} & \sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0\\- \frac{11}{2} \sin{\left (1 \right )} + 4 \cos{\left (1 \right )} & - 3 \sin{\left (1 \right )} + 5 \cos{\left (1 \right )} & 3 \cos{\left (1 \right )} & \sin{\left (1 \right )} & 0 & 0 & 0 & 0\\- 25 \sin{\left (1 \right )} + \frac{11}{3} \cos{\left (1 \right )} & - 19 \sin{\left (1 \right )} + 10 \cos{\left (1 \right )} & - 6 \sin{\left (1 \right )} + 9 \cos{\left (1 \right )} & 4 \cos{\left (1 \right )} & \sin{\left (1 \right )} & 0 & 0 & 0\\- \frac{1231}{12} \sin{\left (1 \right )} - \frac{106}{3} \cos{\left (1 \right )} & - 93 \sin{\left (1 \right )} - \frac{11}{3} \cos{\left (1 \right )} & - \frac{87}{2} \sin{\left (1 \right )} + 18 \cos{\left (1 \right )} & - 10 \sin{\left (1 \right )} + 14 \cos{\left (1 \right )} & 5 \cos{\left (1 \right )} & \sin{\left (1 \right )} & 0 & 0\\- \frac{2171}{6} \sin{\left (1 \right )} - \frac{11209}{30} \cos{\left (1 \right )} & - \frac{775}{2} \sin{\left (1 \right )} - \frac{698}{3} \cos{\left (1 \right )} & - 231 \sin{\left (1 \right )} - 37 \cos{\left (1 \right )} & - 82 \sin{\left (1 \right )} + 28 \cos{\left (1 \right )} & - 15 \sin{\left (1 \right )} + 20 \cos{\left (1 \right )} & 6 \cos{\left (1 \right )} & \sin{\left (1 \right )} & 0\\- \frac{156113}{60} \cos{\left (1 \right )} - \frac{12301}{15} \sin{\left (1 \right )} & - \frac{61583}{30} \cos{\left (1 \right )} - \frac{14863}{12} \sin{\left (1 \right )} & - \frac{3953}{4} \sin{\left (1 \right )} - \frac{1595}{2} \cos{\left (1 \right )} & - 472 \sin{\left (1 \right )} - \frac{349}{3} \cos{\left (1 \right )} & - \frac{275}{2} \sin{\left (1 \right )} + 40 \cos{\left (1 \right )} & - 21 \sin{\left (1 \right )} + 27 \cos{\left (1 \right )} & 7 \cos{\left (1 \right )} & \sin{\left (1 \right )}\end{matrix}\right]$$

In [ ]:
inspect(C_sin.rhs) # takes long to evaluate

cos function


In [55]:
f_cos, g_cos, G_cos = functions_catalog.cos(eigendata, Phi_polynomials)

In [56]:
C_cos = G_cos(C)    
C_cos


Out[56]:
$$\operatorname{C_{ 8 }}{\left (\mathcal{C}_{ 8 } \right )} = \left[\begin{matrix}\cos{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0\\- 2 \sin{\left (1 \right )} - \cos{\left (1 \right )} & - 2 \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0 & 0 & 0 & 0 & 0\\- 4 \sin{\left (1 \right )} - \frac{11}{2} \cos{\left (1 \right )} & - 5 \sin{\left (1 \right )} - 3 \cos{\left (1 \right )} & - 3 \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0 & 0 & 0 & 0\\- 25 \cos{\left (1 \right )} - \frac{11}{3} \sin{\left (1 \right )} & - 19 \cos{\left (1 \right )} - 10 \sin{\left (1 \right )} & - 9 \sin{\left (1 \right )} - 6 \cos{\left (1 \right )} & - 4 \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0 & 0 & 0\\- \frac{1231}{12} \cos{\left (1 \right )} + \frac{106}{3} \sin{\left (1 \right )} & - 93 \cos{\left (1 \right )} + \frac{11}{3} \sin{\left (1 \right )} & - \frac{87}{2} \cos{\left (1 \right )} - 18 \sin{\left (1 \right )} & - 14 \sin{\left (1 \right )} - 10 \cos{\left (1 \right )} & - 5 \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0 & 0\\- \frac{2171}{6} \cos{\left (1 \right )} + \frac{11209}{30} \sin{\left (1 \right )} & - \frac{775}{2} \cos{\left (1 \right )} + \frac{698}{3} \sin{\left (1 \right )} & - 231 \cos{\left (1 \right )} + 37 \sin{\left (1 \right )} & - 82 \cos{\left (1 \right )} - 28 \sin{\left (1 \right )} & - 20 \sin{\left (1 \right )} - 15 \cos{\left (1 \right )} & - 6 \sin{\left (1 \right )} & \cos{\left (1 \right )} & 0\\- \frac{12301}{15} \cos{\left (1 \right )} + \frac{156113}{60} \sin{\left (1 \right )} & - \frac{14863}{12} \cos{\left (1 \right )} + \frac{61583}{30} \sin{\left (1 \right )} & - \frac{3953}{4} \cos{\left (1 \right )} + \frac{1595}{2} \sin{\left (1 \right )} & - 472 \cos{\left (1 \right )} + \frac{349}{3} \sin{\left (1 \right )} & - \frac{275}{2} \cos{\left (1 \right )} - 40 \sin{\left (1 \right )} & - 27 \sin{\left (1 \right )} - 21 \cos{\left (1 \right )} & - 7 \sin{\left (1 \right )} & \cos{\left (1 \right )}\end{matrix}\right]$$

In [ ]:
inspect(C_sin.rhs) # takes long to evaluate

In [57]:
assert (C_sin.rhs**2 + C_cos.rhs**2).applyfunc(trigsimp) == Matrix(m,m, identity_matrix())