
# Process the results of the search for naturally labeled NRZ posets:
#   1. recompute the W-polynomials via the naive ('linear') algorithm,
#      and check that the results agree with the 'fastW' algorithm,
#   2. reconfirm that they have non-real zeros,
#   3. prettyprint the results, sorted in order of W_P(1).

read allrealzeros;
read fastW;
read `../data/natnrz.out`;    # this will assign n:= number of vertices
read `posets2.2.1v.txt`;

# set flag to true to save PostScript plots of each poset
flag:=false;

foo:=proc(P,f,j)
  plotsetup(ps,plotoutput=cat(`figs/plot`,j,`.eps`),
    plotoptions=`portrait,noborder`);
  print(posets['plot_poset'](P,title=cat(`     `,convert(f,'string')),
    titlefont=[TIMES,ROMAN,10]));
end;

# prettyprint a nonempty set of edges in sorted order

mypr:=proc(V) local sV,i,flag;
  sV:=[op(V)]; flag:=`{[`;
  sV:=sort(sV,(u,v)->evalb(u[1]<v[1] or (u[1]=v[1] and u[2]<v[2])));
  cat(flag,sV[1][1],`,`,sV[1][2],
    seq(cat(`],[`,sV[i][1],`,`,sV[i][2]),i=2..nops(sV)),`]}`);
end;

# We first relabel the vertices and dualize, so that the results
# look more like what is in Figures 1 and 6 of the paper.

N:=nops(sa);
pi:=[1,3,5,7,9,11,13,15,2,4,6,8,10,12,14,16,17]:
sa:=subs({seq(18-i=pi[i],i=1..17)},map(posets['dual'],sa)):
P0:=`intersect`(op(sa)):
Q0:=`union`(op(sa)) minus P0:
sa:=[seq([P,fastW(P,n,t)],P=sa)]:
sa:=sort(sa,(u,v)->evalb(subs(t=1,u[2]<=v[2]))):

interface(quiet=true);
P0; Q0;
for i to N do
  P:=sa[i][1]: f:=sa[i][2]:
  if f<>posets['W'](P,n,1,t,'linear') or allrealzeros(f,t) then
    ERROR(`this cannot happen`) fi;
  f:=[seq(coeff(f,t,j),j=1..degree(f,t))]:
  if flag then foo(P,f,i) fi;
  printf(`\n%2d  %-36s %-36s\n`,
    i,cat(`[`,op(map(x->(x,` `),f)),`]`),mypr(P minus P0));
od:
interface(quiet=false);

quit;

