!  Computing Probabilities in LINGO;
! 1) Suppose we want to compute the 
binomial probability of getting N bad items
in a sample of M items from an infinitely large population
in which a fraction p of the items are bad.  The formula is:
! Incidentally, the term
is the number of ways of choosing N bad items out of M items,
taking into account all possible sequences for encountering the
N items.
If M is large, e.g., > 170, you do not want to use this
formula directly because M! may be very large, too large to 
be represented without overflow on a typical computer.
Similarly, the terms p^N or (1-p)^(M-N) may be very small,
resulting in underflow to zero, in which case the results
will be incorrect.  The usual resolution of this numerical
problem is to work with logarithms.
In mathematics, the functions Gamma and Log Gamma (LGM) are
defined as:
   Gamma(N+1) = N!, and LGM(N+1) = Log(Gamma(N+1)). So the
binomial probability is computed by;
 M = 15;  ! Take a sample of size M;
 N =  2;  ! Number of bad items we might find;
 p = .05; ! Fraction of bad items in entire population;
 ProbBin = @EXP( @LGM( M + 1) - @LGM( N + 1) 
                - @LGM( M - N + 1) 
                + N*@LOG(p) + (M-N)*@LOG(1-p));
! Alternatively, you can just use the builtin probability
 function for the binomial in LINGO...;
 BuiltinBin = @PBINOPDF( M, p, N);

  !2)  Similar comments apply to the Poisson distribution.
If customers arrive at mean rate Lambda per unit time, 
then in an interval of length T, 
the probability of seeing N customers is:
      @EXP(-Lambda*T)*((Lambda*T)^N)/N! ;
! Again, there is a factorial term that may overflow for large N and
a power term that might also overflow for large N. 
Taking Logs, we can compute the Poisson probability by...;
  Lambda = 3;
  T = 2;
  ProbPois = @EXP( -Lambda*T + N*@LOG( Lambda*T) - @LGM( N+1));

! Alternatively, you can just use the builtin probability
 function for the Poisson in LINGO...;
  BuiltinPois = @PPOISPDF( Lambda*T, N);

! To see all the probabiity distributions available in LINGO,
 click on:  Edit -> Paste Function -> Distributions;

! Keywords: Probability computation, Binomial probability,
     Poisson probability;