23
OBJECT-ORIENTED DESIGN IN NUMERICAL LINEAR ALGEBRA by John Alan McDonald TECHNICAL REPORT No. 109 September 1987 Department of Statistics, GN-22 University of Washington Seattle, Washington 98195 USA

OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

OBJECT-ORIENTED DESIGN IN NUMERICAL LINEAR ALGEBRA

by

John Alan McDonald

TECHNICAL REPORT No. 109

September 1987

Department of Statistics, GN-22

University of Washington

Seattle, Washington 98195 USA

Page 2: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

Object-oriented designin numerical linear algebra. *

JOHN ALAN McDoNALDDept. of Statistics, University of Washington

September.6, 1981

Abstract

Straightforward application of object-oriented design to standardalgorithms in numerical linear algebra improves clarity and expres­siveness, without sacrificing speed or accuracy.

of Na.val undeI' Young Investiga.torunder contract FG0685-ER2500.

1

Page 3: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

1 . INTRODUCTION

1 Introduction

2

The underlying premise of this paper is that quantitative, scientific com­puting needs and deserves good programming languages and programmingeavironments-e-aa much as artificial intelligence.

I hope to show how straightforward application of object-oriented designto standard algorithms in numerical analysis yields immense improvement inclarity, without sacrificing speed or accuracy. My example is an elementaryproblem from numerical linear algebra-e-solving systems of linear equationsvia. ga9-ssian elimination. I will use a linear alg~bra syst~m called Cactus,whichisinlplelllented in Common Lppps[~,3J, an object-oriented extensipnof C0mIn<>n. Lisp[141.

Objec~-orientedprogJCa.rnmingissometimessaidto only be usefuL forgraphicsliJ1d user interface and, perhaps al$p,knowledgerepresentationanddatabase management. Even Lisp machine manufacturers seem to think thatFortran is somehow superior for traditional, quantitative scientific comput­ing. When numerical software is written in Lisp (eg. (121), the author usuallyadopts a Fortran or Algol style and neglects the potential for designing moreappropriate abstractions[1j.

Cactus is based on a collection of linear transformation classes and appro­priate generic operations. This level of abstraction greatly simplifies manyalgorithms innuIIl7rical.linear,lge~ra. 1'r~itional li1l~aralgebrasysteInS

(I.in:p~c~[~I,~L).p:pel',teat.• the ·1~~el~fa.rl',y~aI1dcon.founli the deta.ils.ofwhere data. is kept with· how>itismeanttobeused.

I am developing Cactus primarily as a building block of a Lisp-based sci­entific c0m.:putingenvironm.ent.Inadditipn, I hope that it wi1l1ealitpmoreserious consideration·. for.nl1mericalcomputing •in Lisp (and Smalltalk[7],etc. )andhelptpput•••to .rest •the notion of coupled systems, wheresym­belie computing is done in Lisp an~Sc::i<>tls~u.IIl7ricalt?m.:p}lti1lgi~4(.)ne

in •••• anotherlanglla.ge()reveD.0na.np~herma.chine). /Theiliea ••of .c<>ll.pledsystems arises because, although existing Lisp environments have much. tooffer scientific computing, they have twp serious deficiencies when comparedto more traditional environments [eg. Unix plus C and Fortran):

• No analogs of numerical subroutine libraries like Linpack, Eispack, etc.

• Poor pelrtO]~mll.nc:e

complex numbers.arithmetic, especially doub;le p:rec:tslc.n or

Page 4: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

2' A SIMPLE PROBLEM 3

Building collections of basic numerical software should be done by ex­perts, which requires convincing· numerical analysts that there are suJtti<::lelltadvantages that it is worth re-implementing (and re-designing!) the existingsubroutine libraries. However, I will present the case to numerical analystsin another paper.

This paper is instead aimed at the designers and implementors of object­oriented programming systems. One purpose is to convince them to provideefficient arithmetic. But perhaps more interesting is the fact that linearalgebra is a fairly novel domain for object-oriented programming. As a re­sult, Cactus provides\another perspective on what'siD:lportant in an object­orientf:ld progr~mrnin{1;systetn' Inparticula.r, nUD:lf:lricallinear algebra re..quil'f:lss()D:le of the relativelyunusua.lfeaturf:lsof C0D:lD:lon Loops-includingmetliodsthatdispatchonseveralar{1;lItnen~,changingor modifying theclass\of an existing instance, and specialized method combination rules­which are missing or less well supported in older object-oriented languageslike Smalltalk or Flavors{lO,llJ.

This paper assumes the reader is familiar with Lisp and object-orientedprogramming, specifically as embodied in Common Loops. I will review, inpassing, some elementary numerical linear algebra.

2 A simple problem

Suppose

is a linear transformation, b E 1<.17\ and we want to solve for x E 1<.n suchthat:

Ax=b.

Atn<t.tlietna.ticiaJl WQ~l1dprobablyviewthis as a.ive<:tor equation. If.......to makethings easy........we.assume that A is square and invertible, then the obvious,naive solution is to invert A and apply it to b:

Unfortunately, this isn't such a good idea in floating point arithmetic{5,8,15J.The problem we can approximation A-I. For someA's,

Page 5: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

2· A SIMPLE PROBLEM

[setf a #2a((2.0 3.0e6 9.0e6 1.0e6)(8.03.0e62.0e61.0e6)(2.0 9.0e61.0e6 1.0e6)(3.0 5.0e6 7.0e6 9.0e6)))

(setf x #(0.0 1.0 100.0 10000.0))

[setf b (matrix-multiply a x))

(setf a-I (matrix-inverse a))

(setfx-tilde (matrix-multi.plya-l b))

x-tilde - #(-64.00.9993286100.00006 10000.002)

Figure 1: An example of unstable inversion.

4

Page 6: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

2 A SIMPLE PROBLEM 5

maybe be far from the true solution z, See figure 1 for an example.

To get reliable solutions, every numerical linear algebra text recom­mends:

• Avoid computing inverses.

• Think in terms of solving a system of linear scalar equations, ratherthan a single vector equation. (Linpack is described not as a linearalgebra package, but as "a collection of Fortran subroutines which an­alyze and solve various systems of simultaneous linear equations."[5J)

• Notice that we can di17ectlyspecial structure:

If U is upper triangular (Ui,; is zero

linear equations with

then

Un-l,n-lXn-l + Un-1,nXn = bn-l,

and so on, which means that we can first solve for X n and substituteit in the second equation to get Xn-l and so on. This is called backsubstitution.

If L is lower triangular (Li,i is zero if j > i), then we can solve Le = bwith a similar forward elimination.

• If we can decompose A4LU, then we can solve Ax -bin two steps,first solving Ly = b and then Ux = y.

• Then the problem is to find an accurate and efficient way to carry outthe LU decomposition.

The usual recommendation is to use gaussian elimination with. partialpivoting. The "partial pivoting" is introduced to improve numericalstability. Instead of the simple LU decomposition, we get somethinga bit more complicated:

A -+ (POGOP1G1 . . • PnGnUJ.

where the PIli'S are pivot transformations (permutations)are triangular (gau~) traLnsforma.tic~ns.

to

Pili and Gill can be solved more directly.

Page 7: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

2' A SIMPLE PROBLEM 6

(multiple-value-setq (p lu) (Iu-decomposition a»

p -+ ~(1 203)lu -+ #2A((0.25 0.21212128 8363636.5 545454.56)

(8.0 3000000.0 2000000.0 1000000.0)(0.25 8250000.0 500000.0 150000.0)(0.3150.469696910.11920291880435.0»

(Iu-solveplu\b) -+#(0.0 0.9999295 100.00001510000.0)

.. The true answer:x #(0.0 1.0000000 100.000000 10000.0)

Figure 2: Using a Fortran-style LU decomposition.

In addition to improved numerical stability, this approach is 2-3 times as fastas explicitly computing the inverse matrix and then using matrix multiply toapply it to b (because computing the inverse matrix is equivalent to solvingseveral systems of equations).

2 shows what happens when we use an LU decomposition on1. is expressed in Lisp, it has

cQI'reslpond:i.ng Fortran routines in Linpack.)

answer, we may be troubled by

• p is pel~mll1ta,tion vector that corresponds to the composition of thePh'S. Pk'sin<this way relies on subtleties in the waythey are ('(UllltT:1'll("!:l:!('! and related to the Gh'S.

Page 8: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

3 . WHAT'S WRONG WITH THIS?

used to construct the Gauss matrices G,,:

7

(e" is the kth canonical basis vector of ,.en. lu-sclve uses the ale'sdirectly and never explicitly forms the corresponding G".

3 What's wrong with this?

There are two problems with even the best Fortran subroutine libraries (likeLinpack):

• It is difficult to modify a routine like lu-decomposition to produce some­thing slightly different.

• It is difficult to use the results of lu-decomposition in a way that'sdifferent from what the designer intended.

Both cases require understanding how the contents of the two arrays, p andlu are meant to be interpreted. This information is buried in the code forlu-decomposition and In-solve. Understanding the code for an LU decompo­sition requires following a trail that starts with a abstract, often geometric,overvie\V.•·in.a nU.Illerical analy~is.text,~4rough.· a fairly -clean "implemen­tation" in.AlgQI-like pseudo-code,tofinally the dirty realities of FortranIV control structures and parameter passing tricks. Information about themeaning of what going on is stripped out at each stage. The final Fortranprogram has very little resemblance to the abstract description we startedwith.

Of course, Linpack, Eispack, etc. were never intended to be anythingelse otll.~r tll.l:!!Jl,kitsQfblack boxes. One sometimes hears the argument thatnumerical linear algebra is sufficiently well understood that there is neverreason to modify the existing libraries. Even if this were true for linearalgebra, it's definitely not the case for important applications of linear alge­bra, like optimization or statistical data analysis, and that require adjusting,tuning, modifying, or re-building alg.orithms for each specific problem.

Page 9: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

-4 LINEAR TRANSFORMATIONS

4 Linear transformations

8

The primary reason why traditional numerical packages are difficult to mod­ify is that they are not written at the right level abstraction (which unavoid­able when working in Fortran). In the case of linear algebra this means thefailure to distinguish the abstract notion of a linear trans/ormation [9j fromits concrete representation as an array or some part of an array.

By definition, A is a linear trans/ormation taking R n f--l. R m, if, for allx, y E Rn and a, bE R,

A(ax+ by) = aAx+ bAy.

A machine representation of a linear transformation must provide an encod­ing of its state and methods for essential operations:

• Transformation of a vector: Ax = 11.

• Scalar multiplication: (aA)x = A(ax).

• Sum: (A+B)x=Ax+Bx.

• Composition: (AB)x = A(Bx).

Although "matrix algebra" is often used interchangeably with "linearalgebra," in algorithms like the LU decomposition, matrices serve only as astorage mechanism, and an inconsistantly used storage mechanism at that.The canonical representation of a linear transformation is the matrix ofits elements (in the canonical basis for Rn) and the composition method,for example, is matrix multiply. However, some linear transformations arebetter served by an alternate representation. The key entities in an LUdecomposition are all linear transformations, but not all are matrices:

• A is represented by the matrix a.

• U is represented by the upper triangle of lu.

• Gle is represented by the sub-columns of lu.

• Pie is represented by p.

Page 10: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

5 IMPLEMENTATION IN COMMON LOOPS 9

The natural way to solve Ax = 0, is using an inverse: x+- A-Io (assum­ing, again to make things easy, that A is both square and invertible). It isbad practice to do this if both A and A-I must be matrices, but that's nolonger true ifwe can represent by an instance of an appropriate Inverse­Transformation class. The state of A-I would be represented by somethingequivalent to the lu and p produced by lu-decemposition and A-l>s methodfor transforming a vector would be equivalent to In-solve.

5 Implementatdon in Common Loops

Cactus dealsionly<with transformations froIl1 ;Zn ...... ;zm. Linear tJ:'~mstol~­

mations are represented in Cactus by instances of a Common Loops lineartransfor:r:n.ation •.class.

Two examples of simple linear transformation classes are given in fig­ure 3. All linear transformation classes inherit from the abstract class Linear­Transformation, which establishes a common protocol and default methods.The Matrix-Transformation class provides the canonical representation, inessence just wrapping a Common Loops object around a two-dimensionalCommon Lisp array kept in the matrix slot. Upper-Triangular-Transformationinherits the matrix slot from Matrix-Transformation, but its methods assumethat the subdiagonal elements are zero to save roughly half the work intypic~o~erations.

Vectqrsarerepresented in Cactus by one-dimensional Common LiSp ar­rays of numbers.

The algebra of linear transformations on a vector space requires fouroperations:sclilar multiply,vector transform, compose, and sum. The.firstthree areirepresented by a< generic multiply function: muL The sum oflinear transformatio.ns is represe~7ed bythe~eneri<:funftion:~um.~i~llre4

comPlires.themetltqdsfor.trlinlJforrninga.vector, which lire.identical, exceptthat the inner loop for Upper-Triangular-Transformation avoids unnecessarymultiplies and adds of o. (The iterations are expressed using the LOOPmacro of Burke and Moon[4J.)

In Cactus, we can solve an equation like Ax = 0, not .as a system of linearequations, a vector square

dotransformation class. 1.

Page 11: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

5' IMPLEMENTATION IN COMMON LOOPS

(defclass Matrix.Transformation

:: super classes(linear.Transformation)

;; slots(matrix))

(defclass Upper.Triangular-Transformation

;; super classes(Matrix·Transformation)

;; slots(»

Figure 3: Two simple transformation classes

10

Page 12: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

5· IMPLEMENTATION IN COMMON LOOPS 11

siIl1lple classes.

from! below (domain tr)(* (aref m i j) (aref v j»))

for i from 0 below (range tr]do

(loop with r - (make-array (range tr»with m (matrix tr)for i from 0 below (range tr)do (setf (aref r i)

(loop for j from 0 below (domain tr]sum (* (ar-;f m i j) (aref v j»»

finally (return r»))

(defmethod mul ((tr Matrix-Transformation)(v Vector»

(defmethod mul «tr Upper-Triangular-Transformation)(v Vector» .

Page 13: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

x

5 IMPLEMENTATION IN OOMMON LOOPS

(setf ta (make-instance 'Matrix-Transformation :matrix a»(setf ta-I (inverse tan

(mul ta-I b) -+ #(0.00.9999205 100.000015 10000.0)

-+ #(0.0 1.0000000 100.00000 10000.0)

(defclass Inverse-Transformation :: an abstract class

:: super classes(linear-Transformation)

:: slots(sire»

Figure 6: An abstract inverse class.

12

The key point is the existance of the generic inverse function, which returnsan inverse object appropriate for the type of transformation being inverted,

All inverse transformation classes inherit from the abstract class Inverse­Transformation (see figure 6). Inverse-Transformation provides one slot, namedsire, which points to the transformation whose inverse

con-

So an instance Inverse-of-Upper-Triangular is eS~lentiaHy

Page 14: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

[defclass inverse-of-Upper-Triangular

Figure 7: An instantiable inverse class.

13

Inverse-of-Upiper-Triangular)Unit-list list))

;; super classes(Inverse-Transformation)

make-ilnsl:anl:e .J,nvE:rse-ot··Up,per'-Tl'jangular :sire self»

;; slots

(setf (sire

(defmethod initialj;ze

(defmetbod inverse «self Upper-Triangular-Transformation»

5- IMPLEMENTATION IN COMMON LOOPS

Page 15: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

s IMPLEMENTATION IN COMMON LOOPS

[defmethod mul «tr Inverse-of-Upper-Triangular)(v Vector»

(loop with r = (make-array (range tr))with u = (matrix (sire tr))with n = (domain tr)

fr<:>m (+ i 1) below nsum (* (aref u i j) (aref r j))))

(aref u i i»))

finally (return r»))

14

inv'ersle of upper triangular is back sub-

makes it an inversemethOiq 011"'VYU in figure 8, which uses

partIal pivoting the tactormg ISgaussian eIlllliIlatj[on

so that

A

how to rep.resent inver~~sof

Page 16: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

5 IMPLEMENTATION IN COMMON LOOPS

[defdass Inverse-of-Matrix-Transformation

:: super classes(Inverse-Transformation)

.: slots[u-inversel-factors] )

(defmethod mul «trlnverse-of-Matrix-Transformation)(v Vector»

(loop with r = (make-array (range tr»for factor in [l-factors tr)do (mul! factor r)finally (return (mul! [u-inverse tr) r»)

)

15

Figure 9: inverse class for general matrix transformations.

The fnverse-of-Matrix-Transformation class is shown in figure 9. It pro­vides two slots, one to hold the inverse oLthe upper triangular factor andanother to hold a list of the inverses of the gauss and pivot factors. The mulme.thod isalso<~own .•• ItsimpIYiiterates over the factors, .usiIlgthegellericmull function to destructively modify the result vector, r, without allocatingtemporary vectors at each iteration. (This strategy only works in situationswhere all the factors are square.)

The actllalfactormg is done by the initialize method for Inverse-of-Matrix-Transformation, as shown in 10. is iterative. At theithstep a pivot transformation chosen rows of (to

Page 17: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

6 Implications

Although I have only dls,cussed. a Q~Uj::,~"" somewhat simplified Ihope to have made a is a natural domain

improve the numerical stability of the next step):

A~ +- PiAt-I'

Then a gauss transformation is chosen to zero the sub-diagonal elements ofthe ith column of A~:

16

A· - G ·A~. ..'Each Pi and Gi affect only the lower right (n - i + 1) x (n - i + 1) block ofAt. At the end, U +- A n- 1 is upper triangular. The chosen Pi's and Gi'sare actually the inverses of the factors of A, so they can be collected directlyin a list of the factors of A -1.

The actual implementation, shown in figure 10, differs from the descrip­tion in one significant way. We don't wish to allocate two new linear trans­formation objects at each step (to hold A~ and Ai) so we use mul!, whichoverwrites its second argument, to destructively convert a copy of the orig­inal A to triangular form.

A the end of the iteration, u is a Matrix-Transformation whose sub­diagonal elements are zero. To get the right kind of inverse, we need u tobean Upper-Triangular-Transformation. Fortunately, Common Loops allowsus to change the class of the existing instance u.

This implementation is almost as efficient as the carefully coded Fortranversion in Linpack, which uses subtle knowledge of where zeros are to savespace and avoid zero adds and multiplies at each step of the iteration. TheCactus version gets similar savings in space and time in a more modular way.Every class is responsible for providing its instances with information thatallows them to be used efficiently and every method (for mul for example)is responsible for using that information appropriately. For example, mulmethods for Gauss-Transformation take advantage of implicit block structureto save time. An implementor of a decomposition can assume that opera­tions between pre-defined transformation classes will be efficient and canignore internal details. For example, we can expect to get an efficient QRdecomposition (which is be a better choice than LU when A is not square) bysimply replacing Gauss-Transformation's with Householder-Transformation'sand need not worry about how internal details differ.

8 IMPLICATIONS

Page 18: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

6' IMPLICATIONS

(defmethod initialize «self Inverse-of-Matrix-Transformation)(init-list list))

(setf (sire self) (getf init-list :sire))

(loop with u =(copy self)with gwith p

for i from 0 below (- (range self) 1)do (setf p (choose-pivot-transformation u i»

(mul! p u)(setf g (choose-gauss-transformation u i))(mul! g u)

collect p. into l-facscollect g into l-facs

17

finally[change-class u [class-named 'Upper-Triangular-Transformation»(setf (u-inverse self) (inverse u)(setf (I-factors self) I-facs»))

Figure 10: Gaussian elimination with partial pivoting,

Page 19: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

6- IMPLICATIONS 18

for object-oriented programming. It seems reasonable to expect similar valuein other numerical problems, like optimization, differential equations, andstatistical data analysis.

A full understanding of the implications of numerical computing for thedesign of objeet-oriented programming systems requires a more completeimplementation than the current version of Cactus. However some pointsare already clear.

6.1 A large class lattice

A comprehensive linear algebra system would contain a surprisingly largenumber of classes-whose relationships may not be completely modeled byan inheritance lattice. To get a rough estimate of how many classes theremight be, we can list several groups:

• Storage classes determine the Common Lisp data structures used tohold the state of the transformation, like Matrix. Vector. list-of-Vectors.and so on.

• Sparsity classes describe a patterns of zeros and/or other constantswithin a given storage class. For example, Upper-Triangular-Transformationasserts that all sub-diagonal elements of a matrix are zero,which is.irnp()rtan.t to/know. in .mulorinverse.

• AsSertion· classes declare··that their ttallsformations a certainproperty that is important in choosing the algorithm for one or moremethods. Some assertions are easy to verify once, like Symmetric, butexpensive to verifyrepea.tedly. Others are difficult to verify directlybut may beknownfroDJ ()utside inforD.1ationor deduced from the waythe transform is created, Iike.Positive-Definite.

• Elementary transformations are created for of composingwith a particular instance, like Gauss, Householder, Givens[81trans­forrna.tions that are used in various triangularization algorithms.

• Inverse-Transformation is an eXlil.J:llple of classes whose instance have aspecial and need tochange sire chl!ln~:es.

Page 20: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

6- IMPLICATIONS 19

• A general algebraic expression class represents a linear transformationas the sums and products of other transformations. Most of Linpackand Eispack are devoted to replacing linear transformations by equiv­alent algebraic expressions in transformations that are easier to dealwith. For example, inverse replaces a Matrix-Transformation by a prod­uct of transformations that are individually easy to invert. It would bevery useful for the system to be able to deduce properties of an expres­sion from the properties of its components, ego the sum of symmetrictransformations is symmetric.

• Other expression classe$involveoperations like direct sum andquotient[9Jtha.t<;orrespolld to block structure in matrices.

• If we have an explicit repJ,'esentati()n ofrnClre abstract vector spacesthaniRn, then. we have the possibility of linear transformation classesthat are distinguished by their range and domain spaces.

Simply counting up all possible mixtures of classes like PositiveDefinite­Square-Symmetric-Tridiagonal-Matrix leads to hundreds, if not thousands ofclasses.

The potential complexity of the class lattice is intimidating and mightlead one to prefer the simplicity of two-dimensional arrays. However, thatapparent simpli~ity isrrti~leadingj a. system like Linpack mustdeal.'Vith asmanytypesQflineartra.llsf0l"~atiClnsasano1:>je<;t-oriented systern' TheoIllydiffeJ,'ence isthat,inFCll"tran, theexistance of the types and the methodsfor using them are implicit in the code, rather than explicitly represented indefctass'a and defmethod's.

A key issue in further development is designing a minimal and sufficientclass lattice.15ven so, .there are likely to be more possible classes thenthere are instances at any tim.e. ltrzright conc~i~~bly ~e. useflll .. t() provi~e

automaticgen~rationofrnixture classes, which raises the issue of how touse the logical, mathematical structure relating the classes. For example,asking the system to produce a class the inherits from both Triangular andSymmetric ought to produce a Diagonal-Transformation class.

6.2 Multi-methods

The key in linear algebra mul and sum) d1S.pa1~ch on 2or 3 arguments. The ability to dlSpal~ch on multiple ar~~UInelt1ts is one of

Page 21: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

REFERENCES 20

the more between Common Loops and most otherobject-oriented languages.

Because of the large number of classes there may be as many as 104- 106

distinct methods for a given generic function like mul. Good programmingtools are vital for merely keeping track, for example, of all the mul meth­ods that have an Triangular-Transformation as one of their arguments. Inparticular we want to take advantage of any possible shortcuts for filling inmethod tables. Using class inheritance to provide defaults and more gener­ally coercing a transformation to another class are traditional tecaniquesjl].There are also possibilities for using sophisticated method combination rulesto logicaUycieduceithe correct method.

6.3 Changing classes

The Change-class operation provided in Common Loops is a natural opera­tion for linear algebra. It is the implicit paradigm underlying Linpaek andEispack: replace a given representation of a linear transformation by an al­ternative that's more suitable. Change-class preserves "eq-ness," which is aclose analogy to Linpack, where the original matrix is usually overwritten byits decomposition. Eq-ness preservation is essential if we allow destructivemodification of the state of linear transformations, which is unavoidable, atleast. for the largest probleIIlS. Changing asingle IIlatJ,"ix element.may als.ocausealin~ar ii. transfor~~tionto gaini"J,"I"se •• pr"peJ,"ti~s ••likesy~etryorpositive-definiteness, which should. be reflected in the. dass of the transfor­mation.

References

[I} ABELSON, H., SUSSMAN, G., AND SUSSMAN, J.(1985)Structure and Interpretation of Computer Programs. MIT Press, Cam­bridge, Mass.

[2} BOBROW, D.G.,STEFIK, M., ANDOOMMONLOOPS:

KAHN, K., KICZALES, G., MASINTER, L.,F. (1985)

object-orientedXerox

Page 22: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

REFERENCES 21

[3} BOBROW, D.G., KAHN, K., KICZALES, G., MASINTER, L.,STE.FIK, M., and ZDYBEL, F. (1986)Oommonboop«: Merging Lisp and Object-Oriented Programming, Pro­ceedings OOPSLA'S6 (SIGPLAN Notices 21: 11 p. 17-29).

[4} BURKE, G. and MOON, D. (1981)LOOP Iteration Macro, MIT LCS TM-169.

[5} DONGARRA, J.J., MOLER, C.B., BUNCH, J .R., and STEWART,G. W. (1979)UNPACK Users' Guide. SIAM, Philiadelphia.

[6} GARBOW, B.S., BOYLE, J.M., DONGARRA, J.J., and MOLER,C.B. (1977)Matrix Eigensystem Routines-EISPACK Guide Extension, Springer­Verlag, Berlin.

[7} GOLDBERG, A. and ROBSON, D. (1983b)Smalltalk-SO, The Language and Its Implementation. Addison-Wesley,Reading, Mass.

[8} GOLUB, G.H. and VAN LOAN, C.F. (1983)Matrix Computations, The Johns Hopkins UNiversity Press, Baltimore.

[9} HALMOS, P.R. (1958)Finite-dimensional Vector Spaces, VanNostrand, Princeton, New Jersey.

[10} KEENE, S.E., and MOON, D.A. (1985)Flavors: Object-oriented programming on Symbolics computers, pre­sentedat the Common Lisp Conference, Boston, Ma., December 1985jSymbolics Ine., 11 Cambridge Center, Cambridge, Ma. 02142.

[11} MOON D .A. (1986)Object"'Oriented Program;f1jinwith Flavors, Proceedings OOPSLA'S6(SIGPLAN Notices 21: 11 p. 1-8).

[12} ROYLANCE, G. (1984)Some Scientific Subroutines in Lisp, MIT AI Memo 774.

SMITH, a.r., BOYLE, J.M., DONGARRA, J.J., GARBOW,B.S., Y., KLEMA, .C. and MOLER, C.B. (1976)Matrix Eigensystem Routines-EISPACK Guide, 2nd Edition, Springer­Verlag, Ol::r·ll11.

Page 23: OBJECT-ORIENTEDDESIGN IN NUMERICAL LINEAR ALGEBRA · 2017-09-01 · Object-orienteddesign in numerical linear algebra. * JOHN ALAN McDoNALD Dept. of Statistics, University of Washington

REFERENCES

[14] STEELE, G .L. (1984)Common Lisp. The Language. Digital Press.

[15] STEWART, G. W . (1973)Introduction to Matrix Computations. Academic Press, New York.

22