 <!DOCTYPE article PUBLIC  "-//OASIS//DTD DocBook V4.1//EN" [
<!--LTC Mark B. Wroth -->
<!ENTITY HP48 "HP-48G Series">
<!-- These two parameter entities are used to provide alternate forms
     of general entity declarations for the printed and HTML versions
     of this document.  At least in principle, although less so in 
     practice, the printed version should be able to use correct glyphs
     for more of the special symbols than the web version.
-->
<!-- HP48 Programming Constructs -->
  <!ENTITY StartProg  "<<"     -- left angle quote, ISO Latin 1 -->
  <!ENTITY EndProg    ">>"     -- right angle quote, ISO Latin 1 -->
  <!ENTITY To         "->"      -- the -> programming command -->
  <!ENTITY ToTag      "&To;TAG"     -- the ->TAG programming command -->
  <!ENTITY LeftShift  "<KeyCap>Left-Shift</KeyCap>"  
                                    -- the HP48 left shift key -->
  <!ENTITY RightShift "<KeyCap>Right-Shift</KeyCap>" 
                                    -- the HP48 right shift key -->
  <!ENTITY AlphaShift "<KeyCap>&alpha;</KeyCap>-Shift" 
                                    -- the HP48 alpha shift key -->
<!-- Math Symbols -->
  <!ENTITY alpha     "&agr;" -- lowercase alpha -->
  <!ENTITY chisq     "X&sup2;" -- Chi-squared -->
  <!ENTITY mu        "&micro;" -- lowercase mu (population mean) -->
  <!ENTITY sqrt      "[sqrt]"  -- Surd; (Square root sign) -->
  <!ENTITY xbar      "[xbar]"  -- x with overbar (sample mean) -->
  <!ENTITY Int       "[integral]" -- Integral sign -->
  <!ENTITY Sum       "[sum]"    -- uppercase Sigma, summation -->
<!-- Cross Reference Entities -->
<!-- These are intended to provide for an easy and consistent way
     of making references to the three common references cited. -->
<!ENTITY UsersGuide "<citation><xref linkend='UsersGuide' EndTerm='title-UsersGuide'></citation>"
         -- Citation/cross reference to the HP Users Guide -->
<!ENTITY AURM "<citation><xref linkend='AURM'></citation>"
         -- Citation/cross reference to the HP Advanced Users Reference -->
<!ENTITY Devore "<citation><xref linkend='Devore'></citation>"
         -- Citation/cross reference to the course text -->

]>
<article id="MA206Program">
<articleinfo>
<Author><FirstName>Mark</FirstName><Surname>Wroth</Surname></Author>
<title>The "MA206" HP-48 Program</title>
</articleinfo>
<sect1><title>Background and Purpose</title>

<para>The "MA206" &HP48; program was written at some time during or
preceding the 1998-1999 academic year to consolidate the various
&HP48; programs in use supporting MA206.  The individual sub-programs
were written by a number of different authors; Major Jim Gigrich
wrote the menu driven program documented here, which consolidated
the existing programs.</para>

<para>This article describes that program.  It was written as an aid
to understanding the structure and usage of the program, from the
perspective that one must understand a program in order to be able to
use it.  As a result, this article may be read in either of two
ways. It can be read by looking at the description of the program
structure, to understand the program itself, followed by examining the
usage. Or it can be read to understand what needs to be done and how
to do it (the usage), followed by a study of how the program is
written to accomplish it.</para>

<Para>This article was written with the MA206 instructor as the target
audience.  In addition to providing information of general interest to
any user of the MA206 calculator program, this article makes a number
of comments about programming choices embodied in the program, and
discusses possible changes and extensions to the program.  While there
is nothing included here which students should not be allowed to see,
much of this additional discussion is somewhat beyond the needs of the
average student and may tend to confuse rather than clarify.  This
additional material is primarily aimed at providing a deeper
understanding of the program with a view towards allowing instructors
(including the author) to understand the program, diagnose student
difficulties with the program, and (potentially) modify or extend the
program.</Para>

<Para>However, this article is not beyond the student who expresses an
interest in the techniques of programming the &HP48;, and could be
profitably shared with such students.</Para>
</sect1>
<sect1><title>Usage</title>
<Sect2><Title>Overview</Title>
<Para>The MA206 program provides a single &HP48; program which
automates many of the calculations required in the Probability and
Statistics course. In particular, the MA206 program permits the
user to calculate:
<ItemizedList>

<ListItem><Para>Binomial interval probabilities.  Calculate the
probability that a random variable following a binomial distribution
lies in a user specified interval.</Para></ListItem>

<ListItem><Para>Poisson interval probabilities. Calculate the
probability that a Poisson distributed random variable lies in a user
supplied interval.</Para></ListItem> <ListItem><Para>Hypergeometric
interval probabilities. Calculate the probability that a random
variable from a hypergeometric distribution lies in a user supplied
interval.</Para></ListItem> <ListItem><Para>Uniform interval
probabilities.</Para></ListItem> 

