The Museum of HP Calculators


Normal And Inverse Normal Distribution for the HP-67

This program is Copyright © 1976 by Hewlett-Packard and is used here by permission. This program was originally published in the HP-67 Stat Pac 1.

This program is supplied without representation or warranty of any kind. Hewlett-Packard Company and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Card Labels
Normal And Inverse Normal Distribution 1
Shift          
Label Start        
Key A B C D E
Card Labels
Normal And Inverse Normal Distribution 2
Shift          
Label   P? x→f(x) x→Q(x) Q(x)→x
Key A B C D E

Overview

This program evaluates the standard normal density function f(x) and the normal integral Q(x) for given x. If Q is given, x can also be found. The standard normal distribution has mean 0 and standard deviation 1.

Equations

1. Standard normal density

        f(x) = (1/√(2π))e(-x2/2)


2. Normal integral

        Q(x) = (1/√(2π))(x..infinity)e(-t2/2)dt

Polynomial approximation is used to compute Q(x) for given x.

Define R = f(x) (b1t + b2t2 + b3t3 + b4t4 + b5t5) + E(X)

where |E(X)| < 7.5 x 10-8

   t = 1/(1 + r|x|) ,   r = 0.2316419
   b1 = .319381530,  b2 =-.356563782
   b3 = 1.781477937, b4 =-1.821255978
   b5 = 1.330274429

             R     if x ≥ O
Then Q(x) = or
             1-R   if x < 0

3. Inverse normal

For a given Q > 0, x can be found such that

Q = (1/√(2π))*(x..infinity)e(-t2/2)dt.

The following rational approximation is used:

                c0 + c1t + c2t2
Define y = t - --------------------- + E(Q)
               1 + d1t + d2t2 + d3t3

where |E(Q)| < 4.5 x 10-4

            √(ln(1/Q2))      if 0 < Q ≤ 0.5
      t = or
            √(ln(1/(1-Q)2))  if 0.5 < Q < 01

   c0 = 2.515517     d1 = 1.432788
   cl = 0.802853     d2 = 0.189269
   c2 = 0.010328     d3 = 0.001308

           y     if 0 < Q ≤ 0.5
Then x = or
          -y     if 0.5 < Q < 01

Reference

Abramowitz and Stegun, Handbook of Mathematical Functions, National Bureau of Standards 1970.

Instructions

Step Instructions Input Data/Units Keys Output Data/Units
1 Load side 1 and side 2 of card 1      
2 Initialize   A 0.00
3 Load side 1 and side 2 of card 2      
4 To set print mode*   B 1.00
  Optional: Step 5      
5 Input x to compute f(x) x C f(x)
6 Input x to compute Q(x) x D Q(x)
  For a new case of x, go to 5 or 6      
7 Input Q(x) to compute x Q(x) E x
  For a new case of Q(x), go to 7      
         
  *Note: to clear print mode press-->   0 STO A STO B  

Example 1

Find f(x) and Q(x) for x = 1.18 and x = -2.28.

Keystrokes                         Outputs
Load side 1 and side 2 of card 1
A                                    0.00

Load side 1 and side 2 of card 2
B                                    1.00
1.18 C                               1.18 ***
                                     0.20 *** (f(1.18))

1.18 D                               1.18 ***
                                     0.12 *** (Q(1.18))

2.28 CHS D                          -2.28 ***
                                     0.99 *** (Q(-2.28))

2.28 CHS C                          -2.28 ***
                                     0.03 *** (f(-2.28))

Example 2

Given Q = 0.12 and Q = 0.95, find x.

(If you have run through Example 1, then you can proceed; otherwise you have to load programs as described in Example 1).

Keystrokes                         Outputs
0.12 E                               0.12 ***
                                     1.18 *** (x)

.95 E                                0.95 ***
                                    -1.65 *** (x)

The Program Card 1

