(* BigWPx.nb ------------------------------------------------------------ *)

(* Writes out the polynomials WP(x) for all posets in the given list.
Will work for posets with 2 to 14 elements;  designed with all connected
posets having 8 or 9 elements in mind. *)

(* Utility Needed: WriteLstOfLst[]. *)
(* Function Needed: InvStdTab[]. *)
(* Data Needed: stdisos*, lookups*, invexts* for 1 <= * <= 7. *) 

(* User must specify the directory, a poset size, and input and output 
	file sudirectory/names. *)

(* Change Directory: *)
SetDirectory["J:/isis/home/c/a/cagann/public_html/Posets"];

<< GenrlUtils.m;   << PosetUtils.m;   << HookUtils.m;

(* Change size of posets considered: *)    psiz = 9; 

(* Change input family: *) infam = "Connets/connets";
(* Change output family: *) outfam = "ConWPxs/conwpxs";

stmem = MaxMemoryUsed[]; sttim = AbsoluteTime[]; stcpu = TimeUsed[];

(* Get isomorphisms, lookups, and inverse extensions. *)
ssfil[nn_] := StringJoin["StdIsos/stdisos",ToString[nn]];
mmfil[nn_] := StringJoin["Lookups/lookups",ToString[nn]];
iifil[nn_] := StringJoin["InvExts/invexts",ToString[nn]];
Do[
	<< (ssfil[sz]);
	<< (mmfil[sz]);
	invrsex[sz] = ReadList[iifil[sz]]
,{sz,Floor[psiz/2],Ceiling[psiz/2]}];

(* Get list of posets of size psiz. *)
allpsts = ReadList[ StringJoin[infam,ToString[psiz]] ];

wpxlist = {};
Do[                                (* Run through all posets in the list. *)

	posst = allpsts[[kase]];	
	wpz = 0;
	idels = Select[                          (* All ideals of size psiz/2. *)
		AntiChnsIdls[posst][[2]],
		(Length[#]\[Equal]Floor[psiz/2])&
	]; 

	Do[               (* Run through all ideals with half of the elements. *)
		iddl = idels[[kk]];
		fltr = Complement[Range[psiz],iddl];

(* Combine the ideal/
            filter inverse extensions in all possible ways. *)        
		someinvexts = Flatten[Outer[
			Join,
(* Get inverse exts for the ideal and for the filter. *)
			InvStdTab[posst,iddl],
			InvStdTab[posst,fltr],
		1],1];

		wpz = Plus[wpz,
			Apply[Plus,                                 (* Adds powers of z. *)
				Map[Function[x,
					z^(Apply[Plus,            (* Adds doubled descent indices. *)
						Map[
							((Sign[x[[#]]-x[[#+1]]]+1)*#)&, (* Doubles desc psts *)
							Range[psiz-1]           (* Potential descent posits. *)
						]
					]/2)                                  (* Removes doubling. *)
				],someinvexts]
			]
		];

	,{kk,Length[idels]}];

	AppendTo[ wpxlist, CoefficientList[wpz,z] ]

,{kase,Length[allpsts]}];

WriteLstOfLst[
	StringJoin[outfam,ToString[psiz]],
	wpxlist
];

emem = MaxMemoryUsed[]; etim = AbsoluteTime[]; ecpu = TimeUsed[];
PrntCnsmptn[stmem,emem,sttim,etim,stcpu,ecpu];

(* End of BigWPx.nb. *)