function mp = mpmak(coefs,d,k,center,dimpjd,mm)
%MPMAK multivariate polynomial in (shifted normalized) power form
%
%        MP = MPMAK(COEFS,D[,K,CENTER,DIMPJD,MM])
%
% Returns in MP the given (and other helpful) information about the polynomial
%
%   p(x) = sum_a (x-center)^a (|a| choose a) coefs(nn(a)) ,
%
% with  nn(a) := dim Pi_{<|a|}(R^d) + n(a) ,  and  n(a)  the position of  a  in 
% the lexicographic ordering of  A_{|a|}(d) , where  |a| := sum_{i=1:d} a(i) 
% and  A_j(d) := {a in Z_+^d : |a| = j} .
% The combinatorial factor is just right to make the evaluation of  p  by 
% Horner's scheme very simple (see MPVAL).
%
% Further, DIMPJD = (dim Pi_j(R^d): j=-1:k) ,  and  MM  contains indexing 
% information related to the lexicographic ordering. Precisely,
%
%    MM(i,nn(a)) = n(a+e_i), i=1:d .
%

% cb 26jul97; reverted to v4 7sep97
%   Copyright (c) 1997 by C. de Boor

[df,nc] = size(coefs);
if nargin<3 % we must deduce  K  from  NC 
   index = ones(1,d+1); k = 0;
   while index(d+1)<nc, index = cumsum(index); k = k+1; end
   if index(d+1)>nc
      mp = []; error('For every k, length(coefs(1,:)) neq dim Pi_k(R^d) .'), end
end

if nargin < 4, center = zeros(d,1); end

if nargin < 5 % we must generate  DIMPJD  and  MM 
   [mm,blaises,m,pm] = mpnext(d); dimpjd = [0 1];
   for j=1:k
      [mj,blaises,m,pm] = mpnext(blaises,m,pm);
      mm = [mm mj]; dimpjd = [dimpjd blaises(d+1)];
   end
   mm = [mm m(ones(d,1),:)]; % the most recent M is stored (d-fold, in order
                % to conform to MM's size) in the last part of MM, for 
                % possible use, in degree-raising, integration, etc.
end

% of use on MATLAB versions prior to v5
mp = [94, df, d, reshape(center,1,d), k, dimpjd, reshape(coefs,1,df*nc), ...
     reshape(mm,1,d*nc)];

%v5 mp = {94, center, coefs, dimpjd, mm};