<ListItem><Para>Exponential interval
probabilities.</Para></ListItem> 

<ListItem><Para>Lower tail Normal
probabilities.</Para></ListItem> 

<ListItem><Para>Upper tail Normal
probabilities and critical values.</Para></ListItem>

<ListItem><Para>Upper tail Student's T probabilities and critical
values.</Para></ListItem> 

<ListItem><Para>Upper tail Chi-Squared
probabilities and critical values.</Para></ListItem>

<ListItem><Para>Clean up stored intermediate
variables.</Para></ListItem>
</ItemizedList>
</Para>

<Para>The three functions which compute upper tail probabilities and
critical values use the &HP48; <Application>SOLVE</Application> application,
with the result that any of the parameters of the distribution, the
critical value, and the upper tail probability can be computed if the
remaining values are known.
</Para>
</Sect2>
<Sect2><Title>Program Invocation</Title>
<Para>The <Application>MA206</Application> program is invoked by
pressing the user menu key corresponding to the screen label
<Application>MA206</Application>. This label will be visible when
the current directory is set to the directory in which the
<Application>MA206</Application> program is installed, and user variables
are selected.  If user variables are not visible, pressing the
<KeyCap>VAR</KeyCap> key will cause them to be visible.</Para>

<Para>After the <KeyCap>MA206</KeyCap> key is pressed, a user
selection box labeled <GUILabel>MA206 PROGRAMS</GUILabel> will appear,
showing the first four functions.  To scroll to the other functions,
use the cursor arrow keys.  Note that when the top of the list is
visible, a "down arrow" will appear in the lower right of the box,
indicating that there are more selections available below those
visible.  When the middle of the list is displayed, arrows will appear
in both the bottom and top of the dialog box.</Para>

<Para>Even when the top or bottom of the list is displayed, you
can scroll in both directions. If you scroll up off of the list,
the selection moves to the bottom of the list and vice versa. This can
be convenient if you know that the desired item is near the
bottom of the list.</Para>

<Para>Once the desired item is highlighted, select
<KeyCap>ENTER</KeyCap>.</Para>

</Sect2>
<Sect2><Title>Binomial</Title>

<Para>This option calculates the probability that a random variable
following a binomial distribution lies in a user specified
interval.</Para>

<Para>When the <GUILabel>Binomial</GUILabel> option is selected, the
screen will display a data entry form labeled <GUILabel>BINOMIAL
DIST. X~BIN(N,P)</GUILabel>, with spaces for the distribution's
parameters and the endpoints of the desired interval.</Para>
<Para>The four values to be entered are:
<VariableList>
<VarListEntry><Term>N</Term><ListItem><Para>The number of binomial
trials.  By the definition of the binomial distribution, this must be
a positive integer.</Para></ListItem></VarListEntry>
<VarListEntry><Term>P</Term><ListItem><Para>The probability of success
on each trial.  By the definition of the binomial distribution this
must be a probability.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X1</Term><ListItem><Para>The lower limit of the
desired interval. This value is included in the interval.  This number
should be a non-negative integer, less than or equal to X2, and less
than or equal to N.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X2</Term><ListItem><Para>The upper limit of the
desired interval.  This value should be a non-negative integer,
greater than or equal to X1 and less than or equal to
N.</Para></ListItem></VarListEntry>
</VariableList>
</Para>

<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be calculated. The
probability distribution, including its parameter values is displayed
on stack level 3.  The probability statement (including the selected
interval) is shown on stack level 2, and the probability itself is
shown on stack level 1.</Para> 

<Para>If you enter values in the variables which do not satisfy the
conditions described above, the results are not easily predictable,
and will in any case be unlikely to have any practical value.</Para>

</Sect2>
<Sect2><Title>Poisson</Title>

<Para>This option allows you to calculate the probability that a
Poisson distributed random variable lies in an
interval you supply.</Para>

<Para>When the <GUILabel>Poisson</GUILabel> option is selected, the
screen will display a data entry form labeled <GUILabel>POISSON
DIST. X~P(&lambda;), &lambda;>0</GUILabel>, with spaces for the
distribution's parameters and the (inclusive) end points of the
interval. The three variables are:
<VariableList>
<VarListEntry><Term>&lambda</Term><ListItem><Para>The rate parameter
of the Poisson distribution.  By definition, this must be greater than
zero.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X1</Term><ListItem><Para>The lower limit of the
desired interval. This value is included in the interval.  This number
should be a non-negative integer, less than or equal to
X2.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X2</Term><ListItem><Para>The upper limit of the
desired interval.  This value should be a non-negative integer,
greater than or equal to X1.</Para></ListItem></VarListEntry>
</VariableList>
</Para>
<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be
calculated. The probability distribution, with its parameter value,
and the interval selected are displayed for your reference on levels 3
and 2 of the stack, and the probability it redisplayed on level 1 for
use in further calculations.</Para>

