Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!nott!dgbt!netfs!psinntp!psinntp!rpi!uwm.edu!spool.mu.edu!agate!netsys!decwrl!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: C prog for cumulative normal dist translated into J
Message-ID: <1993Feb3.230204.20576@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Feb3.073347.19716@csus.edu>
Distribution: NA
Date: Wed, 3 Feb 1993 23:02:04 GMT
Lines: 68

NB.    Arg. Nexplicit0 in my earlier post had an incorrect statment
NB.    and the comments in Nexplicit1 weren't what I meant. These
NB.    should be better.

   p =. i. 0 0
   p =. p,' NB. Nexplicit0 is a verb preserving the original way of'
   p =. p,' NB. of thinking of the problem while thinking in J'
   p =. p,' NB. It returns the univariate cumulative normal value of phi(x)'
   p =. p,' NB. emclean 2/2/93'
   p =. p,' d =. y.'
   p =. p,' C0 =. 0.231642'
   p =. p,' C12345 =. 0.319382 _0.356564 1.781478 _1.821256 1.330274'
   p =. p,' SQRT2PI =. %: +: o. 1'
   p =. p,' x =. (^@-@-:@*: y.) % SQRT2PI'
   p =. p,' NB. x =. (^@-@-:@*: % %:@+:@o.@1:) d'
   p =. p,' y =. % >: C0 * | d'
   p =. p,' z =. +/ C12345 * (y^1 2 3 4 5)'
   p =. p,' y. =. (x*z) (1: - [)`([) @.(0&>@]) d'
   Nexplicit0 =. p : ''
   
   p =. i. 0 0
   p =. p,' NB. Nexplicit1 is an literal translation of the C code'
   p =. p,' NB. it returns the univariate cumulative normal value of phi(x)'
   p =. p,' NB. emclean 2/2/93'
   p =. p,' d  =. y.'
   p =. p,' C0 =.   0.2316419'
   p =. p,' C1 =.   0.31938153'
   p =. p,' C2 =.  -0.356563782'
   p =. p,' C3 =.  -0.356563782'
   p =. p,' C3 =.  1.781477937'
   p =. p,' C4 =. -1.821255978'
   p =. p,' C5 =.  1.330274429'
   p =. p,' PI =.  3.141592654'
   p =. p,' exp =. pow =. ^   '
   p =. p,' fabs =. |  '
   p =. p,' sqrt =. %: '
   p =. p,' pow =.  ^  '
   p =. p,' sumscan =. +/'
   p =. p,' NB. x =   exp  (- pow(d,2.) / 2.   /  sqrt( 2. * PI); '
   p =. p,'     x =. (exp (- (d pow 2) % 2.0)) % (sqrt 2.0 * PI)  '
   p =. p,' NB. y =  (C0 * fabs(d)) + 1.;'
   p =. p,'     y =. (C0 * fabs d) + 1.0 ' 
   p =. p,' NB. y     =  1.0 / y;'
   p =. p,'     y     =. 1.0 % y '
   p =. p,' NB. z= C1*y+C2*pow(y,2.)+C3*pow(y,3.)+C4*pow(y,4.)+C5*pow(y,5.);'
   p =. p,' z =. sumscan (C1,C2,C3,C4,C5) * y ^ 1 2 3 4 5'
   p =. p,'NB.   if (d < 0) return(x * z);'
   p =. p,'NB.   else return(1. - x * z); '
   p =. p,'y. =. (x*z) (1: - [)`([) @.  (0&>@]) d'
   Nexplicit1 =. p : ''
   4!:55 <'p'
1
   

   ((,.Nexplicit0"0);(,.Nexplicit1"0)) 1-0.2*i.@-10
NB. +-------------+-------------+
NB. |_0.8 0.211855|_0.8 0.211855|
NB. |_0.6 0.274253|_0.6 0.274253|
NB. |_0.4 0.344578|_0.4 0.344578|
NB. |_0.2  0.42074|_0.2  0.42074|
NB. |   0      0.5|   0      0.5|
NB. | 0.2  0.57926| 0.2  0.57926|
NB. | 0.4 0.655422| 0.4 0.655422|
NB. | 0.6 0.725747| 0.6 0.725747|
NB. | 0.8 0.788145| 0.8 0.788145|
NB. |   1 0.841345|   1 0.841345|
NB. +-------------+-------------+

