(*******************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which
typically will have the same name as this file except ending in
".nb" instead of ".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent
to using the Evaluate Initialization Cells menu command in the front
end.

DO NOT EDIT THIS FILE.  This entire file is regenerated
automatically each time the parent Notebook file is saved in the
Mathematica front end.  Any changes you make to this file will be
overwritten.
***********************************************************************)



numsplit[a_,n_]:={Mod[a,n,1],Quotient[a,n]}

assgr::usage=
    "assgr[ic,n] is the n-th graph after ic.  The graphs are pair lists, \
starting from node 1.";

assgr[ic_,aa_]:=Module[{ans=ic,hairs,a=aa,new,poss,k,newcon,baseno},
    new=Max[ans];
    hairs=
      Sort[Fold[DeleteCases[#1,#2,{1},1]&,
          Join[Range[new],Range[new],Range[new]],Flatten[ans]]];
    While[a\[NotEqual]0,
      new++;
      poss=Union[hairs];
      {k,a}=numsplit[a,If[Length[poss]\[Equal]3,2,Min[3,Length[poss]]]];
      newcon=
        poss[[Rest[
              FoldList[Module[{dum},{dum,a}=numsplit[a,#2-#1];dum+#1]&,0,
                Length[poss]+Range[-k+1,0]]]]];
      
      hairs=
        Join[Fold[DeleteCases[#1,#2,{1},1]&,hairs,newcon],Table[new,{3-k}]];
      ans=Join[ans,{#,new}&/@newcon]];ans
    ]

grls[aa_,ls_List]:=Module[{ans,hairs,a=aa,new,poss,k,newcon,baseno},
    {baseno,a}=numsplit[a,Length[ls]];
    ans=ls[[baseno]];
    new=Max[ans];
    hairs=
      Sort[Fold[DeleteCases[#1,#2,{1},1]&,
          Join[Range[new],Range[new],Range[new]],Flatten[ans]]];
    While[a\[NotEqual]0,
      new++;
      poss=Union[hairs];
      {k,a}=numsplit[a,If[Length[poss]\[Equal]3,2,Min[3,Length[poss]]]];
      newcon=
        poss[[Rest[
              FoldList[Module[{dum},{dum,a}=numsplit[a,#2-#1];dum+#1]&,0,
                Length[poss]+Range[-k+1,0]]]]];
      
      hairs=
        Join[Fold[DeleteCases[#1,#2,{1},1]&,hairs,newcon],Table[new,{3-k}]];
      ans=Join[ans,{#,new}&/@newcon]];ans
    ]

canned::usage=
    "canned[k,n] is the k-th graph after the line 1,2,...,n.  Other nodes can \
attach to these nodes, but at most once.  For use with strongiso to find \
lists of graphs to append to n-haired graphs, to make initial conditions \
easier to compute by reducing redundant graphs.";

canned[aa_Integer,n_Integer]:=Module[{ans,hairs,a=aa,new,poss,k,newcon},
    ans=Partition[Range[n],2,1];
    new=n;
    hairs=Range[n];
    While[a\[NotEqual]0,
      new++;
      poss=Union[hairs];
      {k,a}=numsplit[a,If[Length[poss]\[Equal]3,2,Min[3,Length[poss]]]];
      newcon=
        poss[[Rest[
              FoldList[Module[{dum},{dum,a}=numsplit[a,#2-#1];dum+#1]&,0,
                Length[poss]+Range[-k+1,0]]]]];
      
      hairs=
        Join[Fold[DeleteCases[#1,#2,{1},1]&,hairs,newcon],Table[new,{3-k}]];
      ans=Join[ans,{#,new}&/@newcon]];ans
    ]