<Para>If you enter values in the variables which do not satisfy the
conditions described above, the results are not easily predictable,
and will in any case be unlikely to have any practical value.</Para>

</Sect2>
<Sect2><Title>Hypergeometric</Title>

<Para>This option allows you to calculate the probability that a
raandom variable from a hypergeometric distribution falls in an
interval you define.</Para>

<Para>This sub-program was originally written by Major Dennis
Day.</Para>

<Para>After you select the <GUILabel>Hypergeometric</GUILabel> option,
a user input form labeled <GUILabel>HYPERGEOMETRIC
DIST.</GUILabel> will appear.  This form has spaces for the
distribution's parameters and the endpoints of the desired interval:
<VariableList>
<VarListEntry><Term>M</Term><ListItem><Para>The number of possible
successes of the hypergeometric distribution.  By definition, this
must be a non-negative integer.</Para></ListItem></VarListEntry>
<VarListEntry><Term>N</Term><ListItem><Para>The population size.  By
definition, this must be a non-negative integer, greater than or equal
to "Small 'N'".</Para></ListItem></VarListEntry>
<VarListEntry><Term>Small 'N'</Term><ListItem><Para>The number of
items drawn.  By definition, this must be a non-negative integer,
less than or equal to N.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X1</Term><ListItem><Para>The lower limit of the
desired interval. This value is included in the interval.  This number
should be a non-negative integer, less than or equal to X2, and less
than or equal to n.</Para></ListItem></VarListEntry>
<VarListEntry><Term>X2</Term><ListItem><Para>The upper limit of the
desired interval.  This value should be a non-negative integer,
greater than or equal to X1.</Para></ListItem></VarListEntry>
</VariableList>
[TBR]
</Para>


<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be calculated. The
probability distribution, including its parameter values is displayed
on stack level 3.  The probability statement (including the selected
interval) is shown on stack level 2, and the probability itself is
shown on stack level 1.</Para> 

<Para>If you enter values in the variables which do not satisfy the
conditions described above, the results are not easily predictable,
and will in any case be unlikely to have any practical value.</Para>
</Sect2>

<Sect2><Title>Uniform</Title> <Para>The <GUILabel>MA206</GUILabel> option
allows you to compute the probability that a random variable uniformly
distributed on a defined interval lies in an interval you
supply. </Para>

<Para>After the <GUILabel>Uniform</GUILabel> option is selected, a
user input form labeled <GUILabel>UNIFORM
DIST. X~UNF(A,B)</GUILabel>. The input form has spaces for the
distribution's parameters and the endpoints of the interval:
<VariableList>

<VarListEntry><Term>A</Term><ListItem><Para>The lower limit of the
interval on which the uniform distribution has non-zero probability. A
may be any real number less than B.</Para></ListItem></VarListEntry>

<VarListEntry><Term>B</Term><ListItem><Para>The upper limit of the
interval on which the uniform distribution has non-zero probability. B
may be any real number greater than A.</Para></ListItem></VarListEntry>

<VarListEntry><Term>X1</Term><ListItem><Para>The lower limit of the
desired interval. This value is included in the interval.  This number
should be greater than or equal to A and less than both X2 and B.</Para></ListItem></VarListEntry>

<VarListEntry><Term>X2</Term><ListItem><Para>The upper limit of the
desired interval.  This value should be greater than or equal to X1
and less than B.</Para></ListItem></VarListEntry>
</VariableList>
</Para>


<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be calculated. The
probability distribution, including its parameter values is displayed
on stack level 3.  The probability statement (including the selected
interval) is shown on stack level 2, and the probability itself is
shown on stack level 1.</Para> 

<Para>If you enter values in the variables which do not satisfy the
conditions described above, the results are not easily predictable,
and will in any case be unlikely to have any practical value.</Para>

<Para>In particular, you should be cautious about the relationships
between the interval [<LITERAL>A</LITERAL>, <LITERAL>B</LITERAL>] and
the interval [<LITERAL>X1</LITERAL>, <LITERAL>X2</LITERAL>]. If
<LITERAL>X1</LITERAL> and <LITERAL>X2</LITERAL> are not contained in
[<LITERAL>A</LITERAL>, <LITERAL>B</LITERAL>], the returned probability
will be numerically incorrect, although the program will appear to
have returned correctly.</Para> 

</Sect2>
<Sect2><Title>Exponential</Title>
<Para>This option allows you to compute the proabability that an
exponentially distributed random variable lies in an interval you
supply.</Para>

<Para>After the <GUILabel>Exponential</GUILabel> option is selected, a
user input form labeled <GUILabel>EXPONENTIAL
DIST. X~EXP(&lambda;)</GUILabel>. The input form has spaces for the
distribution's parameters and the endpoints of the interval:
<VariableList>

<VarListEntry><Term>&lambda;</Term><ListItem><Para>The rate parameter
of the exponential distribution.  &lambda; should be a non-negative
real number.</Para></ListItem></VarListEntry>

