One goal of this section is to introduce you to the joys of numerical linear algebra with Sage.
Suppose \(A\) is the adjacency matrix of \(X\). We define \(H(t)=H_X(t)\) by
To use this formula we need an orthogonal basis for each eigenspace. The difficulty if that if we work in floating point, then we have to decide which eigenvalues are actually equal before we determine an eigenspace.
We are going to use scipy and numpy. It seems that numpy is basically an array package, which provides such things as \(k\)-dimensional arrays. (Computer scientists seem to think these are useful, I have no idea why.) Scipy builds on numpy, providing access to standard linear algebra routines (eigenthings, svd, etc.) There is on-line documentation for scipy and numpy, but it is not very good. (For example it illustrates how to solve linear equations by inverting the matrix of coefficients.) The syntax for scipy and numpy is not consistent with Sage, or with python.
Anyway, here is the opening incantation:
We will go through some simple computations, so you can get a feel for things.
we get the eigenvalues of \(AP\) (in \(\la\)) and the eigenvectors (in \(v\)). The routine linalg.eigh takes a Hermitian matrix and returns real eigenvalues. Eigenvectors corresponding to distinct eigenvalues are orthogonal. Note that the eigenvectors are returned by linalg.eigh as numpy arrays, and there is a argument for wrapping it in a routine that immediately transforms them into Sage vectors.
We intend to make use of the fact that if the vectors \(\seq z1m\) are an orthogonal basis for a subspace then the matrix representing projection onto the subspace is
Given this it is straightforward to write the code that takes this dictionary and returns a list of pairs consisting of an eigenvalue and its associated projection.