Massimo Nocentini

February 28, 2018: splitting from "big" notebook



Abstract
Theory of matrix functions, matricial characterization of Hermite interpolating polynomials.

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

from matrix_functions import *
from sequences import *

init_printing()

In [2]:
d = IndexedBase('d')
g = Function('g')
m_sym = symbols('m')


In [3]:
m=8
R = define(Symbol(r'\mathcal{R}'), 
           Matrix(m, m, riordan_matrix_by_recurrence(m, lambda n, k: {(n, k):1 if n == k else d[n, k]})))
R


Out[3]:
$$\mathcal{R} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\d_{1,0} & 1 & 0 & 0 & 0 & 0 & 0 & 0\\d_{2,0} & d_{2,1} & 1 & 0 & 0 & 0 & 0 & 0\\d_{3,0} & d_{3,1} & d_{3,2} & 1 & 0 & 0 & 0 & 0\\d_{4,0} & d_{4,1} & d_{4,2} & d_{4,3} & 1 & 0 & 0 & 0\\d_{5,0} & d_{5,1} & d_{5,2} & d_{5,3} & d_{5,4} & 1 & 0 & 0\\d_{6,0} & d_{6,1} & d_{6,2} & d_{6,3} & d_{6,4} & d_{6,5} & 1 & 0\\d_{7,0} & d_{7,1} & d_{7,2} & d_{7,3} & d_{7,4} & d_{7,5} & d_{7,6} & 1\end{matrix}\right]$$

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


Out[4]:
$$\sigma{\left (\mathcal{R} \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=False)
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 - \lambda_{1}, \quad \left ( 1, \quad 3\right ) : \Phi_{ 1, 3 }{\left (z \right )} = \frac{z^{2}}{2} - z \lambda_{1} + \frac{\lambda_{1}^{2}}{2}, \quad \left ( 1, \quad 4\right ) : \Phi_{ 1, 4 }{\left (z \right )} = \frac{z^{3}}{6} - \frac{z^{2} \lambda_{1}}{2} + \frac{z \lambda_{1}^{2}}{2} - \frac{\lambda_{1}^{3}}{6}, \quad \left ( 1, \quad 5\right ) : \Phi_{ 1, 5 }{\left (z \right )} = \frac{z^{4}}{24} - \frac{z^{3} \lambda_{1}}{6} + \frac{z^{2} \lambda_{1}^{2}}{4} - \frac{z \lambda_{1}^{3}}{6} + \frac{\lambda_{1}^{4}}{24}, \quad \left ( 1, \quad 6\right ) : \Phi_{ 1, 6 }{\left (z \right )} = \frac{z^{5}}{120} - \frac{z^{4} \lambda_{1}}{24} + \frac{z^{3} \lambda_{1}^{2}}{12} - \frac{z^{2} \lambda_{1}^{3}}{12} + \frac{z \lambda_{1}^{4}}{24} - \frac{\lambda_{1}^{5}}{120}, \quad \left ( 1, \quad 7\right ) : \Phi_{ 1, 7 }{\left (z \right )} = \frac{z^{6}}{720} - \frac{z^{5} \lambda_{1}}{120} + \frac{z^{4} \lambda_{1}^{2}}{48} - \frac{z^{3} \lambda_{1}^{3}}{36} + \frac{z^{2} \lambda_{1}^{4}}{48} - \frac{z \lambda_{1}^{5}}{120} + \frac{\lambda_{1}^{6}}{720}, \quad \left ( 1, \quad 8\right ) : \Phi_{ 1, 8 }{\left (z \right )} = \frac{z^{7}}{5040} - \frac{z^{6} \lambda_{1}}{720} + \frac{z^{5} \lambda_{1}^{2}}{240} - \frac{z^{4} \lambda_{1}^{3}}{144} + \frac{z^{3} \lambda_{1}^{4}}{144} - \frac{z^{2} \lambda_{1}^{5}}{240} + \frac{z \lambda_{1}^{6}}{720} - \frac{\lambda_{1}^{7}}{5040}\right \}$$

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


Out[8]:
$$\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 [9]:
res_expt = M_expt, z_expt, Phi_expt =(
    Matrix(m, m, lambda n,k: (-lamda_indexed[1])**(n-k)/(factorial(n-k)) if n-k >= 0 else 0),
    Matrix([z**i/factorial(i, evaluate=i<2) for i in range(m)]),
    Matrix([Function(r'\Phi_{{ {}, {} }}'.format(1, j))(z) for j in range(1, m+1)]))

res_expt


Out[9]:
$$\left ( \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \lambda_{1} & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0\\- \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0\\\frac{\lambda_{1}^{6}}{720} & - \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0\\- \frac{\lambda_{1}^{7}}{5040} & \frac{\lambda_{1}^{6}}{720} & - \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1\end{matrix}\right], \quad \left[\begin{matrix}1\\z\\\frac{z^{2}}{2!}\\\frac{z^{3}}{3!}\\\frac{z^{4}}{4!}\\\frac{z^{5}}{5!}\\\frac{z^{6}}{6!}\\\frac{z^{7}}{7!}\end{matrix}\right], \quad \left[\begin{matrix}\Phi_{ 1, 1 }{\left (z \right )}\\\Phi_{ 1, 2 }{\left (z \right )}\\\Phi_{ 1, 3 }{\left (z \right )}\\\Phi_{ 1, 4 }{\left (z \right )}\\\Phi_{ 1, 5 }{\left (z \right )}\\\Phi_{ 1, 6 }{\left (z \right )}\\\Phi_{ 1, 7 }{\left (z \right )}\\\Phi_{ 1, 8 }{\left (z \right )}\end{matrix}\right]\right )$$

In [10]:
production_matrix(M_expt)


Out[10]:
$$\left[\begin{matrix}- \lambda_{1} & 1 & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{2}}{2} & 0 & 1 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{6} & 0 & 0 & 1 & 0 & 0 & 0\\- \frac{\lambda_{1}^{4}}{24} & 0 & 0 & 0 & 1 & 0 & 0\\- \frac{\lambda_{1}^{5}}{120} & 0 & 0 & 0 & 0 & 1 & 0\\- \frac{\lambda_{1}^{6}}{720} & 0 & 0 & 0 & 0 & 0 & 1\\- \frac{\lambda_{1}^{7}}{5040} & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$$

In [11]:
exp(-lamda_indexed[1]*t).series(t, n=m)


Out[11]:
$$1 - t \lambda_{1} + \frac{t^{2} \lambda_{1}^{2}}{2} - \frac{t^{3} \lambda_{1}^{3}}{6} + \frac{t^{4} \lambda_{1}^{4}}{24} - \frac{t^{5} \lambda_{1}^{5}}{120} + \frac{t^{6} \lambda_{1}^{6}}{720} - \frac{t^{7} \lambda_{1}^{7}}{5040} + \mathcal{O}\left(t^{8}\right)$$

In [12]:
g, f = Function('g'), Function('f')
ERA = Matrix(m, m, riordan_matrix_by_convolution(m, 
                                                 d=Eq(g(t), exp(-lamda_indexed[1]*t)), 
                                                 h=Eq(f(t), t)))
ERA


Out[12]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \lambda_{1} & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0 & 0\\- \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0 & 0\\\frac{\lambda_{1}^{6}}{720} & - \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1 & 0\\- \frac{\lambda_{1}^{7}}{5040} & \frac{\lambda_{1}^{6}}{720} & - \frac{\lambda_{1}^{5}}{120} & \frac{\lambda_{1}^{4}}{24} & - \frac{\lambda_{1}^{3}}{6} & \frac{\lambda_{1}^{2}}{2} & - \lambda_{1} & 1\end{matrix}\right]$$

In [13]:
assert M_expt == ERA

In [14]:
exp(z*t).series(t, n=m), [factorial(i) for i in range(m)]


Out[14]:
$$\left ( 1 + t z + \frac{t^{2} z^{2}}{2} + \frac{t^{3} z^{3}}{6} + \frac{t^{4} z^{4}}{24} + \frac{t^{5} z^{5}}{120} + \frac{t^{6} z^{6}}{720} + \frac{t^{7} z^{7}}{5040} + \mathcal{O}\left(t^{8}\right), \quad \left [ 1, \quad 1, \quad 2, \quad 6, \quad 24, \quad 120, \quad 720, \quad 5040\right ]\right )$$

In [15]:
exp(t*(z-lamda_indexed[1])).series(t, n=m)


Out[15]:
$$1 + t \left(z - \lambda_{1}\right) + t^{2} \left(\frac{z^{2}}{2} - z \lambda_{1} + \frac{\lambda_{1}^{2}}{2}\right) + t^{3} \left(\frac{z^{3}}{6} - \frac{z^{2} \lambda_{1}}{2} + \frac{z \lambda_{1}^{2}}{2} - \frac{\lambda_{1}^{3}}{6}\right) + t^{4} \left(\frac{z^{4}}{24} - \frac{z^{3} \lambda_{1}}{6} + \frac{z^{2} \lambda_{1}^{2}}{4} - \frac{z \lambda_{1}^{3}}{6} + \frac{\lambda_{1}^{4}}{24}\right) + t^{5} \left(\frac{z^{5}}{120} - \frac{z^{4} \lambda_{1}}{24} + \frac{z^{3} \lambda_{1}^{2}}{12} - \frac{z^{2} \lambda_{1}^{3}}{12} + \frac{z \lambda_{1}^{4}}{24} - \frac{\lambda_{1}^{5}}{120}\right) + t^{6} \left(\frac{z^{6}}{720} - \frac{z^{5} \lambda_{1}}{120} + \frac{z^{4} \lambda_{1}^{2}}{48} - \frac{z^{3} \lambda_{1}^{3}}{36} + \frac{z^{2} \lambda_{1}^{4}}{48} - \frac{z \lambda_{1}^{5}}{120} + \frac{\lambda_{1}^{6}}{720}\right) + t^{7} \left(\frac{z^{7}}{5040} - \frac{z^{6} \lambda_{1}}{720} + \frac{z^{5} \lambda_{1}^{2}}{240} - \frac{z^{4} \lambda_{1}^{3}}{144} + \frac{z^{3} \lambda_{1}^{4}}{144} - \frac{z^{2} \lambda_{1}^{5}}{240} + \frac{z \lambda_{1}^{6}}{720} - \frac{\lambda_{1}^{7}}{5040}\right) + \mathcal{O}\left(t^{8}\right)$$