<VarListEntry><Term>X1</Term><ListItem><Para>The lower limit of the
desired interval. This value is included in the interval.  This number
should be greater than or equal to zero.</Para></ListItem></VarListEntry>

<VarListEntry><Term>X2</Term><ListItem><Para>The upper limit of the
desired interval.  This value should be greater than or equal to
X1.</Para></ListItem></VarListEntry>
</VariableList>
</Para>


<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be calculated. The
probability distribution, including its parameter values is displayed
on stack level 3.  The probability statement (including the selected
interval) is shown on stack level 2, and the probability itself is
shown on stack level 1.</Para> 

<Para>If you enter values in the variables which do not satisfy the
conditions described above, the results are not easily predictable,
and will in any case be unlikely to have any practical value.</Para>


</Sect2>
<Sect2><Title>Normal</Title>
<Para>The <GUILabel>Normal</GUILabel> optional allows you to evaluate
the <ACRONYM>CDF</ACRONYM> of the Normal distribution, effectively
replacing the standard Normal tables.</Para>

<Para>Once you select the <GUILabel>Normal</GUILabel> option, a window
will appear reminding you that this is the <GUILabel>NORMAL
DISTRIBUTION P(X&le;x)</GUILabel>. Press the <KeyCap>ENTER</KeyCap>
key and the user input form will appear.</Para>

<Para>This input form allows you to set the parameters of the
distribution and the value of the random variable at which you want to
evaluate the <Acronym>CDF</Acronym>.
<VariableList>

<VarListEntry><Term>X</Term><ListItem><Para>The value at which you
want to evaluate the <Acronym>CDF</Acronym>.</Para></ListItem></VarListEntry>

<VarListEntry><Term>&mu;</Term><ListItem><Para>The mean of the Normal
distribution.</Para></ListItem></VarListEntry>

<VarListEntry><Term>&sigma;</Term><ListItem><Para>The standard
deviation of the Normal distribution.</Para></ListItem></VarListEntry>
</VariableList>
</Para>

<Para>Once you have filled in the values appropriate to your problem,
select <KeyCap>OK</KeyCap> and the probability will be calculated. The
probability distribution, including its parameter values is displayed
on stack level 3.  The probability statement (including the selected
interval) is shown on stack level 2, and the probability itself is
shown on stack level 1.</Para> 

</Sect2>
<Sect2><Title>Using the <Application>SOLVE</Application> Form</Title>
<Figure>
  <Title>Solve Application Window</Title>
  <graphic fileref="Graphics\SlvWndw.gif" format="GIF">
</Figure>
<Para>The <Application>SOLVE</Application> application is one of the
standard &HP48; applications.  It allows the user to specify the
values of all but one of the variables in an equation or expression,
and solve for the remaining unknown value. (In the case of an
expression, the root of the expressions is found.)</Para>

<Para>The next three of the <Application>MA206</Application> functions use the
<Application>SOLVE</Application> to let you find values associated with the
upper tail probabilities of the Normal, Student's T, and Chi-Squared
distributions. </Para>

<Para>Use the cursor keys to move the highlight to each known variable
in turn, enter the value, and then press <KeyCap>ENTER</KeyCap>.  The
highlight will jump to the next variable; if this is not the one you
want, you can again use the cursor keys to move.  Once all known
values are entered, more the highlight to the
<Emphasis>unknown</Emphasis> value and press <KeyCap>OK</KeyCap>.
After it is done calculating, the &HP48; will fill in the value for
the unknown variable.  If you then press <KeyCap>ENTER</KeyCap>, you
will be returned to the normal stack view, with the value on level
1.</Para>

<Para>Figure 1 [TBR] shows the cursor in the first variable position,
ready to enter the upper tail probability.</Para>

<Para>For additional information on using the <Application>SOLVE</Application>
application, see the &UsersGuide;.</Para>
</Sect2>
<Sect2><Title>Normal Find</Title><Para></Para></Sect2>
<Sect2><Title>T-Distribution</Title><Para></Para></Sect2>
<Sect2><Title>Chi-Squared</Title><Para></Para></Sect2>
<Sect2><Title>Clear Garbage</Title><Para></Para></Sect2>
<Sect2><Title>Installation</Title><Para></Para></Sect2>
</Sect1>
<sect1><title>Structure and Implementation</title>

