/usr/share/axiom-20170501/src/algebra/MATRIX.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 | )abbrev domain MATRIX Matrix
++ Author: Grabmeier, Gschnitzer, Williamson
++ Date Created: 1987
++ Date Last Updated: July 1990
++ Description:
++ \spadtype{Matrix} is a matrix domain where 1-based indexing is used
++ for both rows and columns.
Matrix(R) : SIG == CODE where
R : Ring
Row ==> Vector R
Col ==> Vector R
mnRow ==> 1
mnCol ==> 1
MATLIN ==> MatrixLinearAlgebraFunctions(R,Row,Col,$)
MATSTOR ==> StorageEfficientMatrixOperations(R)
SIG ==> MatrixCategory(R,Row,Col) with
diagonalMatrix : Vector R -> $
++ \spad{diagonalMatrix(v)} returns a diagonal matrix where the elements
++ of v appear on the diagonal.
if R has ConvertibleTo InputForm then ConvertibleTo InputForm
if R has Field then
inverse : $ -> Union($,"failed")
++ \spad{inverse(m)} returns the inverse of the matrix m.
++ If the matrix is not invertible, "failed" is returned.
++ Error: if the matrix is not square.
CODE ==> InnerIndexedTwoDimensionalArray(R,mnRow,mnCol,Row,Col) add
minr ==> minRowIndex
maxr ==> maxRowIndex
minc ==> minColIndex
maxc ==> maxColIndex
mini ==> minIndex
maxi ==> maxIndex
minRowIndex x == mnRow
minColIndex x == mnCol
swapRows_!(x,i1,i2) ==
(i1 < minRowIndex(x)) or (i1 > maxRowIndex(x)) or _
(i2 < minRowIndex(x)) or (i2 > maxRowIndex(x)) =>
error "swapRows!: index out of range"
i1 = i2 => x
minRow := minRowIndex x
xx := x pretend PrimitiveArray(PrimitiveArray(R))
n1 := i1 - minRow; n2 := i2 - minRow
row1 := qelt(xx,n1)
qsetelt_!(xx,n1,qelt(xx,n2))
qsetelt_!(xx,n2,row1)
xx pretend $
positivePower:($,Integer,NonNegativeInteger) -> $
positivePower(x,n,nn) ==
(n = 1) => x
-- no need to allocate space for 3 additional matrices
n = 2 => x * x
n = 3 => x * x * x
n = 4 => (y := x * x; y * y)
a := new(nn,nn,0) pretend Matrix(R)
b := new(nn,nn,0) pretend Matrix(R)
c := new(nn,nn,0) pretend Matrix(R)
xx := x pretend Matrix(R)
power_!(a,b,c,xx,n :: NonNegativeInteger)$MATSTOR pretend $
x:$ ** n:NonNegativeInteger ==
not((nn := nrows x) = ncols x) =>
error "**: matrix must be square"
zero? n => scalarMatrix(nn,1)
positivePower(x,n,nn)
if R has commutative("*") then
determinant x == determinant(x)$MATLIN
minordet x == minordet(x)$MATLIN
if R has EuclideanDomain then
rowEchelon x == rowEchelon(x)$MATLIN
if R has IntegralDomain then
rank x == rank(x)$MATLIN
nullity x == nullity(x)$MATLIN
nullSpace x == nullSpace(x)$MATLIN
if R has Field then
inverse x == inverse(x)$MATLIN
x:$ ** n:Integer ==
nn := nrows x
not(nn = ncols x) =>
error "**: matrix must be square"
zero? n => scalarMatrix(nn,1)
positive? n => positivePower(x,n,nn)
(xInv := inverse x) case "failed" =>
error "**: matrix must be invertible"
positivePower(xInv :: $,-n,nn)
diagonalMatrix(v: Vector R) ==
n := #v; ans := zero(n,n)
for i in minr(ans)..maxr(ans) for j in minc(ans)..maxc(ans) _
for k in mini(v)..maxi(v) repeat qsetelt_!(ans,i,j,qelt(v,k))
ans
if R has ConvertibleTo InputForm then
convert(x:$):InputForm ==
convert [convert("matrix"::Symbol)@InputForm,
convert listOfLists x]$List(InputForm)
|