(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 118464, 3316] NotebookOptionsPosition[ 115100, 3225] NotebookOutlinePosition[ 115446, 3240] CellTagsIndexPosition[ 115403, 3237] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[BoxData[{ RowBox[{ RowBox[{"<<", "Combinatorica`"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"$IterationLimit", "=", "\[Infinity]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"$RecursionLimit", "=", "\[Infinity]"}], ";"}]}], "Input", CellChangeTimes->{{3.417881558734375*^9, 3.417881582140625*^9}, { 3.417949763828125*^9, 3.417949800890625*^9}, {3.4184783691875*^9, 3.418478369609375*^9}, {3.418479053875*^9, 3.418479062453125*^9}, 3.422367521375*^9, {3.430228652890625*^9, 3.43022865328125*^9}, { 3.4571222317521725`*^9, 3.4571222331271377`*^9}, {3.4571222711417894`*^9, 3.4571222778603673`*^9}, 3.457122520453125*^9}], Cell[TextData[{ StyleBox["Section 1 - BASIC TOOLS:", FontWeight->"Bold"], " These are some methods that are generally useful." }], "Text", CellChangeTimes->{{3.417881592203125*^9, 3.41788160346875*^9}, { 3.422366266890625*^9, 3.422366276203125*^9}, 3.457122520453125*^9}], Cell[TextData[{ StyleBox["Merge", FontWeight->"Bold"], " has the same functionality as ", StyleBox["Join", FontWeight->"Bold"], ".\n", StyleBox["TableN", FontWeight->"Bold"], " has the same functionality as ", StyleBox["Range", FontWeight->"Bold"], ".\n", StyleBox["RemoveN", FontWeight->"Bold"], " removes all elements from the given list that are between the ", StyleBox["min", FontSlant->"Italic"], " and ", StyleBox["max", FontSlant->"Italic"], " entries, inclusive." }], "Text", CellChangeTimes->{{3.457122524265625*^9, 3.4571225645*^9}, { 3.457123527611426*^9, 3.457123548057644*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Merge", "[", RowBox[{"X_", ",", RowBox[{"{", "}"}]}], "]"}], ":=", "X"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Merge", "[", RowBox[{"X_", ",", RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}]}], "]"}], ":=", RowBox[{"Merge", "[", RowBox[{ RowBox[{"Append", "[", RowBox[{"X", ",", "F"}], "]"}], ",", RowBox[{"{", "R", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"MergeAll", "[", "L_", "]"}], ":=", RowBox[{"Fold", "[", RowBox[{"Merge", ",", RowBox[{"First", "[", "L", "]"}], ",", RowBox[{"Rest", "[", "L", "]"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TableN", "[", "n_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{"i", ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TableN", "[", RowBox[{"min_", ",", "max_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{"i", ",", RowBox[{"{", RowBox[{"i", ",", "min", ",", "max"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"X_", "\[SubsetEqual]", "Y_"}], ":=", RowBox[{ RowBox[{"Sort", "[", RowBox[{"Intersection", "[", RowBox[{"X", ",", "Y"}], "]"}], "]"}], "\[Equal]", RowBox[{"Sort", "[", "X", "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "}"}], ",", "final_List", ",", "min_", ",", "max_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "final_List", ",", "min_", ",", "max_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"min", "\[LessEqual]", "f", "\[LessEqual]", "max"}], ",", RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "final", ",", "min", ",", "max"}], "]"}], ",", RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", "f"}], "]"}], ",", "min", ",", "max"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "}"}], ",", "final_List", ",", "n_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "final_List", ",", "n_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"f", "\[LessEqual]", "n"}], ",", RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "final", ",", "n"}], "]"}], ",", RowBox[{"RemoveN", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", "f"}], "]"}], ",", "n"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"RemoveN", "[", RowBox[{"L", ",", RowBox[{"{", "}"}], ",", "n"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveN", "[", RowBox[{"L_", ",", "min_Integer", ",", "max_Integer"}], "]"}], ":=", RowBox[{"RemoveN", "[", RowBox[{"L", ",", RowBox[{"{", "}"}], ",", "min", ",", "max"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveNAll", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RemoveN", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}], "/@", "L"}], ",", RowBox[{ RowBox[{"#", "\[NotEqual]", RowBox[{"{", "}"}]}], "&"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"RemoveNAll", "[", RowBox[{"L_", ",", "min_", ",", "max_"}], "]"}], ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"RemoveN", "[", RowBox[{"#", ",", "min", ",", "max"}], "]"}], "&"}], "/@", "L"}], ",", RowBox[{ RowBox[{"#", "\[NotEqual]", RowBox[{"{", "}"}]}], "&"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"AddSingleton", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"Append", "[", RowBox[{"L", ",", RowBox[{"{", "n", "}"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AddMissing", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"A", "=", RowBox[{"Complement", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", RowBox[{"Flatten", "[", "L", "]"}]}], "]"}]}], "}"}], ",", RowBox[{"Fold", "[", RowBox[{"AddSingleton", ",", "L", ",", "A"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"AddMissing", "[", RowBox[{"L_", ",", "min_", ",", "max_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"A", "=", RowBox[{"Complement", "[", RowBox[{ RowBox[{"TableN", "[", RowBox[{"min", ",", "max"}], "]"}], ",", RowBox[{"Flatten", "[", "L", "]"}]}], "]"}]}], "}"}], ",", RowBox[{"Fold", "[", RowBox[{"AddSingleton", ",", "L", ",", "A"}], "]"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"PLength", "[", "P_", "]"}], ":=", RowBox[{"Length", "[", RowBox[{"Flatten", "[", "P", "]"}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"AddOneAtPosition", "[", RowBox[{"L_", ",", "i_"}], "]"}], ":=", RowBox[{"ReplacePart", "[", RowBox[{"L", ",", RowBox[{"{", RowBox[{"i", "\[Rule]", RowBox[{ RowBox[{"L", "[", RowBox[{"[", "i", "]"}], "]"}], "+", "1"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SubtractIfLargeEnough", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SubtractIfLargeEnough", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"f", "\[LessEqual]", "n"}], ",", RowBox[{"SubtractIfLargeEnough", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Append", "[", RowBox[{"final", ",", "f"}], "]"}]}], "]"}], ",", RowBox[{"SubtractIfLargeEnough", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"f", "-", "n"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"SubtractIfLargeEnough", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"SubtractIfLargeEnough", "[", RowBox[{"L", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"NegativeQ", "[", "n_", "]"}], ":=", RowBox[{"n", "<", "0"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"NewKSubsets", "[", RowBox[{"L_", ",", "k_Integer"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"k", "<", "0"}], ",", RowBox[{"{", "}"}], ",", RowBox[{"KSubsets", "[", RowBox[{"L", ",", "k"}], "]"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"PolyEquivQ", "[", RowBox[{"P1_", ",", "P2_"}], "]"}], ":=", RowBox[{ RowBox[{"Expand", "[", "P1", "]"}], "\[Equal]", RowBox[{"Expand", "[", "P2", "]"}]}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Pairs", "[", RowBox[{ RowBox[{"{", "}"}], ",", "_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Pairs", "[", RowBox[{"_", ",", RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Pairs", "[", RowBox[{ RowBox[{"{", RowBox[{"f1_", ",", "r1___"}], "}"}], ",", RowBox[{"{", RowBox[{"f2_", ",", "r2___"}], "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"Pairs", "[", RowBox[{ RowBox[{"{", "r1", "}"}], ",", RowBox[{"{", "r2", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{"f1", ",", "f2"}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Pairs", "[", RowBox[{"L1_", ",", "L2_"}], "]"}], ":=", RowBox[{"Pairs", "[", RowBox[{"L1", ",", "L2", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Duplicates", "[", "L_", "]"}], ":=", RowBox[{"First", "/@", RowBox[{"Select", "[", RowBox[{ RowBox[{"Tally", "[", "L", "]"}], ",", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "2"}], "&"}]}], "]"}]}]}]}], "Input", CellChangeTimes->CompressedData[" 1:eJxTTMoPSmViYGCQAGIQzdBwoFG8/KUjkNcOoRdMh9C7ZoDphsIiCTA/sBxM N0xklgTz+YXAdMM7eQjfSgnCN1OD8Iu0IDRPEES8PBzCr18F4VethvCj0s3B 9L1MMN0w871tBYiv/A9Ch7LYgeiGEn4I/V4XQpdbQGihzYlgde+gtP8+MN2w +gCEz9OZBOYnd4FpBouuTDDfoR9MM9hNgdDuUyH04fkQ+YtQeqX7vxqQuJ43 mG4Ia4PQGzoh4id7IbRGH4jWMzCe/OHgS8e7siVgWl3eZw6I9pBSngeif7Z+ Wwii3R44LgHRAILFn5E= "]], Cell[BoxData[{ RowBox[{ RowBox[{"TotalDegree", "[", "a_Power", "]"}], ":=", RowBox[{ RowBox[{"TotalDegree", "[", RowBox[{"a", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}], "*", RowBox[{"a", "[", RowBox[{"[", "2", "]"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Times", "]"}], ":=", RowBox[{"Plus", "@@", RowBox[{"(", RowBox[{"TotalDegree", "/@", RowBox[{"(", RowBox[{"List", "@@", "a"}], ")"}]}], ")"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Plus", "]"}], ":=", RowBox[{"Max", "@@", RowBox[{"(", RowBox[{"TotalDegree", "/@", RowBox[{"(", RowBox[{"List", "@@", "a"}], ")"}]}], ")"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Integer", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Rational", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Real", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "a_Complex", "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TotalDegree", "[", "_", "]"}], ":=", "1"}]}], "Input", CellChangeTimes->{{3.422366427734375*^9, 3.422366428078125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"PolynomialFactorList", "[", "poly_", "]"}], ":=", RowBox[{"Rest", "[", RowBox[{"Sort", "[", RowBox[{"MergeAll", "[", RowBox[{ RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"#", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"{", RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}], "}"}]}], "]"}], "&"}], "/@", RowBox[{"FactorList", "[", "poly", "]"}]}], "]"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"UniqueFactorList", "[", "poly_", "]"}], ":=", RowBox[{"Rest", "[", RowBox[{"First", "/@", RowBox[{"FactorList", "[", "poly", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MaxFactorExponentList", "[", "poly_", "]"}], ":=", RowBox[{"Rest", "[", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}], "&"}], "/@", RowBox[{"FactorList", "[", "poly", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorListSeparateHelper", "[", RowBox[{ RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorListSeparateHelper", "[", RowBox[{"A_", ",", "final_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{"Min", "[", RowBox[{ RowBox[{ RowBox[{"Exponent", "[", RowBox[{"#", ",", "x"}], "]"}], "&"}], "/@", "A"}], "]"}]}], "}"}], ",", RowBox[{"PolynomialFactorListSeparateHelper", "[", RowBox[{ RowBox[{"Select", "[", RowBox[{"A", ",", RowBox[{ RowBox[{ RowBox[{"Exponent", "[", RowBox[{"#", ",", "x"}], "]"}], "!=", "n"}], "&"}]}], "]"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"Select", "[", RowBox[{"A", ",", RowBox[{ RowBox[{ RowBox[{"Exponent", "[", RowBox[{"#", ",", "x"}], "]"}], "\[Equal]", "n"}], "&"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorListSeparate", "[", "poly_", "]"}], ":=", RowBox[{"PolynomialFactorListSeparateHelper", "[", RowBox[{ RowBox[{"PolynomialFactorList", "[", "poly", "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorDegreeList", "[", "poly_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"TotalDegree", "[", RowBox[{"First", "[", "#", "]"}], "]"}], "&"}], "/@", RowBox[{ "PolynomialFactorListSeparate", "[", "poly", "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorMaxList", "[", "poly_", "]"}], ":=", RowBox[{"Length", "/@", RowBox[{"PolynomialFactorListSeparate", "[", "poly", "]"}]}]}]}], "Input", CellChangeTimes->{{3.42236646128125*^9, 3.4223664653125*^9}, { 3.4571241985827093`*^9, 3.457124200394595*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"PolyEqualsQ", "[", RowBox[{"P1_", ",", "P2_"}], "]"}], ":=", RowBox[{ RowBox[{"List", "@@", RowBox[{"Expand", "[", "P1", "]"}]}], "\[Equal]", RowBox[{"List", "@@", RowBox[{"Expand", "[", "P2", "]"}]}]}]}]], "Input", CellChangeTimes->{{3.42236646721875*^9, 3.422366471546875*^9}, { 3.4226205420625*^9, 3.422620552875*^9}, {3.42262498053125*^9, 3.422624991265625*^9}, {3.4453448263833356`*^9, 3.4453448336333356`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FirstLexicoList", "[", "maxes_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"Length", "[", "maxes", "]"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NextLexicoListHelper", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NextLexicoListHelper", "[", RowBox[{"L_", ",", "maxes_", ",", "final_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"l", "=", RowBox[{"Last", "[", "L", "]"}]}], ",", RowBox[{"L1", "=", RowBox[{"Drop", "[", RowBox[{"L", ",", RowBox[{"-", "1"}]}], "]"}]}], ",", RowBox[{"m", "=", RowBox[{"Last", "[", "maxes", "]"}]}], ",", RowBox[{"M1", "=", RowBox[{"Drop", "[", RowBox[{"maxes", ",", RowBox[{"-", "1"}]}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"l", "\[Equal]", "m"}], ",", RowBox[{"NextLexicoListHelper", "[", RowBox[{"L1", ",", "M1", ",", RowBox[{"Prepend", "[", RowBox[{"final", ",", "0"}], "]"}]}], "]"}], ",", RowBox[{"Merge", "[", RowBox[{ RowBox[{"Append", "[", RowBox[{"L1", ",", RowBox[{"l", "+", "1"}]}], "]"}], ",", "final"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NextLexicoList", "[", RowBox[{"L_", ",", "maxes_"}], "]"}], ":=", RowBox[{"NextLexicoListHelper", "[", RowBox[{"L", ",", "maxes", ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.42236647253125*^9, 3.42236648065625*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{"FirstLexicoList", "[", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}], "\[IndentingNewLine]", RowBox[{"NextLexicoList", "[", RowBox[{"%", ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "2"}], "}"}]}], "]"}]}], "Input", CellChangeTimes->{{3.4571245130478697`*^9, 3.4571245171566925`*^9}, { 3.4571245852881594`*^9, 3.4571245949431114`*^9}}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "0", ",", "0"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "0", ",", "1"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "0", ",", "2"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "1", ",", "0"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "1", ",", "1"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "1", ",", "2"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "2", ",", "0"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "2", ",", "1"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}], Cell[BoxData[ RowBox[{"{", RowBox[{"0", ",", "2", ",", "2"}], "}"}]], "Output", CellChangeTimes->{{3.4571245177659855`*^9, 3.457124544153064*^9}, 3.4571245958492393`*^9, 3.4572925390965023`*^9, 3.4573699278970933`*^9, 3.457882349635144*^9, 3.4579434375687437`*^9, 3.4582942530851135`*^9, 3.4669632393682117`*^9, 3.466963647571286*^9}] }, Open ]], Cell[BoxData[{ RowBox[{ RowBox[{"SubsetToPoly", "[", RowBox[{ RowBox[{"{", "}"}], ",", "factors_"}], "]"}], ":=", "1"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SubsetToPoly", "[", RowBox[{"set_", ",", "factors_"}], "]"}], ":=", RowBox[{"Product", "[", RowBox[{ RowBox[{"factors", "[", RowBox[{"[", RowBox[{"set", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "set", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ListToPoly", "[", RowBox[{"nums_", ",", "factors_"}], "]"}], ":=", RowBox[{"Product", "[", RowBox[{ RowBox[{ RowBox[{"factors", "[", RowBox[{"[", "i", "]"}], "]"}], "^", RowBox[{"nums", "[", RowBox[{"[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "factors", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"HowManyFactors", "[", RowBox[{"poly_", ",", "factors_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"Exponent", "[", RowBox[{"poly", ",", "#"}], "]"}], "&"}], "/@", "factors"}]}]}], "Input", CellChangeTimes->{{3.422357507171875*^9, 3.422357563640625*^9}, { 3.422357957078125*^9, 3.4223579589375*^9}, {3.422358307125*^9, 3.42235832984375*^9}, {3.4223590536875*^9, 3.422359103578125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FirstPolynomialDivisor", "[", "poly_", "]"}], ":=", RowBox[{"ListToPoly", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"Length", "[", RowBox[{"UniqueFactorList", "[", "poly", "]"}], "]"}], "}"}]}], "]"}], ",", RowBox[{"UniqueFactorList", "[", "poly", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NextPolynomialDivisor", "[", RowBox[{"div_", ",", "poly_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"nums", "=", RowBox[{"HowManyFactors", "[", RowBox[{"div", ",", RowBox[{"UniqueFactorList", "[", "poly", "]"}]}], "]"}]}], ",", RowBox[{"maxes", "=", RowBox[{"MaxFactorExponentList", "[", "poly", "]"}]}]}], "}"}], ",", RowBox[{"ListToPoly", "[", RowBox[{ RowBox[{"NextLexicoList", "[", RowBox[{"nums", ",", "maxes"}], "]"}], ",", RowBox[{"UniqueFactorList", "[", "poly", "]"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.42235802903125*^9, 3.422358298609375*^9}, { 3.4223587495*^9, 3.42235898490625*^9}, {3.42235912615625*^9, 3.42235913565625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"ExtendSequenceHelper", "[", RowBox[{"L_", ",", "coeffs_", ",", "0"}], "]"}], ":=", RowBox[{"Reverse", "[", "L", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ExtendSequenceHelper", "[", RowBox[{"L_", ",", "coeffs_", ",", "n_"}], "]"}], ":=", RowBox[{"ExtendSequenceHelper", "[", RowBox[{ RowBox[{"Prepend", "[", RowBox[{"L", ",", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"L", "[", RowBox[{"[", "i", "]"}], "]"}], "*", RowBox[{"coeffs", "[", RowBox[{"[", "i", "]"}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "coeffs", "]"}]}], "}"}]}], "]"}]}], "]"}], ",", "coeffs", ",", RowBox[{"n", "-", "1"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ExtendSequence", "[", RowBox[{"L_", ",", "coeffs_", ",", "n_"}], "]"}], ":=", RowBox[{"ExtendSequenceHelper", "[", RowBox[{ RowBox[{"Reverse", "[", "L", "]"}], ",", "coeffs", ",", "n"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CheckRecurrence", "[", RowBox[{"L_", ",", "coeffs_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "coeffs", "]"}], ">", RowBox[{ RowBox[{"Length", "[", "L", "]"}], "-", "2"}]}], ",", "False", ",", RowBox[{ RowBox[{"ExtendSequence", "[", RowBox[{ RowBox[{"Take", "[", RowBox[{"L", ",", RowBox[{"Length", "[", "coeffs", "]"}]}], "]"}], ",", "coeffs", ",", RowBox[{ RowBox[{"Length", "[", "L", "]"}], "-", RowBox[{"Length", "[", "coeffs", "]"}]}]}], "]"}], "\[Equal]", "L"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.422359308328125*^9, 3.4223593093125*^9}, 3.422359577375*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"SmallestFactorDegree", "[", RowBox[{"1", ",", "P_"}], "]"}], ":=", "0"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SmallestFactorDegree", "[", RowBox[{"curdiv_", ",", "P_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"low", "=", RowBox[{"First", "[", RowBox[{"UniqueFactorList", "[", "P", "]"}], "]"}]}], "}"}], ",", RowBox[{"Exponent", "[", RowBox[{"curdiv", ",", "low"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.422624398515625*^9, 3.422624398953125*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"OnlySmallestFactorPower", "[", RowBox[{"curdiv_", ",", "P_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"L", "=", RowBox[{"UniqueFactorList", "[", "curdiv", "]"}]}], "}"}], ",", RowBox[{ RowBox[{ RowBox[{"Length", "[", "L", "]"}], "\[Equal]", "1"}], "&&", RowBox[{"PolyEqualsQ", "[", RowBox[{ RowBox[{"First", "[", "L", "]"}], ",", RowBox[{"First", "[", RowBox[{"UniqueFactorList", "[", "P", "]"}], "]"}]}], "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.422624752671875*^9, 3.422624915671875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"PolyToRecurrence", "[", RowBox[{"1", ",", "var_"}], "]"}], ":=", RowBox[{"{", "1", "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolyToRecurrence", "[", RowBox[{"P_", ",", "var_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"L", "=", RowBox[{"-", RowBox[{"Drop", "[", RowBox[{ RowBox[{"Reverse", "[", RowBox[{"CoefficientList", "[", RowBox[{"P", ",", "var"}], "]"}], "]"}], ",", "1"}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"L", "[", RowBox[{"[", "1", "]"}], "]"}], "<", "0"}], ",", RowBox[{"-", "L"}], ",", "L"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L_", ",", "P_", ",", "var_"}], "]"}], ":=", RowBox[{"CheckRecurrence", "[", RowBox[{"L", ",", RowBox[{"PolyToRecurrence", "[", RowBox[{"P", ",", "var"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418559666578125*^9, 3.4185597043125*^9}, { 3.418559795265625*^9, 3.41855981628125*^9}, {3.418560409671875*^9, 3.418560437234375*^9}, {3.41856058065625*^9, 3.41856058165625*^9}, { 3.422359283171875*^9, 3.422359288453125*^9}, {3.422623517734375*^9, 3.422623535515625*^9}, {3.422624034046875*^9, 3.422624042609375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"RecurrenceFinderHelper", "[", RowBox[{"L_", ",", "poly_", ",", "1"}], "]"}], ":=", RowBox[{"RecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"NextPolynomialDivisor", "[", RowBox[{"1", ",", "poly"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RecurrenceFinderHelper", "[", RowBox[{"L_", ",", "poly_", ",", "curdiv_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{"(*", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"OnlySmallestFactorPower", "[", RowBox[{"curdiv", ",", "poly"}], "]"}], ",", RowBox[{"Print", "[", "curdiv", "]"}], ",", "Null"}], "]"}], ";"}], "*)"}], RowBox[{"If", "[", RowBox[{ RowBox[{"PolyEqualsQ", "[", RowBox[{"poly", ",", "curdiv"}], "]"}], ",", RowBox[{"Expand", "[", "poly", "]"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L", ",", "curdiv", ",", "x"}], "]"}], ",", RowBox[{"Expand", "[", "curdiv", "]"}], ",", RowBox[{"RecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"NextPolynomialDivisor", "[", RowBox[{"curdiv", ",", "poly"}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RecurrenceFinder", "[", RowBox[{"L_", ",", "poly_"}], "]"}], ":=", RowBox[{"RecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"FirstPolynomialDivisor", "[", "poly", "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4223592379375*^9, 3.422359261734375*^9}, { 3.422359324296875*^9, 3.422359474921875*^9}, {3.422359680046875*^9, 3.422359713453125*^9}, {3.422360056234375*^9, 3.4223600599375*^9}, { 3.42236168903125*^9, 3.422361692140625*^9}, {3.422362064625*^9, 3.422362112296875*^9}, {3.42236482825*^9, 3.422364832828125*^9}, { 3.422367358*^9, 3.422367395765625*^9}, {3.422620460234375*^9, 3.42262050425*^9}, 3.4226205709375*^9, {3.422624404484375*^9, 3.422624425546875*^9}, {3.42262503203125*^9, 3.422625035*^9}, { 3.4226258238125*^9, 3.422625829296875*^9}, 3.42262586375*^9, { 3.422625901328125*^9, 3.4226259230625*^9}, {3.430476722625*^9, 3.43047672521875*^9}, {3.430476765265625*^9, 3.43047677925*^9}, { 3.430476820578125*^9, 3.430476833953125*^9}, {3.44328017546875*^9, 3.443280177859375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L_", ",", "poly_", ",", "1", ",", "possibilities_"}], "]"}], ":=", RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"NextPolynomialDivisor", "[", RowBox[{"1", ",", "poly"}], "]"}], ",", "possibilities"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L_", ",", "poly_", ",", "curdiv_", ",", "possibilities_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"PolyEqualsQ", "[", RowBox[{"poly", ",", "curdiv"}], "]"}], ",", RowBox[{"Append", "[", RowBox[{"possibilities", ",", "curdiv"}], "]"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L", ",", "curdiv", ",", "x"}], "]"}], ",", RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"NextPolynomialDivisor", "[", RowBox[{"curdiv", ",", "poly"}], "]"}], ",", RowBox[{"Append", "[", RowBox[{"possibilities", ",", "curdiv"}], "]"}]}], "]"}], ",", RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"NextPolynomialDivisor", "[", RowBox[{"curdiv", ",", "poly"}], "]"}], ",", "possibilities"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AllRecurrenceFinder", "[", RowBox[{"L_", ",", "poly_"}], "]"}], ":=", RowBox[{"AllRecurrenceFinderHelper", "[", RowBox[{"L", ",", "poly", ",", RowBox[{"FirstPolynomialDivisor", "[", "poly", "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.422363071671875*^9, 3.4223631105625*^9}, { 3.42236317646875*^9, 3.422363198375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Untally", "[", RowBox[{ RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Untally", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"e_", ",", "n_"}], "}"}], ",", "R___"}], "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"Untally", "[", RowBox[{ RowBox[{"{", "R", "}"}], ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"Table", "[", RowBox[{"e", ",", RowBox[{"{", "n", "}"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Untally", "[", "L_", "]"}], ":=", RowBox[{"Untally", "[", RowBox[{"L", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MultiSubset", "[", RowBox[{"L_", ",", "I_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"L", "[", RowBox[{"[", RowBox[{"I", "[", RowBox[{"[", "i", "]"}], "]"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "I", "]"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FirstMultiSubset", "[", "L_", "]"}], ":=", RowBox[{"{", "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"NextMultiSubset", "[", RowBox[{"L_", ",", "I_"}], "]"}], ":=", RowBox[{"MultiSubset", "[", RowBox[{"L", ",", RowBox[{"NextSubset", "[", RowBox[{ RowBox[{"TableN", "[", RowBox[{"Length", "[", "L", "]"}], "]"}], ",", "I"}], "]"}]}], "]"}]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"PolynomialFactorList", "[", "poly_", "]"}], ":=", RowBox[{"Sort", "[", RowBox[{"Untally", "[", RowBox[{"FactorList", "[", "poly", "]"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AllPolynomialFactors", "[", "poly_", "]"}], ":=", RowBox[{"Sort", "[", RowBox[{"Union", "[", RowBox[{ RowBox[{ RowBox[{"Expand", "[", RowBox[{"Times", "@@", "#"}], "]"}], "&"}], "/@", RowBox[{"Subsets", "[", RowBox[{"PolynomialFactorList", "[", "poly", "]"}], "]"}]}], "]"}], "]"}]}]}], "Input", CellChangeTimes->{{3.422366387234375*^9, 3.422366387640625*^9}, { 3.4571265451457863`*^9, 3.4571265606294675`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FindMinimalRecurrenceSlowHelper", "[", RowBox[{"L_", ",", RowBox[{"{", "}"}], ",", "var_"}], "]"}], ":=", "False"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindMinimalRecurrenceSlowHelper", "[", RowBox[{"L_", ",", RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "var_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L", ",", "F", ",", "var"}], "]"}], ",", RowBox[{"PolyToRecurrence", "[", RowBox[{"F", ",", "var"}], "]"}], ",", RowBox[{"FindMinimalRecurrenceSlowHelper", "[", RowBox[{"L", ",", RowBox[{"{", "R", "}"}], ",", "var"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindMinimalRecurrenceSlow", "[", RowBox[{"L_", ",", "poly_", ",", "var_"}], "]"}], ":=", RowBox[{"FindMinimalRecurrenceSlowHelper", "[", RowBox[{"L", ",", RowBox[{"AllPolynomialFactors", "[", "poly", "]"}], ",", "var"}], "]"}]}]}], "Input", CellChangeTimes->{{3.41856093875*^9, 3.4185609638125*^9}, { 3.41856111171875*^9, 3.418561194015625*^9}, {3.418561232140625*^9, 3.418561232484375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FindMinimalRecurrenceHelper", "[", RowBox[{ "L_", ",", "factors_", ",", "tableN_", ",", "tableN_", ",", "var_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"P", "=", RowBox[{"Times", "@@", RowBox[{"MultiSubset", "[", RowBox[{"factors", ",", "tableN"}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L", ",", "P", ",", "var"}], "]"}], ",", RowBox[{"PolyToRecurrence", "[", RowBox[{"P", ",", "var"}], "]"}], ",", "False"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindMinimalRecurrenceHelper", "[", RowBox[{"L_", ",", "factors_", ",", "cur_", ",", "tableN_", ",", "var_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"P", "=", RowBox[{"Times", "@@", RowBox[{"MultiSubset", "[", RowBox[{"factors", ",", "cur"}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"CheckRecurrenceFromPoly", "[", RowBox[{"L", ",", "P", ",", "var"}], "]"}], ",", RowBox[{"PolyToRecurrence", "[", RowBox[{"P", ",", "var"}], "]"}], ",", RowBox[{"FindMinimalRecurrenceHelper", "[", RowBox[{"L", ",", "factors", ",", RowBox[{"NextSubset", "[", RowBox[{"tableN", ",", "cur"}], "]"}], ",", "tableN", ",", "var"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindMinimalRecurrence", "[", RowBox[{"L_", ",", "poly_", ",", "var_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"factors", "=", RowBox[{"PolynomialFactorList", "[", "poly", "]"}]}], "}"}], ",", RowBox[{"FindMinimalRecurrenceHelper", "[", RowBox[{"L", ",", "factors", ",", RowBox[{"{", "}"}], ",", RowBox[{"TableN", "[", RowBox[{"Length", "[", "factors", "]"}], "]"}], ",", "var"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418559835796875*^9, 3.418559857296875*^9}, { 3.4185599074375*^9, 3.418560128109375*^9}, {3.418560215203125*^9, 3.418560245421875*^9}, {3.41856039325*^9, 3.418560394390625*^9}, { 3.41856078065625*^9, 3.41856078375*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"MatrixMinimalPolynomial", "[", RowBox[{ RowBox[{"a_List", "?", "MatrixQ"}], ",", "x_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"n", "=", "1"}], ",", RowBox[{"qu", "=", RowBox[{"{", "}"}]}], ",", RowBox[{"mnm", "=", RowBox[{"{", RowBox[{"Flatten", "[", RowBox[{"IdentityMatrix", "[", RowBox[{"Length", "[", "a", "]"}], "]"}], "]"}], "}"}]}]}], "}"}], ",", RowBox[{ RowBox[{"While", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "qu", "]"}], "\[Equal]", "0"}], ",", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"mnm", ",", RowBox[{"Flatten", "[", RowBox[{"MatrixPower", "[", RowBox[{"a", ",", "n"}], "]"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"qu", "=", RowBox[{"NullSpace", "[", RowBox[{"Transpose", "[", "mnm", "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"n", "++"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"First", "[", "qu", "]"}], ".", RowBox[{"Table", "[", RowBox[{ RowBox[{"x", "^", "i"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.417946960109375*^9, 3.41794696875*^9}, 3.418059965*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"ToMathematicaGraph", "[", RowBox[{"E_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"MakeGraph", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", RowBox[{ RowBox[{ RowBox[{"MemberQ", "[", RowBox[{"E", ",", RowBox[{"{", RowBox[{"#1", ",", "#2"}], "}"}]}], "]"}], "||", RowBox[{"MemberQ", "[", RowBox[{"E", ",", RowBox[{"{", RowBox[{"#2", ",", "#1"}], "}"}]}], "]"}]}], "&"}], ",", RowBox[{"Type", "\[Rule]", "Undirected"}], ",", RowBox[{"VertexLabel", "\[Rule]", "False"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ShowMathematicaGraph", "[", RowBox[{"E_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"ShowGraph", "[", RowBox[{"ToMathematicaGraph", "[", RowBox[{"E", ",", "n"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NumSpTrees", "[", RowBox[{"E_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"NumberOfSpanningTrees", "[", RowBox[{"ToMathematicaGraph", "[", RowBox[{"E", ",", "n"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"IsConnected", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"ConnectedQ", "[", RowBox[{"ToMathematicaGraph", "[", RowBox[{"E", ",", "n"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ConnectedGraphs", "[", "n_", "]"}], ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{"Subsets", "[", RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", "2"}], "]"}], "]"}], ",", RowBox[{ RowBox[{"IsConnected", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NextConnectedGraph", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"F", "=", RowBox[{"NextSubset", "[", RowBox[{ RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", "2"}], "]"}], ",", "E"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"IsConnected", "[", RowBox[{"F", ",", "n"}], "]"}], ",", "F", ",", RowBox[{"NextConnectedGraph", "[", RowBox[{"F", ",", "n"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FirstConnectedGraph", "[", "n_", "]"}], ":=", RowBox[{"NextConnectedGraph", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n"}], "]"}]}]}], "Input", CellChangeTimes->{{3.417881754875*^9, 3.417881761265625*^9}, { 3.417881804234375*^9, 3.41788187871875*^9}, {3.4178819169375*^9, 3.41788191971875*^9}, {3.417881969984375*^9, 3.417882026171875*^9}, { 3.417948957625*^9, 3.41794900921875*^9}, {3.41794904271875*^9, 3.4179491540625*^9}, {3.41794933871875*^9, 3.4179494038125*^9}, { 3.4179513626875*^9, 3.417951379546875*^9}, {3.41855799403125*^9, 3.418557999046875*^9}, {3.42141129503125*^9, 3.421411306609375*^9}, { 3.444140339703125*^9, 3.4441403401875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"ToGridCoordinates", "[", RowBox[{"len_", ",", "height_"}], "]"}], ":=", RowBox[{"MergeAll", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"i", "-", "1"}], ",", RowBox[{"j", "-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "height"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "len"}], "}"}]}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ShowGridGraph", "[", RowBox[{"E_", ",", "len_", ",", "height_"}], "]"}], ":=", RowBox[{"ShowGraph", "[", RowBox[{"ChangeVertices", "[", RowBox[{ RowBox[{"ToMathematicaGraph", "[", RowBox[{"E", ",", RowBox[{"len", "*", "height"}]}], "]"}], ",", RowBox[{"ToGridCoordinates", "[", RowBox[{"len", ",", "height"}], "]"}]}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"ShowGridGraphWithColor", "[", RowBox[{"E_List", ",", "len_Integer", ",", "height_Integer"}], "]"}], ":=", RowBox[{"ShowGraph", "[", RowBox[{ RowBox[{"ChangeVertices", "[", RowBox[{ RowBox[{"ToMathematicaGraph", "[", RowBox[{"E", ",", RowBox[{"len", "*", "height"}]}], "]"}], ",", RowBox[{"ToGridCoordinates", "[", RowBox[{"len", ",", "height"}], "]"}]}], "]"}], ",", RowBox[{"EdgeColor", "\[Rule]", "Red"}], ",", RowBox[{"EdgeStyle", "\[Rule]", "Thick"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.42097603884375*^9, 3.420976039125*^9}, { 3.420976071125*^9, 3.420976072671875*^9}, {3.420976122546875*^9, 3.420976156234375*^9}, {3.42097631109375*^9, 3.420976386046875*^9}, { 3.420976427953125*^9, 3.42097643325*^9}, {3.444146819078125*^9, 3.444146847375*^9}, {3.444146920234375*^9, 3.44414698171875*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"ToNormalGraph", "[", "G_", "]"}], ":=", RowBox[{"{", RowBox[{ RowBox[{"Edges", "[", "G", "]"}], ",", RowBox[{"V", "[", "G", "]"}]}], "}"}]}]], "Input", CellChangeTimes->{{3.418024031203125*^9, 3.4180241089375*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"AllExtraEdges", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"Merge", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"i", "+", "n"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}], ",", RowBox[{"E", "+", "n"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4178821866875*^9, 3.4178822319375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"PolynomialHelper", "[", RowBox[{"init_", ",", "i_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"1", "/", RowBox[{"x", "^", "i"}]}], ")"}], "*", "A"}], "-", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"init", "[", RowBox[{"[", "j", "]"}], "]"}], "/", RowBox[{"x", "^", RowBox[{"(", RowBox[{"i", "-", "j"}], ")"}]}]}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "i"}], "}"}]}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GeneratingFunction1", "[", RowBox[{"rec_", ",", "init_"}], "]"}], ":=", RowBox[{"First", "[", RowBox[{"A", "/.", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"l", "=", RowBox[{"Length", "[", "init", "]"}]}], "}"}], ",", RowBox[{"Solve", "[", RowBox[{ RowBox[{ RowBox[{"PolynomialHelper", "[", RowBox[{"init", ",", "l"}], "]"}], "\[Equal]", RowBox[{"Sum", "[", RowBox[{ RowBox[{ RowBox[{"rec", "[", RowBox[{"[", "i", "]"}], "]"}], "*", RowBox[{"PolynomialHelper", "[", RowBox[{"init", ",", RowBox[{"l", "-", "i"}]}], "]"}]}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "l"}], "}"}]}], "]"}]}], ",", "A"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GeneratingFunctionFromPolynomialAndSequence", "[", RowBox[{"poly_", ",", "seq_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"coeff", "=", RowBox[{"Rest", "[", RowBox[{"Reverse", "[", RowBox[{"-", RowBox[{"CoefficientList", "[", RowBox[{"poly", ",", "x"}], "]"}]}], "]"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", "seq", "]"}], "<", RowBox[{"Length", "[", "coeff", "]"}]}], ",", "Null", ",", RowBox[{"GeneratingFunction1", "[", RowBox[{"coeff", ",", RowBox[{"Take", "[", RowBox[{"seq", ",", RowBox[{"Length", "[", "coeff", "]"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.422366726640625*^9, 3.42236672703125*^9}, { 3.4453452281645856`*^9, 3.4453452312739606`*^9}, {3.457127339751799*^9, 3.457127341595419*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{"P_", ",", "e_", ",", "0", ",", "_"}], "]"}], ":=", RowBox[{"Append", "[", RowBox[{"P", ",", "e"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{"P_", ",", "e_", ",", "1", ",", RowBox[{"{", "X_", "}"}]}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"e", "\[SubsetEqual]", "X"}], ",", RowBox[{"{", "}"}], ",", RowBox[{"Append", "[", RowBox[{ RowBox[{"Complement", "[", RowBox[{"P", ",", RowBox[{"{", "X", "}"}]}], "]"}], ",", RowBox[{"X", "\[Union]", "e"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{"P_", ",", "e_", ",", "2", ",", RowBox[{"{", RowBox[{"X_", ",", "Y_"}], "}"}]}], "]"}], ":=", RowBox[{"Append", "[", RowBox[{ RowBox[{"Complement", "[", RowBox[{"P", ",", RowBox[{"{", RowBox[{"X", ",", "Y"}], "}"}]}], "]"}], ",", RowBox[{"X", "\[Union]", "Y"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{"P_", ",", "e_", ",", "_", ",", "_"}], "]"}], ":=", RowBox[{"{", "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{ RowBox[{"{", "}"}], ",", "e_"}], "]"}], ":=", RowBox[{"{", "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeOneEdge", "[", RowBox[{"P_", ",", "e_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"A", "=", RowBox[{"Select", "[", RowBox[{"P", ",", RowBox[{ RowBox[{ RowBox[{"#", "\[Intersection]", "e"}], "\[NotEqual]", RowBox[{"{", "}"}]}], "&"}]}], "]"}]}], "}"}], ",", RowBox[{"MergeOneEdge", "[", RowBox[{"P", ",", "e", ",", RowBox[{"Length", "[", "A", "]"}], ",", "A"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{"P_", ",", "E_"}], "]"}], ":=", RowBox[{"Sort", "[", RowBox[{"Fold", "[", RowBox[{"MergeOneEdge", ",", "P", ",", "E"}], "]"}], "]"}]}]}], "Input", CellChangeTimes->{{3.417882199*^9, 3.417882205109375*^9}, {3.417882235625*^9, 3.417882252421875*^9}, {3.417883085390625*^9, 3.4178831610625*^9}, { 3.41788338996875*^9, 3.41788339396875*^9}, {3.41788343396875*^9, 3.417883463203125*^9}, {3.4178836030625*^9, 3.41788385753125*^9}, { 3.41788391009375*^9, 3.41788391465625*^9}, {3.417884225640625*^9, 3.4178842316875*^9}, 3.417952058921875*^9, {3.418553408546875*^9, 3.418553408703125*^9}, {3.4185560380625*^9, 3.418556041421875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AllExtraEdgesCylinder", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"Merge", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"i", "+", "n"}], ",", RowBox[{"i", "+", RowBox[{"2", "n"}]}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}], ",", RowBox[{"E", "+", RowBox[{"2", "n"}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CylinderEdges", "[", "n_", "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"i", "+", "n"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418483868953125*^9, 3.41848387328125*^9}, { 3.4184839311875*^9, 3.418483934578125*^9}, {3.41848402990625*^9, 3.418484041359375*^9}, {3.418488010234375*^9, 3.4184880438125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"EdgesToPartition", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", "i", "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"EdgesToPartition", "[", RowBox[{ RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "n_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{ RowBox[{"{", "F", "}"}], ",", RowBox[{"{", "R", "}"}]}], "]"}], "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"{", "}"}], ",", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{ RowBox[{"{", "F", "}"}], ",", RowBox[{"{", "R", "}"}]}], "]"}], ",", "n"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4179470691875*^9, 3.417947138078125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AddItUp", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"Sort", "[", "final", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AddItUp", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"AddItUp", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{"f", ",", RowBox[{"f", "+", "n"}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AddItUp", "[", RowBox[{"L_", ",", "n_"}], "]"}], ":=", RowBox[{"AddItUp", "[", RowBox[{"L", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"EdgesToPartitionCylinder", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"i", "+", "n"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "n"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"EdgesToPartitionCylinder", "[", RowBox[{ RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "n_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"AddItUp", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}], "/@", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{ RowBox[{"{", "F", "}"}], ",", RowBox[{"{", "R", "}"}]}], "]"}], ",", "n"}], "]"}]}]}]}], "Input", CellChangeTimes->{{3.4184875461875*^9, 3.4184875514375*^9}, { 3.418487623421875*^9, 3.418487854765625*^9}, {3.41848794059375*^9, 3.4184879534375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"CleanUpPartition", "[", RowBox[{"P_", ",", "n_"}], "]"}], ":=", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{ RowBox[{"RemoveNAll", "[", RowBox[{"P", ",", "n"}], "]"}], "-", RowBox[{"(", "n", ")"}]}], ",", "n"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CleanUpPartitionCylinder", "[", RowBox[{"P_", ",", "n_"}], "]"}], ":=", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"SubtractIfLargeEnough", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}], "/@", RowBox[{"RemoveNAll", "[", RowBox[{"P", ",", RowBox[{"n", "+", "1"}], ",", RowBox[{"2", "n"}]}], "]"}]}], ",", RowBox[{"2", "n"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4178822548125*^9, 3.417882265578125*^9}, { 3.417883471046875*^9, 3.4178835074375*^9}, {3.417883722296875*^9, 3.417883722890625*^9}, {3.4178838025625*^9, 3.417883804359375*^9}, { 3.417883861578125*^9, 3.4178838705*^9}, {3.41788414928125*^9, 3.417884203625*^9}, {3.41788424034375*^9, 3.41788424571875*^9}, { 3.417884548984375*^9, 3.417884555984375*^9}, {3.4178846015*^9, 3.417884639171875*^9}, {3.4178851815*^9, 3.4178851940625*^9}, { 3.417885301125*^9, 3.41788530125*^9}, {3.417885397546875*^9, 3.417885404640625*^9}, {3.417943645015625*^9, 3.4179437475*^9}, { 3.418484506515625*^9, 3.418484543625*^9}, {3.418485028578125*^9, 3.418485042734375*^9}, {3.41848520003125*^9, 3.41848521171875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"GoodTransitionQ", "[", RowBox[{"P1_", ",", "P2_", ",", "E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"PP", "=", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{"P1", ",", "E"}], "]"}], ",", RowBox[{"2", "n"}]}], "]"}]}], "}"}], ",", RowBox[{ RowBox[{ RowBox[{"Length", "[", "PP", "]"}], "\[Equal]", RowBox[{"Length", "[", "P2", "]"}]}], "&&", RowBox[{ RowBox[{"Sort", "[", "P2", "]"}], "\[Equal]", RowBox[{"Sort", "[", RowBox[{"CleanUpPartition", "[", RowBox[{"PP", ",", "n"}], "]"}], "]"}]}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GoodTransitionQ", "[", RowBox[{"P1_", ",", "P2_", ",", "E_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{"Length", "[", RowBox[{"Flatten", "[", "P1", "]"}], "]"}]}], "}"}], ",", RowBox[{"GoodTransitionQ", "[", RowBox[{"P1", ",", "P2", ",", "E", ",", "n"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GoodTransitionCylinderQ", "[", RowBox[{"P1_", ",", "P2_", ",", "E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"PP", "=", RowBox[{"AddMissing", "[", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{"P1", ",", "E"}], "]"}], ",", RowBox[{"3", "n"}]}], "]"}]}], "}"}], ",", RowBox[{ RowBox[{ RowBox[{"Length", "[", "PP", "]"}], "\[Equal]", RowBox[{"Length", "[", "P2", "]"}]}], "&&", RowBox[{ RowBox[{"Sort", "[", "P2", "]"}], "\[Equal]", RowBox[{"Sort", "[", RowBox[{"CleanUpPartitionCylinder", "[", RowBox[{"PP", ",", "n"}], "]"}], "]"}]}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GoodTransitionCylinderQ", "[", RowBox[{"P1_", ",", "P2_", ",", "E_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{ RowBox[{"Length", "[", RowBox[{"Flatten", "[", "P1", "]"}], "]"}], "/", "2"}]}], "}"}], ",", RowBox[{"GoodTransitionCylinderQ", "[", RowBox[{"P1", ",", "P2", ",", "E", ",", "n"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.417883891796875*^9, 3.4178838969375*^9}, { 3.41788466703125*^9, 3.4178846706875*^9}, {3.41788519959375*^9, 3.417885211*^9}, {3.417885281609375*^9, 3.41788528653125*^9}, { 3.417885531578125*^9, 3.41788559784375*^9}, {3.417943766171875*^9, 3.4179438673125*^9}, {3.417944320921875*^9, 3.4179443565625*^9}, { 3.418486137796875*^9, 3.418486245796875*^9}, {3.418486697984375*^9, 3.418486720078125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1_", ",", "P2_", ",", RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1_", ",", "P2_", ",", RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"GoodTransitionQ", "[", RowBox[{"P1", ",", "P2", ",", "F"}], "]"}], ",", RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"{", "R", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", "F"}], "]"}]}], "]"}], ",", RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"{", "R", "}"}], ",", "final"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1_", ",", "P2_", ",", "E_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{"Length", "[", RowBox[{"Flatten", "[", "P1", "]"}], "]"}]}], "}"}], ",", RowBox[{"FindGoodEdgeSets", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"AllExtraEdges", "[", RowBox[{"E", ",", "n"}], "]"}], ",", RowBox[{ RowBox[{"Length", "[", "P1", "]"}], "-", RowBox[{"Length", "[", "P2", "]"}], "+", "n"}]}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.417885601515625*^9, 3.417885615328125*^9}, { 3.417885864359375*^9, 3.417885880015625*^9}, {3.41788593159375*^9, 3.417886102203125*^9}, {3.41788613265625*^9, 3.4178861541875*^9}, 3.418558002578125*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1_", ",", "P2_", ",", RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1_", ",", "P2_", ",", RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"GoodTransitionCylinderQ", "[", RowBox[{"P1", ",", "P2", ",", "F"}], "]"}], ",", RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"{", "R", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", "F"}], "]"}]}], "]"}], ",", RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"{", "R", "}"}], ",", "final"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1_", ",", "P2_", ",", "E_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{ RowBox[{"Length", "[", RowBox[{"Flatten", "[", "P1", "]"}], "]"}], "/", "2"}]}], "}"}], ",", RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"P1", ",", "P2", ",", RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"AllExtraEdgesCylinder", "[", RowBox[{"E", ",", "n"}], "]"}], ",", RowBox[{ RowBox[{"Length", "[", "P1", "]"}], "-", RowBox[{"Length", "[", "P2", "]"}], "+", "n"}]}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418486880984375*^9, 3.418486910828125*^9}, { 3.41848695925*^9, 3.418486979515625*^9}, 3.41855800546875*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"TransitionMatrix", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"P", "=", RowBox[{"SetPartitions", "[", "n", "]"}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"Length", "[", RowBox[{"FindGoodEdgeSets", "[", RowBox[{ RowBox[{"P", "[", RowBox[{"[", "j", "]"}], "]"}], ",", RowBox[{"P", "[", RowBox[{"[", "i", "]"}], "]"}], ",", "E"}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", RowBox[{"Length", "[", "P", "]"}]}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "P", "]"}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVectorHelper", "[", RowBox[{"allEdges_", ",", "allEdges_", ",", "n_", ",", "v_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"F", "=", RowBox[{"EdgesToPartition", "[", RowBox[{"allEdges", ",", "n"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"F", "\[Equal]", RowBox[{"{", "}"}]}], ",", "v", ",", RowBox[{"AddOneAtPosition", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"RankSetPartition", "[", "F", "]"}], "+", "1"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVectorHelper", "[", RowBox[{"E_", ",", "allEdges_", ",", "n_", ",", "v_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"F", "=", RowBox[{"EdgesToPartition", "[", RowBox[{"E", ",", "n"}], "]"}]}], ",", RowBox[{"next", "=", RowBox[{"NextSubset", "[", RowBox[{"allEdges", ",", "E"}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"F", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"InitialVectorHelper", "[", RowBox[{"next", ",", "allEdges", ",", "n", ",", "v"}], "]"}], ",", RowBox[{"InitialVectorHelper", "[", RowBox[{"next", ",", "allEdges", ",", "n", ",", RowBox[{"AddOneAtPosition", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"RankSetPartition", "[", "F", "]"}], "+", "1"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVector", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"InitialVectorHelper", "[", RowBox[{ RowBox[{"{", "}"}], ",", "E", ",", "n", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", RowBox[{"SetPartitions", "[", "n", "]"}], "]"}]}], "}"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.417886156640625*^9, 3.417886175109375*^9}, { 3.417886881078125*^9, 3.41788688765625*^9}, {3.417886923171875*^9, 3.41788704375*^9}, {3.4179464500625*^9, 3.41794646928125*^9}, { 3.41794684828125*^9, 3.417946882515625*^9}, {3.417946980125*^9, 3.41794698253125*^9}, {3.417947159046875*^9, 3.417947184015625*^9}, { 3.41794722428125*^9, 3.417947268375*^9}, {3.417947376921875*^9, 3.41794749934375*^9}, {3.417947571109375*^9, 3.417947639859375*^9}, { 3.417947987140625*^9, 3.417947990546875*^9}, 3.418557041390625*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"TransitionMatrixCylinderRow", "[", RowBox[{"E_", ",", "n_", ",", "P2_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"Length", "[", RowBox[{"FindGoodEdgeSetsCylinder", "[", RowBox[{"#", ",", "P2", ",", "E"}], "]"}], "]"}], "&"}], "/@", RowBox[{"SetPartitions", "[", RowBox[{"2", "n"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"TransitionMatrixCylinder", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"P", "=", RowBox[{"SetPartitions", "[", RowBox[{"2", "n"}], "]"}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"TransitionMatrixCylinderRow", "[", RowBox[{"E", ",", "n", ",", RowBox[{"P", "[", RowBox[{"[", "i", "]"}], "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", "P", "]"}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVectorCylinderHelper", "[", RowBox[{"allEdges_", ",", "allEdges_", ",", "n_", ",", "v_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"F", "=", RowBox[{"EdgesToPartitionCylinder", "[", RowBox[{"allEdges", ",", "n"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"F", "\[Equal]", RowBox[{"{", "}"}]}], ",", "v", ",", RowBox[{"AddOneAtPosition", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"RankSetPartition", "[", "F", "]"}], "+", "1"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVectorCylinderHelper", "[", RowBox[{"E_", ",", "allEdges_", ",", "n_", ",", "v_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"F", "=", RowBox[{"EdgesToPartitionCylinder", "[", RowBox[{"E", ",", "n"}], "]"}]}], ",", RowBox[{"next", "=", RowBox[{"NextSubset", "[", RowBox[{"allEdges", ",", "E"}], "]"}]}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"F", "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{"InitialVectorCylinderHelper", "[", RowBox[{"next", ",", "allEdges", ",", "n", ",", "v"}], "]"}], ",", RowBox[{"InitialVectorCylinderHelper", "[", RowBox[{"next", ",", "allEdges", ",", "n", ",", RowBox[{"AddOneAtPosition", "[", RowBox[{"v", ",", RowBox[{ RowBox[{"RankSetPartition", "[", "F", "]"}], "+", "1"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"InitialVectorCylinder", "[", RowBox[{"E_", ",", "n_"}], "]"}], ":=", RowBox[{"InitialVectorCylinderHelper", "[", RowBox[{ RowBox[{"{", "}"}], ",", "E", ",", "n", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", RowBox[{"SetPartitions", "[", RowBox[{"2", "n"}], "]"}], "]"}]}], "}"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418487267421875*^9, 3.41848731046875*^9}, { 3.418556979078125*^9, 3.41855700025*^9}, {3.41855735715625*^9, 3.418557457421875*^9}, {3.418558080015625*^9, 3.41855809325*^9}, { 3.418558179671875*^9, 3.41855818528125*^9}, 3.418558253609375*^9, { 3.418642905109375*^9, 3.418642905984375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"CylinderSequenceWithMatrix", "[", RowBox[{"E_", ",", RowBox[{"m_List", "?", "MatrixQ"}], ",", "n_", ",", "len_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"v", "=", RowBox[{"InitialVectorCylinder", "[", RowBox[{"E", ",", "n"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"DotProductVector", "[", "n", "]"}]}]}], "}"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{"MatrixPower", "[", RowBox[{"m", ",", "i", ",", "v"}], "]"}], ".", "b"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "len"}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"CylinderSequence", "[", RowBox[{"E_", ",", "n_", ",", "len_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"m", "=", RowBox[{"TransitionMatrixCylinder", "[", RowBox[{"E", ",", "n"}], "]"}]}], "}"}], ",", RowBox[{"CylinderSequenceWithMatrix", "[", RowBox[{"E", ",", "m", ",", "n", ",", "len"}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.422184961734375*^9, 3.4221851695625*^9}, { 3.422185285765625*^9, 3.422185301796875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"IsGoodAdditionForCylinder", "[", RowBox[{"P_", ",", "E_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{"PLength", "[", "P", "]"}]}], "}"}], ",", RowBox[{ RowBox[{"MergeAllEdges", "[", RowBox[{"P", ",", "E"}], "]"}], "\[Equal]", RowBox[{"{", RowBox[{"TableN", "[", "n", "]"}], "}"}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GoodWaysForCylinder", "[", RowBox[{"P_", ",", "n_"}], "]"}], ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{"Subsets", "[", RowBox[{"CylinderEdges", "[", "n", "]"}], "]"}], ",", RowBox[{ RowBox[{"IsGoodAdditionForCylinder", "[", RowBox[{"P", ",", "#"}], "]"}], "&"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"NumberOfGoodWaysForCylinder", "[", RowBox[{"P_", ",", "n_"}], "]"}], ":=", RowBox[{"Length", "[", RowBox[{"GoodWaysForCylinder", "[", RowBox[{"P", ",", "n"}], "]"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"DotProductVector", "[", "n_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"NumberOfGoodWaysForCylinder", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}], "/@", RowBox[{"SetPartitions", "[", RowBox[{"2", "n"}], "]"}]}]}]}], "Input", CellChangeTimes->{{3.418556002546875*^9, 3.418556076921875*^9}, { 3.418556183328125*^9, 3.41855619103125*^9}, {3.41855623415625*^9, 3.418556339453125*^9}, {3.4185563755*^9, 3.41855640328125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"GraphPathSequenceHelper", "[", RowBox[{"m_", ",", "now_", ",", "v_", ",", "0", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPathSequenceHelper", "[", RowBox[{"m_", ",", "now_", ",", "v_", ",", "k_", ",", "final_"}], "]"}], ":=", RowBox[{"GraphPathSequenceHelper", "[", RowBox[{"m", ",", RowBox[{"m", ".", "now"}], ",", "v", ",", RowBox[{"k", "-", "1"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"First", "[", RowBox[{"now", ".", "v"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPathSequence", "[", RowBox[{"E_List", ",", "n_Integer", ",", "k_Integer"}], "]"}], ":=", RowBox[{"GraphPathSequenceHelper", "[", RowBox[{ RowBox[{"TransitionMatrix", "[", RowBox[{"E", ",", "n"}], "]"}], ",", RowBox[{"IdentityMatrix", "[", RowBox[{"Length", "[", RowBox[{"SetPartitions", "[", "n", "]"}], "]"}], "]"}], ",", RowBox[{"InitialVector", "[", RowBox[{"E", ",", "n"}], "]"}], ",", "k", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPathSequence", "[", RowBox[{"E_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"GraphPathSequence", "[", RowBox[{"E", ",", "n", ",", RowBox[{"2", "*", RowBox[{"Length", "[", RowBox[{"SetPartitions", "[", "n", "]"}], "]"}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPathSequence", "[", RowBox[{ RowBox[{"m_List", "?", "MatrixQ"}], ",", "v_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"GraphPathSequenceHelper", "[", RowBox[{"m", ",", RowBox[{"IdentityMatrix", "[", RowBox[{"Length", "[", "m", "]"}], "]"}], ",", "v", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphPathSequence", "[", RowBox[{ RowBox[{"m_List", "?", "MatrixQ"}], ",", "v_List"}], "]"}], ":=", RowBox[{"GraphPathSequence", "[", RowBox[{"m", ",", "v", ",", RowBox[{ RowBox[{"Length", "[", "v", "]"}], "+", "5"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.41794724496875*^9, 3.417947245421875*^9}, { 3.417947590875*^9, 3.417947607234375*^9}, {3.4179476441875*^9, 3.417947651078125*^9}, {3.41794793228125*^9, 3.417948012125*^9}, { 3.417948104609375*^9, 3.417948305296875*^9}, {3.41794841228125*^9, 3.417948418203125*^9}, {3.417948453046875*^9, 3.4179484690625*^9}, { 3.417950661*^9, 3.417950681453125*^9}, {3.4184784774375*^9, 3.4184785348125*^9}, {3.418478566546875*^9, 3.41847869278125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"GraphCylinderSequenceHelper", "[", RowBox[{"m_", ",", "now_", ",", "v_", ",", "b_", ",", "0", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphCylinderSequenceHelper", "[", RowBox[{ "m_", ",", "now_", ",", "v_", ",", "b_", ",", "k_", ",", "final_"}], "]"}], ":=", RowBox[{"GraphCylinderSequenceHelper", "[", RowBox[{"m", ",", RowBox[{"m", ".", "now"}], ",", "v", ",", "b", ",", RowBox[{"k", "-", "1"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{ RowBox[{"(", RowBox[{"now", ".", "v"}], ")"}], ".", "b"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GraphCylinderSequence", "[", RowBox[{"E_List", ",", "n_Integer"}], "]"}], ":=", RowBox[{"GraphCylinderSequenceHelper", "[", RowBox[{ RowBox[{"TransitionMatrixCylinder", "[", RowBox[{"E", ",", "n"}], "]"}], ",", RowBox[{"IdentityMatrix", "[", RowBox[{"Length", "[", RowBox[{"SetPartitions", "[", RowBox[{"2", "n"}], "]"}], "]"}], "]"}], ",", RowBox[{"InitialVectorCylinder", "[", RowBox[{"E", ",", "n"}], "]"}], ",", RowBox[{"DotProductVector", "[", "n", "]"}], ",", "200", ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4185614444375*^9, 3.4185616354375*^9}, { 3.466964266020172*^9, 3.466964293768751*^9}}], Cell[BoxData[ RowBox[{"GraphCylinderSequence", "[", RowBox[{ RowBox[{"{", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}], "}"}], ",", "4"}], "]"}]], "Input", CellChangeTimes->{{3.46696414663566*^9, 3.466964152541608*^9}}], Cell[CellGroupData[{ Cell[BoxData["IdentityMatrix"], "Input", CellChangeTimes->{{3.4669642000547996`*^9, 3.4669642017890863`*^9}}], Cell[BoxData["$Aborted"], "Output", CellChangeTimes->{3.466964155135225*^9}] }, Open ]], Cell[BoxData[ RowBox[{ RowBox[{"WriteGraphInformationWithHelp", "[", RowBox[{ "str_", ",", "E_", ",", "n_", ",", "time_", ",", "mat_", ",", "init_", ",", "seq_", ",", "charpoly_", ",", "rec_", ",", "genfun_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{ RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "E"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "mat"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "init"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", RowBox[{"Factor", "[", "charpoly", "]"}]}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "seq"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "rec"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "genfun"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", "time", "]"}], "<>", "\"\< seconds to find matrix.\\n\\n\>\""}]}], "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.41864317696875*^9, 3.418643185796875*^9}, { 3.42236563171875*^9, 3.422365796859375*^9}, {3.42236729065625*^9, 3.4223672965625*^9}, {3.4223680196875*^9, 3.422368020640625*^9}, { 3.42236806615625*^9, 3.42236809284375*^9}, {3.422368134265625*^9, 3.4223681536875*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"WriteGraphInformation", "[", RowBox[{"str_", ",", "E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"T", "=", RowBox[{"Timing", "[", RowBox[{"TransitionMatrix", "[", RowBox[{"E", ",", "n"}], "]"}], "]"}]}], ",", RowBox[{"v", "=", RowBox[{"InitialVector", "[", RowBox[{"E", ",", "n"}], "]"}]}]}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"seq", "=", RowBox[{"GraphPathSequence", "[", RowBox[{ RowBox[{"T", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "v"}], "]"}]}], ",", RowBox[{"char", "=", RowBox[{"CharacteristicPolynomial", "[", RowBox[{ RowBox[{"T", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "x"}], "]"}]}]}], "}"}], ",", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"rec", "=", RowBox[{"RecurrenceFinder", "[", RowBox[{"seq", ",", "char"}], "]"}]}], "}"}], ",", RowBox[{"WriteGraphInformationWithHelp", "[", RowBox[{"str", ",", "E", ",", "n", ",", RowBox[{"T", "[", RowBox[{"[", "1", "]"}], "]"}], ",", RowBox[{"T", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "v", ",", "seq", ",", "char", ",", "rec", ",", RowBox[{"GeneratingFunctionFromPolynomialAndSequence", "[", RowBox[{"rec", ",", "seq"}], "]"}]}], "]"}]}], "]"}]}], "]"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.417948650921875*^9, 3.417948662734375*^9}, { 3.41794878025*^9, 3.4179487944375*^9}, {3.417948839765625*^9, 3.4179488405625*^9}, {3.417948917484375*^9, 3.41794894421875*^9}, { 3.417950270015625*^9, 3.4179502858125*^9}, {3.417950337875*^9, 3.4179503498125*^9}, {3.41795038359375*^9, 3.417950461484375*^9}, { 3.417950513421875*^9, 3.4179506949375*^9}, {3.41795156953125*^9, 3.417951575984375*^9}, {3.4179532511875*^9, 3.417953325390625*^9}, { 3.417953517609375*^9, 3.4179535314375*^9}, {3.418478442953125*^9, 3.41847844403125*^9}, {3.41847870315625*^9, 3.4184787406875*^9}, { 3.422365541109375*^9, 3.422365626953125*^9}, {3.42236580478125*^9, 3.422365960671875*^9}, {3.422366171921875*^9, 3.42236624928125*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"WriteGraphCylinderInformation", "[", RowBox[{"str_", ",", "E_", ",", "n_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"T", "=", RowBox[{"Timing", "[", RowBox[{"TransitionMatrixCylinder", "[", RowBox[{"E", ",", "n"}], "]"}], "]"}]}], ",", RowBox[{"v", "=", RowBox[{"InitialVectorCylinder", "[", RowBox[{"E", ",", "n"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"DotProductVector", "[", "n", "]"}]}]}], "}"}], ",", RowBox[{ RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "E"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", RowBox[{"T", "[", RowBox[{"[", "2", "]"}], "]"}]}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "v"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", "b"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", RowBox[{"Factor", "[", RowBox[{"CharacteristicPolynomial", "[", RowBox[{ RowBox[{"T", "[", RowBox[{"[", "2", "]"}], "]"}], ",", "x"}], "]"}], "]"}]}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", "\"\\""}], "]"}], ";", RowBox[{"Write", "[", RowBox[{"str", ",", RowBox[{"GraphCylinderSequence", "[", RowBox[{"E", ",", "n"}], "]"}]}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", RowBox[{"\"\\"", "<>", RowBox[{"ToString", "[", RowBox[{"T", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}], "<>", "\"\< seconds to find matrix.\\n\\n\>\""}]}], "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.41856168228125*^9, 3.418561779421875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"WriteAllGraphInformation", "[", RowBox[{"str_", ",", "E_", ",", "n_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"E", "\[Equal]", RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", "2"}], "]"}]}], ",", RowBox[{ RowBox[{"WriteGraphInformation", "[", RowBox[{"str", ",", "E", ",", "n"}], "]"}], ";", RowBox[{"WriteString", "[", RowBox[{"str", ",", RowBox[{"\"\<\\nFinished with graphs on \>\"", "<>", RowBox[{"ToString", "[", "n", "]"}], "<>", "\"\< vertices.\\n\>\""}]}], "]"}]}], ",", RowBox[{ RowBox[{"WriteGraphInformation", "[", RowBox[{"str", ",", "E", ",", "n"}], "]"}], ";", RowBox[{"WriteAllGraphInformation", "[", RowBox[{"str", ",", RowBox[{"NextConnectedGraph", "[", RowBox[{"E", ",", "n"}], "]"}], ",", "n"}], "]"}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"WriteAllGraphInformation", "[", RowBox[{"str_", ",", "n_Integer"}], "]"}], ":=", RowBox[{"WriteAllGraphInformation", "[", RowBox[{"str", ",", RowBox[{"FirstConnectedGraph", "[", "n", "]"}], ",", "n"}], "]"}]}]}], "Input", CellChangeTimes->{{3.417951061203125*^9, 3.41795135125*^9}, { 3.41795138534375*^9, 3.417951396171875*^9}, 3.418558012171875*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"WriteMultipleGraphInformation", "[", RowBox[{"str_", ",", RowBox[{"{", "}"}]}], "]"}], ":=", RowBox[{"WriteString", "[", RowBox[{ "str", ",", "\"\<\\nFinished Looking At Current List of Graphs.\>\""}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"WriteMultipleGraphInformation", "[", RowBox[{"str_", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"E_", ",", "n_"}], "}"}], ",", "R___"}], "}"}]}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{ RowBox[{"WriteGraphInformation", "[", RowBox[{"str", ",", "E", ",", "n"}], "]"}], ";", RowBox[{"WriteMultipleGraphInformation", "[", RowBox[{"str", ",", RowBox[{"{", "R", "}"}]}], "]"}]}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.418478767015625*^9, 3.418478873046875*^9}, { 3.41847890528125*^9, 3.418478908546875*^9}, {3.41847895365625*^9, 3.41847895925*^9}, {3.4221859346875*^9, 3.422185936015625*^9}, 3.422367904953125*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"WriteMultipleGraphCylinderInformation", "[", RowBox[{"str_", ",", RowBox[{"{", "}"}]}], "]"}], ":=", RowBox[{"WriteString", "[", RowBox[{ "str", ",", "\"\<\\n---\\nFinished Looking At Current List of Graphs\\n---\\n\>\""}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"WriteMultipleGraphCylinderInformation", "[", RowBox[{"str_", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"E_", ",", "n_"}], "}"}], ",", "R___"}], "}"}]}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", "}"}], ",", RowBox[{ RowBox[{"WriteGraphCylinderInformation", "[", RowBox[{"str", ",", "E", ",", "n"}], "]"}], ";", RowBox[{"WriteMultipleGraphCylinderInformation", "[", RowBox[{"str", ",", RowBox[{"{", "R", "}"}]}], "]"}]}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4221855141875*^9, 3.422185518734375*^9}, { 3.422185550015625*^9, 3.422185592328125*^9}, {3.4221859074375*^9, 3.422185941046875*^9}, {3.42218638146875*^9, 3.422186386109375*^9}, { 3.422187041234375*^9, 3.422187042734375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AllMathematicaGraphs", "[", "n_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"ToMathematicaGraph", "[", RowBox[{"#", ",", "n"}], "]"}], "&"}], "/@", RowBox[{"Subsets", "[", RowBox[{"NewKSubsets", "[", RowBox[{ RowBox[{"TableN", "[", "n", "]"}], ",", "2"}], "]"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AllConnectedMathematicaGraphs", "[", "n_", "]"}], ":=", RowBox[{"Select", "[", RowBox[{ RowBox[{"AllMathematicaGraphs", "[", "n", "]"}], ",", "ConnectedQ"}], "]"}]}]}], "Input", CellChangeTimes->{{3.41797086340625*^9, 3.417970864546875*^9}, { 3.417970897125*^9, 3.41797091675*^9}, {3.41802326809375*^9, 3.418023307984375*^9}, {3.418023341703125*^9, 3.418023344734375*^9}, { 3.41802373709375*^9, 3.418023753421875*^9}, 3.418474166931402*^9, 3.418558015453125*^9}], Cell[BoxData[{ RowBox[{ RowBox[{"AddElementToEquivalenceClassHelper", "[", RowBox[{"x_", ",", RowBox[{"{", "}"}], ",", "final_", ",", "Q_"}], "]"}], ":=", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"{", "x", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AddElementToEquivalenceClassHelper", "[", RowBox[{"x_", ",", RowBox[{"{", RowBox[{"F_", ",", "R___"}], "}"}], ",", "final_", ",", "Q_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{"Q", "[", RowBox[{"x", ",", RowBox[{"First", "[", "F", "]"}]}], "]"}], ",", RowBox[{"Merge", "[", RowBox[{ RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"Append", "[", RowBox[{"F", ",", "x"}], "]"}]}], "]"}], ",", RowBox[{"{", "R", "}"}]}], "]"}], ",", RowBox[{"AddElementToEquivalenceClassHelper", "[", RowBox[{"x", ",", RowBox[{"{", "R", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", "F"}], "]"}], ",", "Q"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AddElementToEquivalenceClass", "[", RowBox[{"x_", ",", "L_", ",", "Q_"}], "]"}], ":=", RowBox[{"AddElementToEquivalenceClassHelper", "[", RowBox[{"x", ",", "L", ",", RowBox[{"{", "}"}], ",", "Q"}], "]"}]}]}], "Input", CellChangeTimes->{{3.41802337859375*^9, 3.418023560859375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"EquivClasses", "[", RowBox[{ RowBox[{"{", "}"}], ",", "L_", ",", "Q_"}], "]"}], ":=", "L"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"EquivClasses", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "L_", ",", "Q_"}], "]"}], ":=", RowBox[{"EquivClasses", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", RowBox[{"AddElementToEquivalenceClass", "[", RowBox[{"f", ",", "L", ",", "Q"}], "]"}], ",", "Q"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"EquivClasses", "[", RowBox[{"L_", ",", "Q_"}], "]"}], ":=", RowBox[{"EquivClasses", "[", RowBox[{"L", ",", RowBox[{"{", "}"}], ",", "Q"}], "]"}]}]}], "Input", CellChangeTimes->{{3.418022692765625*^9, 3.418022693484375*^9}, { 3.418022786125*^9, 3.41802279265625*^9}, {3.418022898015625*^9, 3.41802290025*^9}, {3.418023018625*^9, 3.418023076453125*^9}, { 3.418023110609375*^9, 3.418023117921875*^9}, {3.41802316015625*^9, 3.418023249078125*^9}, {3.4180233599375*^9, 3.4180233671875*^9}, { 3.41802357284375*^9, 3.418023683515625*^9}, {3.41802378721875*^9, 3.41802381375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AllConnectedUndirectedMathematicaGraphs", "[", "n_", "]"}], ":=", RowBox[{"First", "/@", RowBox[{"EquivClasses", "[", RowBox[{ RowBox[{"AllConnectedMathematicaGraphs", "[", "n", "]"}], ",", "IsomorphicQ"}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AllConnectedUndirectedNormalGraphs", "[", "n_", "]"}], ":=", RowBox[{"ToNormalGraph", "/@", RowBox[{ "AllConnectedUndirectedMathematicaGraphs", "[", "n", "]"}]}]}]}], "Input", CellChangeTimes->{{3.41802394503125*^9, 3.418023984234375*^9}, { 3.418474035618902*^9, 3.418474074087652*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FindDegreeVerts", "[", RowBox[{"E_", ",", "d_"}], "]"}], ":=", RowBox[{"First", "/@", RowBox[{"Select", "[", RowBox[{ RowBox[{"Tally", "[", RowBox[{"Flatten", "[", "E", "]"}], "]"}], ",", RowBox[{ RowBox[{ RowBox[{"#", "[", RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "d"}], "&"}]}], "]"}]}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveLeavesOnce", "[", "E_", "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"V", "=", RowBox[{"FindDegreeVerts", "[", RowBox[{"E", ",", "1"}], "]"}]}], "}"}], ",", RowBox[{"Select", "[", RowBox[{"E", ",", RowBox[{ RowBox[{ RowBox[{"#", "\[Intersection]", "V"}], "==", RowBox[{"{", "}"}]}], "&"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveLeavesHelper", "[", RowBox[{"E_", ",", "E_"}], "]"}], ":=", "E"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveLeavesHelper", "[", RowBox[{"old_", ",", "new_"}], "]"}], ":=", RowBox[{"RemoveLeavesHelper", "[", RowBox[{"new", ",", RowBox[{"RemoveLeavesOnce", "[", "new", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"RemoveLeaves", "[", "E_", "]"}], ":=", RowBox[{"RemoveLeavesHelper", "[", RowBox[{"E", ",", RowBox[{"RemoveLeavesOnce", "[", "E", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"IsTree", "[", "E_", "]"}], ":=", RowBox[{ RowBox[{"RemoveLeaves", "[", "E", "]"}], "\[Equal]", RowBox[{"{", "}"}]}]}]}], "Input", CellChangeTimes->{{3.420899621328125*^9, 3.420899718421875*^9}, { 3.42089976246875*^9, 3.420900106921875*^9}, {3.420900417875*^9, 3.42090043853125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"MinSumEdge", "[", RowBox[{ RowBox[{"{", "}"}], ",", "pick_"}], "]"}], ":=", "pick"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MinSumEdge", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "pick_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "f"}], "<", RowBox[{"Plus", "@@", "pick"}]}], ",", RowBox[{"MinSumEdge", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "f"}], "]"}], ",", RowBox[{"MinSumEdge", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "pick"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MinSumEdge", "[", "E_", "]"}], ":=", RowBox[{"MinSumEdge", "[", RowBox[{ RowBox[{"Rest", "[", "E", "]"}], ",", RowBox[{"First", "[", "E", "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MaxSumEdge", "[", RowBox[{ RowBox[{"{", "}"}], ",", "pick_"}], "]"}], ":=", "pick"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MaxSumEdge", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "pick_"}], "]"}], ":=", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "f"}], ">", RowBox[{"Plus", "@@", "pick"}]}], ",", RowBox[{"MaxSumEdge", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "f"}], "]"}], ",", RowBox[{"MaxSumEdge", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "pick"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MaxSumEdge", "[", "E_", "]"}], ":=", RowBox[{"MaxSumEdge", "[", RowBox[{ RowBox[{"Rest", "[", "E", "]"}], ",", RowBox[{"First", "[", "E", "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.420900907328125*^9, 3.42090100728125*^9}, { 3.420901061828125*^9, 3.4209010678125*^9}, {3.420901257546875*^9, 3.420901278578125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"JoinAtEnd", "[", RowBox[{"Tree1_", ",", "len_", ",", "height_", ",", "End_"}], "]"}], ":=", RowBox[{"Union", "[", RowBox[{"Tree1", ",", RowBox[{"End", "+", RowBox[{"height", "*", RowBox[{"(", RowBox[{"len", "-", "1"}], ")"}]}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinEndsHelper", "[", RowBox[{"Tree_", ",", "len_", ",", "height_", ",", RowBox[{"{", "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"Map", "[", RowBox[{"Sort", ",", "final", ",", "2"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinEndsHelper", "[", RowBox[{"Tree_", ",", "len_", ",", "height_", ",", RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "final_"}], "]"}], ":=", RowBox[{"JoinEndsHelper", "[", RowBox[{"Tree", ",", "len", ",", "height", ",", RowBox[{"{", "r", "}"}], ",", RowBox[{"Append", "[", RowBox[{"final", ",", RowBox[{"JoinAtEnd", "[", RowBox[{"Tree", ",", "len", ",", "height", ",", "f"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinEnds", "[", RowBox[{"Tree_", ",", "len_", ",", "height_", ",", "Ends_"}], "]"}], ":=", RowBox[{"JoinEndsHelper", "[", RowBox[{"Tree", ",", "len", ",", "height", ",", "Ends", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinAllEndsHelper", "[", RowBox[{ RowBox[{"{", "}"}], ",", "len_", ",", "height_", ",", "Ends_", ",", "final_"}], "]"}], ":=", RowBox[{"Map", "[", RowBox[{"Sort", ",", "final", ",", "2"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinAllEndsHelper", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "len_", ",", "height_", ",", "Ends_", ",", "final_"}], "]"}], ":=", RowBox[{"JoinAllEndsHelper", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "len", ",", "height", ",", "Ends", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"JoinEnds", "[", RowBox[{"f", ",", "len", ",", "height", ",", "Ends"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"JoinAllEnds", "[", RowBox[{"Trees_", ",", "len_", ",", "height_", ",", "Ends_"}], "]"}], ":=", RowBox[{"JoinAllEndsHelper", "[", RowBox[{"Trees", ",", "len", ",", "height", ",", "Ends", ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.421411826859375*^9, 3.421411906296875*^9}, { 3.42141207815625*^9, 3.42141217890625*^9}, {3.421413010796875*^9, 3.4214130113125*^9}, {3.42141338546875*^9, 3.421413460671875*^9}, { 3.421413552234375*^9, 3.421413552296875*^9}, {3.421413709890625*^9, 3.421413734890625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"FixTree", "[", RowBox[{"T_", ",", "min_", ",", "max_", ",", "4"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"n", "=", RowBox[{"Max", "[", RowBox[{"Flatten", "[", "T", "]"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Plus", "@@", "max"}], "\[Equal]", RowBox[{"n", "+", "n", "-", "1"}]}], ",", RowBox[{"Select", "[", RowBox[{"T", ",", RowBox[{ RowBox[{"#", "\[NotEqual]", "min"}], "&"}]}], "]"}], ",", RowBox[{"Select", "[", RowBox[{"T", ",", RowBox[{ RowBox[{"#", "\[NotEqual]", "max"}], "&"}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"FixTree", "[", RowBox[{"T_", ",", "min_", ",", "max_", ",", "_"}], "]"}], ":=", RowBox[{"Select", "[", RowBox[{"T", ",", RowBox[{ RowBox[{"#", "\[NotEqual]", "max"}], "&"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MakeNewTree", "[", RowBox[{"Tree1_", ",", "len_", ",", "End_"}], "]"}], ":=", RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"T", "=", RowBox[{"JoinAtEnd", "[", RowBox[{"Tree1", ",", "len", ",", "End"}], "]"}]}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"IsTree", "[", "T", "]"}], ",", RowBox[{"Sort", "[", "T", "]"}], ",", RowBox[{"Sort", "[", RowBox[{"FixTree", "[", RowBox[{"T", ",", RowBox[{"MinSumEdge", "[", RowBox[{"RemoveLeaves", "[", "T", "]"}], "]"}], ",", RowBox[{"MaxSumEdge", "[", RowBox[{"RemoveLeaves", "[", "T", "]"}], "]"}], ",", RowBox[{"Length", "[", RowBox[{"RemoveLeaves", "[", "T", "]"}], "]"}]}], "]"}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MakeNewTrees", "[", RowBox[{"Tree1_", ",", "len_", ",", "Ends_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"MakeNewTree", "[", RowBox[{"Tree1", ",", "len", ",", "#"}], "]"}], "&"}], "/@", "Ends"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MakeAllNewTrees", "[", RowBox[{ RowBox[{"{", "}"}], ",", "len_", ",", "Ends_", ",", "final_"}], "]"}], ":=", RowBox[{"Sort", "[", "final", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MakeAllNewTrees", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "len_", ",", "Ends_", ",", "final_"}], "]"}], ":=", RowBox[{"MakeAllNewTrees", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "len", ",", "Ends", ",", RowBox[{"Merge", "[", RowBox[{ RowBox[{"MakeNewTrees", "[", RowBox[{"f", ",", "len", ",", "Ends"}], "]"}], ",", "final"}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"MakeAllNewTrees", "[", RowBox[{"Trees_", ",", "len_", ",", "Ends_"}], "]"}], ":=", RowBox[{"MakeAllNewTrees", "[", RowBox[{"Trees", ",", "len", ",", "Ends", ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.420899722890625*^9, 3.420899758828125*^9}, { 3.420899840609375*^9, 3.420899841765625*^9}, {3.42089990515625*^9, 3.420899951921875*^9}, {3.42090011215625*^9, 3.420900114421875*^9}, { 3.42090037815625*^9, 3.420900389703125*^9}, {3.42090045165625*^9, 3.42090048225*^9}, {3.420900514984375*^9, 3.420900524328125*^9}, { 3.420901112078125*^9, 3.420901215671875*^9}, {3.4209012913125*^9, 3.420901328*^9}, {3.420901388125*^9, 3.420901417984375*^9}, { 3.420901565171875*^9, 3.420901605046875*^9}, {3.420901870140625*^9, 3.420901950484375*^9}, {3.420903166109375*^9, 3.42090317040625*^9}, 3.4209032814375*^9, {3.420904720125*^9, 3.420904720265625*^9}, { 3.420904762296875*^9, 3.42090476234375*^9}, {3.420904802109375*^9, 3.420904808328125*^9}, {3.42097494946875*^9, 3.4209750484375*^9}, { 3.42097508896875*^9, 3.420975323125*^9}, {3.42097559571875*^9, 3.42097559609375*^9}, {3.42097571684375*^9, 3.420975720046875*^9}, { 3.421411823875*^9, 3.4214118245625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"AppendTreeEndsToTree", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTreeEndsToTree", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"AppendTreeEndsToTree", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{ RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "-", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "n"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}]}], "}"}]}], "]"}], ",", RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "-", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "+", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}]}], "}"}]}], "]"}], ",", RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"2", "n"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "+", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}]}], "}"}]}], "]"}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTreeEndsToTree", "[", RowBox[{"T_", ",", "n_"}], "]"}], ":=", RowBox[{"AppendTreeEndsToTree", "[", RowBox[{"T", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToTree", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToTree", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"AppendForestEndsToTree", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{ RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "-", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]}], "}"}], "}"}]}], "]"}], ",", RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"2", "n"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}], "}"}]}], "]"}]}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToTree", "[", RowBox[{"T_", ",", "n_"}], "]"}], ":=", RowBox[{"AppendForestEndsToTree", "[", RowBox[{"T", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTreeEndsToForest", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTreeEndsToForest", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"AppendTreeEndsToForest", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "-", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "n"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "+", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}]}], "}"}]}], "]"}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTreeEndsToForest", "[", RowBox[{"T_", ",", "n_"}], "]"}], ":=", RowBox[{"AppendTreeEndsToForest", "[", RowBox[{"T", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToForest", "[", RowBox[{ RowBox[{"{", "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", "final"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToForest", "[", RowBox[{ RowBox[{"{", RowBox[{"f_", ",", "r___"}], "}"}], ",", "n_", ",", "final_"}], "]"}], ":=", RowBox[{"AppendForestEndsToForest", "[", RowBox[{ RowBox[{"{", "r", "}"}], ",", "n", ",", RowBox[{"Merge", "[", RowBox[{"final", ",", RowBox[{"{", RowBox[{"Union", "[", RowBox[{"f", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"2", "n"}], "-", "1"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", "n"}], ",", RowBox[{ RowBox[{"2", "n"}], "+", "2"}]}], "}"}]}], "}"}]}], "]"}], "}"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendForestEndsToForest", "[", RowBox[{"T_", ",", "n_"}], "]"}], ":=", RowBox[{"AppendForestEndsToForest", "[", RowBox[{"T", ",", "n", ",", RowBox[{"{", "}"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.420903485046875*^9, 3.42090350128125*^9}, { 3.4209035334375*^9, 3.420903721625*^9}, {3.420903803046875*^9, 3.4209039384375*^9}, {3.4209040835625*^9, 3.420904159296875*^9}, { 3.420904347875*^9, 3.420904350890625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"SpanningTrees", "[", "1", "]"}], ":=", RowBox[{"{", RowBox[{"{", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}], "}"}], "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SpanningForests", "[", "1", "]"}], ":=", RowBox[{"{", RowBox[{"{", "}"}], "}"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SpanningTrees", "[", "n_", "]"}], ":=", RowBox[{"Union", "[", RowBox[{ RowBox[{"AppendTreeEndsToTree", "[", RowBox[{ RowBox[{"SpanningTrees", "[", RowBox[{"n", "-", "1"}], "]"}], ",", RowBox[{"n", "-", "1"}]}], "]"}], ",", RowBox[{"AppendTreeEndsToForest", "[", RowBox[{ RowBox[{"SpanningForests", "[", RowBox[{"n", "-", "1"}], "]"}], ",", RowBox[{"n", "-", "1"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SpanningForests", "[", "n_", "]"}], ":=", RowBox[{"Union", "[", RowBox[{ RowBox[{"AppendForestEndsToTree", "[", RowBox[{ RowBox[{"SpanningTrees", "[", RowBox[{"n", "-", "1"}], "]"}], ",", RowBox[{"n", "-", "1"}]}], "]"}], ",", RowBox[{"AppendForestEndsToForest", "[", RowBox[{ RowBox[{"SpanningForests", "[", RowBox[{"n", "-", "1"}], "]"}], ",", RowBox[{"n", "-", "1"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.4209034385625*^9, 3.420903462765625*^9}, { 3.420904167109375*^9, 3.420904269359375*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"GridEdges", "[", RowBox[{"1", ",", "height_"}], "]"}], ":=", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{"i", ",", RowBox[{"i", "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"height", "-", "1"}]}], "}"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"GridEdges", "[", RowBox[{"len_", ",", "height_"}], "]"}], ":=", RowBox[{"Union", "[", RowBox[{ RowBox[{"GridEdges", "[", RowBox[{ RowBox[{"len", "-", "1"}], ",", "height"}], "]"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"len", "-", "2"}], ")"}], "*", "height"}], "+", "i"}], ",", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"len", "-", "1"}], ")"}], "*", "height"}], "+", "i"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "height"}], "}"}]}], "]"}], ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"len", "-", "1"}], ")"}], "*", "height"}], "+", "i"}], ",", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"len", "-", "1"}], ")"}], "*", "height"}], "+", "i", "+", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"height", "-", "1"}]}], "}"}]}], "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.421412224234375*^9, 3.421412416125*^9}, { 3.421412471296875*^9, 3.4214124714375*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"AllSpanningTrees", "[", RowBox[{"len_", ",", "height_"}], "]"}], ":=", RowBox[{"Map", "[", RowBox[{"Sort", ",", RowBox[{"Select", "[", RowBox[{ RowBox[{"KSubsets", "[", RowBox[{ RowBox[{"GridEdges", "[", RowBox[{"len", ",", "height"}], "]"}], ",", RowBox[{ RowBox[{"len", "*", "height"}], "-", "1"}]}], "]"}], ",", RowBox[{ RowBox[{"IsConnected", "[", RowBox[{"#", ",", RowBox[{"len", "*", "height"}]}], "]"}], "&"}]}], "]"}], ",", "2"}], "]"}]}]], "Input", CellChangeTimes->{{3.421412207390625*^9, 3.421412218765625*^9}, { 3.421412489875*^9, 3.42141253465625*^9}, {3.4214136166875*^9, 3.42141363403125*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"str", "=", RowBox[{"OpenWrite", "[", "\"\\"", "]"}]}]], "Input", CellChangeTimes->{{3.4669636540397873`*^9, 3.4669636627582026`*^9}}], Cell[BoxData[ RowBox[{"OutputStream", "[", RowBox[{"\<\"c:\\\\test.txt\"\>", ",", "17"}], "]"}]], "Output", CellChangeTimes->{3.466963663039442*^9}] }, Open ]], Cell[BoxData[ RowBox[{"WriteGraphCylinderInformation", "[", RowBox[{"str", ",", RowBox[{"{", RowBox[{"{", RowBox[{"1", ",", "2"}], "}"}], "}"}], ",", "2"}], "]"}]], "Input", CellChangeTimes->{{3.466963671585989*^9, 3.466963679554433*^9}}] }, WindowSize->{615, 750}, WindowMargins->{{Automatic, 491}, {30, Automatic}}, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (February 18, 2009)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[545, 20, 670, 13, 72, "Input"], Cell[1218, 35, 279, 6, 29, "Text"], Cell[1500, 43, 621, 24, 65, "Text"], Cell[2124, 69, 9628, 297, 1052, "Input"], Cell[11755, 368, 1297, 37, 172, "Input"], Cell[13055, 407, 3042, 87, 312, "Input"], Cell[16100, 496, 481, 11, 31, "Input"], Cell[16584, 509, 1777, 52, 172, "Input"], Cell[CellGroupData[{ Cell[18386, 565, 1450, 37, 192, "Input"], Cell[19839, 604, 351, 6, 30, "Output"], Cell[20193, 612, 351, 6, 30, "Output"], Cell[20547, 620, 351, 6, 30, "Output"], Cell[20901, 628, 351, 6, 30, "Output"], Cell[21255, 636, 351, 6, 30, "Output"], Cell[21609, 644, 351, 6, 30, "Output"], Cell[21963, 652, 351, 6, 30, "Output"], Cell[22317, 660, 351, 6, 30, "Output"], Cell[22671, 668, 351, 6, 30, "Output"] }, Open ]], Cell[23037, 677, 1438, 42, 132, "Input"], Cell[24478, 721, 1237, 34, 152, "Input"], Cell[25718, 757, 1847, 51, 232, "Input"], Cell[27568, 810, 581, 15, 72, "Input"], Cell[28152, 827, 646, 18, 72, "Input"], Cell[28801, 847, 1397, 36, 132, "Input"], Cell[30201, 885, 2505, 55, 232, "Input"], Cell[32709, 942, 1825, 42, 252, "Input"], Cell[34537, 986, 2406, 75, 272, "Input"], Cell[36946, 1063, 1184, 30, 132, "Input"], Cell[38133, 1095, 2296, 59, 272, "Input"], Cell[40432, 1156, 1518, 43, 132, "Input"], Cell[41953, 1201, 3081, 81, 292, "Input"], Cell[45037, 1284, 1894, 48, 172, "Input"], Cell[46934, 1334, 266, 7, 31, "Input"], Cell[47203, 1343, 468, 14, 31, "Input"], Cell[47674, 1359, 2442, 71, 232, "Input"], Cell[50119, 1432, 2658, 71, 192, "Input"], Cell[52780, 1505, 982, 28, 72, "Input"], Cell[53765, 1535, 985, 32, 92, "Input"], Cell[54753, 1569, 1784, 55, 152, "Input"], Cell[56540, 1626, 1504, 34, 72, "Input"], Cell[58047, 1662, 2800, 76, 232, "Input"], Cell[60850, 1740, 1771, 46, 192, "Input"], Cell[62624, 1788, 1763, 45, 212, "Input"], Cell[64390, 1835, 3494, 91, 292, "Input"], Cell[67887, 1928, 3470, 92, 352, "Input"], Cell[71360, 2022, 1262, 35, 132, "Input"], Cell[72625, 2059, 1523, 41, 152, "Input"], Cell[74151, 2102, 2643, 63, 252, "Input"], Cell[76797, 2167, 1435, 36, 172, "Input"], Cell[78235, 2205, 237, 6, 31, "Input"], Cell[CellGroupData[{ Cell[78497, 2215, 110, 1, 31, "Input"], Cell[78610, 2218, 77, 1, 30, "Output"] }, Open ]], Cell[78702, 2222, 2167, 49, 252, "Input"], Cell[80872, 2273, 2390, 55, 172, "Input"], Cell[83265, 2330, 2364, 60, 272, "Input"], Cell[85632, 2392, 1372, 34, 152, "Input"], Cell[87007, 2428, 1061, 28, 112, "Input"], Cell[88071, 2458, 1136, 29, 132, "Input"], Cell[89210, 2489, 886, 22, 92, "Input"], Cell[90099, 2513, 1410, 37, 152, "Input"], Cell[91512, 2552, 1165, 29, 92, "Input"], Cell[92680, 2583, 621, 14, 92, "Input"], Cell[93304, 2599, 1772, 52, 192, "Input"], Cell[95079, 2653, 1906, 59, 172, "Input"], Cell[96988, 2714, 2748, 66, 292, "Input"], Cell[99739, 2782, 4101, 102, 332, "Input"], Cell[103843, 2886, 6728, 197, 472, "Input"], Cell[110574, 3085, 1444, 40, 172, "Input"], Cell[112021, 3127, 1682, 52, 112, "Input"], Cell[113706, 3181, 758, 21, 72, "Input"], Cell[CellGroupData[{ Cell[114489, 3206, 178, 3, 31, "Input"], Cell[114670, 3211, 153, 3, 30, "Output"] }, Open ]], Cell[114838, 3217, 258, 6, 31, "Input"] } ] *) (* End of internal cache information *)