10.07.2015 Views

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

212 van Wijngaarden, et el./ALGOL <strong>68</strong> Revised Report21311.7. Determinant of a matrixproc det = (ref [,] real x, ref [ ] int p) real :ifref [,] reala =x [@ I, @ i ];1 upba=2upba ^ 1 upba=upbp-lwbp+lthen int n = 1 upb a;¢ the determinant of the square matrix 'a' of order 'n' by themethod of Crout with row interchanges: 'a' is replaced by itstriangular decomposition, l x u, with all u [k, k] = 1. Thevector 'p' gives as output the pivotal row indices; the k-thpivot is chosen in the k-th column of 'l' such thatabs l [i, k] / row norm is maximal ¢[1 : n] real v; real d : = 1, s, pivot;for i to n do v [i] := norm (a [ i, ]) od;fork tondo int kl = k - 1; refintpk =p [@ 1 ] [k]; real r := -1;ref[,] realal=a [, I : kl ], au=a [1 : kl, ];ref [ ] real ak = a [ k, ], ka = a [, k ], alk = al [ k, ], kau = au [, k ];for i from k to ndo ref real aik = ka [ i ];if (s := abs (aik -: = innerproduct 2 (al [ i, ], kau)) / v [ i ]) > rthen r := s; pk :=iflod;v [pk] := v [k]; pivot := ka [pk]; ref [ ] real apk = a [pk, ];for j to ndo ref real akj = ak [j], apkj = apk [j];r : = akj;akj : = if j ~ k then apkjelse (apkj - innerproduct 2 (alk, au [ ,j])) / pivot fl;if pk ~ k then apkj : = - r fifiod;d x: = pivotod;dA call using det:det (y2, il)11.8. Greatest common divisorproc gcd = (int a, b) int :¢ the greatest common divisor of two integers ¢(b = 0 ] abs a I gcd (b, a mod b))A call using gcd:gcd (n, 124)11.9. Continued fractionop / = ([ ] real a, [ ] real b) real :¢ the value of a / b is that of the continued fractional /(bl +a2/(b2+... an / bn)...) ¢if Iwb a = I ^ Iwb b = 1 a upb a = upb bthen(upba=OlOI a [1]/(b [1] +a [2: ]/b [2: ]))fiA formula using/:xl / yl{The use of recursion may often be elegant rather than efficient as inthe recursive procedure 11.8 and the recursive operation 11.9. See,however, 11.10 and 11.13 for examples in which recursion is of theessence.}11.10. Formula manipulationbeginmode form = union (tel const, ref var, ref triple, ref cell);mode const = struct (reel value);mode var = struct (string name, real value);mode triple = struct (form left operand, int operator,form right operand);mode function = struct (ref car bound car, form body);mode call = slruct (ref function function name, form parameter);intplus = 1, minus = 2, times = 3, by = 4, to = 5;heap const zero, one; value of zero := O; value of one : = 1;op = = (form a, ref const b) bool : (a I (ref const ec): ec : =: b I false);op + = (form a, b) form :(a = zero I b I: b = zero I a I heap triple : = (a, plus, b));op - = (form a, b) form : (b = zero I a I heap triple : = (a, minus, b));op x = (form a, b) form : (a = zero v b = zero I zero I: a = one I b I: b = one l a Iheap triple : = (a, times, b));op / = (form a, b) form : (a = zero ^ - (b = zero) J zero I: b = one l a Jheap triple := (a, by, b));op ! = (form a, ref const b) form:(a = one v (b : =: zero) I one J : b : =: one I a I heap triple : = (a, to, b));proc derivative of = (form e, ¢ with respect to ¢ ref car x) form :case e in(ref const): zero,(refvarev): (ev :=: x Jonelzero),(ref triple et):case form u = left operand of et, v = right operand of et;form udash = derivative of(u, ¢ with respect to ¢ x),vdash = derivative of(u, ¢ with respect to ¢ x);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!