<Sect2><Title>Top Level Structure</Title>
<Para>The top level structure of the program is a
<Application>CHOOSE</Application> box which allows the user to select among
the various functions used in MA206.
</Para>
<programlisting>
&StartProg;
"   MA206 PROGRAMs"
{ { "Binomial" 1}
{ "Poisson" 2}
{ "Hypergeometric" 3}
{ "Uniform" 4}
{ "Exponential" 5 }
{ "Normal" 6 }
{ "Normal Find" 7 }
{ "T-Distribution" 8 }
{ "Chi-Squared" 9 }
{ "Clear Garbage" 10 } }
1 CHOOSE DROP &To; c
</programlisting>
<para>The remainder of the program is a <Application>CASE</Application>
statement which executes the various options.</para>
</Sect2>
<Sect2 id="binomial"><Title>The Binomial Distribution</Title>
<Para>The first choice is the binomial distribution, structured
as an <Application>INFORM</Application> block to solicit the user's input,
followed by a loop which calculates the binomial distribution. Finally
the variables used in the calculation are
<Application>PURGE</Application>ed.</Para> 
<Para>There is no error checking on the user input parameters, either
for the distribution or for the interval.</Para>
<programlisting id="binomial-listing">
&StartProg;
CASE 'c==1'
THEN
   "BINOMIAL DIST.  X~BIN(n,p)"
{ { } { } 
  { "n:" "Enter Number of trials" 0 }
  { "p:" "Enter Probability" 0 }
  { } { }
  { "X1:" "Input Lower Limit" 0 }
  { "X2" "Input Upper Limit" 0 }<LineAnnotation></LineAnnotation>
} { 2 } { } { }
INFORM DROP OBJ&To;
DROP
'X2' STO
'X1' STO
'p' STO
'n' STO
"X~Binomial(" 
n &To;STR + "," + p &To;STR + ")"
+ '&Sum;(X=X1,X2,COMB(n,X)*p^X*(1-p)^(n-X))'
&To;NUM 'ANS' STO
ANS 4 RND 
&To;STR
"P(" X1 &To;STR + "&le;X&le;" + X2 &To;STR + ")=" 
+ SWAP + ANS
'X1' PURGE
'X2' PURGE
'n' PURGE
'p' PURGE
'ANS' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="poisson">
<Title>The Poisson Distribution</Title>
<Para>This section computes the probability that a Poisson
distributed random variable lies in a user-specified interval.</Para>
<Para>The second section deals with the Poisson distribution. As
with the binomial distribution, the basic calculation is a loop
over the integers contained in the user supplied interval.  We get
the user inputs via an <Application>INFORM</Application> box, and after the
computations are complete we <Application>PURGE</Application> the variables
we use.</Para>
<Para>There is no error checking to establish that the endpoints
of the interval are non-negative, which is required by the definition
of the Poisson distribution.</Para>
<programlisting id="poisson-listing">
'c==2' THEN
"POISSON DIST. X~P(&lambda), &lambda;>0"
{ { } { } 
{ "&lambda;:" "input the rate: &lambda; >0" 0 }
{ } { } { } 
{ "x1:" "input lower Limit" 0 }
{ "X2:" "Input upper Limit" 0 }
} { 2 } { } { }
INFORM DROP OBJ&To; DROP 'X2' STO
'X1' STO
'&lambda;' STO
"X~POISSON(&lambda;=" &lambda; &To;STR + ")" +
'&Sum;(X= X1,X2,EXP(-&lambda)*&lambda;^X/X!)'
&To;NUM 'ANS' STO
ANS 4 RND &To;STR
"P(" X1 &To;STR + "&le;X&le;" + X2 &To;STR + ")=" +
SWAP + ANS 
'X1' PURGE
X2' PURGE
'&lambda;' PURGE
'ANS' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="hypergeometric">
<Title>The Hypergeometric Distribution</Title>
<Para>The hypergeometric distribution follows the pattern of the other
discrete distributions.  We get the user's input via an 
<Application>INFORM</Application> box, loop over the relevant integers,
and then <Application>PURGE</Application> the variables used.</Para>
<Para>There is no error checking on the parameters of the distribution
or on the interval over which the probability is requested.</Para>
<programlisting id="hypergeometric-listing">
'c==3' THEN
"HYPERGEOMETRIC DIST."
{ { "M:" "number of possible successes" 0 }
{ "N:" "population size" 0 }
{ "Small 'n':" "total number of items drawn" 0 }<LineAnnotation>Notice
that despite the used of the lower case "n" here, it will appear
uppercased in the <Application>INFORM</Application> box, as do all letters.</LineAnnotation>
{ } { } { } 
{ "X1:" "LOWER # of desired successes" 0}
{ "X2:" "UPPER # of desired successes" 0} }
{ 2 } { } { }
INFORM DROP OBJ&To; DROP
'X2' STO
'X1' STO
'n' STO
'N' STO
'M' STO
"X~Hyp(x:" n &To;STR +
"," + M &To,STR + "," + 
N &To;STR + ")" +
'&Sum;(X=X1,X2, COMB(M,X) *COMB(N-M,n-X)/COMB(N,n))'
&To;NUM 'ANS' STO ANS 4 RND &To;STR "P(" X1 &To;STR + "&le;X&le;" + X2 &To;STR + ")=" + SWAP + ANS 
'ANS' PURGE
'X1' PURGE
'X2' PURGE
'n' PURGE
'M' PURGE
'N' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="uniform">
<Title>The Uniform Distribution</Title>
<Para>This section computes the probability that a uniformly
distributed random variable lies in a specific interval.</Para>
<Para>The uniform distribution is the first of the continuous
distributions dealt with in this program. The structure of the
program is similar to the preceding discrete sections, except 
that in the computation section we are able to compute the desired 
interval probability directly in a single expression.</Para>
<Para>There appears to be no error checking to ensure that the 
interval over which the probability is desired is contained
in the interval over which the probability is non-zero, although
the computational formula employed assumes that this is so.</Para>
<programlisting id="uniform-listing">
'c==4' THEN
"UNIFORM DIST. X~UNF(a,b)"
{ { } { } 
{ "A:" "Enter A" 0 }
{ "B:" "Enter B" 0 }
{ } { }
{ "X1:" "Enter Lower limit" 0 }
{ "X2:" "Enter upper limit" 0 }
} { 2 } { } { } 
INFORM DROP OBJ&To; DROP
'X2' STO
'X1' STO
'B' STO
'A' STO
"X~Uniform(x;" A &To;STR +
"," + B &To;STR + ")" +
'&Int;(X1, X2, 1/(B-A), X)'
&To;NUM 'ANS' STO
"P(" X1 &To;STR + "&le;X&le;" + X2 &To;STR + ")=" + ANS 4 RND &To;STR + ANS 
'X1' PURGE
'X2' PURGE
'A' PURGE
'B' PURGE
'ANS' PURGE
'IERR' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="exponential">
<Title>The Exponential Distribution</Title> <Para>Similar in
concept to the uniform distribution, this subprogram uses an
<Application>INFORM</Application> box to get the user's input, stores the
results in named variables, computes the relevant probability, and
<Application>PURGE</Application>s the variables before it exits.</Para>
<Para>In this case, the computational section evaluates the
probability in question by directly integrating the
<Acronym>PDF</Acronym> over the user supplied interval.</Para>
<Para>There is no error checking on the parameter of the distribution
(which must be non-negative), or the user-supplied interval.</Para>
<programlisting id="exponential-listing">
'c==5' THEN
"Exponential DIST.x~exp(&lambda)"
{ { } { }
{ "&lambda:" "Enter the rate: &lambda;>0" 0 }
{ } { } { } 
{ "X1:" "Enter the LOWER limit" 0 }
{ "X2:" "Enter the UPPER limit" 0 }
} { 2 } { } { }
INFORM DROP OBJ&To;
DROP 
'X2' STO
'X1' STO
'&lambda;' STO
'&Int;(X1, X2, &lambda; *EXP(-&lambda;*X), X)'
&To;NUM
'ANS' STO
"X~EXP(x:" &lambda &To;STR + ")" + "P(" X1 &To;STR 
+ "&le;X&le;" + X2 &To;STR + ")=" + ANS 4 RND&To;STR + ANS 
'X1' PURGE
'X2' PURGE
'&lambda' PURGE
'ANS' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="normal-lowertail">
<Title>Lower Tail Normal Probabilities</Title>
<Para>This subprogram finds the lower tail probabilities associated
with the Normal distribution. In other words, it evaluates the Normal 
<Acronym>CDF</Acronym>.</Para>
<Para>The general form of the subprogram is similar to the majority of
the other subprograms; an <Application>INFORM</Application> dialog is used to
obtain the user's input, the relevant values are stored in named
variables, the computation is performed, and the stored variables are
cleared.</Para>
<Para>The computational section uses the built-in &HP48; function
<Application>UTPN</Application> (Upper Tail Probability Normal).</Para>
<Para>The program performs no error checking.</Para>
<programlisting id="normal-lowertail-listing">
'c==6' THEN
"     NORMAL      DISTRIBUTION       P(X&le;x)"
MSGBOX CLEAR 
"Normal (lower tail) X~n(&mu;,&sigma;)"
{ { } { }
{ "x:" "Enter X" 0 }
{ } { }
{ "&mu;:" "input the mean" 0 }
{ "&sigma;:" "input the Standard Deviation" 0 }
} { 2 } { } { }
INFORM DROP OBJ&To; DROP
'&sigma;' STO
'&mu;' STO
'&sigma;^2' EVAL 
x UTPN 'ANS' STO
"X~Normal(x;"
&mu;&To;STR + "," + &sigma; &To;STR + ")" 
+ "P(X&le;" x &To;STR + ")=" + '1-ANS' &To;NUM 4 RND &To;STR 
+ '1-ANS' EVAL
'x' PURGE
'&mu;' PURGE
'&sigma;' PURGE
'ANS' PURGE
END
</programlisting>
</Sect2>
<Sect2 id="normal-uppertail">
<Title>Upper Tail Normal Probabilities</Title>
<Para>This program allows the user to compute values associates with
the upper tail (survival) probabilities of the Normal
distribution.</Para>
<Para>In contract to the preceding subprograms, this program defines
an appropriate equation and then invokes the &HP48;
<Application>SOLVE</Application> application.  The user interaction is
delegated to the <Application>SOLVE</Application> application, as is the
display of the answer (and, for the matter, the choice of which answer
the user is seeking).</Para>
<programlisting id="normal-uppertail-listing">
'c==7' THEN 
"     NORMAL     DISTRIBUTION    (Upper Tail)" MSGBOX
&StartProg;
UPPER &mu; &sigma;2 X UTPN -
&EndProg;
STEQ # 737281d LIBEVAL
END
</programlisting>
</Sect2>
<Sect2 id="tdist">
<Title>Upper Tail T Probabilities</Title>
<Para>This subprogram allows the user to compute values associated
with the upper tail of Student's T distribution.</Para>
<Para>As with the upper tail Normal subprogram, this subprogram
invokes the <Application>SOLVE</Application> application to obtain user input
and perform the relevant calculations.</Para>
<programlisting id="tdist-listing">
'c==8' THEN
"t-DISTRIBUTION
 (Upper Tail)" MSGBOX
