210 van Wijngaarden, et al.!ALGOL <strong>68</strong> Revised Report211endif x >_ O then rp .L ip else abs ip .L (y >-01 rp l - rp) fiCalls {5.4.3} using compsqrt:compsqrt (w)compsqrt (-3.14)compsqrt (-1)11.2. Innerproduct 1proc innerproduct I = (int n, proc (int) real x, y) real :¢ the innerproduct of two vectors, each with 'n' comppnents, x (i),y (i), i = 1 ..... n, where 'x' and 'y' are arbitrary mappings frominteger to real number ¢begin long real s : = long O;for i ton do s + : = leng x (i) x leng y (i) od;shorten sendReal-calls using innerproduct 1:innerproduct I (m, (intj) real : xl [j], (intj) real : yl [j])innerproduct I (n, nsin, ncos)11.3. Innerproduct 2proc innerproduct 2 = (ref [ ] real a, b) real :if upb a - Iwb a = upb b - Iwb bthen ¢ the innerproduct of two vectors 'a' and 'b' with equal numbersof elements ¢long real s : = long O;ref[ ] realal =a [@I], bl =b [@•];¢ note that the bounds of 'a [@ 1 ]' are [1 : upb a - Iwb a + 1 ] ¢for i to upb al do s +: = leng al [i] x leng b l [i] od;flshorten sReal-calls using innerproduct2:innerproduct 2 (xl, yl)innerproduct 2 (y2 [2, ], y2 [ ,3 ])begin y := - 1;for p from I Iwb a to I upb aenddoodfor q from 2 Iwb a to 2 upb adoifabsa [p, q] > y then y := abs a [i := p, k := q] flodCalls using absmax:absmax (x2, x, i, j)absmax (x2, x, Ioc int, Ioc int)11.5. Euler summationproc euler = (proc (int) real f, real eps, int tim) real :¢ the sum for 'i' from 1 to infinity of 'f(i)', computed by means ofa suitably refined Euler transformation. The summation isterminated when the absolute values of the terms of thetransformed series are found to be less than 'eps' 'tim' times insuccession. This transformation is particularly efficient in thecase of a slowly convergent or divergent alternating series ¢begin int n : = l, t; real mn, ds : = eps; [1 : 16]realm;realsum := (m [1] :=f(1)) /2;for i from 2 while (t := (abs ds < eps ] t + 111)) ~ timdo mn : = f(/kfork to n do mn := ((ds := mn) + m [ k ]) / 2; m [k] := ds od;sum +: = (ds := (abs mn < abs m In] ^ n < 16 f n +: = 1; m In] := mn;mn / 21 mn))od;sumendA call using euler:euler ((int i) real : (odd i j - 1 / i ] 1 / i), 11o-5, 2)11.6. The norm of a vector11.4. Largest elementproc absmax = (ref [, ] real a, ¢ result ¢ ref real y,¢ subscripts ¢ refint i, k) void :¢ the absolute value of the element of greatest absolute value ofthe matrix 'a' is assigned to 'y', and the subscripts of this elementto 'i' and 'k'¢proc norm = (ref [ ] real a) real :¢ the euclidean norm of the vector 'a' ¢(long real s : = long O;fork from lwb a to upb a do s + : = leng a [k]shorten long sqrt (s))For a use of norm in a call, see 11.7.! 2 od;
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);
- Page 2 and 3:
van Wijngaarden, et al.1.1.4.2. Par
- Page 4:
Acknowledgements{Habent sua fata li
- Page 8 and 9:
14 van Wijngaarden, et al.0.3.4. Mo
- Page 10 and 11:
. . . . . . . 4 " ' 0 . . . . . . .
- Page 12 and 13:
22 van Wijngaarden, et al.• let P
- Page 14 and 15:
26 van Wijngaarden, et al.{Since so
- Page 16 and 17:
30 van Wijngaarden, et aLloperandfo
- Page 18 and 19:
34 van Wijngaarden, et al.j) WHETHE
- Page 20 and 21:
38 van Wijngaarden, et al.A protono
- Page 22 and 23:
42 van Wijngaarden, et al.d) If N i
- Page 24 and 25:
46 van Wijngaarden, et al.c) {There
- Page 26 and 27:
50 van Wijngaarden, et al.c) The ph
- Page 28 and 29:
54 van Wijngaarden, et al.3.1.1. Sy
- Page 30 and 31:
58 van Wijngaarden, et al.where (RO
- Page 32 and 33:
62 van Wijngaarden, et al.1) SOlD N
- Page 34 and 35:
66 van Wijngaarden, et al.ALGOL 68
- Page 36 and 37:
70 van Wijngaarden, et el.For each
- Page 38 and 39:
74 van Wijngaarden, et al.If 'MODE"
- Page 40 and 41:
78 J van Wijngaarden, et al.C) SECO
- Page 42 and 43:
82 van Wijngaarden, et al.ALGOL 68
- Page 44 and 45:
86 van Wijngaarden. et al.ALGOL 68
- Page 46 and 47:
90 van Wijngaarden, et al.5.4.4.1.
- Page 48 and 49:
94van Wijngaarden, et al.ALGOL 68 R
- Page 50 and 51:
98 van Wijngaarden, et al.Assignati
- Page 52 and 53:
102 van Wijngaarden, et at.{A nest,
- Page 54 and 55:
106 van Wijngaarden, et al.'HEAD's
- Page 56 and 57: 110 van Wijngaarden, et al.ALGOL 68
- Page 58 and 59: 114van Wijngaarden, et al.ALGOL 68
- Page 60 and 61: 118 van Wijngaarden, et al.ALGOL 68
- Page 62 and 63: 122 van Wijngaarden, et al.style ii
- Page 64 and 65: 126 van Wijngaarden, et al.b) The c
- Page 66 and 67: 130van Wijngaarden, et al.ALGOL 68
- Page 68 and 69: 134van Wijngaarden, et al.ALGOL 68
- Page 70 and 71: 138d)e)f)g)h)i)J)k)1)m)n)van Wijnga
- Page 72 and 73: 142 van Wijngaarden, et al.physics
- Page 74 and 75: 146 van Wijngaarden, et al.gg) On s
- Page 76 and 77: 150van Wijngaarden, et al.ALGOL 68
- Page 78 and 79: 154/van Wijngaarden, et al.ALGOL 68
- Page 80 and 81: 158 van Wijngaarden, et el.fi;ref p
- Page 82 and 83: 162van Wijngaarden, et al.ALGOL 68
- Page 84 and 85: 166van Wijngaarden, et al.ALGOL 68
- Page 86 and 87: 170/van Wijngaarden, etal.ALGOL 68
- Page 88 and 89: 174J)K)L)M)N)O)P)a)b)c)d)e)van Wijn
- Page 90 and 91: 178/van Wijngaarden, et al.ALGOL 68
- Page 92 and 93: 182 van Wijngaarden, et al.• let
- Page 94 and 95: 186van Wijngaarden, et al./ALGOL 68
- Page 96 and 97: 190 van Wijngaarden, etal.composed
- Page 98 and 99: 194h)i)J)van Wijngaa(rden, et al.pr
- Page 100 and 101: 198 van Wijngaarden, et al.¢ strin
- Page 102 and 103: 202tvan Wijngaarden, et al.ALGOL 68
- Page 104 and 105: 206 van Wijngaa~den. et al.10.3.6.1
- Page 108 and 109: 214 van Wijngaarden, et al.inoperat
- Page 110 and 111: 218fvan Wijngaarden, et al.¢ move
- Page 112 and 113: 222 van Wijngaarden, etaL{overflow}
- Page 114 and 115: 226 van Wijngaarden, et al.ALGOL 68
- Page 116 and 117: 230max int 10.2.1.cmax real 10.2.l.
- Page 118 and 119: 234 van Wijngaarden, et al.ALGOL 68