In [16]:
partials = Matrix(m, m, lambda n, k: Subs(f(t).diff(t, n), [t], [lamda_indexed[1]]) if n==k else 0)
partials


Out[16]:
$$\left[\begin{matrix}\left. f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & \left. \frac{d}{d t} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & \left. \frac{d^{2}}{d t^{2}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & \left. \frac{d^{3}}{d t^{3}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & \left. \frac{d^{4}}{d t^{4}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & \left. \frac{d^{5}}{d t^{5}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & \left. \frac{d^{6}}{d t^{6}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & \left. \frac{d^{7}}{d t^{7}} f{\left (t \right )} \right|_{\substack{ t=\lambda_{1} }}\end{matrix}\right]$$

In [17]:
DE = (partials * M_expt).applyfunc(lambda i: i.doit())
DE


Out[17]:
$$\left[\begin{matrix}f{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{d}{d \lambda_{1}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d}{d \lambda_{1}} f{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{2}}{2} \frac{d^{2}}{d \lambda_{1}^{2}} f{\left (\lambda_{1} \right )} & - \frac{d^{2}}{d \lambda_{1}^{2}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{2}}{d \lambda_{1}^{2}} f{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{6} \frac{d^{3}}{d \lambda_{1}^{3}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \frac{d^{3}}{d \lambda_{1}^{3}} f{\left (\lambda_{1} \right )} & - \frac{d^{3}}{d \lambda_{1}^{3}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{3}}{d \lambda_{1}^{3}} f{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{4}}{24} \frac{d^{4}}{d \lambda_{1}^{4}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \frac{d^{4}}{d \lambda_{1}^{4}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \frac{d^{4}}{d \lambda_{1}^{4}} f{\left (\lambda_{1} \right )} & - \frac{d^{4}}{d \lambda_{1}^{4}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{4}}{d \lambda_{1}^{4}} f{\left (\lambda_{1} \right )} & 0 & 0 & 0\\- \frac{\lambda_{1}^{5}}{120} \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{4}}{24} \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} & - \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{5}}{d \lambda_{1}^{5}} f{\left (\lambda_{1} \right )} & 0 & 0\\\frac{\lambda_{1}^{6}}{720} \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{5}}{120} \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{4}}{24} \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & - \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{6}}{d \lambda_{1}^{6}} f{\left (\lambda_{1} \right )} & 0\\- \frac{\lambda_{1}^{7}}{5040} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{6}}{720} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{5}}{120} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{4}}{24} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} & - \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )} \lambda_{1} & \frac{d^{7}}{d \lambda_{1}^{7}} f{\left (\lambda_{1} \right )}\end{matrix}\right]$$

In [ ]:
production_matrix(DE).applyfunc(simplify) # takes long to evaluate

$f(z)=\frac{1}{z}$


In [18]:
DE_inv = DE.subs({f:Lambda(t, 1/t)}).applyfunc(lambda i: i.doit())
DE_inv


Out[18]:
$$\left[\begin{matrix}\frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{1}{\lambda_{1}^{2}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{2}{\lambda_{1}^{2}} & \frac{2}{\lambda_{1}^{3}} & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{3}{\lambda_{1}^{2}} & \frac{6}{\lambda_{1}^{3}} & - \frac{6}{\lambda_{1}^{4}} & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{4}{\lambda_{1}^{2}} & \frac{12}{\lambda_{1}^{3}} & - \frac{24}{\lambda_{1}^{4}} & \frac{24}{\lambda_{1}^{5}} & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{5}{\lambda_{1}^{2}} & \frac{20}{\lambda_{1}^{3}} & - \frac{60}{\lambda_{1}^{4}} & \frac{120}{\lambda_{1}^{5}} & - \frac{120}{\lambda_{1}^{6}} & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{6}{\lambda_{1}^{2}} & \frac{30}{\lambda_{1}^{3}} & - \frac{120}{\lambda_{1}^{4}} & \frac{360}{\lambda_{1}^{5}} & - \frac{720}{\lambda_{1}^{6}} & \frac{720}{\lambda_{1}^{7}} & 0\\\frac{1}{\lambda_{1}} & - \frac{7}{\lambda_{1}^{2}} & \frac{42}{\lambda_{1}^{3}} & - \frac{210}{\lambda_{1}^{4}} & \frac{840}{\lambda_{1}^{5}} & - \frac{2520}{\lambda_{1}^{6}} & \frac{5040}{\lambda_{1}^{7}} & - \frac{5040}{\lambda_{1}^{8}}\end{matrix}\right]$$

In [19]:
production_matrix(DE_inv)


Out[19]:
$$\left[\begin{matrix}1 & - \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0\\0 & 1 & - \frac{2}{\lambda_{1}} & 0 & 0 & 0 & 0\\0 & 0 & 1 & - \frac{3}{\lambda_{1}} & 0 & 0 & 0\\0 & 0 & 0 & 1 & - \frac{4}{\lambda_{1}} & 0 & 0\\0 & 0 & 0 & 0 & 1 & - \frac{5}{\lambda_{1}} & 0\\0 & 0 & 0 & 0 & 0 & 1 & - \frac{6}{\lambda_{1}}\\0 & 0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$$

In [22]:
Matrix(m, m, columns_symmetry(DE_inv))


Out[22]:
$$\left[\begin{matrix}\frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{1}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{2}{\lambda_{1}^{3}} & - \frac{2}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0\\- \frac{6}{\lambda_{1}^{4}} & \frac{6}{\lambda_{1}^{3}} & - \frac{3}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0\\\frac{24}{\lambda_{1}^{5}} & - \frac{24}{\lambda_{1}^{4}} & \frac{12}{\lambda_{1}^{3}} & - \frac{4}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0 & 0 & 0\\- \frac{120}{\lambda_{1}^{6}} & \frac{120}{\lambda_{1}^{5}} & - \frac{60}{\lambda_{1}^{4}} & \frac{20}{\lambda_{1}^{3}} & - \frac{5}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0 & 0\\\frac{720}{\lambda_{1}^{7}} & - \frac{720}{\lambda_{1}^{6}} & \frac{360}{\lambda_{1}^{5}} & - \frac{120}{\lambda_{1}^{4}} & \frac{30}{\lambda_{1}^{3}} & - \frac{6}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}} & 0\\- \frac{5040}{\lambda_{1}^{8}} & \frac{5040}{\lambda_{1}^{7}} & - \frac{2520}{\lambda_{1}^{6}} & \frac{840}{\lambda_{1}^{5}} & - \frac{210}{\lambda_{1}^{4}} & \frac{42}{\lambda_{1}^{3}} & - \frac{7}{\lambda_{1}^{2}} & \frac{1}{\lambda_{1}}\end{matrix}\right]$$

In [23]:
inspect(_)


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

In [24]:
DE_inv_RA = Matrix(m, m, 
       riordan_matrix_by_recurrence(m, 
                                    lambda n, k: {(n-1,k-1):-k/lamda_indexed[1], (n-1,k):1} if k else {(n-1,k):1},
                                    init={(0,0):1/lamda_indexed[1]}))
DE_inv_RA


