
# Test NATURALLY labeled ORDINARY W-polynomials
# of ALL (connected) posets for non-real zeros.
#
# There is no need to check both P and P-dual.
#
# Example: testall(8);

read allrealzeros;
read fastW;
read traverse;
read ideals;
read `posets2.2.1v.txt`;

# A cheap test that allows us to avoid considering both P and its dual,
# in most cases. The 'dualsquash' test is better, but too expensive for
# searches of naturally labeled posets.
#
# Return true if we can cheaply distinguish P from its dual,
# and P is the one that is "heavy" (i.e., may be ignored).

heavy:=proc(P,n) local X,Y,PX,PY,F,G;
  X:={$1..n}; Y:={$1..n}; PX:=P; PY:=P;
  while nops(X)>0 do
    F:=X minus map(x->x[2],PX);
    G:=Y minus map(x->x[1],PY);
    if nops(F)<>nops(G) then break fi;
    X:=X minus F; Y:=Y minus G;
    PX:=map(proc(x,y) if not member(x[1],y) then x fi end,PX,F);
    PY:=map(proc(x,y) if not member(x[2],y) then x fi end,PY,G);
  od;
  evalb(nops(F)>nops(G))
end;

# If P is connected and not heavy, compute its W-polynomial
# and test it for non-real zeros.

test:=proc(ct,P,down,n,t) local X,g;
  if posets['connected'](P,n) and not heavy(P,n) then
    X:={$1..n};
    g:=fastW(P,X,t,ideals(down,X));
    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 on n points for non-real zeros.

testall:=proc(n) local st,res;
  st:=time(); printf(`\n`);
  res:=traverse(n,[0,0],test,t);
  if `+`(0)=0 then st:=time()-st,kernelopts(bytesalloc)
    else st:=time()-st,4*status[2] fi;
  printf(`all_nat_o  n=%-2d  tot=[%8d,%8d]  time=%10.2f  space=%7d\n`,
    n,op(res),st);
end;

