Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!rutgers!clyde!cuae2!ihnp4!inuxc!pur-ee!uiucdcs!uiucdcsb!kenny From: kenny@uiucdcsb.cs.uiuc.edu Newsgroups: sci.math Subject: Re: Algorithm Description Message-ID: <162000001@uiucdcsb> Date: Thu, 13-Nov-86 13:03:00 EST Article-I.D.: uiucdcsb.162000001 Posted: Thu Nov 13 13:03:00 1986 Date-Received: Sun, 16-Nov-86 00:26:05 EST References: <1266@megaron.UUCP> Lines: 91 Nf-ID: #R:megaron.UUCP:1266:uiucdcsb:162000001:000:4186 Nf-From: uiucdcsb.cs.uiuc.edu!kenny Nov 13 12:03:00 1986 I'm always amazed at the way academic pedants flame people for couching ideas in a language appropriate to their readership, when a more elegant if less straightforward statement is available. Witness the following: /* Written 10:28 am Oct 30, 1986 by johnk@megaron.UUCP in uiucdcsb:sci.math */ /* ---------- "Algorithm Description" ---------- */ > I'm always amazed at the manner in which mathematicians describe >algorithms. In a recent discussion on the generation of variates from a >normal distribution, one of the most interesting presentations of the >Box-Muller-Marsaglia algorithm was the following: > > V1 = 2*RND - 1 <--------+ > V2 = 2*RND - 1 | > S = V1*V1 + V2*V2 | > IF S >= 1 THEN GOTO ----+ > X1 = V1 * SQRT (-2 * LOG(S) / S) > X2 = V2 * SQRT (-2 * LOG(S) / S) > >While this is a clever improvement on the ghastly "step 1", "step 2", "go to >step i" style, why not simply > > repeat { > v1 = 2*rand() - 1 > v2 = 2*rand() - 1 > s = v1^2 + v2^2 > } until ( s < 1 ) > x1 = v1 * sqrt(-2 * ln(s) / s) > x2 = v2 * sqrt(-2 * ln(s) / s) > >Admittedly, this algorithm is trivial; here the manner of presentation >makes little difference. I think the computer scientist most >mathematicians know of is Knuth, and by presenting the algorithms of his >_The_Art_of_Computer_Programming_ in the numbered step form, he legitimized >a style which should, in our enlightened age, be obsolete. >-- >John Kececioglu / arizona!johnk >"Chess, like love, like music, has the power to make men happy." -- S. Tarrasch /* End of text from uiucdcsb:sci.math */ I am the original poster of that version of the polar method. I think that the flame is perhaps a bit misplaced. First, you are flaming me incorrectly for being a mathematician; I am, in fact, a computer scientist by trade. I responded in the ugly fashion because the original poster asked for a solution expressed in BASIC. The tone of theoriginal request suggested that perhaps the poster was unfamiliar with structured languages and therefore would find the ``repeat { ... } until (condition)'' notation (which I used in my working notes before composing the version that I posted) confusing. You will probably argue that anyone who cannot understand that notation has no business attempting to program. I contend that it is very desirable to learn that notation; that it is essential if one intends to be a serious programmer; that ones programming is crippled without it. It probably, however, is not relevant to a non-programmer doing a BASIC program for his own use. Such people do not need to know even the fundamentals. To carry the argument to absurdity, I suppose that if you were an exponent of the applicative style of programming, you would favor something like: ------------------------------------------------------------------------ (defun deviate-pair () (make-deviate-pair (make-dotprod-and-xy))) (defun make-deviate-pair (x) (let ((c (sqrt (quotient (times -2. (ln (car x))) (car x) )))) (mapcar (cdr x) (closure (lambda (v) (times v c)))))) (defun make-dotprod-and-xy () (check-dotprod-and-xy '(2. 1. 1.))) (defun check-dotprod-and-xy (l) (cond ((lessp (car l) 1.) l) (t (check-dotprod-and-xy (new-dotprod-and-xy))))) (defun new-dotprod-and-xy () (let ((x (new-coord)) (y (new-coord))) (list (dotprod x y) x y))) (defun new-coord () (sub1 (times 2 (random)))) (defun dotprod (x y) (plus (times x x) (times y y))) ------------------------------------------------------------------------ What then of the BASIC (or C or PASCAL) programmer who doesn't speak LISP? Need he spend several months learning LISP, SCHEME, and the applicative style of programming so that he can take the algorithm as presented and map it back into his von-Neumann-model language? In short, I was attempting to adapt my reply to my audience, not to perpetuate a programming style that I, too, consider inferior. Kevin Kenny UUCP: {ihnp4,pur-ee,convex}!uiucdcs!kenny Department of Computer Science ARPA: kenny@B.CS.UIUC.EDU (kenny@UIUC.ARPA) University of Illinois CSNET: kenny@UIUC.CSNET 1304 W. Springfield Ave. Urbana, Illinois, 61801 Voice: (217) 333-8740