Out[24]:
$$\left[\begin{matrix}\frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{1}{\lambda_{1}^{2}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{2}{\lambda_{1}^{2}} & \frac{2}{\lambda_{1}^{3}} & 0 & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{3}{\lambda_{1}^{2}} & \frac{6}{\lambda_{1}^{3}} & - \frac{6}{\lambda_{1}^{4}} & 0 & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{4}{\lambda_{1}^{2}} & \frac{12}{\lambda_{1}^{3}} & - \frac{24}{\lambda_{1}^{4}} & \frac{24}{\lambda_{1}^{5}} & 0 & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{5}{\lambda_{1}^{2}} & \frac{20}{\lambda_{1}^{3}} & - \frac{60}{\lambda_{1}^{4}} & \frac{120}{\lambda_{1}^{5}} & - \frac{120}{\lambda_{1}^{6}} & 0 & 0\\\frac{1}{\lambda_{1}} & - \frac{6}{\lambda_{1}^{2}} & \frac{30}{\lambda_{1}^{3}} & - \frac{120}{\lambda_{1}^{4}} & \frac{360}{\lambda_{1}^{5}} & - \frac{720}{\lambda_{1}^{6}} & \frac{720}{\lambda_{1}^{7}} & 0\\\frac{1}{\lambda_{1}} & - \frac{7}{\lambda_{1}^{2}} & \frac{42}{\lambda_{1}^{3}} & - \frac{210}{\lambda_{1}^{4}} & \frac{840}{\lambda_{1}^{5}} & - \frac{2520}{\lambda_{1}^{6}} & \frac{5040}{\lambda_{1}^{7}} & - \frac{5040}{\lambda_{1}^{8}}\end{matrix}\right]$$

In [25]:
assert DE_inv == DE_inv_RA

In [26]:
DEz = (DE_inv* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[26]:
$$\left[\begin{matrix}\frac{1}{\lambda_{1}}\\- \frac{1}{\lambda_{1}^{2}} \left(z - \lambda_{1}\right)\\\frac{1}{\lambda_{1}^{3}} \left(z - \lambda_{1}\right)^{2}\\- \frac{1}{\lambda_{1}^{4}} \left(z - \lambda_{1}\right)^{3}\\\frac{1}{\lambda_{1}^{5}} \left(z - \lambda_{1}\right)^{4}\\- \frac{1}{\lambda_{1}^{6}} \left(z - \lambda_{1}\right)^{5}\\\frac{1}{\lambda_{1}^{7}} \left(z - \lambda_{1}\right)^{6}\\- \frac{1}{\lambda_{1}^{8}} \left(z - \lambda_{1}\right)^{7}\end{matrix}\right]$$

In [27]:
g_v = ones(1, m) * DEz
g_inv_eq = Eq(g(z), g_v[0,0], evaluate=False)
g_inv_eq.subs(eigenvals)


Out[27]:
$$g{\left (z \right )} = - z - \left(z - 1\right)^{7} + \left(z - 1\right)^{6} - \left(z - 1\right)^{5} + \left(z - 1\right)^{4} - \left(z - 1\right)^{3} + \left(z - 1\right)^{2} + 2$$

In [28]:
g_Z_12 = Eq(g(z), Sum((-z)**(j), (j,0,m_sym-1)))
g_Z_12


Out[28]:
$$g{\left (z \right )} = \sum_{j=0}^{m - 1} \left(- z\right)^{j}$$

In [31]:
with lift_to_matrix_function(g_Z_12.subs({m_sym:m}).doit()) as g_Z_12_fn:
    P = Matrix(m, m, binomial)
    I = eye(m, m)
    Z_12 = define(Symbol(r'Z_{1,2}'), P - I)
    P_inv = g_Z_12_fn(Z_12)
P_inv


Out[31]:
$$g{\left (Z_{1,2} \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\1 & -2 & 1 & 0 & 0 & 0 & 0 & 0\\-1 & 3 & -3 & 1 & 0 & 0 & 0 & 0\\1 & -4 & 6 & -4 & 1 & 0 & 0 & 0\\-1 & 5 & -10 & 10 & -5 & 1 & 0 & 0\\1 & -6 & 15 & -20 & 15 & -6 & 1 & 0\\-1 & 7 & -21 & 35 & -35 & 21 & -7 & 1\end{matrix}\right]$$

In [34]:
assert P * P_inv.rhs == I

In [35]:
g_Z_12.subs({m_sym:oo}).doit()


Out[35]:
$$g{\left (z \right )} = \begin{cases} \frac{1}{z + 1} & \text{for}\: \left|{z}\right| < 1 \\\sum_{j=0}^{\infty} \left(- z\right)^{j} & \text{otherwise} \end{cases}$$

$f(z)=z^{r}$


In [36]:
DE_pow = DE.subs({f:Lambda(t, t**r)}).applyfunc(lambda i: i.doit().factor())
DE_pow


Out[36]:
$$\left[\begin{matrix}\lambda_{1}^{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- r \lambda_{1}^{r} & \frac{r \lambda_{1}^{r}}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{r \lambda_{1}^{r}}{2} \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}} \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{2}} \left(r - 1\right) & 0 & 0 & 0 & 0 & 0\\- \frac{r \lambda_{1}^{r}}{6} \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}} \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{2}} \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{3}} \left(r - 2\right) \left(r - 1\right) & 0 & 0 & 0 & 0\\\frac{r \lambda_{1}^{r}}{24} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{2}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{3}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{4}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0 & 0 & 0\\- \frac{r \lambda_{1}^{r}}{120} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{2}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{3}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{4}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{5}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0 & 0\\\frac{r \lambda_{1}^{r}}{720} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{120 \lambda_{1}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}^{2}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{3}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{4}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{5}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{6}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0\\- \frac{r \lambda_{1}^{r}}{5040} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{720 \lambda_{1}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{120 \lambda_{1}^{2}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}^{3}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{4}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{5}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{6}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{7}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right)\end{matrix}\right]$$

In [37]:
DE_pow_ff = Matrix(m, m, lambda n, k: ((-1)**(n-k)*ff(r, n, evaluate=False)*(lamda_indexed[1])**r/(ff(n-k, n-k, evaluate=False)*lamda_indexed[1]**k) if k<=n else S(0)).powsimp())
DE_pow_ff


Out[37]:
$$\left[\begin{matrix}\frac{{\left(r\right)}_{0} \lambda_{1}^{r}}{{\left(0\right)}_{0}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{{\left(r\right)}_{1} \lambda_{1}^{r}}{{\left(1\right)}_{1}} & \frac{{\left(r\right)}_{1}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 1} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{{\left(r\right)}_{2} \lambda_{1}^{r}}{{\left(2\right)}_{2}} & - \frac{{\left(r\right)}_{2}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 1} & \frac{{\left(r\right)}_{2}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 2} & 0 & 0 & 0 & 0 & 0\\- \frac{{\left(r\right)}_{3} \lambda_{1}^{r}}{{\left(3\right)}_{3}} & \frac{{\left(r\right)}_{3}}{{\left(2\right)}_{2}} \lambda_{1}^{r - 1} & - \frac{{\left(r\right)}_{3}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 2} & \frac{{\left(r\right)}_{3}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 3} & 0 & 0 & 0 & 0\\\frac{{\left(r\right)}_{4} \lambda_{1}^{r}}{{\left(4\right)}_{4}} & - \frac{{\left(r\right)}_{4}}{{\left(3\right)}_{3}} \lambda_{1}^{r - 1} & \frac{{\left(r\right)}_{4}}{{\left(2\right)}_{2}} \lambda_{1}^{r - 2} & - \frac{{\left(r\right)}_{4}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 3} & \frac{{\left(r\right)}_{4}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 4} & 0 & 0 & 0\\- \frac{{\left(r\right)}_{5} \lambda_{1}^{r}}{{\left(5\right)}_{5}} & \frac{{\left(r\right)}_{5}}{{\left(4\right)}_{4}} \lambda_{1}^{r - 1} & - \frac{{\left(r\right)}_{5}}{{\left(3\right)}_{3}} \lambda_{1}^{r - 2} & \frac{{\left(r\right)}_{5}}{{\left(2\right)}_{2}} \lambda_{1}^{r - 3} & - \frac{{\left(r\right)}_{5}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 4} & \frac{{\left(r\right)}_{5}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 5} & 0 & 0\\\frac{{\left(r\right)}_{6} \lambda_{1}^{r}}{{\left(6\right)}_{6}} & - \frac{{\left(r\right)}_{6}}{{\left(5\right)}_{5}} \lambda_{1}^{r - 1} & \frac{{\left(r\right)}_{6}}{{\left(4\right)}_{4}} \lambda_{1}^{r - 2} & - \frac{{\left(r\right)}_{6}}{{\left(3\right)}_{3}} \lambda_{1}^{r - 3} & \frac{{\left(r\right)}_{6}}{{\left(2\right)}_{2}} \lambda_{1}^{r - 4} & - \frac{{\left(r\right)}_{6}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 5} & \frac{{\left(r\right)}_{6}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 6} & 0\\- \frac{{\left(r\right)}_{7} \lambda_{1}^{r}}{{\left(7\right)}_{7}} & \frac{{\left(r\right)}_{7}}{{\left(6\right)}_{6}} \lambda_{1}^{r - 1} & - \frac{{\left(r\right)}_{7}}{{\left(5\right)}_{5}} \lambda_{1}^{r - 2} & \frac{{\left(r\right)}_{7}}{{\left(4\right)}_{4}} \lambda_{1}^{r - 3} & - \frac{{\left(r\right)}_{7}}{{\left(3\right)}_{3}} \lambda_{1}^{r - 4} & \frac{{\left(r\right)}_{7}}{{\left(2\right)}_{2}} \lambda_{1}^{r - 5} & - \frac{{\left(r\right)}_{7}}{{\left(1\right)}_{1}} \lambda_{1}^{r - 6} & \frac{{\left(r\right)}_{7}}{{\left(0\right)}_{0}} \lambda_{1}^{r - 7}\end{matrix}\right]$$

In [38]:
assert DE_pow.applyfunc(powsimp) == DE_pow_ff.doit()

In [42]:
ff(r, 7), factorial(7), ff(7,7)


Out[42]:
$$\left ( r \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right), \quad 5040, \quad 5040\right )$$

In [43]:
assert binomial(r,7).combsimp() == (ff(r, 7)/ff(7,7))

In [44]:
production_matrix(DE_pow)


Out[44]:
$$\left[\begin{matrix}- r & \frac{r}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}}{2} \left(r + 1\right) & 1 & \frac{1}{\lambda_{1}} \left(r - 1\right) & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{2}}{6} \left(r + 1\right) & 0 & 1 & \frac{1}{\lambda_{1}} \left(r - 2\right) & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{24} \left(r + 1\right) & 0 & 0 & 1 & \frac{1}{\lambda_{1}} \left(r - 3\right) & 0 & 0\\- \frac{\lambda_{1}^{4}}{120} \left(r + 1\right) & 0 & 0 & 0 & 1 & \frac{1}{\lambda_{1}} \left(r - 4\right) & 0\\- \frac{\lambda_{1}^{5}}{720} \left(r + 1\right) & 0 & 0 & 0 & 0 & 1 & \frac{1}{\lambda_{1}} \left(r - 5\right)\\- \frac{\lambda_{1}^{6}}{5040} \left(r + 1\right) & 0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$$

In [45]:
def rec(n, k):
    if k:
        return {(n-1, k-1):( r+1-k)/lamda_indexed[1], (n-1,k):1}
    else:
        return {(n-1, j): -((r+1)*lamda_indexed[1]**j/factorial(j+1) if j else r)  for j in range(n)}
DE_pow_rec = Matrix(m, m, riordan_matrix_by_recurrence(m, rec, init={(0,0):lamda_indexed[1]**r}))
DE_pow_rec = DE_pow_rec.applyfunc(factor)
DE_pow_rec