LINE  KEYS
001  *LBL A
002   .
003   2
004   3
005   1
006   6
007   4
008   1
009   9
010   STO 3
011   1
012   .
013   3
014   3
015   0
016   2
017   7
018   4
019   4
020   2         Store constants for normal distribution.
021   9
022   STO 4
023   1
024   .
025   8
026   2
027   1
028   2
029   5
030   5
031   9
032   7
033   8
034   CHS
035   STO 5
036   1
037   .
038   7
039   8
040   1
041   4
042   7
043   7
044   9
045   3
046   7
047   STO 6
048   .
049   3
050   5
051   6
052   5
053   6
054   3
055   7
056   8
057   2
058   CHS
059   STO 7
060   .
061   3
062   1
063   9
064   3
065   8
066   1
067   5
068   3
069   STO 8
070   P⇔S
071   2
072   .
073   5
074   1
075   5
076   5
077   1
078   7
079   STO 1
080   .
081   8
082   0
083   2
084   8
085   5
086   3
087   STO 2
088   .
089   0
090   1
091   0
092   3
093   2
094   8
095   STO 3     Strore constants for inverse N.D.
096   1
097   .
098   4
099   3
100   2
101   7
102   8
103   8
104   STO 4
105   .
106   1
107   8
108   9
109   2
110   6
111   9
112   STO 5
113   .
114   0
115   0
116   1
117   3
118   0
119   8
120   STO 6
121   P⇔S
122   0
123   STO A
124   STO B
125   RTN

Card 2

LINE  KEYS
001  *LBL B
002   1         Store 1 in RA for print.
003   STO A
004   RTN
005  *LBL C
006   GSB 9
007   STO 1
008   ENTER↑
009   ×         Input x and compute f(x)
010   2
011   ÷
012   CHS
013   eX
014   π
015   2
016   ×
017   √x
018   ÷
019   STO 2
020   GSB 9
021   GSB 6
022   GSB 3
023   RCL 2
024   RTN
025  *LBL D
026   GSB 9
027   STO 1
028   GSB 5
029   GSB C
030   RCL 1
031   X<0?
032   GTO 1     Input x and calculate Q(x)
033   SF 0
034  *LBL c
035   1
036   RCL 1
037   RCL 3
038   ×
039   +
040   1/X
041   ENTER↑
042   ENTER↑
043   ENTER↑
044   RCL 4
045   ×
046   RCL 5
047   +
048   ×
049   RCL 6
050   +
051   ×
052   RCL 7
053   +
054   ×
055   RCL 8
056   +
057   ×
058   RCL 2
059   ×
060   F0?
061   GSB 9
062   F0?
063   GSB 6
064   RTN
065  *LBL 1
066   CF 0
067   RCL 1
068   CHS
069   STO 1
070   GSB c
071   1
072   X⇔Y
073   -
074   STO 9
075   GSB 9
076   GSB 6
077   RCL 9
078   RTN
079  *LBL E
080   GSB 9
081   X<0?      Input Q(x) and calculate x.
082   GTO 0
083   1
084   X≤Y?
085   GTO 0
086   R↓
087   .
088   5
089   X⇔Y
090   X>Y?
091   GSB 8
092   ENTER↑
093   ×
094   1/X
095   LN
096   √x
097   P⇔S
098   STO 7
099   RCL 3
100   ×
101   RCL 2
102   +
103   RCL 7
104   ×
105   RCL 1
106   +
107   RCL 7
108   RCL 6
109   ×
110   RCL 5
111   +
112   RCL 7
113   ×
114   RCL 4
115   +
116   RCL 7
117   ×
118   1
119   +
120   ÷
121   RCL 7
122   X⇔Y
123   -
124   P⇔S
125   F1?
126   CHS
127   GSB 9
128   GSB 6
129   CF 1
130   RTN
131  *LBL 8     For (1-Q)
132   SF 1
133   1
134   -
135   CHS
136   RTN
137  *LBL 9     Subroutine to print.
138   RCL A
139   X>0?
140   GSB 7
141   R↓
142   RTN
143  *LBL 7
144   R↓
145   PRTX
146   R↑
147   RTN
148  *LBL 6     Subroutine for space.
149   RCL A
150   X>0?
151   PRT SPC
152   R↓
153   RTN
154  *LBL 5
155   RCL A     Clear RA for calculating Q(x).
156   X>0?
157   GSB 4
158   R↓
159   RTN
160  *LBL 4
161   STO B
162   CLX
163   STO A
164   RTN
165  *LBL 3
166   RCL B
167   X>0?
168   GSB 2
169   RTN
170  *LBL 2     Restore 1 to RA,
171   1
172   STO A
173   RTN

Register Use

R1  x
R2  f(x)
R3  r
R4  b5
R5  b4
R6  b3
R7  b2
R8  b1
R9  Used
S1  C0
S2  C1
S3  C2
S4  d1
S5  d2
S6  d3
S7  t
A   1 or 0
B   1 or 0

Go back to the software library
Go back to the main exhibit hall