function Pr = PathPr(pu,N)
% Octave/MATLAB function to compute the probability
% of a path in a recombining binomial tree X with
% depth N, given up probabilities pu stored in an 
% NxN matrix, and store them in a non-recombining
% tree indexed by m=1:2*2^N-1.
% INPUTS:                                (Example)
%   pu = recombining tree matrix       (3x3 lower)
%   N = tree height, must be >0                (3)
% OUTPUTS:
%   Pr = probability of each m-path to (n(m),j(m))
% EXAMPLE:
%   pu = [.51,0,0; .52,.53,0;.54,.55,.56];
%   Pr = PathPr(pu,3);
% Visualize the probabilities of the longest paths:
%   plot(Pr(8:15))
%
  pubar = NRTinject(pu,N-1); % inject rows 1:(N-1)
  Pr = ones(1,2*2^N-1); %...so Pr(1)=1
  for m=1:2^N-1  % all m indices before row N
    Pr(2*m)   = (1-pubar(m))*Pr(m); % down state
    Pr(2*m+1) = pubar(m)*Pr(m); % up state
  end 
  return
end