&StartProg;
UPPER df T UTPT -
&EndProg;
STEQ
# 737281d LIBEVAL END
</programlisting>
</Sect2>
<Sect2 id="chi-squared">
<Title>Upper Tail Chi-Squared Probabilities</Title>
<Para>This subprogram allows the user to obtain values associated
with the upper tail of the Chi-Squared distribution.</Para>
<Para>Similar in implementation to the other upper tail subprograms,
this section uses the &HP48; <Application>SOLVE</Application> application.</Para>
<programlisting id="chi-squared-listing">
'c==9' THEN
"    Chi-Squared    DISTRIBUTION 
(Upper Tail)" MSGBOX
&StartProg
UPPER df X2 UTPC -
&EndProg; STEQ
# 737281d LIBEVAL END
</programlisting>
</Sect2>
<Sect2 id="cleanup"><Title>Cleanup</Title>
<Para>This subprogram <Application>PURGE</Application>s the variables which
may be left in the user's directory by the other subprograms.</Para>
<Para>No error checking is done before purging these variables.
Indeed, it is difficult to see how error checking could be performed,
given the overall structure of the MA206 program. This issue is
further discussed below, as it is a general design issue for the
program, not just this subprogram.</Para>
<programlisting id="cleanup-listing">
'c==10' THEN
'EXPR' PURGE
'EQ' PURGE
'UPPER' PURGE
'df' PURGE
'T' PURGE'
'X2' PURGE
'&mu;' PURGE
'&sigma;2' PURGE
'X' PURGE
'X1' PURGE
'n' PURGE
'p' PURGE
'ANS' PURGE
'&lambda;' PURGE
'M' PURGE
'N' PURGE
'A' PURGE
'B' PURGE
'&lambda;' PURGE <LineAnnotation>This second <Application>PURGE</Application>
of &lambda; appears to be redundant.</LineAnnotation>
'x' PURGE
'&sigma;' PURGE
'IERR' PURGE
END
END
&EndProg;
&EndProg;
</programlisting>
</Sect2>
</Sect1>
<Sect1><Title>Implementation Notes</Title>
<Sect2><Title>Overwriting Stored Variables</Title>
<Para>A consequence of
this is that if any of these variables are used other than as
temporary variables in the MA206 program, the MA206 program may
overwrite or delete them without warning.  Since a number of the
variables were chosen to have mnemonic value matching the names of
variables commonly used in the subject area.... [TBR]</Para></Sect2>

