#
# Evaluate the appropriate pfaffian for Q(<lambda>) or the skew
# Schur Q-function Q(<lambda>,<mu>) (<mu>=inner shape), expressing the
# result in terms of one and two-rowed Q-functions. 
#
`QF/pfaff`:=proc(mu) local nu,l,i,j,mat;
  if nargs>1 then nu:=args[2] else nu:=[] fi;
  l:=nops(mu)+nops(nu);
  if l=0 then RETURN(1) fi;
  if modp(l,2)=1 then nu:=[op(nu),0]; l:=l+1 fi;
  mat:=array(1..l,1..l);
  for i to l do
    for j from i+1 to nops(mu) do mat[i,j]:=Q[mu[i],mu[j]] od;
    for j from 1 to nops(nu) do
      if i>nops(mu) then mat[i,l-j+1]:=0 else
        mat[i,l-j+1]:=`QF/pfaff/ent`(mu[i]-nu[j]) fi;
    od
  od;
  `QF/pfaff/ian`(mat)
end:
#
`QF/pfaff/ent`:=proc(x) if x>0 then Q[x] elif x=0 then 1 else 0 fi end:
#
# If A is an antisymmetric matrix of even dimension, this routine
# computes the pfaffian using Laplace-type expansions. The only entries
# of A that need to be defined are those above the main diagonal.
#
`QF/pfaff/ian`:=proc(A) local n,i,inds,res;
  n:=linalg['coldim'](A);
  if modp(n,2)=1 then ERROR(`matrix has odd dimension`) fi;
  if n=2 then RETURN(A[1,2]) fi;
  res:=0;
  for i to n-1 do
    inds:=subsop(i=NULL,[$1..n-1]);
    if A[i,n] <> 0 then res:=res+(-1)^(n-i-1)*A[i,n]*
      `QF/pfaff/ian`(linalg['submatrix'](A,inds,inds)) fi;
  od; res
end:
#
save `QF/pfaff`, `QF/pfaff/ian`, `QF/pfaff/ent`, cat(HomeLib,`/QF/pfaff.m`);
read cat(HomeLib,`/help/QF/pfaff`);
quit;

