/usr/share/axiom-20170501/src/algebra/REP.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | )abbrev package REP RadicalEigenPackage
++ Author: P.Gianni
++ Date Created: Summer 1987
++ Date Last Updated: October 1992
++ Description:
++ Package for the computation of eigenvalues and eigenvectors.
++ This package works for matrices with coefficients which are
++ rational functions over the integers.
++ (see \spadtype{Fraction Polynomial Integer}).
++ The eigenvalues and eigenvectors are expressed in terms of radicals.
RadicalEigenPackage() : SIG == CODE where
R ==> Integer
P ==> Polynomial R
F ==> Fraction P
RE ==> Expression R
SE ==> Symbol()
M ==> Matrix(F)
MRE ==> Matrix(RE)
ST ==> SuchThat(SE,P)
NNI ==> NonNegativeInteger
EigenForm ==> Record(eigval:Union(F,ST),eigmult:NNI,eigvec:List(M))
RadicalForm ==> Record(radval:RE,radmult:Integer,radvect:List(MRE))
SIG ==> with
radicalEigenvectors : M -> List(RadicalForm)
++ radicalEigenvectors(m) computes
++ the eigenvalues and the corresponding eigenvectors of the
++ matrix m;
++ when possible, values are expressed in terms of radicals.
radicalEigenvector : (RE,M) -> List(MRE)
++ radicalEigenvector(c,m) computes the eigenvector(s) of the
++ matrix m corresponding to the eigenvalue c;
++ when possible, values are
++ expressed in terms of radicals.
radicalEigenvalues : M -> List RE
++ radicalEigenvalues(m) computes the eigenvalues of the matrix m;
++ when possible, the eigenvalues are expressed in terms of radicals.
eigenMatrix : M -> Union(MRE,"failed")
++ eigenMatrix(m) returns the matrix b
++ such that \spad{b*m*(inverse b)} is diagonal,
++ or "failed" if no such b exists.
normalise : MRE -> MRE
++ normalise(v) returns the column
++ vector v
++ divided by its euclidean norm;
++ when possible, the vector v is expressed in terms of radicals.
gramschmidt : List(MRE) -> List(MRE)
++ gramschmidt(lv) converts the list of column vectors lv into
++ a set of orthogonal column vectors
++ of euclidean length 1 using the Gram-Schmidt algorithm.
orthonormalBasis : M -> List(MRE)
++ orthonormalBasis(m) returns the orthogonal matrix b such that
++ \spad{b*m*(inverse b)} is diagonal.
++ Error: if m is not a symmetric matrix.
CODE ==> add
PI ==> PositiveInteger
RSP := RadicalSolvePackage R
import EigenPackage R
---- Local Functions ----
evalvect : (M,RE,SE) -> MRE
innerprod : (MRE,MRE) -> RE
---- eval a vector of F in a radical expression ----
evalvect(vect:M,alg:RE,x:SE) : MRE ==
n:=nrows vect
xx:=kernel(x)$Kernel(RE)
w:MRE:=zero(n,1)$MRE
for i in 1..n repeat
v:=eval(vect(i,1) :: RE,xx,alg)
setelt(w,i,1,v)
w
---- inner product ----
innerprod(v1:MRE,v2:MRE): RE == (((transpose v1)* v2)::MRE)(1,1)
---- normalization of a vector ----
normalise(v:MRE) : MRE ==
normv:RE := sqrt(innerprod(v,v))
normv = 0$RE => v
(1/normv)*v
---- Eigenvalues of the matrix A ----
radicalEigenvalues(A:M): List(RE) ==
x:SE :=new()$SE
pol:= characteristicPolynomial(A,x) :: F
radicalRoots(pol,x)$RSP
---- Eigenvectors belonging to a given eigenvalue ----
---- expressed in terms of radicals ----
radicalEigenvector(alpha:RE,A:M) : List(MRE) ==
n:=nrows A
B:MRE := zero(n,n)$MRE
for i in 1..n repeat
for j in 1..n repeat B(i,j):=(A(i,j))::RE
B(i,i):= B(i,i) - alpha
[v::MRE for v in nullSpace B]
---- eigenvectors and eigenvalues ----
radicalEigenvectors(A:M) : List(RadicalForm) ==
leig:List EigenForm := eigenvectors A
n:=nrows A
sln:List RadicalForm := empty()
veclist: List MRE
for eig in leig repeat
eig.eigval case F =>
veclist := empty()
for ll in eig.eigvec repeat
m:MRE:=zero(n,1)
for i in 1..n repeat m(i,1):=(ll(i,1))::RE
veclist:=cons(m,veclist)
sln:=cons([(eig.eigval)::F::RE,eig.eigmult,veclist]$RadicalForm,sln)
sym := eig.eigval :: ST
xx:= lhs sym
lval : List RE := radicalRoots((rhs sym) :: F ,xx)$RSP
for alg in lval repeat
nsl:=[alg,eig.eigmult,
[evalvect(ep,alg,xx) for ep in eig.eigvec]]$RadicalForm
sln:=cons(nsl,sln)
sln
---- orthonormalization of a list of vectors ----
---- Grahm - Schmidt process ----
gramschmidt(lvect:List(MRE)) : List(MRE) ==
lvect=[] => []
v:=lvect.first
n := nrows v
RMR:=RectangularMatrix(n:PI,1,RE)
orth:List(MRE):=[(normalise v)]
for v in lvect.rest repeat
pol:=((v:RMR)-(+/[(innerprod(w,v)*w):RMR for w in orth])):MRE
orth:=cons(normalise pol,orth)
orth
---- The matrix of eigenvectors ----
eigenMatrix(A:M) : Union(MRE,"failed") ==
lef:List(MRE):=[:eiv.radvect for eiv in radicalEigenvectors(A)]
n:=nrows A
#lef <n => "failed"
d:MRE:=copy(lef.first)
for v in lef.rest repeat d:=(horizConcat(d,v))::MRE
d
---- orthogonal basis for a symmetric matrix ----
orthonormalBasis(A:M):List(MRE) ==
^symmetric?(A) => error "the matrix is not symmetric"
basis:List(MRE):=[]
lvec:List(MRE) := []
alglist:List(RadicalForm):=radicalEigenvectors(A)
n:=nrows A
for alterm in alglist repeat
if (lvec:=alterm.radvect)=[] then error "sorry "
if #(lvec)>1 then
lvec:= gramschmidt(lvec)
basis:=[:lvec,:basis]
else basis:=[normalise(lvec.first),:basis]
basis
|