function [X,Y] = CorrectionTerm(A,u,v,k)
% A is n-by-n, u and v are n-by-1, and k is a positive integer.
% X and Y are n-by-k such that (A+u*v')^k = A^k + X*Y'

% (A^k + XY')(A + uv') = A^(k+1) + XY'(A+uv') + (A^k u)v'
% = A^{k+1) + [ X , (A^k *u)] * [(A + uv')'*Y , v]'
% = A^(k+1) + [X , w] * [ (A'*Y + v*(u'*Y)) , v ]'
% where
% w = (A^k)*u

X = u;
Y = v;
w = u;
for j=2:k
w = A*w;
X = [X w];
Y = [ (A'*Y + v*(u'*Y)) v];
end

% Flop analysis each time through the loop...
% w update = 2n^2
% A'*Y = (2n^2)(j-1)
% u'*Y = 2n(j-1)
% v*(u'*Y) = 2n(j-1)
%
% so (2n^2)j per pass through the loop so (n^2)(k^2) total

% If you have something like Apower = A*Apower in the loop, -2 points
% If you have something like (A^(j-1))*u in the loop, -3 points