(* DrctSum.nb ----------------------------------------------------------- *)

(* Given lists of posets of Type X with fewer than n elements and a list 
	of posets of Type Y with n elements, writes out the sorted list of 
	standard forms of all direct sums of two posets of Type X with a total
	of n elements together with the n-posets of Type Y. *)

(* Utility Needed: WriteLstOfLst[]. *)
(* Functions Needed: StdFormIso[], DirectSm[]. *)

(* User must specify the directory, a poset size, an input file family,
	an input file, and an output file. *)

(* Change the directory: *)
SetDirectory["J:/isis/home/c/a/cagann/public_html/Posets"];
<< GenrlUtils.m;   << PosetUtils.m;   << InvExIsoFncts.m;   << HookUtils.m; 

(* Change the size of posets: *) nn = 9;

(* Change file family for posets of Type X: *) xxfam = "HookPos/hookpos";
(* Change file for posets of Type Y: *) yyfam = "EmptyPs/emptyps";
(* Change output file: *)  outfam = "SmHLPos/smhlpos";

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

Do[
	xxlst[ix] = ReadList[ StringJoin[xxfam,ToString[ix]] ]
,{ix,nn-1}];

yylst = ReadList[ StringJoin[yyfam,ToString[nn]] ];

diffsizs = Flatten[
	Table[
		Outer[ DirectSm, xxlst[kk], xxlst[nn-kk] ,1]
	,{kk,Floor[(nn-1)/2]}]
,2];

Which[
	Mod[nn,2]\[Equal]1,
	samesize = {},
	Mod[nn,2]\[Equal]0,
	samesize = Flatten[
		Table[
			Table[
				DirectSm[ xxlst[nn/2][[iz]], xxlst[nn/2][[jz]] ]
			,{jz,iz}]
		,{iz,Length[xxlst[nn/2]]}]
	,1]
];


WriteLstOfLst[
	StringJoin[ outfam, ToString[nn] ],
	Union[ Map[StdFormIso[#][[1]]&,Join[diffsizs,samesize,yylst]] ]
];

emem = MaxMemoryUsed[]; etim = AbsoluteTime[]; ecpu = TimeUsed[];
PrntCnsmptn[stmem,emem,sttim,etim,stcpu,ecpu];
(* End of DrctSum.nb. *)