## -*- texinfo -*-
## @deftypefn {FunctionFile} {@var{y} = } reduce (@var{f},@var{x})
##
## Reduces the vector @var(x) to a scalar by repeatedly folding the
## arguments into the function @var(f) from the left.
## @end deftypefn

function y = reduce(f,x)
  # Check the arguments
  if (nargin!=2 || !isvector(x) || length(x)<2)
    print_usage();
  endif

  # Reduce x
  n=length(x);
  y=x(1);

  for i=2:n
    y=f(y,x(i));
  endfor
endfunction