<Sect2><Title>Calling the <Application>SOLVE</Application> Application</Title>
<Para>Neat Trick! [TBR]</Para>
</Sect2>
<Sect2><Title>Using the <Application>INFORM</Application> Dialog</Title>
<Para>As it is used in this program, the <Application>INFORM</Application>
programming construct causes a program error if the user selects
<KeyCap>CANCEL</KeyCap> from within the <Application>INFORM</Application>
screen.  This occurs because when the user exits
<Application>INFORM</Application>, the routine returns a status value, which
is <Application>DROP</Application>ped without examination in the existing
program, and the resulting stack does not contain the right number or
type of values.</Para> <Para>Causing the program to exit with an error
is not catastrophic. The error occurs if the user selects
<KeyCap>CANCEL</KeyCap>, and results in program termination. Since the
user presumably wants out of the program if they select
<KeyCap>CANCEL</KeyCap>, the actual result matches reasonably with the
user's expectation.  However, creating a program error (and thus
displaying an apparently unrelated error message) is bad programming
style because it may be confusing, especially to an unsophisticated
user.</Para>
</Sect2>
</Sect1>
<Sect1><Title>Potential Extensions to the MA206 Program</Title>
<Sect2><Title>Normal Intervals</Title>
<Para></Para>
</Sect2>
</Sect1>
<bibliography id="references">
<title>References</title>
<BiblioDiv>
<title>Primary References</title>
<biblioentry id="Devore">
<Author>
  <Surname>Devore</Surname>
  <FirstName>Jay</FirstName>
  <OtherName>L.</OtherName>
</Author>
<Title>Probability and Statistics for
Engineering and the Sciences</Title>
<Edition>4th ed.</Edition>
<Publisher>
  <PublisherName>Duxbury Press</PublisherName>
  <Address>Belmont CA</Address>
