
# Test NATURALLY labeled ENRICHED W-polynomials
# of narrow posets for non-real zeros.
#
# Here, minimal examples are either irreducible, or irreducible
# after deleting a minimum element. The latter show up as examples
# for ordinary W-polynomials, so we only check irreducible cases.
# We cannot eliminate P-dual after testing P, however. 
#
# Example: testall(8);

read allrealzeros;
read fastW;
read canform;
read narrow;
read ideals;

# If P is in canonical form, compute its enriched W-polynomial
# and test it for real zeros.

test:=proc(ct,P,down,N,t,pg) local X,g;
  if canform(P,pg) then
    X:={$1..N};
    g:=fastW(P,X,t,ideals(down,X),'enriched');
    if not allrealzeros(g,t) then print(`Counterexample:`,P) fi;
    RETURN([ct[1]+1,ct[2]+1])
  fi;
  [ct[1],ct[2]+1]
end;

# Test all W-polynomials for real zeros.

testall:=proc(n) local st0,tot,pg,m,st,i,res;
  st0:=time(); tot:=[0,0]; pg:=[];
  printf(`\n`);
  for m from 1 to n/2 do
    st:=time();
    if 2*m=n then pg:=[{seq(i=i+m,i=1..m),seq(i+m=i,i=1..m)}] fi;
    res:=narrow([[n-m,m]],[0,0],test,t,pg);
    tot:=zip((x,y)->x+y,tot,res);
    printf(` type=[%2d,%2d]  ct=[%7d,%7d]  time=%9.2f  space=%7d\n`,
      n-m,m,op(res),stat(st));
  od:
  printf(`nar_nat_e  n=%-2d  tot=[%8d,%8d]  time=%10.2f  space=%7d\n`,
    n,op(tot),stat(st0));
end;

if `+`(0)=0 then # we are using Maple V.4 or later
  stat:=proc(st) time()-st,kernelopts(bytesalloc) end
else
  stat:=proc(st) time()-st,4*status[2] end
fi;

