1\documentstyle[11pt,reduce,fancyheadings]{article}
2\title{The Sparse Matrices Package. \\
3Sparse Matrix Calculations and a Linear Algebra Package for Sparse
4Matrices in \REDUCE{}}
5\author{Stephen Scowcroft \\
6        Konrad-Zuse-Zentrum f\"ur Informationstechnik Berlin}
7\date{June 1995}
8
9\def\foottitle{The Sparse Matrices Package}
10\pagestyle{fancy}
11\lhead[]{{\footnotesize\leftmark}{}}
12\rhead[]{\thepage}
13\setlength{\headrulewidth}{0.6pt}
14\setlength{\footrulewidth}{0.6pt}
15\cfoot{}
16\rfoot{\small\foottitle}
17
18\def\exprlist  {expr$_{1}$,expr$_{2}$, \ldots ,expr$_{{\tt n}}$}
19\def\lineqlist {lin\_eqn$_{1}$,lin\_eqn$_{2}$, \ldots ,lin\_eqn$_{n}$}
20\def\matlist   {mat$_{1}$,mat$_{2}$, \ldots ,mat$_{n}$}
21\def\veclist   {vec$_{1}$,vec$_{2}$, \ldots ,vec$_{n}$}
22
23\def\lazyfootnote{\footnote{The \{\}'s can be omitted.}}
24
25\renewcommand{\thefootnote}{\fnsymbol{footnote}}
26
27\begin{document}
28\maketitle
29\index{Linear Algebra package}
30
31\section{Introduction}
32A very powerful feature of \REDUCE{} is the ease with which matrix
33calculations can be performed.
34This package extends the available matrix feature to enable calculations
35with sparse matrices. This package also provides a selection of
36functions that are useful in the world of linear algebra with respect to
37sparse matrices.
38
39\subsection*{Loading the Package}
40The package is loaded by: {\tt load\_package sparse;}
41
42\section{Sparse Matrix Calculations}
43To extend the the syntax to this class of calculations we need to add an
44expression type {\tt sparse}.
45
46\subsection{Sparse Variables}
47An identifier may be declared a sparse variable by the declaration
48{\tt SPARSE}.
49The size of the sparse matrix must be declared explicitly in the matrix
50declaration. For example,
51\begin{verbatim}
52sparse aa(10,1),bb(200,200);
53\end{verbatim}
54declares {\tt AA} to be a 10 x 1 (column) sparse matrix and {\tt Y} to
55be a 200 x 200 sparse matrix.
56The declaration {\tt SPARSE} is similar to the declaration {\tt MATRIX}.
57Once a symbol is declared to name a sparse matrix, it can not also be
58used to name an array, operator, procedure, or used as an ordinary
59variable. For more information see the Matrix Variables section in The
60\REDUCE {} User's Manual[2].
61
62\subsection{Assigning Sparse Matrix Elements}
63Once a matix has been declared a sparse matrix all elements of the
64matrix are initialized to 0. Thus when a sparse matrix is initially
65referred to the message
66\begin{verbatim}
67"The matrix is dense, contains only zeros"
68\end{verbatim}
69is returned. When printing out a matrix only the non-zero elements are
70printed. This is due to the fact that only the non-zero elements of the
71matrix are stored.
72To assign the elements of the declared matrix we use the following
73syntax. Assuming {\tt AA} and {\tt BB} have been declared as spasre
74matrices, we simply write,
75\begin{verbatim}
76aa(1,1):=10;
77bb(100,150):=a;
78\end{verbatim}
79etc. This then sets the element in the first row and first column to 10,
80or the element in the 100th row and 150th column to {\tt a}.
81
82\subsection{Evaluating Sparse Matrix Elements}
83Once an element of a sparse matrix has been assingned, it may be referred
84to in standard array element notation. Thus {\tt aa(2,1)} refers to the
85element in the second row and first column of the sparse matrix {\tt AA}.
86
87\section{Sparse Matrix Expressions}
88These follow the normal rules of matrix algebra. Sums and products must
89be of compatible size; otherwise an error will result during evaluation.
90Similarly, only square matrices may be raised to a power.
91A negative power is computed as the inverse of the matrix raised to the
92corresponding positive power. For more information and the syntax for
93matrix algebra see the Matrix Expressions section in The \REDUCE{}
94User's Manual[2].
95
96\section{Operators with Sparse Matrix Arguments}
97The operators in the Sparse Matix Package are the same as those in the
98Matrix Packge with the exception that the {\tt NULLSPACE} operator is
99not defined. See section Operators with Matrix Arguments in The
100\REDUCE{} User's Manual[2] for more details.
101\subsection{Examples}
102In the examples the matrix ${\cal AA}$ will be
103
104\begin{flushleft}
105\begin{math}
106{\cal AA} = \left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 3 & 0 & 0 \\
1070 & 0 & 5 & 0 \\ 0 & 0 & 0 & 9
108\end{array} \right)
109\end{math}
110\end{flushleft}
111\begin {verbatim}
112det ppp;
113
114135
115
116trace ppp;
117
11818
119
120rank ppp;
121
1224
123
124spmateigen(ppp,eta);
125
126{{eta - 1,1,
127
128  spm(1,1) := arbcomplex(4)$
129  },
130
131 {eta - 3,1,
132
133  spm(2,1) := arbcomplex(5)$
134  },
135
136 {eta - 5,1,
137
138  spm(3,1) := arbcomplex(6)$
139  },
140
141 {eta - 9,1,
142
143  spm(4,1) := arbcomplex(7)$
144  }}
145\end{verbatim}
146
147\section{The Linear Algebra Package for Sparse Matrices}
148This package is an extension of the Linear Algebra Package for \REDUCE{}.[1]
149These functions are described
150alphabetically in section 6 of this document and are labelled 6.1 to
1516.47. They can be classified into four sections(n.b: the numbers after
152the dots signify the function label in section 6).
153\subsection{Basic matrix handling}
154\begin{center}
155\begin{tabular}{l l l l l l}
156spadd\_columns     & \ldots & 6.1  &
157spadd\_rows        & \ldots & 6.2  \\
158spadd\_to\_columns & \ldots & 6.3  &
159spadd\_to\_rows    & \ldots & 6.4  \\
160spaugment\_columns & \ldots & 6.5  &
161spchar\_poly       & \ldots & 6.9  \\
162spcol\_dim      & \ldots & 6.12  &
163spcopy\_into       & \ldots & 6.14 \\
164spdiagonal         & \ldots & 6.15 &
165spextend           & \ldots & 6.16 \\
166spfind\_companion  & \ldots & 6.17  &
167spget\_columns     & \ldots & 6.18 \\
168spget\_rows        & \ldots & 6.19 &
169sphermitian\_tp    & \ldots & 6.21 \\
170spmatrix\_augment  & \ldots & 6.27 &
171spmatrix\_stack    & \ldots & 6.29 \\
172spminor            & \ldots & 6.30 &
173spmult\_columns    & \ldots & 6.31 \\
174spmult\_rows       & \ldots & 6.32 &
175sppivot            & \ldots & 6.33 \\
176spremove\_columns  & \ldots & 6.35 &
177spremove\_rows     & \ldots & 6.36 \\
178sprow\_dim         & \ldots & 6.37 &
179sprows\_pivot      & \ldots & 6.38 \\
180spstack\_rows      & \ldots & 6.41 &
181spsub\_matrix      & \ldots & 6.42 \\
182spswap\_columns    & \ldots & 6.44 &
183spswap\_entries    & \ldots & 6.45 \\
184spswap\_rows       & \ldots & 6.46 &
185\end{tabular}
186\end{center}
187
188\subsection{Constructors}
189
190Functions that create sparse matrices.
191
192\begin{center}
193\begin{tabular}{l l l l l l}
194spband\_matrix       & \ldots & 6. 6 &
195spblock\_matrix      & \ldots & 6. 7 \\
196spchar\_matrix       & \ldots & 6. 8 &
197spcoeff\_matrix      & \ldots & 6. 11 \\
198spcompanion          & \ldots & 6. 13 &
199sphessian            & \ldots & 6. 22 \\
200spjacobian           & \ldots & 6. 23 &
201spjordan\_block      & \ldots & 6. 24 \\
202spmake\_identity     & \ldots & 6. 26 &
203\end{tabular}
204\end{center}
205
206\subsection{High level algorithms}
207
208\begin{center}
209\begin{tabular}{l l l l l l}
210spchar\_poly       & \ldots & 6.9 &
211spcholesky         & \ldots & 6.10 \\
212spgram\_schmidt    & \ldots & 6.20 &
213splu\_decom        & \ldots & 6.25 \\
214sppseudo\_inverse  & \ldots & 6.34 &
215svd                & \ldots & 6.43
216\end{tabular}
217\end{center}
218
219\subsection{Predicates}
220
221\begin{center}
222\begin{tabular}{l l l l l l}
223matrixp     & \ldots & 6.28 &
224sparsematp  & \ldots & 6.39 \\
225squarep     & \ldots & 6.40 &
226symmetricp  & \ldots & 6.47
227\end{tabular}
228\end{center}
229
230\subsection*{Note on examples:}
231
232In the examples the matrix ${\cal A}$ will be
233
234\begin{flushleft}
235\begin{math}
236{\cal A} = \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
237\end{array} \right)
238\end{math}
239\end{flushleft}
240Unfortunately, due to restrictions of size, it is not practical to use
241``large'' sparse matrices in the examples. As a result the examples
242shown may appear trivial, but they give an idea of how the functions
243work.
244
245\subsection*{Notation}
246
247Throughout ${\cal I}$ is used to indicate the identity matrix and
248${\cal A}^T$ to indicate the transpose of the matrix ${\cal A}$.
249
250\section{Available Functions}
251
252\subsection{spadd\_columns, spadd\_rows}
253
254\hspace*{0.175in} {\tt spadd\_columns(${\cal A}$,c1,c2,expr);}
255
256\hspace*{0.1in}
257\begin{tabular}{l l l}
258${\cal A}$ & :- & a sparse matrix. \\
259c1,c2      & :- & positive integers. \\
260expr       & :- & a scalar expression.
261\end{tabular}
262
263{\bf Synopsis:}
264
265\begin{addtolength}{\leftskip}{0.22in}
266\parbox[t]{0.95\linewidth}{{\tt spadd\_columns} replaces column c2 of
267${\cal A}$ by expr $*$ column(${\cal A}$,c1) $+$ column(${\cal A}$,c2).}
268
269{\tt spadd\_rows} performs the equivalent task on the rows of ${\cal A}$.
270
271\end{addtolength}
272
273{\bf Examples:}
274
275\begin{flushleft}
276\begin{math}
277\hspace*{0.16in}
278\begin{array}{ccc}
279{\tt spadd\_columns}({\cal A},1,2,x) & = &
280\left( \begin{array}{ccc} 1 & x & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
281\end{array} \right)
282\end{array}
283\end{math}
284\end{flushleft}
285
286\vspace*{0.1in}
287
288\begin{flushleft}
289\hspace*{0.1in}
290\begin{math}
291\begin{array}{ccc}
292{\tt spadd\_rows}({\cal A},2,3,5) & = &
293\left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 25 & 9
294\end{array} \right)
295\end{array}
296\end{math}
297\end{flushleft}
298
299{\bf Related functions:}
300
301\hspace*{0.175in} {\tt spadd\_to\_columns}, {\tt spadd\_to\_rows},
302{\tt spmult\_columns}, {\tt spmult\_rows}.
303
304
305\subsection{spadd\_rows}
306
307\hspace*{0.175in} see: {\tt spadd\_columns}.
308
309
310\subsection{spadd\_to\_columns, spadd\_to\_rows}
311
312\hspace*{0.175in} {\tt spadd\_to\_columns(${\cal A}$,column\_list,expr);}
313
314\hspace*{0.1in}
315\begin{tabular}{l l l}
316${\cal A}$   &:-& a sparse matrix. \\
317column\_list &:-& a positive integer or a list of positive integers. \\
318expr        &:-& a scalar expression.
319\end{tabular}
320
321{\bf Synopsis:}
322
323\begin{addtolength}{\leftskip}{0.22in}
324{\tt spadd\_to\_columns} adds expr to each column specified in
325column\_list of ${\cal A}$.
326
327{\tt spadd\_to\_rows} performs the equivalent task on the rows of
328${\cal A}$.
329
330\end{addtolength}
331
332{\bf Examples:}
333
334\begin{flushleft}
335\hspace*{0.175in}
336\begin{math}
337\begin{array}{ccc}
338{\tt spadd\_to\_columns}({\cal A},\{1,2\},10) & = &
339\left( \begin{array}{ccc} 11 & 10 & 0 \\ 10 & 15 & 0 \\ 10 & 10 & 9
340\end{array} \right)
341\end{array}
342\end{math}
343\end{flushleft}
344
345\vspace*{0.1in}
346
347\begin{flushleft}
348\hspace*{0.175in}
349\begin{math}
350\begin{array}{ccc}
351{\tt spadd\_to\_rows}({\cal A},2,-x) & = &
352\left( \begin{array}{ccc} 1 & 0 & 0 \\ -x & -x+5 & -x \\ 0 & 0 & 9
353\end{array} \right)
354\end{array}
355\end{math}
356\end{flushleft}
357
358{\bf Related functions:}
359
360\hspace*{0.175in}
361{\tt spadd\_columns}, {\tt spadd\_rows}, {\tt spmult\_rows},
362{\tt spmult\_columns}.
363
364
365\subsection{spadd\_to\_rows}
366
367\hspace*{0.175in} see: {\tt spadd\_to\_columns}.
368
369
370\subsection{spaugment\_columns, spstack\_rows}
371
372\hspace*{0.175in} {\tt spaugment\_columns(${\cal A}$,column\_list);}
373
374\hspace*{0.1in}
375\begin{tabular}{l l l}
376${\cal A}$  &:-& a sparse matrix. \\
377column\_list &:-&  either a positive integer or a list of positive
378                   integers.
379\end{tabular}
380
381{\bf Synopsis:}
382
383\begin{addtolength}{\leftskip}{0.22in}
384{\tt spaugment\_columns} gets hold of the columns of ${\cal A}$ specified
385in column\_list and sticks them together.
386
387{\tt spstack\_rows} performs the same task on rows of
388                ${\cal A}$.
389
390\end{addtolength}
391
392{\bf Examples:}
393
394\begin{flushleft}
395\hspace*{0.1in}
396\begin{math}
397\begin{array}{ccc}
398{\tt spaugment\_columns}({\cal A},\{1,2\}) & = &
399\left( \begin{array}{cc} 1 & 0 \\ 0 & 5 \\ 0 & 0
400\end{array} \right)
401\end{array}
402\end{math}
403\end{flushleft}
404
405\vspace*{0.1in}
406
407\begin{flushleft}
408\hspace*{0.1in}
409\begin{math}
410\begin{array}{ccc}
411{\tt spstack\_rows}({\cal A},\{1,3\}) & = &
412\left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 0 & 9
413\end{array} \right)
414\end{array}
415\end{math}
416\end{flushleft}
417
418{\bf Related functions:}
419
420\hspace*{0.175in} {\tt spget\_columns}, {\tt spget\_rows},
421{\tt spsub\_matrix}.
422
423
424\subsection{spband\_matrix}
425
426\hspace*{0.175in} {\tt spband\_matrix(expr\_list,square\_size);}
427
428\hspace*{0.1in}
429\begin{tabular}{l l l}
430expr\_list  \hspace*{0.088in} &:-& \parbox[t]{.72\linewidth}
431{either a single scalar expression or a list of an odd number of scalar
432expressions.}
433\end{tabular}
434
435\vspace*{0.04in}
436\hspace*{0.1in}
437\begin{tabular}{l l l}
438square\_size &:-& a positive integer.
439\end{tabular}
440
441{\bf Synopsis:}
442
443\begin{addtolength}{\leftskip}{0.22in}
444                {\tt spband\_matrix} creates a sparse square matrix of
445                dimension square\_size.
446
447\end{addtolength}
448
449{\bf Examples:}
450
451\begin{flushleft}
452\hspace*{0.1in}
453\begin{math}
454\begin{array}{ccc}
455{\tt spband\_matrix}(\{x,y,z\},6) & = &
456\left( \begin{array}{cccccc} y & z & 0 & 0 & 0 & 0 \\ x & y & z & 0 & 0
457& 0 \\ 0 & x & y & z & 0 & 0 \\ 0 & 0 & x & y & z & 0 \\ 0 & 0 & 0 & x &
458 y & z \\ 0 & 0 & 0 & 0 & x & y
459\end{array} \right)
460\end{array}
461\end{math}
462\end{flushleft}
463
464{\bf Related functions:}
465
466\hspace*{0.175in} {\tt spdiagonal}.
467
468
469\subsection{spblock\_matrix}
470
471\hspace*{0.175in} {\tt spblock\_matrix(r,c,matrix\_list);}
472
473\hspace*{0.1in}
474\begin{tabular}{l l l}
475r,c          &:-& positive integers. \\
476matrix\_list &:-& a list of matrices of either sparse or matrix type.
477\end{tabular}
478
479{\bf Synopsis:}
480
481\begin{addtolength}{\leftskip}{0.22in}
482{\tt spblock\_matrix} creates a sparse matrix that consists of r by c matrices
483filled from the matrix\_list row wise.
484
485\end{addtolength}
486
487
488{\bf Examples:}
489
490\begin{flushleft}
491\hspace*{0.1in}
492\begin{math}
493\begin{array}{ccc}
494{\cal B} = \left( \begin{array}{cc} 1 & 0 \\ 0 & 1
495\end{array} \right), &
496{\cal C} = \left( \begin{array}{c} 5 \\ 0
497\end{array} \right), &
498{\cal D} = \left( \begin{array}{cc} 22 & 0 \\ 0 & 0
499\end{array} \right)
500\end{array}
501\end{math}
502\end{flushleft}
503
504\vspace*{0.175in}
505
506\begin{flushleft}
507\hspace*{0.1in}
508\begin{math}
509\begin{array}{ccc}
510{\tt spblock\_matrix}(2,3,\{{\cal B,C,D,D,C,B}\}) & = &
511\left( \begin{array}{ccccc} 1 & 0 & 5 & 22 & 0 \\ 0 & 1 & 0 & 0 & 0
512\\
51322 & 0 & 5 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1
514\end{array} \right)
515\end{array}
516\end{math}
517\end{flushleft}
518
519
520\subsection{spchar\_matrix}
521
522\hspace*{0.175in} {\tt spchar\_matrix(${\cal A},\lambda$);}
523
524\hspace*{0.1in}
525\begin{tabular}{l l l}
526${\cal A}$ &:-& a square sparse matrix. \\
527$\lambda$  &:-& a symbol or algebraic expression.
528\end{tabular}
529
530{\bf Synopsis:}
531
532\begin{addtolength}{\leftskip}{0.22in}
533{\tt spchar\_matrix} creates the characteristic matrix ${\cal C}$ of
534${\cal A}$.
535
536This is ${\cal C} = \lambda * {\cal I} - {\cal A}$.
537
538\end{addtolength}
539
540{\bf Examples:}
541
542\begin{flushleft}
543\hspace*{0.1in}
544\begin{math}
545\begin{array}{ccc}
546{\tt spchar\_matrix}({\cal A},x) & = &
547\left( \begin{array}{ccc} x-1 & 0 & 0 \\ 0 & x-5 & 0 \\ 0 & 0 & x-9
548\end{array} \right)
549\end{array}
550\end{math}
551\end{flushleft}
552
553{\bf Related functions:}
554
555\hspace*{0.175in} {\tt spchar\_poly}.
556
557
558\subsection{spchar\_poly}
559
560\hspace*{0.175in} {\tt spchar\_poly(${\cal A},\lambda$);}
561
562\hspace*{0.1in}
563\begin{tabular}{l l l}
564${\cal A}$ &:-& a sparse square matrix. \\
565$\lambda$ &:-& a symbol or algebraic expression.
566\end{tabular}
567
568{\bf Synopsis:}
569
570\begin{addtolength}{\leftskip}{0.22in}
571{\tt spchar\_poly} finds the characteristic polynomial of
572                ${\cal A}$.
573
574This is the determinant of $\lambda * {\cal I} - {\cal A}$.
575
576\end{addtolength}
577
578{\bf Examples:}
579
580\hspace*{0.175in}
581{\tt spchar\_poly({\cal A},$x$) $= x^3-15*x^2-59*x-45$}
582
583{\bf Related functions:}
584
585\hspace*{0.175in} {\tt spchar\_matrix}.
586
587
588\subsection{spcholesky}
589
590\hspace*{0.175in} {\tt spcholesky(${\cal A}$);}
591
592\hspace*{0.1in}
593\begin{tabular}{l l l}
594${\cal A}$ &:-& a positive definite sparse matrix containing numeric entries.
595\end{tabular}
596
597{\bf Synopsis:}
598
599\begin{addtolength}{\leftskip}{0.22in}
600{\tt spcholesky} computes the cholesky decomposition of ${\cal A}$.
601
602It returns \{${\cal L,U}$\} where ${\cal L}$
603is a lower matrix, ${\cal U}$ is an upper matrix, \\ ${\cal A} =
604{\cal LU}$, and ${\cal U} = {\cal L}^T$.
605
606\end{addtolength}
607
608{\bf Examples:}
609
610\begin{flushleft}
611\hspace*{0.175in}
612\begin{math}
613{\cal F} = \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 &
6149
615\end{array} \right)
616\end{math}
617\end{flushleft}
618
619\begin{flushleft}
620\hspace*{0.1in}
621\begin{math}
622\begin{array}{ccc}
623${\tt cholesky}$({\cal F}) & = &
624\left\{ \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & \sqrt{5}
625& 0 \\
6260 & 0& 3 \end{array} \right), \left(
627\begin{array}{ccc} 1 & 0 & 0 \\ 0 & \sqrt{5} & 0 \\ 0
628& 0 & 3 \end{array} \right)
629\right\} \end{array}
630\end{math}
631\end{flushleft}
632
633{\bf Related functions:}
634
635\hspace*{0.175in} {\tt splu\_decom}.
636
637
638\subsection{spcoeff\_matrix}
639
640\hspace*{0.175in} {\tt spcoeff\_matrix(\{\lineqlist{}\});}
641
642\hspace*{0.1in}
643\begin{tabular}{l l l}
644\lineqlist  &:-& \parbox[t]{.435\linewidth}{linear equations. Can be
645of the form {\it equation $=$ number} or just {\it equation}.}
646\end{tabular}
647
648{\bf Synopsis:}
649
650\begin{addtolength}{\leftskip}{0.22in}
651{\tt spcoeff\_matrix} creates the coefficient matrix
652                ${\cal C}$ of the linear equations.
653
654It returns \{${\cal C,X,B}$\} such that ${\cal CX} = {\cal B}$.
655
656\end{addtolength}
657
658
659{\bf Examples:}
660
661\begin{math}
662\hspace*{0.175in}
663{\tt spcoeff\_matrix}(\{y-20*w=10,y-z=20,y+4+3*z,w+x+50\}) =
664\end{math}
665
666\vspace*{0.1in}
667
668\begin{flushleft}
669\hspace*{0.175in}
670\begin{math}
671\left\{ \left( \begin{array}{cccc} 1 & -20 & 0 & 0 \\ 1 & 0 & -1 & 0 \\
672 1 & 0 & 3 & 0 \\ 0 & 1 & 0 & 1
673\end{array} \right), \left( \begin{array}{c} y \\ w \\ z \\ x \end{array}
674\right), \left( \begin{array}{c} 10 \\ 20 \\ -4 \\ 50
675\end{array} \right) \right\}
676\end{math}
677\end{flushleft}
678
679\subsection{spcol\_dim, sprow\_dim}
680
681\hspace*{0.175in} {\tt column\_dim(${\cal A}$);}
682
683\hspace*{0.1in}
684\begin{tabular}{l l l}
685${\cal A}$ &:-& a sparse matrix.
686\end{tabular}
687
688{\bf Synopsis:}
689
690\hspace*{0.175in} {\tt spcol\_dim} finds the column dimension of
691                ${\cal A}$.
692
693\hspace*{0.175in} {\tt sprow\_dim} finds the row dimension of ${\cal A}$.
694
695{\bf Examples:}
696
697\hspace*{0.175in}
698{\tt spcol\_dim}(${\cal A}$) = 3
699
700\subsection{spcompanion}
701
702\hspace*{0.175in} {\tt spcompanion(poly,x);}
703
704\hspace*{0.1in}
705\begin{tabular}{l l l}
706poly &:-& a monic univariate polynomial in x. \\
707x    &:-& the variable.
708\end{tabular}
709
710{\bf Synopsis:}
711
712\begin{addtolength}{\leftskip}{0.22in}
713                {\tt spcompanion} creates the companion matrix ${\cal C}$
714                of poly.
715
716This is the square matrix of dimension n, where n is the degree of poly
717w.r.t. x.
718
719The entries of ${\cal C}$ are:
720                ${\cal C}$(i,n) = -coeffn(poly,x,i-1) for i = 1
721                \ldots n, ${\cal C}$(i,i-1) = 1 for i = 2 \ldots n and
722                the rest are 0.
723
724\end{addtolength}
725
726
727{\bf Examples:}
728
729\begin{flushleft}
730\hspace*{0.1in}
731\begin{math}
732\begin{array}{ccc}
733{\tt spcompanion}(x^4+17*x^3-9*x^2+11,x) & = &
734\left( \begin{array}{cccc} 0 & 0 & 0 & -11 \\ 1 & 0 & 0 & 0 \\
7350 & 1 & 0 & 9 \\ 0 & 0 & 1 & -17
736\end{array} \right)
737\end{array}
738\end{math}
739\end{flushleft}
740
741{\bf Related functions:}
742
743\hspace*{0.175in} {\tt spfind\_companion}.
744
745
746\subsection{spcopy\_into}
747
748\hspace*{0.175in} {\tt spcopy\_into(${\cal A,B}$,r,c);}
749
750\hspace*{0.1in}
751\begin{tabular}{l l l}
752${\cal A,B}$ &:-& matrices of type sparse or matrix. \\
753r,c          &:-& positive integers.
754\end{tabular}
755
756{\bf Synopsis:} %{\bf What it does:}
757
758\hspace*{0.175in} {\tt spcopy\_into} copies matrix ${\cal A}$ into
759                ${\cal B}$ with ${\cal A}$(1,1) at ${\cal B}$(r,c).
760
761{\bf Examples:}
762
763\begin{flushleft}
764\hspace*{0.175in}
765\begin{math}
766{\cal G} = \left( \begin{array}{cccc} 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\
7670 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0
768\end{array} \right)
769\end{math}
770\end{flushleft}
771
772\begin{flushleft}
773\hspace*{0.1in}
774\begin{math}
775\begin{array}{ccc}
776{\tt spcopy\_into}({\cal A,G},1,2) & = &
777\left( \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 0 & 0 & 5 & 0 \\ 0 & 0 & 0
778& 9 \\ 0 & 0 & 0 & 0
779\end{array} \right)
780\end{array}
781\end{math}
782\end{flushleft}
783
784{\bf Related functions:}
785
786\begin{addtolength}{\leftskip}{0.22in}
787{\tt spaugment\_columns}, {\tt spextend}, {\tt spmatrix\_augment},
788{\tt spmatrix\_stack}, {\tt spstack\_rows}, {\tt spsub\_matrix}.
789
790\end{addtolength}
791
792
793\subsection{spdiagonal}
794
795\hspace*{0.175in} {\tt spdiagonal(\{\matlist{}\});}\lazyfootnote{}
796
797\hspace*{0.1in}
798\begin{tabular}{l l l}
799\matlist &:-& \parbox[t]{.58\linewidth}{each can be either a scalar
800expr or a square matrix of sparse or matrix type. }
801\end{tabular}
802
803{\bf Synopsis:} %{\bf What it does:}
804
805\hspace*{0.175in} {\tt spdiagonal} creates a sparse matrix that contains the
806input on the diagonal.
807
808{\bf Examples:}
809
810\begin{flushleft}
811\hspace*{0.175in}
812\begin{math}
813{\cal H} = \left( \begin{array}{cc} 66 & 77 \\ 88 & 99
814\end{array} \right)
815\end{math}
816\end{flushleft}
817
818\begin{flushleft}
819\hspace*{0.1in}
820\begin{math}
821\begin{array}{ccc}
822{\tt spdiagonal}(\{{\cal A},x,{\cal H}\}) & = &
823\left( \begin{array}{cccccc} 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 5 & 0 & 0 & 0
824& 0 \\ 0 & 0 & 9 & 0 & 0 & 0 \\ 0 & 0 & 0 & x & 0 & 0 \\ 0 & 0 & 0 & 0
825& 66 & 77 \\ 0 & 0 & 0 & 0 & 88 & 99
826\end{array} \right)
827\end{array}
828\end{math}
829\end{flushleft}
830
831{\bf Related functions:}
832
833\hspace*{0.175in} {\tt spjordan\_block}.
834
835
836\subsection{spextend}
837
838\hspace*{0.175in} {\tt spextend(${\cal A}$,r,c,expr);}
839
840\hspace*{0.1in}
841\begin{tabular}{l l l}
842${\cal A}$ &:-& a sparse matrix. \\
843r,c        &:-& positive integers. \\
844expr      &:-& algebraic expression or symbol.
845\end{tabular}
846
847{\bf Synopsis:}
848
849\begin{addtolength}{\leftskip}{0.22in}
850                {\tt spextend} returns a copy of ${\cal A}$ that has been
851                extended by r rows and c columns. The new entries are
852                made equal to expr.
853
854\end{addtolength}
855
856{\bf Examples:}
857
858\begin{flushleft}
859\hspace*{0.1in}
860\begin{math}
861\begin{array}{ccc}
862{\tt spextend}({\cal A},1,2,0) & = &
863\left( \begin{array}{ccccc} 1 & 0 & 0 & 0 & 0 \\ 0 & 5 & 0 & 0 & 0
864\\ 0 & 0 & 9 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0
865\end{array} \right)
866\end{array}
867\end{math}
868\end{flushleft}
869
870{\bf Related functions:}
871
872\begin{addtolength}{\leftskip}{0.22in}
873\parbox[t]{0.95\linewidth}{{\tt spcopy\_into}, {\tt spmatrix\_augment},
874{\tt spmatrix\_stack}, {\tt spremove\_columns}, {\tt spremove\_rows}.}
875
876\end{addtolength}
877
878
879\subsection{spfind\_companion}
880
881\hspace*{0.175in} {\tt spfind\_companion(${\cal A}$,x);}
882
883\hspace*{0.1in}
884\begin{tabular}{l l l}
885${\cal A}$ &:-& a sparse matrix. \\
886x          &:-& the variable.
887\end{tabular}
888
889{\bf Synopsis:}
890
891\begin{addtolength}{\leftskip}{0.22in}
892  Given a sparse companion matrix, {\tt spfind\_companion} finds the polynomial
893from which it was made.
894
895\end{addtolength}
896
897
898{\bf Examples:}
899
900\begin{flushleft}
901\hspace*{0.175in}
902\begin{math}
903{\cal C} = \left( \begin{array}{cccc} 0 & 0 & 0 & -11 \\ 1 & 0 & 0 & 0
904\\ 0 & 1 & 0 & 9 \\ 0 & 0 & 1 & -17
905\end{array} \right)
906\end{math}
907\end{flushleft}
908
909\vspace*{3mm}
910
911\begin{flushleft}
912\hspace*{0.175in}
913\begin{math}
914{\tt spfind\_companion}({\cal C},x) = x^4+17*x^3-9*x^2+11
915\end{math}
916\end{flushleft}
917
918\vspace*{3mm}
919
920{\bf Related functions:}
921
922\hspace*{0.175in} {\tt spcompanion}.
923
924\subsection{spget\_columns, spget\_rows}
925
926\hspace*{0.175in} {\tt spget\_columns(${\cal A}$,column\_list);}
927
928\hspace*{0.1in}
929\begin{tabular}{l l l}
930${\cal A}$ &:-& a sparse matrix. \\
931c          &:-& either a positive integer or a list of positive
932                integers.
933\end{tabular}
934
935{\bf Synopsis:} %{\bf What it does:}
936
937\begin{addtolength}{\leftskip}{0.22in}
938{\tt spget\_columns} removes the columns of ${\cal A}$ specified in
939                column\_list and returns them as a list of column
940                matrices.
941
942\end{addtolength}
943\hspace*{0.175in} {\tt spget\_rows} performs the same task on the rows of
944                ${\cal A}$.
945
946{\bf Examples:}
947
948\begin{flushleft}
949\hspace*{0.1in}
950\begin{math}
951\begin{array}{ccc}
952{\tt spget\_columns}({\cal A},\{1,3\}) & = &
953\left\{
954        \left( \begin{array}{c} 1 \\ 0 \\ 0 \end{array} \right),
955        \left( \begin{array}{c} 0 \\ 0 \\ 9 \end{array} \right)
956\right\}
957\end{array}
958\end{math}
959\end{flushleft}
960
961\vspace*{0.1in}
962
963\begin{flushleft}
964\hspace*{0.1in}
965\begin{math}
966\begin{array}{ccc}
967{\tt spget\_rows}({\cal A},2) & = &
968\left\{
969        \left( \begin{array}{ccc} 0 & 5 & 0 \end{array} \right)
970\right\}
971\end{array}
972\end{math}
973\end{flushleft}
974
975{\bf Related functions:}
976
977\hspace*{0.175in} {\tt spaugment\_columns}, {\tt spstack\_rows},
978{\tt spsub\_matrix}.
979
980
981\subsection{spget\_rows}
982
983\hspace*{0.175in} see: {\tt spget\_columns}.
984
985
986\subsection{spgram\_schmidt}
987
988\hspace*{0.175in} {\tt spgram\_schmidt(\{\veclist{}\});}
989
990\hspace*{0.1in}
991\begin{tabular}{l l l}
992\veclist &:-& \parbox[t]{.62\linewidth}{linearly independent vectors.
993                             Each vector must be written as a list of
994predefined sparse (column) matrices, eg: sparse a(4,1);, a(1,1):=1;}
995\end{tabular}
996
997{\bf Synopsis:}
998
999\begin{addtolength}{\leftskip}{0.22in}
1000{\tt spgram\_schmidt} performs the gram\_schmidt
1001                orthonormalisation on the input vectors.
1002
1003It returns a list of orthogonal normalised vectors.
1004
1005\end{addtolength}
1006
1007{\bf Examples:}
1008
1009Suppose a,b,c,d correspond to sparse matrices representing the following
1010lists:-  \{\{1,0,0,0\},\{1,1,0,0\},\{1,1,1,0\},\{1,1,1,1\}\}.
1011
1012{\tt spgram\_schmidt(\{\{a\},\{b\},\{c\},\{d\}\})} =
1013\{\{1,0,0,0\},\{0,1,0,0\},\{0,0,1,0\},\{0,0,0,1\}\}
1014
1015\subsection{sphermitian\_tp}
1016
1017\hspace*{0.175in} {\tt sphermitian\_tp(${\cal A}$);}
1018
1019\hspace*{0.1in}
1020\begin{tabular}{l l l}
1021${\cal A}$ &:-& a sparse matrix.
1022\end{tabular}
1023
1024{\bf Synopsis:}
1025
1026\begin{addtolength}{\leftskip}{0.22in}
1027                {\tt sphermitian\_tp} computes the hermitian transpose of
1028                ${\cal A}$.
1029
1030\end{addtolength}
1031
1032{\bf Examples:}
1033
1034\begin{flushleft}
1035\hspace*{0.175in}
1036\begin{math}
1037{\cal J} = \left( \begin{array}{ccc} i+1 & i+2 & i+3 \\ 0 & 0 & 0 \\ 0 &
1038i & 0
1039\end{array} \right)
1040\end{math}
1041\end{flushleft}
1042
1043\vspace*{0.1in}
1044
1045\begin{flushleft}
1046\hspace*{0.1in}
1047\begin{math}
1048\begin{array}{ccc}
1049{\tt sphermitian\_tp}({\cal J}) & = &
1050\left( \begin{array}{ccc} -i+1 & 0 & 0 \\ -i+2 & 0 & -i \\-i+3 & 0 & 0
1051\end{array} \right)
1052\end{array}
1053\end{math}
1054\end{flushleft}
1055
1056{\bf Related functions:}
1057
1058\hspace*{0.175in} {\tt tp}\footnote{standard reduce call for the
1059transpose of a matrix - see {\REDUCE} User's Manual[2].}.
1060
1061
1062\subsection{sphessian}
1063
1064\hspace*{0.175in} {\tt sphessian(expr,variable\_list);}
1065
1066\hspace*{0.1in}
1067\begin{tabular}{l l l}
1068expr           &:-& a scalar expression. \\
1069variable\_list &:-& either a single variable or a list of variables.
1070\end{tabular}
1071
1072{\bf Synopsis:}
1073
1074\begin{addtolength}{\leftskip}{0.22in}
1075                {\tt sphessian} computes the hessian matrix of expr w.r.t.
1076                the variables in variable\_list.
1077
1078\end{addtolength}
1079
1080{\bf Examples:}
1081
1082\begin{flushleft}
1083\hspace*{0.1in}
1084\begin{math}
1085\begin{array}{ccc}
1086{\tt sphessian}(x*y*z+x^2,\{w,x,y,z\}) & = &
1087\left( \begin{array}{cccc} 0 & 0 & 0 & 0 \\ 0 & 2 & z & y \\ 0 & z & 0
1088& x \\ 0 & y & x & 0
1089\end{array} \right)
1090\end{array}
1091\end{math}
1092\end{flushleft}
1093
1094
1095\subsection{spjacobian}
1096
1097\hspace*{0.175in} {\tt spjacobian(expr\_list,variable\_list);}
1098
1099\hspace*{0.1in}
1100\begin{tabular}{l l l}
1101expr\_list   \hspace*{0.175in}  &:-& \parbox[t]{.72\linewidth}{either a
1102single algebraic expression or a list of algebraic expressions.}
1103\end{tabular}
1104
1105\vspace*{0.04in}
1106\hspace*{0.1in}
1107\begin{tabular}{l l l}
1108variable\_list &:-& either a single variable or a list of variables.
1109\end{tabular}
1110
1111{\bf Synopsis:}
1112
1113\begin{addtolength}{\leftskip}{0.22in}
1114{\tt spjacobian} computes the jacobian matrix of expr\_list w.r.t.
1115variable\_list.
1116
1117\end{addtolength}
1118
1119{\bf Examples:}
1120
1121\hspace*{0.175in}
1122{\tt spjacobian(\{$x^4,x*y^2,x*y*z^3$\},\{$w,x,y,z$\})} =
1123
1124\vspace*{0.1in}
1125
1126\begin{flushleft}
1127\hspace*{0.175in}
1128\begin{math}
1129\left( \begin{array}{cccc} 0 & 4*x^3 & 0 & 0 \\ 0 & y^2 & 2*x*y & 0 \\
11300 & y*z^3 & x*z^3 & 3*x*y*z^2
1131\end{array} \right)
1132\end{math}
1133\end{flushleft}
1134
1135{\bf Related functions:}
1136
1137\hspace*{0.175in} {\tt sphessian}, {\tt df}\footnote{standard reduce call
1138for differentiation - see {\REDUCE} User's Manual[2].}.
1139
1140
1141\subsection{spjordan\_block}
1142
1143\hspace*{0.175in} {\tt spjordan\_block(expr,square\_size);}
1144
1145\hspace*{0.1in}
1146\begin{tabular}{l l l}
1147expr        &:-& an algebraic expression or symbol. \\
1148square\_size &:-& a positive integer.
1149\end{tabular}
1150
1151{\bf Synopsis:}
1152
1153\begin{addtolength}{\leftskip}{0.22in}
1154{\tt spjordan\_block} computes the square jordan block matrix ${\cal J}$
1155                of dimension square\_size.
1156
1157\end{addtolength}
1158
1159{\bf Examples:}
1160
1161\begin{flushleft}
1162\hspace*{0.1in}
1163\begin{math}
1164\begin{array}{ccc}
1165{\tt spjordan\_block(x,5)} & = &
1166\left( \begin{array}{ccccc} x & 1 & 0 & 0 & 0 \\ 0 & x & 1 & 0 & 0 \\ 0
1167& 0 & x & 1 & 0 \\ 0 & 0 & 0 & x & 1 \\ 0 & 0 & 0 & 0 & x
1168\end{array} \right)
1169\end{array}
1170\end{math}
1171\end{flushleft}
1172
1173{\bf Related functions:}
1174
1175\hspace*{0.175in} {\tt spdiagonal}, {\tt spcompanion}.
1176
1177
1178\subsection{splu\_decom}
1179
1180%{\bf How to use it:}
1181
1182\hspace*{0.175in} {\tt splu\_decom(${\cal A}$);}
1183
1184\hspace*{0.1in}
1185\begin{tabular}{l l l}
1186${\cal A}$ &:-& \parbox[t]{.848\linewidth}{a sparse matrix containing either
1187numeric entries or imaginary entries with numeric coefficients.}
1188\end{tabular}
1189
1190{\bf Synopsis:} %{\bf What it does:}
1191
1192\begin{addtolength}{\leftskip}{0.22in}
1193              {\tt splu\_decom} performs LU decomposition on ${\cal A}$,
1194              ie: it returns \{${\cal L,U}$\} where ${\cal L}$
1195              is a lower diagonal matrix, ${\cal U}$ an upper diagonal
1196              matrix and ${\cal A} = {\cal LU}$.
1197
1198\end{addtolength}
1199
1200{\bf caution:}
1201
1202\begin{addtolength}{\leftskip}{0.22in}
1203The algorithm used can swap the rows of ${\cal A}$
1204                during the calculation. This means that ${\cal LU}$ does
1205                not equal ${\cal A}$ but a row equivalent of it. Due to
1206                this, {\tt splu\_decom} returns \{${\cal L,U}$,vec\}. The
1207                call {\tt spconvert(${\cal A}$,vec)} will return the
1208                sparse matrix that has been decomposed, ie: ${\cal LU} = $
1209                {\tt spconvert(${\cal A}$,vec)}.
1210
1211\end{addtolength}
1212
1213{\bf Examples:}
1214
1215\begin{flushleft}
1216\hspace*{0.175in}
1217\begin{math}
1218{\cal K} = \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
1219\end{array} \right)
1220\end{math}
1221\end{flushleft}
1222
1223\begin{flushleft}
1224\hspace*{0.1in}
1225\begin{math}
1226\begin{array}{cccc}
1227${\tt lu} := {\tt splu\_decom}$({\cal K}) & = &
1228\left\{
1229        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9 \end{array} \right),
1230        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
1231\end{array} \right),
1232	[\; 1 \; 2 \; 3 \; ]
1233\right\}
1234\end{array}
1235\end{math}
1236\end{flushleft}
1237
1238\vspace*{0.1in}
1239
1240\begin{flushleft}
1241\hspace*{0.1in}
1242\begin{math}
1243\begin{array}{ccc}
1244${\tt first lu * second lu}$ & = &
1245        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
1246 \end{array} \right)
1247\end{array}
1248\end{math}
1249\end{flushleft}
1250
1251\begin{flushleft}
1252\hspace*{0.1in}
1253\begin{math}
1254\begin{array}{ccc}
1255${\tt convert(${\cal K}$,third lu}$) \hspace*{0.055in} & = &
1256        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
1257 \end{array} \right)
1258\end{array}
1259\end{math}
1260\end{flushleft}
1261
1262{\bf Related functions:}
1263
1264\hspace*{0.175in} {\tt spcholesky}.
1265
1266
1267\subsection{spmake\_identity}
1268
1269\hspace*{0.175in} {\tt spmake\_identity(square\_size);}
1270
1271\hspace*{0.1in}
1272\begin{tabular}{l l l}
1273square\_size &:-& a positive integer.
1274\end{tabular}
1275
1276{\bf Synopsis:}
1277
1278\hspace*{0.175in} {\tt spmake\_identity} creates the identity matrix of
1279                dimension square\_size.
1280
1281{\bf Examples:}
1282
1283\begin{flushleft}
1284\hspace*{0.1in}
1285\begin{math}
1286\begin{array}{ccc}
1287{\tt spmake\_identity}(4) & = &
1288        \left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0
1289& 0 & 1 & 0 \\ 0 & 0 & 0 & 1
1290 \end{array} \right)
1291\end{array}
1292\end{math}
1293\end{flushleft}
1294
1295{\bf Related functions:}
1296
1297\hspace*{0.175in} {\tt spdiagonal}.
1298
1299
1300\subsection{spmatrix\_augment, spmatrix\_stack}
1301
1302\hspace*{0.175in} {\tt spmatrix\_augment(\{\matlist\});}\lazyfootnote{}
1303
1304\hspace*{0.1in}
1305\begin{tabular}{l l l}
1306\matlist &:-& matrices.
1307\end{tabular}
1308
1309{\bf Synopsis:}
1310
1311\hspace*{0.175in} {\tt spmatrix\_augment} joins the matrices in
1312                  matrix\_list together horizontally.
1313
1314\hspace*{0.175in}
1315{\tt spmatrix\_stack} joins the matrices in matrix\_list
1316                together vertically.
1317
1318{\bf Examples:}
1319
1320\begin{flushleft}
1321\hspace*{0.1in}
1322\begin{math}
1323\begin{array}{ccc}
1324{\tt spmatrix\_augment}(\{{\cal A,A}\}) & = &
1325        \left( \begin{array}{cccccc} 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 5 & 0
1326& 0 & 5 & 0 \\ 0 & 0 & 9 & 0 & 0 & 9
1327 \end{array} \right)
1328\end{array}
1329\end{math}
1330\end{flushleft}
1331
1332\vspace*{0.1in}
1333
1334\begin{flushleft}
1335\hspace*{0.1in}
1336\begin{math}
1337\begin{array}{ccc}
1338{\tt spmatrix\_stack}(\{{\cal A,A}\}) & = &
1339        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
1340\\ 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9
1341 \end{array} \right)
1342\end{array}
1343\end{math}
1344\end{flushleft}
1345
1346{\bf Related functions:}
1347
1348\hspace*{0.175in} {\tt spaugment\_columns}, {\tt spstack\_rows},
1349{\tt spsub\_matrix}.
1350
1351
1352\subsection{matrixp}
1353
1354%{\bf How to use it:}
1355
1356\hspace*{0.175in} {\tt matrixp(test\_input);}
1357
1358\hspace*{0.1in}
1359\begin{tabular}{l l l}
1360test\_input &:-& anything you like.
1361\end{tabular}
1362
1363{\bf Synopsis:} %{\bf What it does:}
1364
1365\begin{addtolength}{\leftskip}{0.22in}
1366{\tt matrixp} is a boolean function that returns t if
1367                the input is a matrix of type sparse or matrix and nil otherwise.
1368
1369\end{addtolength}
1370
1371{\bf Examples:}
1372
1373\hspace*{0.175in} {\tt matrixp}(${\cal A}$) = t
1374
1375\hspace*{0.175in} {\tt matrixp}(doodlesackbanana) = nil
1376
1377{\bf Related functions:}
1378
1379\hspace*{0.175in} {\tt squarep}, {\tt symmetricp}, {\tt sparsematp}.
1380
1381
1382\subsection{spmatrix\_stack}
1383
1384\hspace*{0.175in} see: {\tt spmatrix\_augment}.
1385
1386
1387\subsection{spminor}
1388
1389\hspace*{0.175in} {\tt spminor(${\cal A}$,r,c);}
1390
1391\hspace*{0.1in}
1392\begin{tabular}{l l l}
1393${\cal A}$ &:-& a sparse matrix. \\
1394r,c        &:-& positive integers.
1395\end{tabular}
1396
1397{\bf Synopsis:}
1398
1399\begin{addtolength}{\leftskip}{0.22in}
1400                {\tt spminor} computes the (r,c)'th minor of ${\cal A}$.
1401
1402\end{addtolength}
1403
1404{\bf Examples:}
1405
1406\begin{flushleft}
1407\hspace*{0.1in}
1408\begin{math}
1409\begin{array}{ccc}
1410{\tt spminor}({\cal A},1,3) & = &
1411        \left( \begin{array}{cc} 0 & 5 \\ 0 & 0
1412 \end{array} \right)
1413\end{array}
1414\end{math}
1415\end{flushleft}
1416
1417{\bf Related functions:}
1418
1419\hspace*{0.175in} {\tt spremove\_columns}, {\tt spremove\_rows}.
1420
1421
1422\subsection{spmult\_columns, spmult\_rows}
1423
1424\hspace*{0.175in} {\tt spmult\_columns(${\cal A}$,column\_list,expr);}
1425
1426\hspace*{0.1in}
1427\begin{tabular}{l l l}
1428${\cal A}$   &:-& a sparse matrix. \\
1429column\_list &:-& a positive integer or a list of positive integers. \\
1430expr        &:-& an algebraic expression.
1431\end{tabular}
1432
1433{\bf Synopsis:}
1434
1435\begin{addtolength}{\leftskip}{0.22in}
1436{\tt spmult\_columns} returns a copy of ${\cal A}$ in which
1437                the columns specified in column\_list have been
1438multiplied by expr.
1439
1440{\tt spmult\_rows} performs the same task on the rows of ${\cal A}$.
1441
1442\end{addtolength}
1443
1444{\bf Examples:}
1445
1446\begin{flushleft}
1447\hspace*{0.1in}
1448\begin{math}
1449\begin{array}{ccc}
1450{\tt spmult\_columns}({\cal A},\{1,3\},x) & = &
1451        \left( \begin{array}{ccc} x & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 9*x
1452 \end{array} \right)
1453\end{array}
1454\end{math}
1455\end{flushleft}
1456
1457\vspace*{0.1in}
1458
1459\begin{flushleft}
1460\hspace*{0.1in}
1461\begin{math}
1462\begin{array}{ccc}
1463{\tt spmult\_rows}({\cal A},2,10) & = &
1464        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 50 & 0 \\ 0 & 0 &
14659 \end{array} \right)
1466\end{array}
1467\end{math}
1468\end{flushleft}
1469
1470{\bf Related functions:}
1471
1472\hspace*{0.175in} {\tt spadd\_to\_columns}, {\tt spadd\_to\_rows}.
1473
1474
1475\subsection{\tt spmult\_rows}
1476
1477\hspace*{0.175in} see: {\tt spmult\_columns}.
1478
1479
1480\subsection{sppivot}
1481
1482\hspace*{0.175in} {\tt sppivot(${\cal A}$,r,c);}
1483
1484\hspace*{0.1in}
1485\begin{tabular}{l l l}
1486${\cal A}$ &:-& a sparse matrix. \\
1487r,c        &:-& positive integers such that ${\cal A}$(r,c) neq 0.
1488\end{tabular}
1489
1490{\bf Synopsis:} %{\bf What it does:}
1491
1492\begin{addtolength}{\leftskip}{0.22in}
1493{\tt sppivot} pivots ${\cal A}$ about it's (r,c)'th entry.
1494
1495To do this, multiples of the r'th row are added to every
1496     other row in the matrix.
1497
1498This means that the c'th column
1499                will be 0 except for the (r,c)'th entry.
1500
1501\end{addtolength}
1502
1503{\bf Related functions:}
1504
1505\hspace*{0.175in} {\tt sprows\_pivot}.
1506
1507
1508\subsection{sppseudo\_inverse}
1509
1510\hspace*{0.175in} {\tt sppseudo\_inverse(${\cal A}$);}
1511
1512\hspace*{0.1in}
1513\begin{tabular}{l l l}
1514${\cal A}$ &:-& a sparse matrix.
1515\end{tabular}
1516
1517{\bf Synopsis:}
1518
1519\begin{addtolength}{\leftskip}{0.22in}
1520{\tt sppseudo\_inverse}, also known as the Moore-Penrose inverse, computes
1521the pseudo inverse of ${\cal A}$.
1522
1523\end{addtolength}
1524
1525{\bf Examples:}
1526
1527\begin{flushleft}
1528\hspace*{0.175in}
1529\begin{math}
1530{\cal R} = \left( \begin{array}{cccc} 0 & 0 & 3 & 0 \\ 9 & 0 & 7 & 0
1531\end{array} \right)
1532\end{math}
1533\end{flushleft}
1534
1535\begin{flushleft}
1536\hspace*{0.1in}
1537\begin{math}
1538\begin{array}{ccc}
1539{\tt sppseudo\_inverse}({\cal R}) & = &
1540        \left( \begin{array}{cc} -0.26 & 0.11 \\ 0 & 0 \\ 0.33 & 0
1541\\ 0.25 & -0.05
1542 \end{array} \right)
1543\end{array}
1544\end{math}
1545\end{flushleft}
1546
1547{\bf Related functions:}
1548
1549\hspace*{0.175in} {\tt spsvd}.
1550
1551\subsection{spremove\_columns, spremove\_rows}
1552
1553\hspace*{0.175in} {\tt spremove\_columns(${\cal A}$,column\_list);}
1554
1555\hspace*{0.1in}
1556\begin{tabular}{l l l}
1557${\cal A}$   &:-& a sparse matrix. \\
1558column\_list &:-& either a positive integer or a list of
1559                  positive integers.
1560\end{tabular}
1561
1562{\bf Synopsis:}
1563
1564\hspace*{0.175in} {\tt spremove\_columns} removes the columns specified in
1565                column\_list from ${\cal A}$.
1566
1567\hspace*{0.175in} {\tt spremove\_rows} performs the same task on the rows
1568                of ${\cal A}$.
1569
1570{\bf Examples:}
1571
1572\begin{flushleft}
1573\hspace*{0.1in}
1574\begin{math}
1575\begin{array}{ccc}
1576{\tt spremove\_columns}({\cal A},2) & = &
1577        \left( \begin{array}{cc} 1 & 0 \\ 0 & 0 \\ 0 & 9
1578 \end{array} \right)
1579\end{array}
1580\end{math}
1581\end{flushleft}
1582
1583\vspace*{0.1in}
1584
1585\begin{flushleft}
1586\hspace*{0.1in}
1587\begin{math}
1588\begin{array}{ccc}
1589{\tt spremove\_rows}({\cal A},\{1,3\}) & = &
1590        \left( \begin{array}{ccc} 0 & 5 & 0
1591 \end{array} \right)
1592\end{array}
1593\end{math}
1594\end{flushleft}
1595
1596
1597{\bf Related functions:}
1598
1599\hspace*{0.175in} {\tt spminor}.
1600
1601
1602\subsection{spremove\_rows}
1603
1604\hspace*{0.175in} see: {\tt spremove\_columns}.
1605
1606
1607\subsection{sprow\_dim}
1608
1609\hspace{0.175in} see: {\tt spcolumn\_dim}.
1610
1611
1612\subsection{sprows\_pivot}
1613
1614\hspace*{0.175in} {\tt sprows\_pivot(${\cal A}$,r,c,\{row\_list\});}
1615
1616\hspace*{0.1in}
1617\begin{tabular}{l l l}
1618${\cal A}$ &:-& a sparse matrix. \\
1619r,c        &:-& positive integers such that ${\cal A}$(r,c) neq 0.\\
1620row\_list  &:-& positive integer or a list of positive integers.
1621\end{tabular}
1622
1623{\bf Synopsis:}
1624
1625\begin{addtolength}{\leftskip}{0.22in}
1626{\tt sprows\_pivot} performs the same task as {\tt sppivot} but applies
1627the pivot only to the rows specified in row\_list.
1628
1629\end{addtolength}
1630
1631{\bf Related functions:}
1632
1633\hspace*{0.175in} {\tt sppivot}.
1634
1635\subsection{sparsematp}
1636
1637\hspace*{0.175in} {\tt sparsematp(${\cal A}$);}
1638
1639\hspace*{0.1in}
1640\begin{tabular}{l l l}
1641${\cal A}$ &:-& a matrix.
1642\end{tabular}
1643
1644{\bf Synopsis:}
1645
1646\begin{addtolength}{\leftskip}{0.22in}
1647{\tt sparsematp} is a boolean function that returns t if
1648                the matrix is declared sparse and nil otherwise.
1649
1650\end{addtolength}
1651
1652{\bf Examples:}
1653
1654\begin{flushleft}
1655\hspace*{0.175in}
1656{\cal L}:= {\tt mat((1,2,3),(4,5,6),(7,8,9));}
1657\end{flushleft}
1658
1659\vspace*{0.1in}
1660
1661\hspace*{0.175in} {\tt sparsematp}(${\cal A}$) = t
1662
1663\hspace*{0.175in} {\tt sparsematp}(${\cal L}$) = nil
1664
1665{\bf Related functions:}
1666
1667\hspace*{0.175in} {\tt matrixp}, {\tt symmetricp}, {\tt squarep}.
1668
1669
1670\subsection{squarep}
1671
1672\hspace*{0.175in} {\tt squarep(${\cal A}$);}
1673
1674\hspace*{0.1in}
1675\begin{tabular}{l l l}
1676${\cal A}$ &:-& a matrix.
1677\end{tabular}
1678
1679{\bf Synopsis:}
1680
1681\begin{addtolength}{\leftskip}{0.22in}
1682{\tt squarep} is a boolean function that returns t if
1683                the matrix is square and nil otherwise.
1684
1685\end{addtolength}
1686
1687{\bf Examples:}
1688
1689\begin{flushleft}
1690\hspace*{0.175in}
1691\begin{math}
1692{\cal L} = \left( \begin{array}{ccc} 1 & 3 & 5
1693\end{array} \right)
1694\end{math}
1695\end{flushleft}
1696
1697\vspace*{0.1in}
1698
1699\hspace*{0.175in} {\tt squarep}(${\cal A}$) = t
1700
1701\hspace*{0.175in} {\tt squarep}(${\cal L}$) = nil
1702
1703{\bf Related functions:}
1704
1705\hspace*{0.175in} {\tt matrixp}, {\tt symmetricp}, {\tt sparsematp}.
1706
1707
1708\subsection{spstack\_rows}
1709
1710\hspace*{0.175in} see: {\tt spaugment\_columns}.
1711
1712
1713\subsection{spsub\_matrix}
1714
1715\hspace*{0.175in} {\tt spsub\_matrix(${\cal A}$,row\_list,column\_list);}
1716
1717\hspace*{0.1in}
1718\begin{tabular}{l l l}
1719${\cal A}$              &:-& a sparse matrix. \\
1720row\_list, column\_list &:-& \parbox[t]{.605\linewidth}{either a
1721positive integer or a list of positive integers.}
1722\end{tabular}
1723
1724{\bf Synopsis:}
1725
1726
1727\begin{addtolength}{\leftskip}{0.22in}
1728
1729{\tt spsub\_matrix} produces the matrix consisting of the
1730              intersection of the rows specified in row\_list and the
1731columns specified in column\_list.
1732
1733\end{addtolength}
1734
1735{\bf Examples:}
1736
1737\begin{flushleft}
1738\hspace*{0.1in}
1739\begin{math}
1740\begin{array}{ccc}
1741{\tt spsub\_matrix}({\cal A},\{1,3\},\{2,3\}) & = &
1742        \left( \begin{array}{cc} 5 & 0\\ 0 & 9
1743 \end{array} \right)
1744\end{array}
1745\end{math}
1746\end{flushleft}
1747
1748{\bf Related functions:}
1749
1750\hspace*{0.175in} {\tt spaugment\_columns}, {\tt spstack\_rows}.
1751
1752
1753\subsection{spsvd (singular value decomposition)}
1754
1755\hspace*{0.175in} {\tt spsvd(${\cal A}$);}
1756
1757\hspace*{0.1in}
1758\begin{tabular}{l l l}
1759${\cal A}$ &:-& a sparse matrix containing only numeric entries.
1760\end{tabular}
1761
1762{\bf Synopsis:} %{\bf What it does:}
1763
1764\begin{addtolength}{\leftskip}{0.22in}
1765{\tt spsvd} computes the singular value decomposition of ${\cal A}$.
1766
1767It returns \{${\cal U},\sum,{\cal V}$\} where ${\cal A} = {\cal U}
1768\sum {\cal V}^T$ and $\sum = diag(\sigma_{1}, \ldots ,\sigma_{n}). \;
1769\sigma_{i}$ for $i= (1 \ldots n)$ are the singular values of ${\cal A}$.
1770
1771
1772n is the column dimension of ${\cal A}$.
1773
1774\end{addtolength}
1775
1776{\bf Examples:}
1777
1778\begin{flushleft}
1779\hspace*{0.175in}
1780\begin{math}
1781{\cal Q} = \left( \begin{array}{cc} 1 & 0 \\ 0 & 3
1782\end{array} \right)
1783\end{math}
1784\end{flushleft}
1785
1786\begin{eqnarray}
1787\hspace*{0.1in}
1788{\tt svd({\cal Q})} & = &
1789\left\{
1790        \left( \begin{array}{cc} -1 & 0 \\ 0 & 0 \end{array} \right),
1791\left( \begin{array}{cc} 1.0 & 0 \\ 0 & 5.0 \end{array} \right),
1792\right. \nonumber \\ & & \left. \: \;
1793\, \left( \begin{array}{cc} -1 & 0 \\ 0 & -1 \end{array} \right)
1794\right\} \nonumber \end{eqnarray}
1795
1796\subsection{spswap\_columns, spswap\_rows}
1797
1798\hspace*{0.175in} {\tt spswap\_columns(${\cal A}$,c1,c2);}
1799
1800\hspace*{0.1in}
1801\begin{tabular}{l l l}
1802${\cal A}$ &:-& a sparse matrix. \\
1803c1,c1      &:-& positive integers.
1804\end{tabular}
1805
1806{\bf Synopsis:}
1807
1808\hspace*{0.175in}
1809{\tt spswap\_columns} swaps column c1 of ${\cal A}$ with column c2.
1810
1811\hspace*{0.175in} {\tt spswap\_rows} performs the same task on 2 rows of
1812                ${\cal A}$.
1813
1814{\bf Examples:}
1815
1816\begin{flushleft}
1817\hspace*{0.1in}
1818\begin{math}
1819\begin{array}{ccc}
1820{\tt spswap\_columns}({\cal A},2,3) & = &
1821        \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 0 & 5 \\ 0 & 9 & 0
1822 \end{array} \right)
1823\end{array}
1824\end{math}
1825\end{flushleft}
1826
1827{\bf Related functions:}
1828
1829\hspace*{0.175in} {\tt spswap\_entries}.
1830
1831
1832\subsection{swap\_entries}
1833
1834\hspace*{0.175in} {\tt spswap\_entries(${\cal A}$,\{r1,c1\},\{r2,c2\});}
1835
1836\hspace*{0.1in}
1837\begin{tabular}{l l l}
1838${\cal A}$  &:-& a sparse matrix. \\
1839r1,c1,r2,c2 &:-& positive integers.
1840\end{tabular}
1841
1842{\bf Synopsis:}
1843
1844\hspace*{0.175in} {\tt spswap\_entries} swaps ${\cal A}$(r1,c1) with
1845                ${\cal A}$(r2,c2).
1846
1847{\bf Examples:}
1848
1849\begin{flushleft}
1850\hspace*{0.1in}
1851\begin{math}
1852\begin{array}{ccc}
1853{\tt spswap\_entries}({\cal A},\{1,1\},\{3,3\}) & = &
1854        \left( \begin{array}{ccc} 9 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 1
1855 \end{array} \right)
1856\end{array}
1857\end{math}
1858\end{flushleft}
1859
1860{\bf Related functions:}
1861
1862\hspace*{0.175in} {\tt spswap\_columns}, {\tt spswap\_rows}.
1863
1864
1865\subsection{spswap\_rows}
1866
1867\hspace*{0.175in} see: {\tt spswap\_columns}.
1868
1869
1870\subsection{symmetricp}
1871
1872%{\bf How to use it:}
1873
1874\hspace*{0.175in} {\tt symmetricp(${\cal A}$);}
1875
1876\hspace*{0.1in}
1877\begin{tabular}{l l l}
1878${\cal A}$ &:-& a matrix.
1879\end{tabular}
1880
1881{\bf Synopsis:} %{\bf What it does:}
1882
1883\begin{addtolength}{\leftskip}{0.22in}
1884{\tt symmetricp} is a boolean function that returns t if the
1885                matrix is symmetric and nil otherwise.
1886
1887\end{addtolength}
1888
1889{\bf Examples:}
1890
1891\begin{flushleft}
1892\hspace*{0.175in}
1893\begin{math}
1894{\cal M} = \left( \begin{array}{cc} 1 & 2 \\ 3 & 4
1895\end{array} \right)
1896\end{math}
1897\end{flushleft}
1898
1899\vspace*{0.1in}
1900
1901\hspace*{0.175in} {\tt symmetricp}(${\cal A}$) = t
1902
1903\hspace*{0.175in} {\tt symmetricp}(${\cal M}$) = nil
1904
1905{\bf Related functions:}
1906
1907\hspace*{0.175in} {\tt matrixp}, {\tt squarep}, {\tt sparsematp}.
1908
1909\section{Fast Linear Algebra}
1910
1911By turning the {\tt fast\_la} switch on, the speed of the following
1912functions will be increased:
1913
1914\begin{tabular}{l l l l}
1915spadd\_columns    & spadd\_rows      & spaugment\_columns & spcol\_dim  \\
1916spcopy\_into      & spmake\_identity & spmatrix\_augment  & spmatrix\_stack\\
1917spminor           & spmult\_column   &  spmult\_row       & sppivot        \\
1918spremove\_columns & spremove\_rows   & sprows\_pivot      & squarep      \\
1919spstack\_rows     & spsub\_matrix    & spswap\_columns    & spswap\_entries\\
1920spswap\_rows      & symmetricp
1921\end{tabular}
1922
1923The increase in speed will be insignificant unless you are making a
1924significant number(i.e: thousands) of calls. When using this switch,
1925error checking is minimised. This means that illegal input may give
1926strange error messages. Beware.
1927
1928\section{Acknowledgments}
1929This package is an extention of the code from the Linear Algebra Package
1930for \REDUCE{} by Matt Rebbeck[1].
1931
1932The algorithms for {\tt spcholesky}, {\tt splu\_decom}, and {\tt spsvd} are
1933taken from the book Linear Algebra - J.H. Wilkinson \& C. Reinsch[3].
1934
1935The {\tt spgram\_schmidt} code comes from Karin Gatermann's Symmetry
1936package[4] for {\REDUCE}.
1937
1938
1939\begin{thebibliography}{}
1940\bibitem{matt} Matt Rebbeck: A Linear Algebra Package for {\REDUCE}, ZIB
1941, Berlin. (1994)
1942\bibitem{Reduce} Anthony C. Hearn: {\REDUCE} User's Manual 3.6.
1943	RAND (1995)
1944\bibitem{WiRe} J. H. Wilkinson \& C. Reinsch: Linear Algebra
1945(volume II). Springer-Verlag (1971)
1946\bibitem{gat} Karin Gatermann: Symmetry: A {\REDUCE} package for the
1947computation of linear representations of groups. ZIB, Berlin. (1992)
1948\end{thebibliography}
1949
1950\end{document}
1951