Out[45]:
$$\left[\begin{matrix}\lambda_{1}^{r} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- r \lambda_{1}^{r} & \frac{r \lambda_{1}^{r}}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{r \lambda_{1}^{r}}{2} \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}} \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{2}} \left(r - 1\right) & 0 & 0 & 0 & 0 & 0\\- \frac{r \lambda_{1}^{r}}{6} \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}} \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{2}} \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{3}} \left(r - 2\right) \left(r - 1\right) & 0 & 0 & 0 & 0\\\frac{r \lambda_{1}^{r}}{24} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{2}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{3}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{4}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0 & 0 & 0\\- \frac{r \lambda_{1}^{r}}{120} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{2}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{3}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{4}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{5}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0 & 0\\\frac{r \lambda_{1}^{r}}{720} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{120 \lambda_{1}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}^{2}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{3}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{4}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{5}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{6}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & 0\\- \frac{r \lambda_{1}^{r}}{5040} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{720 \lambda_{1}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{120 \lambda_{1}^{2}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{24 \lambda_{1}^{3}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{6 \lambda_{1}^{4}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{2 \lambda_{1}^{5}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & - \frac{r \lambda_{1}^{r}}{\lambda_{1}^{6}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) & \frac{r \lambda_{1}^{r}}{\lambda_{1}^{7}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right)\end{matrix}\right]$$

In [46]:
assert DE_pow == DE_pow_rec

In [47]:
DEz = (DE_pow* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[47]:
$$\left[\begin{matrix}\lambda_{1}^{r}\\\frac{r \lambda_{1}^{r}}{\lambda_{1}} \left(z - \lambda_{1}\right)\\\frac{r \left(z - \lambda_{1}\right)^{2}}{2 \lambda_{1}^{2}} \left(r - 1\right) \lambda_{1}^{r}\\\frac{r \left(z - \lambda_{1}\right)^{3}}{6 \lambda_{1}^{3}} \left(r - 2\right) \left(r - 1\right) \lambda_{1}^{r}\\\frac{r \left(z - \lambda_{1}\right)^{4}}{24 \lambda_{1}^{4}} \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) \lambda_{1}^{r}\\\frac{r \left(z - \lambda_{1}\right)^{5}}{120 \lambda_{1}^{5}} \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) \lambda_{1}^{r}\\\frac{r \left(z - \lambda_{1}\right)^{6}}{720 \lambda_{1}^{6}} \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) \lambda_{1}^{r}\\\frac{r \left(z - \lambda_{1}\right)^{7}}{5040 \lambda_{1}^{7}} \left(r - 6\right) \left(r - 5\right) \left(r - 4\right) \left(r - 3\right) \left(r - 2\right) \left(r - 1\right) \lambda_{1}^{r}\end{matrix}\right]$$

In [48]:
DEz_ff = Matrix(m,1,lambda n,_: (ff(r, n,evaluate=False)/(ff(n,n,evaluate=False)*lamda_indexed[1]**n) * lamda_indexed[1]**r * (z-lamda_indexed[1])**n).powsimp())
DEz_ff


Out[48]:
$$\left[\begin{matrix}\frac{{\left(r\right)}_{0} \lambda_{1}^{r}}{{\left(0\right)}_{0}}\\\frac{{\left(r\right)}_{1}}{{\left(1\right)}_{1}} \left(z - \lambda_{1}\right) \lambda_{1}^{r - 1}\\\frac{{\left(r\right)}_{2}}{{\left(2\right)}_{2}} \left(z - \lambda_{1}\right)^{2} \lambda_{1}^{r - 2}\\\frac{{\left(r\right)}_{3}}{{\left(3\right)}_{3}} \left(z - \lambda_{1}\right)^{3} \lambda_{1}^{r - 3}\\\frac{{\left(r\right)}_{4}}{{\left(4\right)}_{4}} \left(z - \lambda_{1}\right)^{4} \lambda_{1}^{r - 4}\\\frac{{\left(r\right)}_{5}}{{\left(5\right)}_{5}} \left(z - \lambda_{1}\right)^{5} \lambda_{1}^{r - 5}\\\frac{{\left(r\right)}_{6}}{{\left(6\right)}_{6}} \left(z - \lambda_{1}\right)^{6} \lambda_{1}^{r - 6}\\\frac{{\left(r\right)}_{7}}{{\left(7\right)}_{7}} \left(z - \lambda_{1}\right)^{7} \lambda_{1}^{r - 7}\end{matrix}\right]$$

In [49]:
DEz_binomial = Matrix(m,1,lambda n,_: binomial(r, n,evaluate=False)*(lamda_indexed[1]**(r-n))  * (z-lamda_indexed[1])**n)
DEz_binomial


Out[49]:
$$\left[\begin{matrix}{\binom{r}{0}} \lambda_{1}^{r}\\\left(z - \lambda_{1}\right) {\binom{r}{1}} \lambda_{1}^{r - 1}\\\left(z - \lambda_{1}\right)^{2} {\binom{r}{2}} \lambda_{1}^{r - 2}\\\left(z - \lambda_{1}\right)^{3} {\binom{r}{3}} \lambda_{1}^{r - 3}\\\left(z - \lambda_{1}\right)^{4} {\binom{r}{4}} \lambda_{1}^{r - 4}\\\left(z - \lambda_{1}\right)^{5} {\binom{r}{5}} \lambda_{1}^{r - 5}\\\left(z - \lambda_{1}\right)^{6} {\binom{r}{6}} \lambda_{1}^{r - 6}\\\left(z - \lambda_{1}\right)^{7} {\binom{r}{7}} \lambda_{1}^{r - 7}\end{matrix}\right]$$

In [50]:
assert DEz.applyfunc(lambda i: i.powsimp()) == DEz_ff.doit().applyfunc(lambda i: i.powsimp()) == DEz_binomial.applyfunc(lambda i: i.combsimp().powsimp())

In [51]:
g_v = ones(1, m) * DEz_binomial
g_v_eq = Eq(g(z), g_v[0,0].collect(z), evaluate=False)
g_v_eq.subs(eigenvals)


Out[51]:
$$g{\left (z \right )} = \left(z - 1\right)^{7} {\binom{r}{7}} + \left(z - 1\right)^{6} {\binom{r}{6}} + \left(z - 1\right)^{5} {\binom{r}{5}} + \left(z - 1\right)^{4} {\binom{r}{4}} + \left(z - 1\right)^{3} {\binom{r}{3}} + \left(z - 1\right)^{2} {\binom{r}{2}} + \left(z - 1\right) {\binom{r}{1}} + {\binom{r}{0}}$$

In [52]:
g_pow_eq = Eq(g(z), Sum(z**(j) * binomial(r,j), (j,0,m_sym-1)))
g_pow_eq


Out[52]:
$$g{\left (z \right )} = \sum_{j=0}^{m - 1} z^{j} {\binom{r}{j}}$$

In [54]:
with lift_to_matrix_function(g_pow_eq.subs({m_sym:m}).doit()) as g_pow_fn:
    P_star_r = g_pow_fn(Z_12)

P_star_r


Out[54]:
$$g{\left (Z_{1,2} \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\r & 1 & 0 & 0 & 0 & 0 & 0 & 0\\r^{2} & 2 r & 1 & 0 & 0 & 0 & 0 & 0\\r^{3} & 3 r^{2} & 3 r & 1 & 0 & 0 & 0 & 0\\r^{4} & 4 r^{3} & 6 r^{2} & 4 r & 1 & 0 & 0 & 0\\r^{5} & 5 r^{4} & 10 r^{3} & 10 r^{2} & 5 r & 1 & 0 & 0\\r^{6} & 6 r^{5} & 15 r^{4} & 20 r^{3} & 15 r^{2} & 6 r & 1 & 0\\r^{7} & 7 r^{6} & 21 r^{5} & 35 r^{4} & 35 r^{3} & 21 r^{2} & 7 r & 1\end{matrix}\right]$$

In [57]:
assert (P**r).applyfunc(simplify) == P_star_r.rhs

In [58]:
g_pow_eq.subs({m_sym:oo}).doit()


Out[58]:
$$g{\left (z \right )} = \begin{cases} \left(z + 1\right)^{r} & \text{for}\: \left(\left|{z}\right| \leq 1 \wedge - \Re{\left(r\right)} < 0\right) \vee \left(- \Re{\left(r\right)} \geq 1 \wedge \left|{z}\right| < 1\right) \vee \left(- \Re{\left(r\right)} \geq 0 \wedge \left|{z}\right| \leq 1 \wedge - \Re{\left(r\right)} < 1 \wedge - z \neq 1\right) \\\sum_{j=0}^{\infty} z^{j} {\binom{r}{j}} & \text{otherwise} \end{cases}$$

$f(z)=\sqrt{z}$


In [59]:
DE_sqrt = DE.subs({f:Lambda(t, sqrt(t))}).applyfunc(lambda i: i.doit().factor())
DE_sqrt


Out[59]:
$$\left[\begin{matrix}\sqrt{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{\sqrt{\lambda_{1}}}{2} & \frac{1}{2 \sqrt{\lambda_{1}}} & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{\sqrt{\lambda_{1}}}{8} & \frac{1}{4 \sqrt{\lambda_{1}}} & - \frac{1}{4 \lambda_{1}^{\frac{3}{2}}} & 0 & 0 & 0 & 0 & 0\\- \frac{\sqrt{\lambda_{1}}}{16} & \frac{3}{16 \sqrt{\lambda_{1}}} & - \frac{3}{8 \lambda_{1}^{\frac{3}{2}}} & \frac{3}{8 \lambda_{1}^{\frac{5}{2}}} & 0 & 0 & 0 & 0\\- \frac{5 \sqrt{\lambda_{1}}}{128} & \frac{5}{32 \sqrt{\lambda_{1}}} & - \frac{15}{32 \lambda_{1}^{\frac{3}{2}}} & \frac{15}{16 \lambda_{1}^{\frac{5}{2}}} & - \frac{15}{16 \lambda_{1}^{\frac{7}{2}}} & 0 & 0 & 0\\- \frac{7 \sqrt{\lambda_{1}}}{256} & \frac{35}{256 \sqrt{\lambda_{1}}} & - \frac{35}{64 \lambda_{1}^{\frac{3}{2}}} & \frac{105}{64 \lambda_{1}^{\frac{5}{2}}} & - \frac{105}{32 \lambda_{1}^{\frac{7}{2}}} & \frac{105}{32 \lambda_{1}^{\frac{9}{2}}} & 0 & 0\\- \frac{21 \sqrt{\lambda_{1}}}{1024} & \frac{63}{512 \sqrt{\lambda_{1}}} & - \frac{315}{512 \lambda_{1}^{\frac{3}{2}}} & \frac{315}{128 \lambda_{1}^{\frac{5}{2}}} & - \frac{945}{128 \lambda_{1}^{\frac{7}{2}}} & \frac{945}{64 \lambda_{1}^{\frac{9}{2}}} & - \frac{945}{64 \lambda_{1}^{\frac{11}{2}}} & 0\\- \frac{33 \sqrt{\lambda_{1}}}{2048} & \frac{231}{2048 \sqrt{\lambda_{1}}} & - \frac{693}{1024 \lambda_{1}^{\frac{3}{2}}} & \frac{3465}{1024 \lambda_{1}^{\frac{5}{2}}} & - \frac{3465}{256 \lambda_{1}^{\frac{7}{2}}} & \frac{10395}{256 \lambda_{1}^{\frac{9}{2}}} & - \frac{10395}{128 \lambda_{1}^{\frac{11}{2}}} & \frac{10395}{128 \lambda_{1}^{\frac{13}{2}}}\end{matrix}\right]$$

In [60]:
production_matrix(DE_sqrt)


Out[60]:
$$\left[\begin{matrix}- \frac{1}{2} & \frac{1}{2 \lambda_{1}} & 0 & 0 & 0 & 0 & 0\\- \frac{3 \lambda_{1}}{4} & 1 & - \frac{1}{2 \lambda_{1}} & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{2}}{4} & 0 & 1 & - \frac{3}{2 \lambda_{1}} & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{16} & 0 & 0 & 1 & - \frac{5}{2 \lambda_{1}} & 0 & 0\\- \frac{\lambda_{1}^{4}}{80} & 0 & 0 & 0 & 1 & - \frac{7}{2 \lambda_{1}} & 0\\- \frac{\lambda_{1}^{5}}{480} & 0 & 0 & 0 & 0 & 1 & - \frac{9}{2 \lambda_{1}}\\- \frac{\lambda_{1}^{6}}{3360} & 0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$$

In [61]:
DEz = (DE_sqrt* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[61]:
$$\left[\begin{matrix}\sqrt{\lambda_{1}}\\\frac{z - \lambda_{1}}{2 \sqrt{\lambda_{1}}}\\- \frac{\left(z - \lambda_{1}\right)^{2}}{8 \lambda_{1}^{\frac{3}{2}}}\\\frac{\left(z - \lambda_{1}\right)^{3}}{16 \lambda_{1}^{\frac{5}{2}}}\\- \frac{5 \left(z - \lambda_{1}\right)^{4}}{128 \lambda_{1}^{\frac{7}{2}}}\\\frac{7 \left(z - \lambda_{1}\right)^{5}}{256 \lambda_{1}^{\frac{9}{2}}}\\- \frac{21 \left(z - \lambda_{1}\right)^{6}}{1024 \lambda_{1}^{\frac{11}{2}}}\\\frac{33 \left(z - \lambda_{1}\right)^{7}}{2048 \lambda_{1}^{\frac{13}{2}}}\end{matrix}\right]$$

In [62]:
g_v = ones(1, m) * DEz
g_sqrt = Eq(g(z), g_v[0,0].collect(z), evaluate=False)
g_sqrt


Out[62]:
$$g{\left (z \right )} = \frac{33 \left(z - \lambda_{1}\right)^{7}}{2048 \lambda_{1}^{\frac{13}{2}}} - \frac{21 \left(z - \lambda_{1}\right)^{6}}{1024 \lambda_{1}^{\frac{11}{2}}} + \frac{7 \left(z - \lambda_{1}\right)^{5}}{256 \lambda_{1}^{\frac{9}{2}}} - \frac{5 \left(z - \lambda_{1}\right)^{4}}{128 \lambda_{1}^{\frac{7}{2}}} + \frac{\left(z - \lambda_{1}\right)^{3}}{16 \lambda_{1}^{\frac{5}{2}}} - \frac{\left(z - \lambda_{1}\right)^{2}}{8 \lambda_{1}^{\frac{3}{2}}} + \frac{z - \lambda_{1}}{2 \sqrt{\lambda_{1}}} + \sqrt{\lambda_{1}}$$

In [63]:
g_sqrt.subs(eigenvals)


Out[63]:
$$g{\left (z \right )} = \frac{z}{2} + \frac{33}{2048} \left(z - 1\right)^{7} - \frac{21}{1024} \left(z - 1\right)^{6} + \frac{7}{256} \left(z - 1\right)^{5} - \frac{5}{128} \left(z - 1\right)^{4} + \frac{1}{16} \left(z - 1\right)^{3} - \frac{1}{8} \left(z - 1\right)^{2} + \frac{1}{2}$$

In [64]:
sqrt(1+t).series(t, n=10)


Out[64]:
$$1 + \frac{t}{2} - \frac{t^{2}}{8} + \frac{t^{3}}{16} - \frac{5 t^{4}}{128} + \frac{7 t^{5}}{256} - \frac{21 t^{6}}{1024} + \frac{33 t^{7}}{2048} - \frac{429 t^{8}}{32768} + \frac{715 t^{9}}{65536} + \mathcal{O}\left(t^{10}\right)$$

according to A002596


In [65]:
g_sqrt_eq = Eq(g(z), Sum(z**(j) * binomial(1/S(2),j), (j,0,m_sym-1)))
g_sqrt_eq


Out[65]:
$$g{\left (z \right )} = \sum_{j=0}^{m - 1} z^{j} {\binom{\frac{1}{2}}{j}}$$

In [67]:
with lift_to_matrix_function(g_sqrt_eq.subs({m_sym:m}).doit()) as g_sqrt_fn:
    P_sqrt_r = g_sqrt_fn(Z_12)

P_sqrt_r


Out[67]:
$$g{\left (Z_{1,2} \right )} = \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{2} & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{1}{4} & 1 & 1 & 0 & 0 & 0 & 0 & 0\\\frac{1}{8} & \frac{3}{4} & \frac{3}{2} & 1 & 0 & 0 & 0 & 0\\\frac{1}{16} & \frac{1}{2} & \frac{3}{2} & 2 & 1 & 0 & 0 & 0\\\frac{1}{32} & \frac{5}{16} & \frac{5}{4} & \frac{5}{2} & \frac{5}{2} & 1 & 0 & 0\\\frac{1}{64} & \frac{3}{16} & \frac{15}{16} & \frac{5}{2} & \frac{15}{4} & 3 & 1 & 0\\\frac{1}{128} & \frac{7}{64} & \frac{21}{32} & \frac{35}{16} & \frac{35}{8} & \frac{21}{4} & \frac{7}{2} & 1\end{matrix}\right]$$

In [68]:
assert (P_sqrt_r.rhs**2).applyfunc(simplify) == P

In [69]:
g_sqrt_eq.subs({m_sym:oo}).doit()


Out[69]:
$$g{\left (z \right )} = \begin{cases} \sqrt{z + 1} & \text{for}\: \left|{z}\right| \leq 1 \\\sum_{j=0}^{\infty} z^{j} {\binom{\frac{1}{2}}{j}} & \text{otherwise} \end{cases}$$

$f(z)=e^{\alpha z}$


In [70]:
DE_expt = DE.subs({f:Lambda(t, exp(alpha*t))}).applyfunc(lambda i: i.doit().factor())
DE_expt


Out[70]:
$$\left[\begin{matrix}e^{\alpha \lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \alpha e^{\alpha \lambda_{1}} \lambda_{1} & \alpha e^{\alpha \lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{\alpha^{2} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{2} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{2} e^{\alpha \lambda_{1}} & 0 & 0 & 0 & 0 & 0\\- \frac{\alpha^{3} \lambda_{1}^{3}}{6} e^{\alpha \lambda_{1}} & \frac{\alpha^{3} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{3} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{3} e^{\alpha \lambda_{1}} & 0 & 0 & 0 & 0\\\frac{\alpha^{4} \lambda_{1}^{4}}{24} e^{\alpha \lambda_{1}} & - \frac{\alpha^{4} \lambda_{1}^{3}}{6} e^{\alpha \lambda_{1}} & \frac{\alpha^{4} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{4} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{4} e^{\alpha \lambda_{1}} & 0 & 0 & 0\\- \frac{\alpha^{5} \lambda_{1}^{5}}{120} e^{\alpha \lambda_{1}} & \frac{\alpha^{5} \lambda_{1}^{4}}{24} e^{\alpha \lambda_{1}} & - \frac{\alpha^{5} \lambda_{1}^{3}}{6} e^{\alpha \lambda_{1}} & \frac{\alpha^{5} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{5} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{5} e^{\alpha \lambda_{1}} & 0 & 0\\\frac{\alpha^{6} \lambda_{1}^{6}}{720} e^{\alpha \lambda_{1}} & - \frac{\alpha^{6} \lambda_{1}^{5}}{120} e^{\alpha \lambda_{1}} & \frac{\alpha^{6} \lambda_{1}^{4}}{24} e^{\alpha \lambda_{1}} & - \frac{\alpha^{6} \lambda_{1}^{3}}{6} e^{\alpha \lambda_{1}} & \frac{\alpha^{6} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{6} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{6} e^{\alpha \lambda_{1}} & 0\\- \frac{\alpha^{7} \lambda_{1}^{7}}{5040} e^{\alpha \lambda_{1}} & \frac{\alpha^{7} \lambda_{1}^{6}}{720} e^{\alpha \lambda_{1}} & - \frac{\alpha^{7} \lambda_{1}^{5}}{120} e^{\alpha \lambda_{1}} & \frac{\alpha^{7} \lambda_{1}^{4}}{24} e^{\alpha \lambda_{1}} & - \frac{\alpha^{7} \lambda_{1}^{3}}{6} e^{\alpha \lambda_{1}} & \frac{\alpha^{7} \lambda_{1}^{2}}{2} e^{\alpha \lambda_{1}} & - \alpha^{7} e^{\alpha \lambda_{1}} \lambda_{1} & \alpha^{7} e^{\alpha \lambda_{1}}\end{matrix}\right]$$

In [71]:
production_matrix(DE_expt)


Out[71]:
$$\left[\begin{matrix}- \alpha \lambda_{1} & \alpha & 0 & 0 & 0 & 0 & 0\\- \frac{\alpha \lambda_{1}^{2}}{2} & 0 & \alpha & 0 & 0 & 0 & 0\\- \frac{\alpha \lambda_{1}^{3}}{6} & 0 & 0 & \alpha & 0 & 0 & 0\\- \frac{\alpha \lambda_{1}^{4}}{24} & 0 & 0 & 0 & \alpha & 0 & 0\\- \frac{\alpha \lambda_{1}^{5}}{120} & 0 & 0 & 0 & 0 & \alpha & 0\\- \frac{\alpha \lambda_{1}^{6}}{720} & 0 & 0 & 0 & 0 & 0 & \alpha\\- \frac{\alpha \lambda_{1}^{7}}{5040} & 0 & 0 & 0 & 0 & 0 & 0\end{matrix}\right]$$

In [72]:
DEz = (DE_expt* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[72]:
$$\left[\begin{matrix}e^{\alpha \lambda_{1}}\\\alpha \left(z - \lambda_{1}\right) e^{\alpha \lambda_{1}}\\\frac{\alpha^{2}}{2} \left(z - \lambda_{1}\right)^{2} e^{\alpha \lambda_{1}}\\\frac{\alpha^{3}}{6} \left(z - \lambda_{1}\right)^{3} e^{\alpha \lambda_{1}}\\\frac{\alpha^{4}}{24} \left(z - \lambda_{1}\right)^{4} e^{\alpha \lambda_{1}}\\\frac{\alpha^{5}}{120} \left(z - \lambda_{1}\right)^{5} e^{\alpha \lambda_{1}}\\\frac{\alpha^{6}}{720} \left(z - \lambda_{1}\right)^{6} e^{\alpha \lambda_{1}}\\\frac{\alpha^{7}}{5040} \left(z - \lambda_{1}\right)^{7} e^{\alpha \lambda_{1}}\end{matrix}\right]$$

In [73]:
g_v = ones(1, m) * DEz
g_exp_v = Eq(g(z), g_v[0,0].collect(z), evaluate=False)
g_exp_v


Out[73]:
$$g{\left (z \right )} = \frac{\alpha^{7}}{5040} \left(z - \lambda_{1}\right)^{7} e^{\alpha \lambda_{1}} + \frac{\alpha^{6}}{720} \left(z - \lambda_{1}\right)^{6} e^{\alpha \lambda_{1}} + \frac{\alpha^{5}}{120} \left(z - \lambda_{1}\right)^{5} e^{\alpha \lambda_{1}} + \frac{\alpha^{4}}{24} \left(z - \lambda_{1}\right)^{4} e^{\alpha \lambda_{1}} + \frac{\alpha^{3}}{6} \left(z - \lambda_{1}\right)^{3} e^{\alpha \lambda_{1}} + \frac{\alpha^{2}}{2} \left(z - \lambda_{1}\right)^{2} e^{\alpha \lambda_{1}} + \alpha \left(z - \lambda_{1}\right) e^{\alpha \lambda_{1}} + e^{\alpha \lambda_{1}}$$

In [74]:
g_exp_v.subs(eigenvals)


Out[74]:
$$g{\left (z \right )} = \frac{\alpha^{7} e^{\alpha}}{5040} \left(z - 1\right)^{7} + \frac{\alpha^{6} e^{\alpha}}{720} \left(z - 1\right)^{6} + \frac{\alpha^{5} e^{\alpha}}{120} \left(z - 1\right)^{5} + \frac{\alpha^{4} e^{\alpha}}{24} \left(z - 1\right)^{4} + \frac{\alpha^{3} e^{\alpha}}{6} \left(z - 1\right)^{3} + \frac{\alpha^{2} e^{\alpha}}{2} \left(z - 1\right)^{2} + \alpha \left(z - 1\right) e^{\alpha} + e^{\alpha}$$

In [75]:
g_exp_eq = Eq(g(z), exp(alpha)*Sum(alpha**j * z**(j) / factorial(j), (j,0,m_sym-1)))
g_exp_eq


Out[75]:
$$g{\left (z \right )} = e^{\alpha} \sum_{j=0}^{m - 1} \frac{\alpha^{j} z^{j}}{j!}$$

In [78]:
with lift_to_matrix_function(g_exp_eq.subs({m_sym:m}).doit()) as g_exp_fn:
    P_exp_r = g_exp_fn(Z_12)

P_exp_r.rhs.applyfunc(powsimp)


Out[78]:
$$\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 + 1\right) e^{\alpha} & 2 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0 & 0\\\alpha \left(\alpha^{2} + 3 \alpha + 1\right) e^{\alpha} & 3 \alpha \left(\alpha + 1\right) e^{\alpha} & 3 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0 & 0\\\alpha \left(\alpha^{3} + 6 \alpha^{2} + 7 \alpha + 1\right) e^{\alpha} & 4 \alpha \left(\alpha^{2} + 3 \alpha + 1\right) e^{\alpha} & 6 \alpha \left(\alpha + 1\right) e^{\alpha} & 4 \alpha e^{\alpha} & e^{\alpha} & 0 & 0 & 0\\\alpha \left(\alpha^{4} + 10 \alpha^{3} + 25 \alpha^{2} + 15 \alpha + 1\right) e^{\alpha} & 5 \alpha \left(\alpha^{3} + 6 \alpha^{2} + 7 \alpha + 1\right) e^{\alpha} & 10 \alpha \left(\alpha^{2} + 3 \alpha + 1\right) e^{\alpha} & 10 \alpha \left(\alpha + 1\right) e^{\alpha} & 5 \alpha e^{\alpha} & e^{\alpha} & 0 & 0\\\alpha \left(\alpha^{5} + 15 \alpha^{4} + 65 \alpha^{3} + 90 \alpha^{2} + 31 \alpha + 1\right) e^{\alpha} & 6 \alpha \left(\alpha^{4} + 10 \alpha^{3} + 25 \alpha^{2} + 15 \alpha + 1\right) e^{\alpha} & 15 \alpha \left(\alpha^{3} + 6 \alpha^{2} + 7 \alpha + 1\right) e^{\alpha} & 20 \alpha \left(\alpha^{2} + 3 \alpha + 1\right) e^{\alpha} & 15 \alpha \left(\alpha + 1\right) e^{\alpha} & 6 \alpha e^{\alpha} & e^{\alpha} & 0\\\alpha \left(\alpha^{6} + 21 \alpha^{5} + 140 \alpha^{4} + 350 \alpha^{3} + 301 \alpha^{2} + 63 \alpha + 1\right) e^{\alpha} & 7 \alpha \left(\alpha^{5} + 15 \alpha^{4} + 65 \alpha^{3} + 90 \alpha^{2} + 31 \alpha + 1\right) e^{\alpha} & 21 \alpha \left(\alpha^{4} + 10 \alpha^{3} + 25 \alpha^{2} + 15 \alpha + 1\right) e^{\alpha} & 35 \alpha \left(\alpha^{3} + 6 \alpha^{2} + 7 \alpha + 1\right) e^{\alpha} & 35 \alpha \left(\alpha^{2} + 3 \alpha + 1\right) e^{\alpha} & 21 \alpha \left(\alpha + 1\right) e^{\alpha} & 7 \alpha e^{\alpha} & e^{\alpha}\end{matrix}\right]$$

In [82]:
g_exp_eq.subs({m_sym:oo}).doit()#.rhs.powsimp()


Out[82]:
$$g{\left (z \right )} = e^{\alpha} e^{\alpha z}$$

$f(z)=\log{z}$


In [83]:
DE_log = DE.subs({f:Lambda(t, log(t))}).applyfunc(lambda i: i.doit().factor())
DE_log


Out[83]:
$$\left[\begin{matrix}\log{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{1}{2} & \frac{1}{\lambda_{1}} & - \frac{1}{\lambda_{1}^{2}} & 0 & 0 & 0 & 0 & 0\\- \frac{1}{3} & \frac{1}{\lambda_{1}} & - \frac{2}{\lambda_{1}^{2}} & \frac{2}{\lambda_{1}^{3}} & 0 & 0 & 0 & 0\\- \frac{1}{4} & \frac{1}{\lambda_{1}} & - \frac{3}{\lambda_{1}^{2}} & \frac{6}{\lambda_{1}^{3}} & - \frac{6}{\lambda_{1}^{4}} & 0 & 0 & 0\\- \frac{1}{5} & \frac{1}{\lambda_{1}} & - \frac{4}{\lambda_{1}^{2}} & \frac{12}{\lambda_{1}^{3}} & - \frac{24}{\lambda_{1}^{4}} & \frac{24}{\lambda_{1}^{5}} & 0 & 0\\- \frac{1}{6} & \frac{1}{\lambda_{1}} & - \frac{5}{\lambda_{1}^{2}} & \frac{20}{\lambda_{1}^{3}} & - \frac{60}{\lambda_{1}^{4}} & \frac{120}{\lambda_{1}^{5}} & - \frac{120}{\lambda_{1}^{6}} & 0\\- \frac{1}{7} & \frac{1}{\lambda_{1}} & - \frac{6}{\lambda_{1}^{2}} & \frac{30}{\lambda_{1}^{3}} & - \frac{120}{\lambda_{1}^{4}} & \frac{360}{\lambda_{1}^{5}} & - \frac{720}{\lambda_{1}^{6}} & \frac{720}{\lambda_{1}^{7}}\end{matrix}\right]$$

In [84]:
production_matrix(DE_log)


Out[84]:
$$\left[\begin{matrix}- \frac{1}{\log{\left (\lambda_{1} \right )}} & \frac{1}{\log{\left (\lambda_{1} \right )} \lambda_{1}} & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}}{2} - \frac{\lambda_{1}}{\log{\left (\lambda_{1} \right )}} & 1 + \frac{1}{\log{\left (\lambda_{1} \right )}} & - \frac{1}{\lambda_{1}} & 0 & 0 & 0 & 0\\- \frac{\left(\log{\left (\lambda_{1} \right )} + 3\right) \lambda_{1}^{2}}{6 \log{\left (\lambda_{1} \right )}} & \frac{\lambda_{1}}{2 \log{\left (\lambda_{1} \right )}} & 1 & - \frac{2}{\lambda_{1}} & 0 & 0 & 0\\- \frac{\left(\log{\left (\lambda_{1} \right )} + 4\right) \lambda_{1}^{3}}{24 \log{\left (\lambda_{1} \right )}} & \frac{\lambda_{1}^{2}}{6 \log{\left (\lambda_{1} \right )}} & 0 & 1 & - \frac{3}{\lambda_{1}} & 0 & 0\\- \frac{\left(\log{\left (\lambda_{1} \right )} + 5\right) \lambda_{1}^{4}}{120 \log{\left (\lambda_{1} \right )}} & \frac{\lambda_{1}^{3}}{24 \log{\left (\lambda_{1} \right )}} & 0 & 0 & 1 & - \frac{4}{\lambda_{1}} & 0\\- \frac{\left(\log{\left (\lambda_{1} \right )} + 6\right) \lambda_{1}^{5}}{720 \log{\left (\lambda_{1} \right )}} & \frac{\lambda_{1}^{4}}{120 \log{\left (\lambda_{1} \right )}} & 0 & 0 & 0 & 1 & - \frac{5}{\lambda_{1}}\\- \frac{\left(\log{\left (\lambda_{1} \right )} + 7\right) \lambda_{1}^{6}}{5040 \log{\left (\lambda_{1} \right )}} & \frac{\lambda_{1}^{5}}{720 \log{\left (\lambda_{1} \right )}} & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$$

In [85]:
DEz = (DE_log* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[85]:
$$\left[\begin{matrix}\log{\left (\lambda_{1} \right )}\\\frac{1}{\lambda_{1}} \left(z - \lambda_{1}\right)\\- \frac{\left(z - \lambda_{1}\right)^{2}}{2 \lambda_{1}^{2}}\\\frac{\left(z - \lambda_{1}\right)^{3}}{3 \lambda_{1}^{3}}\\- \frac{\left(z - \lambda_{1}\right)^{4}}{4 \lambda_{1}^{4}}\\\frac{\left(z - \lambda_{1}\right)^{5}}{5 \lambda_{1}^{5}}\\- \frac{\left(z - \lambda_{1}\right)^{6}}{6 \lambda_{1}^{6}}\\\frac{\left(z - \lambda_{1}\right)^{7}}{7 \lambda_{1}^{7}}\end{matrix}\right]$$

In [86]:
g_v = ones(1, m) * DEz
g_log_v = Eq(g(z), g_v[0,0].collect(z), evaluate=False)
g_log_v


Out[86]:
$$g{\left (z \right )} = \frac{\left(z - \lambda_{1}\right)^{7}}{7 \lambda_{1}^{7}} - \frac{\left(z - \lambda_{1}\right)^{6}}{6 \lambda_{1}^{6}} + \frac{\left(z - \lambda_{1}\right)^{5}}{5 \lambda_{1}^{5}} - \frac{\left(z - \lambda_{1}\right)^{4}}{4 \lambda_{1}^{4}} + \frac{\left(z - \lambda_{1}\right)^{3}}{3 \lambda_{1}^{3}} - \frac{\left(z - \lambda_{1}\right)^{2}}{2 \lambda_{1}^{2}} + \frac{1}{\lambda_{1}} \left(z - \lambda_{1}\right) + \log{\left (\lambda_{1} \right )}$$

In [87]:
g_log_v.subs(eigenvals)


Out[87]:
$$g{\left (z \right )} = z + \frac{1}{7} \left(z - 1\right)^{7} - \frac{1}{6} \left(z - 1\right)^{6} + \frac{1}{5} \left(z - 1\right)^{5} - \frac{1}{4} \left(z - 1\right)^{4} + \frac{1}{3} \left(z - 1\right)^{3} - \frac{1}{2} \left(z - 1\right)^{2} - 1$$

In [88]:
g_log_eq = Eq(g(z), Sum((-1)**(j+1) * z**(j) / j, (j,1,m_sym-1)))
g_log_eq


Out[88]:
$$g{\left (z \right )} = \sum_{j=1}^{m - 1} \frac{z^{j}}{j} \left(-1\right)^{j + 1}$$

In [91]:
with lift_to_matrix_function(g_log_eq.subs({m_sym:m}).doit()) as g_log_fn:
    P_log_r = g_log_fn(Z_12)

P_log_r.rhs.applyfunc(powsimp)


Out[91]:
$$\left[\begin{matrix}0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 2 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 3 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 4 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 5 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 6 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 7 & 0\end{matrix}\right]$$

In [92]:
g_log_eq.subs({m_sym:oo}).doit()


Out[92]:
$$g{\left (z \right )} = - \begin{cases} - \log{\left (z + 1 \right )} & \text{for}\: \left|{z}\right| \leq 1 \wedge - z \neq 1 \\\sum_{j=1}^{\infty} \frac{\left(-1\right)^{j} z^{j}}{j} & \text{otherwise} \end{cases}$$

$f(z)=\sin{z}$


In [93]:
DE_sin = DE.subs({f:Lambda(t, sin(t))}).applyfunc(lambda i: i.doit().factor())
DE_sin


Out[93]:
$$\left[\begin{matrix}\sin{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\- \cos{\left (\lambda_{1} \right )} \lambda_{1} & \cos{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & \sin{\left (\lambda_{1} \right )} \lambda_{1} & - \sin{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{3}}{6} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & \cos{\left (\lambda_{1} \right )} \lambda_{1} & - \cos{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{4}}{24} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & - \sin{\left (\lambda_{1} \right )} \lambda_{1} & \sin{\left (\lambda_{1} \right )} & 0 & 0 & 0\\- \frac{\lambda_{1}^{5}}{120} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{4}}{24} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & - \cos{\left (\lambda_{1} \right )} \lambda_{1} & \cos{\left (\lambda_{1} \right )} & 0 & 0\\- \frac{\lambda_{1}^{6}}{720} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{5}}{120} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{4}}{24} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{3}}{6} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & \sin{\left (\lambda_{1} \right )} \lambda_{1} & - \sin{\left (\lambda_{1} \right )} & 0\\\frac{\lambda_{1}^{7}}{5040} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{6}}{720} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{5}}{120} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{4}}{24} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{3}}{6} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & \cos{\left (\lambda_{1} \right )} \lambda_{1} & - \cos{\left (\lambda_{1} \right )}\end{matrix}\right]$$

In [ ]:
production_matrix(DE_sin) # takes long to evaluate

In [95]:
DEz = (DE_sin* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[95]:
$$\left[\begin{matrix}\sin{\left (\lambda_{1} \right )}\\\left(z - \lambda_{1}\right) \cos{\left (\lambda_{1} \right )}\\- \frac{1}{2} \left(z - \lambda_{1}\right)^{2} \sin{\left (\lambda_{1} \right )}\\- \frac{1}{6} \left(z - \lambda_{1}\right)^{3} \cos{\left (\lambda_{1} \right )}\\\frac{1}{24} \left(z - \lambda_{1}\right)^{4} \sin{\left (\lambda_{1} \right )}\\\frac{1}{120} \left(z - \lambda_{1}\right)^{5} \cos{\left (\lambda_{1} \right )}\\- \frac{1}{720} \left(z - \lambda_{1}\right)^{6} \sin{\left (\lambda_{1} \right )}\\- \frac{1}{5040} \left(z - \lambda_{1}\right)^{7} \cos{\left (\lambda_{1} \right )}\end{matrix}\right]$$

In [96]:
g_v = ones(1, m) * DEz
g_sin = Eq(g(z), g_v[0,0].collect(z), evaluate=False)
g_sin.subs(eigenvals)


Out[96]:
$$g{\left (z \right )} = - \frac{1}{5040} \left(z - 1\right)^{7} \cos{\left (1 \right )} - \frac{1}{720} \left(z - 1\right)^{6} \sin{\left (1 \right )} + \frac{1}{120} \left(z - 1\right)^{5} \cos{\left (1 \right )} + \frac{1}{24} \left(z - 1\right)^{4} \sin{\left (1 \right )} - \frac{1}{6} \left(z - 1\right)^{3} \cos{\left (1 \right )} - \frac{1}{2} \left(z - 1\right)^{2} \sin{\left (1 \right )} + \left(z - 1\right) \cos{\left (1 \right )} + \sin{\left (1 \right )}$$

In [100]:
with lift_to_matrix_function(g_sin) as _g_sin:
    P_sin = _g_sin(Z_12).rhs.subs(eigenvals).applyfunc(trigsimp)

P_sin


Out[100]:
$$\left[\begin{matrix}- \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\frac{389}{720} \cos{\left (1 \right )} + \frac{101}{120} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0 & 0\\\frac{3}{10} \sin{\left (1 \right )} + \frac{199}{144} \cos{\left (1 \right )} & \frac{389}{360} \cos{\left (1 \right )} + \frac{101}{60} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0 & 0 & 0 & 0\\- \frac{97}{60} \sin{\left (1 \right )} + \frac{1817}{720} \cos{\left (1 \right )} & \frac{9}{10} \sin{\left (1 \right )} + \frac{199}{48} \cos{\left (1 \right )} & \frac{389}{240} \cos{\left (1 \right )} + \frac{101}{40} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0 & 0 & 0\\- \frac{149}{20} \sin{\left (1 \right )} + \frac{1691}{720} \cos{\left (1 \right )} & - \frac{97}{15} \sin{\left (1 \right )} + \frac{1817}{180} \cos{\left (1 \right )} & \frac{9}{5} \sin{\left (1 \right )} + \frac{199}{24} \cos{\left (1 \right )} & \frac{389}{180} \cos{\left (1 \right )} + \frac{101}{30} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0 & 0\\- \frac{1327}{60} \sin{\left (1 \right )} - \frac{5911}{720} \cos{\left (1 \right )} & - \frac{149}{4} \sin{\left (1 \right )} + \frac{1691}{144} \cos{\left (1 \right )} & - \frac{97}{6} \sin{\left (1 \right )} + \frac{1817}{72} \cos{\left (1 \right )} & 3 \sin{\left (1 \right )} + \frac{995}{72} \cos{\left (1 \right )} & \frac{389}{144} \cos{\left (1 \right )} + \frac{101}{24} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0 & 0\\- \frac{889}{20} \sin{\left (1 \right )} - \frac{9761}{144} \cos{\left (1 \right )} & - \frac{1327}{10} \sin{\left (1 \right )} - \frac{5911}{120} \cos{\left (1 \right )} & - \frac{447}{4} \sin{\left (1 \right )} + \frac{1691}{48} \cos{\left (1 \right )} & - \frac{97}{3} \sin{\left (1 \right )} + \frac{1817}{36} \cos{\left (1 \right )} & \frac{9}{2} \sin{\left (1 \right )} + \frac{995}{48} \cos{\left (1 \right )} & \frac{389}{120} \cos{\left (1 \right )} + \frac{101}{20} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )} & 0\\- \frac{224023}{720} \cos{\left (1 \right )} + \frac{593}{60} \sin{\left (1 \right )} & - \frac{6223}{20} \sin{\left (1 \right )} - \frac{68327}{144} \cos{\left (1 \right )} & - \frac{9289}{20} \sin{\left (1 \right )} - \frac{41377}{240} \cos{\left (1 \right )} & - \frac{1043}{4} \sin{\left (1 \right )} + \frac{11837}{144} \cos{\left (1 \right )} & - \frac{679}{12} \sin{\left (1 \right )} + \frac{12719}{144} \cos{\left (1 \right )} & \frac{63}{10} \sin{\left (1 \right )} + \frac{1393}{48} \cos{\left (1 \right )} & \frac{2723}{720} \cos{\left (1 \right )} + \frac{707}{120} \sin{\left (1 \right )} & - \frac{4241}{5040} \cos{\left (1 \right )} + \frac{389}{720} \sin{\left (1 \right )}\end{matrix}\right]$$

In [101]:
sin(z).series(z, 1,n=10)


Out[101]:
$$\sin{\left (1 \right )} + \left(z - 1\right) \cos{\left (1 \right )} - \frac{1}{2} \left(z - 1\right)^{2} \sin{\left (1 \right )} - \frac{1}{6} \left(z - 1\right)^{3} \cos{\left (1 \right )} + \frac{1}{24} \left(z - 1\right)^{4} \sin{\left (1 \right )} + \frac{1}{120} \left(z - 1\right)^{5} \cos{\left (1 \right )} - \frac{1}{720} \left(z - 1\right)^{6} \sin{\left (1 \right )} - \frac{1}{5040} \left(z - 1\right)^{7} \cos{\left (1 \right )} + \frac{1}{40320} \left(z - 1\right)^{8} \sin{\left (1 \right )} + \frac{1}{362880} \left(z - 1\right)^{9} \cos{\left (1 \right )} + \mathcal{O}\left(\left(z - 1\right)^{10}; z\rightarrow 1\right)$$

$f(z)=\cos{z}$


In [102]:
DE_cos = DE.subs({f:Lambda(t, cos(t))}).applyfunc(lambda i: i.doit().factor())
DE_cos


Out[102]:
$$\left[\begin{matrix}\cos{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\sin{\left (\lambda_{1} \right )} \lambda_{1} & - \sin{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & \cos{\left (\lambda_{1} \right )} \lambda_{1} & - \cos{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0 & 0\\- \frac{\lambda_{1}^{3}}{6} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & - \sin{\left (\lambda_{1} \right )} \lambda_{1} & \sin{\left (\lambda_{1} \right )} & 0 & 0 & 0 & 0\\\frac{\lambda_{1}^{4}}{24} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & - \cos{\left (\lambda_{1} \right )} \lambda_{1} & \cos{\left (\lambda_{1} \right )} & 0 & 0 & 0\\\frac{\lambda_{1}^{5}}{120} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{4}}{24} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{3}}{6} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & \sin{\left (\lambda_{1} \right )} \lambda_{1} & - \sin{\left (\lambda_{1} \right )} & 0 & 0\\- \frac{\lambda_{1}^{6}}{720} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{5}}{120} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{4}}{24} \cos{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{3}}{6} \cos{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{2}}{2} \cos{\left (\lambda_{1} \right )} & \cos{\left (\lambda_{1} \right )} \lambda_{1} & - \cos{\left (\lambda_{1} \right )} & 0\\- \frac{\lambda_{1}^{7}}{5040} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{6}}{720} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{5}}{120} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{4}}{24} \sin{\left (\lambda_{1} \right )} & - \frac{\lambda_{1}^{3}}{6} \sin{\left (\lambda_{1} \right )} & \frac{\lambda_{1}^{2}}{2} \sin{\left (\lambda_{1} \right )} & - \sin{\left (\lambda_{1} \right )} \lambda_{1} & \sin{\left (\lambda_{1} \right )}\end{matrix}\right]$$