</Publisher>
<PubDate>1995</PubDate>
</BiblioEntry>

<biblioentry id="UsersGuide">
<corpauthor>Hewlett Packard</corpauthor>
<title>HP 48G Series User's Guide</title> 
<TitleAbbrev  id="title-UsersGuide">HP 48 User's Guide</TitleAbbrev>
<Edition>5th ed.</Edition>
<Publisher>
   <PublisherName>Hewlett Packard</PublisherName>
   <Address>Corvallis OR</Address>
</Publisher>
<PubDate>1993</PubDate>
<ProductNumber>00048-90126</ProductNumber>
</biblioentry>

<biblioentry id="AURM">
<CorpAuthor>Hewlett Packard</CorpAuthor>
<title>HP 48G Series Advanced User's Reference Manual</title>
<edition>4th ed.</edition>
<Publisher>
  <PublisherName>Hewlett Packard</PublisherName>
  <address>Corvallis OR</address>
</Publisher>
<PubDate>1994</PubDate>
<ProductNumber>00048-90136</ProductNumber>
</biblioentry>

<biblioentry id="MA206SG">
<CorpAuthor>Department of Mathematical Sciences, USMA</CorpAuthor>
<title>MA206 Probability and Statistics Study Guide</title>
<subtitle>STAP 98-3</subtitle>
<Publisher>
  <PublisherName>United States Military Academy</PublisherName>
  <Address>West Point, NY 10996</Address>
</Publisher>
<PubDate>1998</PubDate>
</biblioentry>
</BiblioDiv>
<BiblioDiv><title>Additional Reading</title>
<para>The following are some additional references which 
may be useful in learning how to program the &HP48;.</para>
<BiblioEntry id="tn052c">
 <CorpAuthor>EduCALC</CorpAuthor>
 <title>Writing Your First HP 48 Program</title>
 <SubTitle>EduCALC Technical Notes</SubTitle>
 <PubDate>Accessed 7/27/98, 1845</PubDate>
 <ProductName><Ulink 
  URL="http://www.educalc.com/TZ/tn052c.htm">http://www.educalc.com/TZ/tn052c.htm</Ulink></ProductName>
<Abstract><para>An introduction to programming the &HP48; and its <quote>object
orientation</quote>, physical organization, and program entry.</para></Abstract>
</BiblioEntry>
<BiblioEntry id="tn054c">
 <CorpAuthor>EduCALC</CorpAuthor>
 <title>Writing Your Second HP 48 Program</title>
 <SubTitle>EduCALC Technical Notes</SubTitle>
 <PubDate>Accessed 7/27/98, 1845</PubDate>
 <ProductName><Ulink 
  URL="http://www.educalc.com/TZ/tn054c.htm">http://www.educalc.com/TZ/tn054c.htm</Ulink></ProductName>
<Abstract><para>Continuing the series of class programming handouts, this
technical note introduces basic input mechanisms and stack manipulation
under program control.</para></Abstract>
</BiblioEntry>
<BiblioEntry id="tn055c">
 <CorpAuthor>EduCALC</CorpAuthor>
 <title>Writing Your Third HP 48 Program</title>
 <SubTitle>EduCALC Technical Notes</SubTitle>
 <PubDate>Accessed 7/27/98, 1846</PubDate>
 <ProductName><Ulink 
  URL="http://www.educalc.com/TZ/tn055c.htm">http://www.educalc.com/TZ/tn055c.htm</Ulink></ProductName>
<Abstract><para>Third in the series of class programming handouts, this
technical note introduces basic output display mechanisms and 
program sizing.</para></Abstract>
</BiblioEntry>
<BiblioEntry id="tn056c">
 <CorpAuthor>EduCALC</CorpAuthor>
 <title>Writing Your Fourth HP 48 Program</title>
 <SubTitle>EduCALC Technical Notes</SubTitle>
 <PubDate>Accessed 7/27/98, 1846</PubDate>
 <ProductName><Ulink 
  URL="http://www.educalc.com/TZ/tn056c.htm">http://www.educalc.com/TZ/tn056c.htm</Ulink></ProductName>
<Abstract><para>Continuing the series of &HP48; programming lessons by 
introducing the concepts of program-controled variable storage and
moularity (calling other programs as part of a system).</para></Abstract>
</BiblioEntry>
<BiblioEntry id="tn050c">
 <CorpAuthor>EduCALC</CorpAuthor>
 <title>INPUT - By Example</title>
 <SubTitle>EduCALC Technical Notes</SubTitle>
 <PubDate>Accessed 7/27/98, 1843</PubDate>
 <ProductName><Ulink 
  URL="http://www.educalc.com/TZ/tn050c.htm">http://www.educalc.com/TZ/tn050c.htm</Ulink></ProductName>
<Abstract><para>An introduction to using the &HP48; <command>INPUT</command>
command.</para></Abstract>
</BiblioEntry>
</BiblioDiv>
</bibliography>
</article>



