%%HP: T(3)A(D)F(.);
@ PROB, by Brian Korver
DIR
  COMBNATION
    \<< \-> N R 'N!/(R!
*(N-R)!)'
    \>>
  BANG
    \<< \-> X 'FACT(X)'
    \>>
  Bin
    \<< 'COMB(n,I)*p^
I*(1-p)^(n-I)'
"Binomial Mass
Function.
Enter n p i"
{ ALG V } INPUT
OBJ\-> \-> n p I
      \<< \->STR STR\->
EVAL "P{X=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Bin.D
    \<< '\GS(x=0,I,COMB
(n,x)*p^x*(1-p)^(n-
x))'
"Binomial Distribution
Function.  
Enter n p i"
{ ALG V } INPUT
OBJ\-> \-> n p I
      \<< \->STR STR\->
EVAL "P{X\<=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Pois
    \<< 'EXP(-L)*L^I/
I!'
"Poisson Mass
Function.
Enter \Gl (or 'n*p') i"
{ ALG V } INPUT
OBJ\-> \-> L I
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Pois.D
    \<< '\GS(x=0,I,EXP(
-L)*L^x/x!)'
"Poisson Distribution
Function. (ok \Gl<200?) 
Enter \Gl (or 'n*p') i"
{ ALG V } INPUT
OBJ\-> \-> L I
      \<< \->STR STR\->
\->NUM "P{X\<=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Geom
    \<< 'p*(1-p)^(n-1
)'
"Geometric Mass
Function.
Enter n p"
{ ALG V } INPUT
OBJ\-> \-> n p
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP n 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  NBin
    \<< 'COMB(n-1,r-1
)*p^r*(1-p)^(n-r)'
"Negative Binomial
Mass Function.
Enter n p r"
{ ALG V } INPUT
OBJ\-> \-> n p r
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP n 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Hyper
    \<< 'COMB(N*p,I)*
COMB(N-N*p,n-I)/
COMB(N,n)'
"Hypergeometric Mass
Function.
Enter N n p i"
{ ALG V } INPUT
OBJ\-> \-> N n p I
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Normal
    \<<
"Normal Distribution
Unit Transformation.
Enter \Gm \Gs x"
{ ALG V } INPUT
OBJ\-> \-> m s x
      \<< "P{X\<=" RCLF
STD SWAP x 4 RND +
"}=\O/(" + '(x-m)/s'
EVAL DUP 3 ROLLD 3
RND + ")=" + SWAP 2
RND 4 FIX 0 1 ROT
UTPN NEG 1 + DUP \->
HLD
        \<< + SWAP
STOF HLD
        \>>
      \>>
    \>>
  UNorm.D
    \<<
"Unit Normal
Distribution.
Enter z"
{ ALG V } INPUT
OBJ\-> \-> Z
      \<< "P{Z\<=" RCLF
STD SWAP Z 4 RND +
"}=" + 4 FIX 0 1 '-
RND(Z,2)' \->NUM UTPN
+ SWAP STOF
      \>>
    \>>
  DeMoivre.Laplace
    \<<
"DeMoivre-Laplace
Distribution.
Enter n p a b"
{ ALG V } INPUT
OBJ\-> \-> n p a b
      \<< 'n*p' EVAL
'\v/(n*p*(1-p))' EVAL
\-> m s
        \<< "'\O/(" '(b
+.5-m)/s' EVAL \->NUM
3 RND + ")-\O/(" + '(
a-.5-m)/s' EVAL
\->NUM 3 RND + ")=" +
0 1 '(b+.5-m)/s'
\->NUM 2 RND UTPN NEG
1 + 0 1 '(a-.5-m)/s
' \->NUM 2 RND UTPN
NEG 1 + - + "'" +
OBJ\->
        \>>
      \>>
    \>>
  Exp.D
    \<< '1-EXP(-L*I)'
"Exponential Distribution
Function.  (\Gl=1/\Gm)
Enter \Gl i"
{ ALG V } INPUT
OBJ\-> \-> L I
      \<< \->STR STR\->
\->NUM "P{X<" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Gam.D
    \<< '1-EXP(-L*I)*
\GS(K=0,T-1,INV(K!)*(
L*I)^K)'
"Gamma Distribution
Function.
Enter \Gl t i"
{ ALG V } INPUT
OBJ\-> \-> L T I
      \<< \->STR STR\->
\->NUM "P{X<" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Weibull
    \<< 'B/A*((X-V)/A
)^(B-1)*EXP(-((X-V)/A)^B)'
"Weibull Density
Function.
Enter \Ga \Gb v i"
{ ALG V } INPUT
OBJ\-> \-> A B V I
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Weib.D
    \<< '1-EXP(-((I-V
)/A)^B)'
"Weibull Distribution
Function.
Enter \Ga \Gb v i"
{ ALG V } INPUT
OBJ\-> \-> A B V I
      \<< \->STR STR\->
\->NUM "P{X<" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Cauc.D
    \<< '.5+INV(\pi)*
ATAN(I-T)'
"Cauchy Distribution
Function.
Enter \Gh i"
{ ALG V } INPUT
OBJ\-> \-> T I
      \<< \->STR STR\->
\->NUM "P{X<" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
  Beta
    \<< 'FACT(A+B-1)/
(FACT(A-1)*FACT(B-1
))*I^(A-1)*(1-I)^(B
-1)'
"Beta Density
Function.
Enter a b i"
{ ALG V } INPUT
OBJ\-> \-> A B I
      \<< \->STR STR\->
\->NUM "P{X=" RCLF
STD SWAP I 4 RND +
SWAP STOF "}=" +
SWAP 4 RND +
      \>>
    \>>
END