In [ ]:
production_matrix(DE_cos) # takes long to evaluate

In [104]:
DEz = (DE_cos* z_expt).applyfunc(lambda i: i.doit().factor())
DEz


Out[104]:
$$\left[\begin{matrix}\cos{\left (\lambda_{1} \right )}\\- \left(z - \lambda_{1}\right) \sin{\left (\lambda_{1} \right )}\\- \frac{1}{2} \left(z - \lambda_{1}\right)^{2} \cos{\left (\lambda_{1} \right )}\\\frac{1}{6} \left(z - \lambda_{1}\right)^{3} \sin{\left (\lambda_{1} \right )}\\\frac{1}{24} \left(z - \lambda_{1}\right)^{4} \cos{\left (\lambda_{1} \right )}\\- \frac{1}{120} \left(z - \lambda_{1}\right)^{5} \sin{\left (\lambda_{1} \right )}\\- \frac{1}{720} \left(z - \lambda_{1}\right)^{6} \cos{\left (\lambda_{1} \right )}\\\frac{1}{5040} \left(z - \lambda_{1}\right)^{7} \sin{\left (\lambda_{1} \right )}\end{matrix}\right]$$

In [105]:
g_v = ones(1, m) * DEz
Eq(g(z), g_v[0,0].collect(z), evaluate=False)


