function v = walker_verify ( n, x, y, a )

%*****************************************************************************80
%
%% walker_verify() verifies a Walker Sampler structure.
%
%  Discussion:
%
%    This test applies the sampling algorithms to a Zipfian distribution.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    21 February 2016
%
%  Author:
%
%    Original C version by Warren Smith.
%    This version by John Burkardt.
%
%  Input:
%
%    integer N, indicates the size of X.
%
%    real X(1:N+1), contains in X(1) through X(N) the
%    probabilities of outcomes 1 through N.
%
%    real Y(1:N+2), the Walker threshold vector.
%
%    integer A(1:N+2), the Walker index vector.
%
%  Output:
%
%    real V, the verification sum, which should be close to zero.
%
  z = zeros ( n + 2, 1 );
%
%  Reverse the scaling.
%
  z(2:n+1) = y(2:n+1) / n;
%
%  Add back the adjustments.
%  Don't try to vectorize this statement!
%
  for i = 1 : n
    z(a(i+1)+1) = z(a(i+1)+1) + ( 1.0 - y(i+1) ) / n;
  end
%
%  Check for discrepancies between Z and X.
%
  v = sum ( abs ( z(2:n+1) - x(2:n+1) ) );

  return
end
 