Out[105]:
$$g{\left (z \right )} = \frac{1}{5040} \left(z - \lambda_{1}\right)^{7} \sin{\left (\lambda_{1} \right )} - \frac{1}{720} \left(z - \lambda_{1}\right)^{6} \cos{\left (\lambda_{1} \right )} - \frac{1}{120} \left(z - \lambda_{1}\right)^{5} \sin{\left (\lambda_{1} \right )} + \frac{1}{24} \left(z - \lambda_{1}\right)^{4} \cos{\left (\lambda_{1} \right )} + \frac{1}{6} \left(z - \lambda_{1}\right)^{3} \sin{\left (\lambda_{1} \right )} - \frac{1}{2} \left(z - \lambda_{1}\right)^{2} \cos{\left (\lambda_{1} \right )} - \left(z - \lambda_{1}\right) \sin{\left (\lambda_{1} \right )} + \cos{\left (\lambda_{1} \right )}$$

In [106]:
cos(z).series(z, 1,n=10)


Out[106]:
$$\cos{\left (1 \right )} - \left(z - 1\right) \sin{\left (1 \right )} - \frac{1}{2} \left(z - 1\right)^{2} \cos{\left (1 \right )} + \frac{1}{6} \left(z - 1\right)^{3} \sin{\left (1 \right )} + \frac{1}{24} \left(z - 1\right)^{4} \cos{\left (1 \right )} - \frac{1}{120} \left(z - 1\right)^{5} \sin{\left (1 \right )} - \frac{1}{720} \left(z - 1\right)^{6} \cos{\left (1 \right )} + \frac{1}{5040} \left(z - 1\right)^{7} \sin{\left (1 \right )} + \frac{1}{40320} \left(z - 1\right)^{8} \cos{\left (1 \right )} - \frac{1}{362880} \left(z - 1\right)^{9} \sin{\left (1 \right )} + \mathcal{O}\left(\left(z - 1\right)^{10}; z\rightarrow 1\right)$$