Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
10191 lines (9676 sloc) 405 KB
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 8.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 157, 7]
NotebookDataLength[ 414509, 10181]
NotebookOptionsPosition[ 404699, 9887]
NotebookOutlinePosition[ 405134, 9904]
CellTagsIndexPosition[ 405091, 9901]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell["Code formatting examples ", "Section",
CellChangeTimes->{{3.539876535071289*^9, 3.5398765371708984`*^9}, {
3.540401492732769*^9, 3.540401501327884*^9}, {3.540401808581986*^9,
3.540401808654826*^9}},
FontWeight->"Plain"],
Cell["\<\
I assembled a rather extensive set of examples, which, to my mind, show that \
the formatter is fairly robust, and we can move on, improving it further \
along the way.\
\>", "Text",
CellChangeTimes->{{3.540401774618687*^9, 3.540401799660094*^9}}],
Cell[BoxData[
RowBox[{
RowBox[{"Needs", "[", "\"\<CodeFormatter`\>\"", "]"}], " "}]], "Input",
InitializationCell->True,
CellChangeTimes->{{3.540387567609852*^9, 3.540387587032259*^9}, {
3.540401509026651*^9, 3.540401512012421*^9}}],
Cell[BoxData[
RowBox[{
RowBox[{"prn", " ", "=", " ",
RowBox[{
RowBox[{"CellPrint", "[",
RowBox[{"Cell", "[",
RowBox[{
RowBox[{"BoxData", "[", "#", "]"}], ",", "\"\<Input\>\""}], "]"}],
"]"}], "&"}]}], ";"}]], "Input",
InitializationCell->True],
Cell[CellGroupData[{
Cell["\<\
An experiment with comments (comments not fully supported yet)\
\>", "Subsubsection",
CellChangeTimes->{{3.5398767920625*^9, 3.5398768085859375`*^9}}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@",
RowBox[{"MakeBoxes", "@",
RowBox[{"If", "[", "\t\t\t", "\n", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "\[Equal]", "0"}], ",",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "=", "1"}], ";",
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=", "index"}]}],
",",
RowBox[{
RowBox[{"indexHash", "[",
RowBox[{"[",
RowBox[{"index", "+", "1"}], "]"}], "]"}], "=", "0"}]}], "\n",
"]"}]}]}]}]], "Input",
CellChangeTimes->{{3.5398768197822266`*^9, 3.5398768263847656`*^9}, {
3.540387558498444*^9, 3.540387558817596*^9}, {3.540387602695869*^9,
3.540387603433409*^9}}],
Cell[BoxData[
RowBox[{"If", "[", "\n", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index", "\[RightDoubleBracket]"}],
"\[Equal]", "0"}], ",", "\n", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index", "\[RightDoubleBracket]"}],
"=", "1"}], ";",
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=", "index"}]}], ",",
"\n", "\t",
RowBox[{"(*", " ", "else", " ", "*)"}], "\n", "\t",
RowBox[{
RowBox[{"indexHash", "\[LeftDoubleBracket]",
RowBox[{"index", "+", "1"}], "\[RightDoubleBracket]"}], "=", "0"}]}],
"\n", "]"}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.540387605023232*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example1", "Subsubsection",
CellChangeTimes->{{3.5391550382490234`*^9, 3.539155038955078*^9},
3.540401561827656*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes", " ", "=", " ",
RowBox[{"MakeBoxes", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"Clear", "[", "a", "]"}], ";",
RowBox[{
RowBox[{"f", "[", "x_", "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"y", "=", "x"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"myFunction", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"resultIndices", "[",
RowBox[{"[",
RowBox[{"++", "ctr"}], "]"}], "]"}], "=",
RowBox[{"resultIndices", "[",
RowBox[{"[",
RowBox[{"++", "ctr"}], "]"}], "]"}]}], ";"}], "]"}]}], "]"}]}]}],
"]"}]}]], "Input",
CellChangeTimes->{{3.5398771964335938`*^9, 3.5398772176416016`*^9}}],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Clear\"\>", ",", "\<\"[\"\>", ",", "\<\"a\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"f\"\>", ",", "\<\"[\"\>", ",", "\<\"x_\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"y\"\>", ",", "\<\"=\"\>", ",", "\<\"x\"\>"}],
"}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"myFunction\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"++\"\>", ",", "\<\"ctr\"\>"}], "}"}], "]"}],
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"++\"\>", ",", "\<\"ctr\"\>"}], "}"}], "]"}],
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\";\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}]], "Output",
CellChangeTimes->{3.5398772191210938`*^9, 3.54030637000332*^9,
3.540387623539931*^9, 3.54038767425146*^9, 3.540401642579062*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes"}]}]], "Input",
CellChangeTimes->{{3.538744911366211*^9, 3.538744985350586*^9}, {
3.538745087064453*^9, 3.5387451694560547`*^9}, 3.538745317541992*^9, {
3.5398766566640625`*^9, 3.5398766611552734`*^9}, {3.5398771895302734`*^9,
3.539877224533203*^9}, 3.540387641306317*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "a", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"f", "[", "x_", "]"}], ":=", "\n", "\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"y", "=", "x"}], "}"}], ",", "\n", "\t", "\t",
RowBox[{"myFunction", "[",
RowBox[{
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=",
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}]}], ";"}], "]"}]}],
"\n", "\t", "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.54030637137939*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes"}]}]], "Input",
CellChangeTimes->{{3.5398772313847656`*^9, 3.5398772324833984`*^9},
3.540387641369846*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "a", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"f", "[", "x_", "]"}], ":=", "\n", "\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"y", "=", "x"}], "}"}], ",", "\n", "\t", "\t",
RowBox[{"myFunction", "[",
RowBox[{
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=",
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}]}], ";"}], "]"}]}],
"]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.540387714942444*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example2", "Subsubsection",
CellChangeTimes->{{3.5391551239716797`*^9, 3.5391551254921875`*^9},
3.540401563608322*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes0", " ", "=", " ", "\[IndentingNewLine]",
RowBox[{"MakeBoxes", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"ClearAll", "[", "generateFastMean", "]"}], ";", "\n",
RowBox[{
RowBox[{"generateFastMean", "[",
RowBox[{"maxIndex_Integer", "?", "Positive"}], "]"}], ":=",
RowBox[{"Compile", "[",
RowBox[{
RowBox[{"{",
RowBox[{"{",
RowBox[{"data", ",", "_Real", ",", "2"}], "}"}], "}"}], ",",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"means", "=",
RowBox[{"Table", "[",
RowBox[{"0.", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",",
RowBox[{"num", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",",
RowBox[{"ctr", "=", "0"}], ",",
RowBox[{"i", "=", "0"}], ",",
RowBox[{"index", "=", "0"}], ",",
RowBox[{"resultIndices", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",",
RowBox[{"indexHash", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}]}], "}"}], ",",
RowBox[{
RowBox[{"Do", "[",
RowBox[{
RowBox[{
RowBox[{"index", "=",
RowBox[{"IntegerPart", "[",
RowBox[{"data", "[",
RowBox[{"[",
RowBox[{"i", ",", "2"}], "]"}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"means", "[",
RowBox[{"[", "index", "]"}], "]"}], "+=",
RowBox[{"data", "[",
RowBox[{"[",
RowBox[{"i", ",", "1"}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"num", "[",
RowBox[{"[", "index", "]"}], "]"}], "++"}], ";",
"\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"indexHash", "[",
RowBox[{"[", "index", "]"}], "]"}], "\[Equal]", "0"}], ",",
RowBox[{
RowBox[{
RowBox[{"indexHash", "[",
RowBox[{"[", "index", "]"}], "]"}], "=", "1"}], ";",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"resultIndices", "[",
RowBox[{"[",
RowBox[{"++", "ctr"}], "]"}], "]"}], "=", "index"}]}]}],
"]"}], ";"}], ",",
RowBox[{"{",
RowBox[{"i", ",",
RowBox[{"Length", "[", "data", "]"}]}], "}"}]}], "]"}], ";",
"\[IndentingNewLine]",
RowBox[{"resultIndices", "=",
RowBox[{"Take", "[",
RowBox[{"resultIndices", ",", "ctr"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"resultIndices", ",",
RowBox[{
RowBox[{"means", "[",
RowBox[{"[", "resultIndices", "]"}], "]"}], "+",
RowBox[{"num", "[",
RowBox[{"[", "resultIndices", "]"}], "]"}]}]}], "}"}],
"]"}]}]}], "]"}], ",",
RowBox[{"(*", "Module", "*)"}],
RowBox[{"CompilationTarget", "\[Rule]", "\"\<C\>\""}], ",",
RowBox[{"RuntimeOptions", "\[Rule]", "\"\<Speed\>\""}]}], "]"}]}],
";"}], "]"}]}]], "Input",
CellChangeTimes->{{3.538073492669922*^9, 3.5380735040498047`*^9}, {
3.5380735499609375`*^9, 3.5380735821572266`*^9}, {3.5391551349746094`*^9,
3.539155151995117*^9}, {3.5391589632373047`*^9, 3.539158966623047*^9},
3.5398768399101562`*^9, 3.5398769497333984`*^9}],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"ClearAll\"\>", ",", "\<\"[\"\>",
",", "\<\"generateFastMean\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"generateFastMean\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"maxIndex_Integer\"\>", ",", "\<\"?\"\>",
",", "\<\"Positive\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Compile\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"data\"\>", ",", "\<\",\"\>",
",", "\<\"_Real\"\>", ",", "\<\",\"\>",
",", "\<\"2\"\>"}], "}"}], "]"}], ",", "\<\"}\"\>"}],
"}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"means\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Table\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0.`\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"maxIndex\"\>",
",", "\<\"}\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"num\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Table\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"maxIndex\"\>",
",", "\<\"}\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"ctr\"\>", ",", "\<\"=\"\>",
",", "\<\"0\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"i\"\>", ",", "\<\"=\"\>", ",", "\<\"0\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"index\"\>", ",", "\<\"=\"\>",
",", "\<\"0\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Table\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"maxIndex\"\>",
",", "\<\"}\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"indexHash\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Table\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"maxIndex\"\>",
",", "\<\"}\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Do\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"index\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"IntegerPart\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"data\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"i\"\>", ",", "\<\",\"\>", ",", "\<\"2\"\>"}],
"}"}], "]"}], ",", "\<\"\[RightDoubleBracket]\"\>"}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"means\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",", "\<\"index\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"+=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"data\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"i\"\>", ",", "\<\",\"\>", ",", "\<\"1\"\>"}],
"}"}], "]"}], ",", "\<\"\[RightDoubleBracket]\"\>"}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"num\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",", "\<\"index\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"++\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"indexHash\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",", "\<\"index\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"\[Equal]\"\>", ",", "\<\"0\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"indexHash\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",", "\<\"index\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"=\"\>", ",", "\<\"1\"\>"}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"++\"\>", ",", "\<\"ctr\"\>"}], "}"}], "]"}],
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"=\"\>", ",", "\<\"index\"\>"}], "}"}], "]"}]}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}], ",", "\<\";\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"i\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"data\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Take\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>", ",", "\<\",\"\>",
",", "\<\"ctr\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Transpose\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"resultIndices\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"means\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>",
",", "\<\"resultIndices\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"+\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"num\"\>",
",", "\<\"\[LeftDoubleBracket]\"\>",
",", "\<\"resultIndices\"\>",
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"}\"\>"}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"CompilationTarget\"\>", ",", "\<\"\[Rule]\"\>",
",", "\<\"\\\"C\\\"\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"RuntimeOptions\"\>", ",", "\<\"\[Rule]\"\>",
",", "\<\"\\\"Speed\\\"\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>"}], "}"}], "]"}]], "Output",
CellChangeTimes->{3.5398769501220703`*^9, 3.540387921190284*^9,
3.540401669214467*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes0"}]}]], "Input",
CellChangeTimes->{
3.538073532786133*^9, {3.539876857970703*^9, 3.5398768591054688`*^9},
3.540387641410295*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"ClearAll", "[", "generateFastMean", "]"}], ";"}], "\n",
RowBox[{
RowBox[{
RowBox[{"generateFastMean", "[",
RowBox[{"maxIndex_Integer", "?", "Positive"}], "]"}], ":=", "\n", "\t",
RowBox[{"Compile", "[", "\t", "\t", "\n", "\t", "\t",
RowBox[{
RowBox[{"{",
RowBox[{"{",
RowBox[{"data", ",", "_Real", ",", "2"}], "}"}], "}"}], ",", "\n",
"\t", "\t",
RowBox[{"Module", "[", "\n", "\t", "\t",
RowBox[{
RowBox[{"{", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{"means", "=",
RowBox[{"Table", "[",
RowBox[{"0.`", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"num", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"ctr", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"i", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"index", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"resultIndices", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"indexHash", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}]}], "\n", "\t", "\t",
"}"}], ",", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Do", "[", "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\n",
"\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"index", "=",
RowBox[{"IntegerPart", "[",
RowBox[{"data", "\[LeftDoubleBracket]",
RowBox[{"i", ",", "2"}], "\[RightDoubleBracket]"}], "]"}]}],
";", "\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"means", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "+=",
RowBox[{"data", "\[LeftDoubleBracket]",
RowBox[{"i", ",", "1"}], "\[RightDoubleBracket]"}]}], ";",
"\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"num", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "++"}], ";", "\n", "\t", "\t", "\t",
"\t",
RowBox[{
"If", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "\[Equal]", "0"}], ",", "\n",
"\t", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "=", "1"}], ";",
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=",
"index"}]}]}], "\n", "\t", "\t", "\t", "\t", "]"}], ";"}],
",", "\n", "\t", "\t", "\t", "\t",
RowBox[{"{",
RowBox[{"i", ",",
RowBox[{"Length", "[", "data", "]"}]}], "}"}]}], "\n", "\t",
"\t", "\t", "]"}], ";", "\n", "\t", "\t", "\t",
RowBox[{"resultIndices", "=",
RowBox[{"Take", "[",
RowBox[{"resultIndices", ",", "ctr"}], "]"}]}], ";", "\n", "\t",
"\t", "\t",
RowBox[{"Transpose", "[", "\n", "\t", "\t", "\t", "\t",
RowBox[{
"{", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t", "\t",
"\t",
RowBox[{
"resultIndices", ",", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"means", "\[LeftDoubleBracket]", "resultIndices",
"\[RightDoubleBracket]"}], "+",
RowBox[{
"num", "\[LeftDoubleBracket]", "resultIndices",
"\[RightDoubleBracket]"}]}]}], "\n", "\t", "\t", "\t", "\t",
"}"}], "\n", "\t", "\t", "\t", "]"}]}]}], "\n", "\t", "\t", "]"}],
",", "\n", "\t", "\t",
RowBox[{"CompilationTarget", "\[Rule]", "\"\<C\>\""}], ",", "\n", "\t",
"\t",
RowBox[{"RuntimeOptions", "\[Rule]", "\"\<Speed\>\""}]}], "\n", "\t",
"]"}]}], ";"}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.540401671748701*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes0"}]}]], "Input",
CellChangeTimes->{{3.5398772557285156`*^9, 3.539877256830078*^9},
3.540387641462608*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"ClearAll", "[", "generateFastMean", "]"}], ";"}], "\n",
RowBox[{
RowBox[{
RowBox[{"generateFastMean", "[",
RowBox[{"maxIndex_Integer", "?", "Positive"}], "]"}], ":=", "\n", "\t",
RowBox[{"Compile", "[", "\t", "\t", "\n", "\t", "\t",
RowBox[{
RowBox[{"{",
RowBox[{"{",
RowBox[{"data", ",", "_Real", ",", "2"}], "}"}], "}"}], ",", "\n",
"\t", "\t",
RowBox[{"Module", "[", "\n", "\t", "\t",
RowBox[{
RowBox[{"{", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{"means", "=",
RowBox[{"Table", "[",
RowBox[{"0.`", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"num", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"ctr", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"i", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"index", "=", "0"}], ",", "\n", "\t", "\t", "\t",
RowBox[{"resultIndices", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}], ",", "\n", "\t",
"\t", "\t",
RowBox[{"indexHash", "=",
RowBox[{"Table", "[",
RowBox[{"0", ",",
RowBox[{"{", "maxIndex", "}"}]}], "]"}]}]}], "}"}], ",", "\t",
"\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Do", "[", "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\t", "\n",
"\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"index", "=",
RowBox[{"IntegerPart", "[",
RowBox[{"data", "\[LeftDoubleBracket]",
RowBox[{"i", ",", "2"}], "\[RightDoubleBracket]"}], "]"}]}],
";", "\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"means", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "+=",
RowBox[{"data", "\[LeftDoubleBracket]",
RowBox[{"i", ",", "1"}], "\[RightDoubleBracket]"}]}], ";",
"\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"num", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "++"}], ";", "\n", "\t", "\t", "\t",
"\t",
RowBox[{
"If", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "\[Equal]", "0"}], ",", "\n",
"\t", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{
"indexHash", "\[LeftDoubleBracket]", "index",
"\[RightDoubleBracket]"}], "=", "1"}], ";",
RowBox[{
RowBox[{"resultIndices", "\[LeftDoubleBracket]",
RowBox[{"++", "ctr"}], "\[RightDoubleBracket]"}], "=",
"index"}]}]}], "]"}], ";"}], ",", "\n", "\t", "\t", "\t",
"\t",
RowBox[{"{",
RowBox[{"i", ",",
RowBox[{"Length", "[", "data", "]"}]}], "}"}]}], "]"}], ";",
"\n", "\t", "\t", "\t",
RowBox[{"resultIndices", "=",
RowBox[{"Take", "[",
RowBox[{"resultIndices", ",", "ctr"}], "]"}]}], ";", "\n", "\t",
"\t", "\t",
RowBox[{"Transpose", "[", "\n", "\t", "\t", "\t", "\t",
RowBox[{
"{", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t", "\t",
"\t",
RowBox[{
"resultIndices", ",", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"means", "\[LeftDoubleBracket]", "resultIndices",
"\[RightDoubleBracket]"}], "+",
RowBox[{
"num", "\[LeftDoubleBracket]", "resultIndices",
"\[RightDoubleBracket]"}]}]}], "}"}], "]"}]}]}], "]"}], ",",
"\n", "\t", "\t",
RowBox[{"CompilationTarget", "\[Rule]", "\"\<C\>\""}], ",", "\n", "\t",
"\t",
RowBox[{"RuntimeOptions", "\[Rule]", "\"\<Speed\>\""}]}], "]"}]}],
";"}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.540401679035092*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example3", "Subsubsection",
CellChangeTimes->{{3.5391589884921875`*^9, 3.5391589897841797`*^9},
3.540401564465898*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes5", " ", "=", " ",
RowBox[{"MakeBoxes", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"Clear", "[", "getSamplesP", "]"}], ";", "\n",
RowBox[{
RowBox[{"getSamplesP", "[",
RowBox[{"data_List", ",",
RowBox[{"minlen_Integer", "?", "Positive"}], ",",
RowBox[{"n", ":",
RowBox[{
RowBox[{"(",
RowBox[{"_Integer", "|", "All"}], ")"}], ":", "All"}]}]}], "]"}], ":=",
RowBox[{"Select", "[",
RowBox[{
RowBox[{
RowBox[{
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"#", ",",
RowBox[{"Range", "[",
RowBox[{"Length", "[", "#", "]"}], "]"}]}], "}"}], "]"}], "&"}],
"@",
RowBox[{"Partition", "[",
RowBox[{"data", ",", "minlen", ",", "1"}], "]"}]}], ",",
RowBox[{
RowBox[{"!",
RowBox[{"MemberQ", "[",
RowBox[{
RowBox[{"First", "@", "#"}], ",",
RowBox[{"0", "|", "Null"}]}], "]"}]}], "&"}], ",",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "=!=", "All"}], ",", "n", ",",
RowBox[{"Sequence", "@@",
RowBox[{"{", "}"}]}]}], "]"}]}], "]"}]}]}], "]"}]}]], "Input",
CellChangeTimes->{{3.5398769276533203`*^9, 3.539876938501953*^9}}],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Clear\"\>", ",", "\<\"[\"\>", ",", "\<\"getSamplesP\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"getSamplesP\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"data_List\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"minlen_Integer\"\>", ",", "\<\"?\"\>",
",", "\<\"Positive\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"n\"\>", ",", "\<\":\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"_Integer\"\>", ",", "\<\"|\"\>",
",", "\<\"All\"\>"}], "}"}], "]"}], ",", "\<\":\"\>",
",", "\<\"All\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Select\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"(\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Transpose\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Range\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"#1\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"}\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\"&\"\>"}], "}"}], "]"}],
",", "\<\")\"\>"}], "}"}], "]"}], ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Partition\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"data\"\>", ",", "\<\",\"\>",
",", "\<\"minlen\"\>", ",", "\<\",\"\>",
",", "\<\"1\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"!\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"MemberQ\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"First\"\>", ",", "\<\"[\"\>",
",", "\<\"#1\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0\"\>", ",", "\<\"|\"\>",
",", "\<\"Null\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"&\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"n\"\>", ",", "\<\"=!=\"\>",
",", "\<\"All\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",", "\<\"n\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Sequence\"\>", ",", "\<\"@@\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"}\"\>"}], "}"}], "]"}]}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}]}], "}"}], "]"}]], "Output",
CellChangeTimes->{3.5398769393779297`*^9, 3.540401727689076*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes5"}]}]], "Input",
CellChangeTimes->{{3.537987332409242*^9, 3.5379873861914687`*^9}, {
3.5398769148876953`*^9, 3.539876916279297*^9}, 3.540387641506598*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "getSamplesP", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"getSamplesP", "[",
RowBox[{"data_List", ",",
RowBox[{"minlen_Integer", "?", "Positive"}], ",",
RowBox[{"n", ":",
RowBox[{"_Integer", "|", "All"}], ":", "All"}]}], "]"}], ":=", "\n",
"\t",
RowBox[{"Select", "[", "\t", "\t", "\n", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"#1", ",",
RowBox[{"Range", "[",
RowBox[{"Length", "[", "#1", "]"}], "]"}]}], "}"}], "]"}], "&"}],
")"}], "[",
RowBox[{"Partition", "[",
RowBox[{"data", ",", "minlen", ",", "1"}], "]"}], "]"}], ",", "\n",
"\t", "\t",
RowBox[{
RowBox[{"!",
RowBox[{"MemberQ", "[",
RowBox[{
RowBox[{"First", "[", "#1", "]"}], ",",
RowBox[{"0", "|", "Null"}]}], "]"}]}], "&"}], ",", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "=!=", "All"}], ",", "n", ",",
RowBox[{"Sequence", "@@",
RowBox[{"{", "}"}]}]}], "]"}]}], "\n", "\t", "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.539876919401367*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes5"}]}]], "Input",
CellChangeTimes->{{3.539877292236328*^9, 3.5398772934121094`*^9},
3.540387641555618*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "getSamplesP", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"getSamplesP", "[",
RowBox[{"data_List", ",",
RowBox[{"minlen_Integer", "?", "Positive"}], ",",
RowBox[{"n", ":",
RowBox[{"_Integer", "|", "All"}], ":", "All"}]}], "]"}], ":=", "\n",
"\t",
RowBox[{"Select", "[", "\t", "\t", "\n", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"#1", ",",
RowBox[{"Range", "[",
RowBox[{"Length", "[", "#1", "]"}], "]"}]}], "}"}], "]"}], "&"}],
")"}], "[",
RowBox[{"Partition", "[",
RowBox[{"data", ",", "minlen", ",", "1"}], "]"}], "]"}], ",", "\n",
"\t", "\t",
RowBox[{
RowBox[{"!",
RowBox[{"MemberQ", "[",
RowBox[{
RowBox[{"First", "[", "#1", "]"}], ",",
RowBox[{"0", "|", "Null"}]}], "]"}]}], "&"}], ",", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "=!=", "All"}], ",", "n", ",",
RowBox[{"Sequence", "@@",
RowBox[{"{", "}"}]}]}], "]"}]}], "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.539877294091797*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example4", "Subsubsection",
CellChangeTimes->{{3.5391590269228516`*^9, 3.5391590281289062`*^9},
3.540401565240886*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"\[IndentingNewLine]",
RowBox[{"boxes4", " ", "=", " ", "\[IndentingNewLine]",
RowBox[{"MakeBoxes", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"findLsts2", "[",
RowBox[{"lst_", ",",
RowBox[{"minLen_Integer", "?", "Positive"}], ",", "maxZeros_", ",",
RowBox[{"n", ":",
RowBox[{
RowBox[{"(",
RowBox[{"_Integer", "|", "All"}], ")"}], ":", "All"}]}]}], "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"zeroLst", ",", "rangeLst"}], "}"}], ",",
RowBox[{
RowBox[{"zeroLst", "=",
RowBox[{"Flatten", "[",
RowBox[{"Position", "[",
RowBox[{"lst", ",",
RowBox[{"(",
RowBox[{"0", "|", "0.", "|", "Null"}], ")"}]}], "]"}], "]"}]}],
";", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"Length", "[", "zeroLst", "]"}], "\[LessEqual]",
"maxZeros"}], ",", "lst", ",",
RowBox[{
RowBox[{"rangeLst", "=",
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{
RowBox[{"Prepend", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "+", "1"}], ",",
RowBox[{"-", "maxZeros"}]}], "]"}], ",", "1"}], "]"}], ",",
RowBox[{"Append", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "-", "1"}], ",", "maxZeros"}], "]"}],
",",
RowBox[{"Length", "[", "lst", "]"}]}], "]"}]}], "}"}],
"]"}]}], ";", "\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"Take", "[",
RowBox[{"lst", ",", "#"}], "]"}], ",", "#"}], "}"}], "&"}], "/@",
RowBox[{"Select", "[",
RowBox[{"rangeLst", ",",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"#", "[",
RowBox[{"[", "2", "]"}], "]"}], "-",
RowBox[{"#", "[",
RowBox[{"[", "1", "]"}], "]"}], "+", "1"}], ")"}],
"\[GreaterEqual]", "minLen"}], "&"}], ",",
RowBox[{"n", "/.",
RowBox[{"All", "\[Rule]",
RowBox[{"Sequence", "[", "]"}]}]}]}], "]"}]}]}]}], "]"}]}]}],
"]"}]}], "]"}]}]}]], "Input",
CellChangeTimes->{{3.5379946334356093`*^9, 3.5379946345899067`*^9}}],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"findLsts2\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"lst_\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"minLen_Integer\"\>", ",", "\<\"?\"\>",
",", "\<\"Positive\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",", "\<\"maxZeros_\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"n\"\>", ",", "\<\":\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"_Integer\"\>", ",", "\<\"|\"\>",
",", "\<\"All\"\>"}], "}"}], "]"}], ",", "\<\":\"\>",
",", "\<\"All\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"zeroLst\"\>", ",", "\<\",\"\>",
",", "\<\"rangeLst\"\>"}], "}"}], "]"}], ",", "\<\"}\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"zeroLst\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Flatten\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Position\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"lst\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"0\"\>", ",", "\<\"|\"\>", ",", "\<\"0.`\"\>",
",", "\<\"|\"\>", ",", "\<\"Null\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"zeroLst\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\"\[LessEqual]\"\>", ",", "\<\"maxZeros\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",", "\<\"lst\"\>",
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"rangeLst\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Transpose\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Prepend\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Drop\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"zeroLst\"\>", ",", "\<\"+\"\>",
",", "\<\"1\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"-\"\>", ",", "\<\"maxZeros\"\>"}], "}"}],
"]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",", "\<\"1\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Append\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Drop\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"zeroLst\"\>", ",", "\<\"-\"\>",
",", "\<\"1\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",", "\<\"maxZeros\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"lst\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"(\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Take\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"lst\"\>", ",", "\<\",\"\>",
",", "\<\"#1\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",", "\<\"#1\"\>"}],
"}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\"&\"\>"}], "}"}], "]"}], ",", "\<\")\"\>"}],
"}"}], "]"}], ",", "\<\"/@\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Select\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"rangeLst\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\"\[LeftDoubleBracket]\"\>",
",", "\<\"2\"\>", ",", "\<\"\[RightDoubleBracket]\"\>"}],
"}"}], "]"}], ",", "\<\"-\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\"\[LeftDoubleBracket]\"\>",
",", "\<\"1\"\>", ",", "\<\"\[RightDoubleBracket]\"\>"}],
"}"}], "]"}], ",", "\<\"+\"\>", ",", "\<\"1\"\>"}],
"}"}], "]"}], ",", "\<\"\[GreaterEqual]\"\>",
",", "\<\"minLen\"\>"}], "}"}], "]"}], ",", "\<\"&\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"n\"\>", ",", "\<\"/.\"\>",
",", "\<\"\[InvisibleSpace]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"All\"\>", ",", "\<\"\[Rule]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Sequence\"\>", ",", "\<\"[\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}]}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]], "Output",
CellChangeTimes->{3.537994636858461*^9, 3.538036716746766*^9,
3.53874382271875*^9, 3.5387494833808594`*^9, 3.5391590868203125`*^9,
3.539184610048828*^9, 3.5398769645527344`*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{
RowBox[{"format", "@",
RowBox[{"preformat", "@", "boxes4"}]}], ";"}]], "Input",
CellChangeTimes->{3.5391973501168594`*^9}],
Cell[BoxData[""], "Input",
CellChangeTimes->{{3.5391969644957657`*^9, 3.5391969646676407`*^9}}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes4"}]}]], "Input",
CellChangeTimes->{{3.5379946466074843`*^9, 3.537994646778383*^9},
3.539876971236328*^9, 3.540387641598422*^9}],
Cell[BoxData[
RowBox[{
RowBox[{"findLsts2", "[",
RowBox[{"lst_", ",",
RowBox[{"minLen_Integer", "?", "Positive"}], ",", "maxZeros_", ",",
RowBox[{"n", ":",
RowBox[{"_Integer", "|", "All"}], ":", "All"}]}], "]"}], ":=", "\n",
"\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"zeroLst", ",", "rangeLst"}], "}"}], ",", "\t", "\t", "\n", "\t",
"\t",
RowBox[{
RowBox[{"zeroLst", "=",
RowBox[{"Flatten", "[",
RowBox[{"Position", "[",
RowBox[{"lst", ",",
RowBox[{"0", "|", "0.`", "|", "Null"}]}], "]"}], "]"}]}], ";", "\n",
"\t", "\t",
RowBox[{"If", "[", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"Length", "[", "zeroLst", "]"}], "\[LessEqual]", "maxZeros"}],
",", "\n", "\t", "\t", "\t", "lst", ",", "\n", "\t", "\t", "\t",
RowBox[{"(*", " ", "else", " ", "*)"}], "\t", "\t", "\t", "\n", "\t",
"\t", "\t",
RowBox[{
RowBox[{"rangeLst", "=", "\n", "\t", "\t", "\t", "\t",
RowBox[{"Transpose", "[", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
"{", "\t", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t", "\t",
RowBox[{
RowBox[{"Prepend", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "+", "1"}], ",",
RowBox[{"-", "maxZeros"}]}], "]"}], ",", "1"}], "]"}], ",",
"\n", "\t", "\t", "\t", "\t", "\t", "\t",
RowBox[{"Append", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "-", "1"}], ",", "maxZeros"}], "]"}], ",",
RowBox[{"Length", "[", "lst", "]"}]}], "]"}]}], "\n", "\t",
"\t", "\t", "\t", "\t", "}"}], "\n", "\t", "\t", "\t", "\t",
"]"}]}], ";", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"Take", "[",
RowBox[{"lst", ",", "#1"}], "]"}], ",", "#1"}], "}"}], "&"}],
")"}], "/@", "\n", "\t", "\t", "\t", "\t",
RowBox[{"Select", "[", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{"rangeLst", ",",
RowBox[{
RowBox[{
RowBox[{
RowBox[{
"#1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}],
"-",
RowBox[{
"#1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}],
"+", "1"}], "\[GreaterEqual]", "minLen"}], "&"}], ",",
RowBox[{"n", "/.", "\[InvisibleSpace]",
RowBox[{"All", "\[Rule]",
RowBox[{"Sequence", "[", "]"}]}]}]}], "\n", "\t", "\t", "\t",
"\t", "]"}]}]}]}], "\n", "\t", "\t", "]"}]}]}], "\n", "\t",
"]"}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398769723779297`*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes4"}]}]], "Input",
CellChangeTimes->{{3.539877307095703*^9, 3.5398773083242188`*^9},
3.540387641641229*^9}],
Cell[BoxData[
RowBox[{
RowBox[{"findLsts2", "[",
RowBox[{"lst_", ",",
RowBox[{"minLen_Integer", "?", "Positive"}], ",", "maxZeros_", ",",
RowBox[{"n", ":",
RowBox[{"_Integer", "|", "All"}], ":", "All"}]}], "]"}], ":=", "\n",
"\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"zeroLst", ",", "rangeLst"}], "}"}], ",", "\t", "\t", "\n", "\t",
"\t",
RowBox[{
RowBox[{"zeroLst", "=",
RowBox[{"Flatten", "[",
RowBox[{"Position", "[",
RowBox[{"lst", ",",
RowBox[{"0", "|", "0.`", "|", "Null"}]}], "]"}], "]"}]}], ";", "\n",
"\t", "\t",
RowBox[{"If", "[", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"Length", "[", "zeroLst", "]"}], "\[LessEqual]", "maxZeros"}],
",", "\n", "\t", "\t", "\t", "lst", ",", "\n", "\t", "\t", "\t",
RowBox[{"(*", " ", "else", " ", "*)"}], "\t", "\t", "\t", "\n", "\t",
"\t", "\t",
RowBox[{
RowBox[{"rangeLst", "=", "\n", "\t", "\t", "\t", "\t",
RowBox[{"Transpose", "[", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
"{", "\t", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t", "\t",
RowBox[{
RowBox[{"Prepend", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "+", "1"}], ",",
RowBox[{"-", "maxZeros"}]}], "]"}], ",", "1"}], "]"}], ",",
"\n", "\t", "\t", "\t", "\t", "\t", "\t",
RowBox[{"Append", "[",
RowBox[{
RowBox[{"Drop", "[",
RowBox[{
RowBox[{"zeroLst", "-", "1"}], ",", "maxZeros"}], "]"}], ",",
RowBox[{"Length", "[", "lst", "]"}]}], "]"}]}], "}"}], "]"}]}],
";", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"Take", "[",
RowBox[{"lst", ",", "#1"}], "]"}], ",", "#1"}], "}"}], "&"}],
")"}], "/@", "\n", "\t", "\t", "\t", "\t",
RowBox[{"Select", "[", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{"rangeLst", ",",
RowBox[{
RowBox[{
RowBox[{
RowBox[{
"#1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}],
"-",
RowBox[{
"#1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}],
"+", "1"}], "\[GreaterEqual]", "minLen"}], "&"}], ",",
RowBox[{"n", "/.", "\[InvisibleSpace]",
RowBox[{"All", "\[Rule]",
RowBox[{"Sequence", "[", "]"}]}]}]}], "]"}]}]}]}], "]"}]}]}],
"]"}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398773090654297`*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example5", "Subsubsection",
CellChangeTimes->{{3.539159118397461*^9, 3.539159119154297*^9},
3.540401566023257*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes3", " ", "=", " ", "\[IndentingNewLine]",
RowBox[{"MakeBoxes", "[",
RowBox[{
RowBox[{"Clear", "[", "maxLen", "]"}], ";", "\[IndentingNewLine]",
RowBox[{
RowBox[{"maxLen", "[", "boxes_", "]"}], ":=", "\[IndentingNewLine]",
RowBox[{"Max", "@",
RowBox[{"Total", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"Split", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"Cases", "[",
RowBox[{"boxes", ",", "\[IndentingNewLine]",
RowBox[{"s_String", "\[RuleDelayed]",
RowBox[{"(",
RowBox[{"s", "/.",
RowBox[{"{",
RowBox[{
RowBox[{"\"\<\\t\>\"", "->", "4"}], ",",
RowBox[{"\"\<\\n\>\"", "\[RuleDelayed]", "0"}], ",",
RowBox[{"ss_", "\[RuleDelayed]",
RowBox[{"StringLength", "[", "ss", "]"}]}]}], "}"}]}],
")"}]}], ",", "\[IndentingNewLine]", "Infinity"}], "]"}], ",",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"#", "=!=", "0"}], "&"}]}], "]"}], ",",
RowBox[{"{", "2", "}"}]}], "]"}]}]}]}], "]"}]}]], "Input"],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Clear\"\>", ",", "\<\"[\"\>", ",", "\<\"maxLen\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"maxLen\"\>", ",", "\<\"[\"\>", ",", "\<\"boxes_\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Max\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Total\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Split\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Cases\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"boxes\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"s_String\"\>", ",", "\<\"\[RuleDelayed]\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"(\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"s\"\>", ",", "\<\"/.\"\>",
",", "\<\"\[VeryThinSpace]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"\\\"\\\\t\\\"\"\>", ",", "\<\"\[Rule]\"\>",
",", "\<\"4\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"\\\"\\\\n\\\"\"\>",
",", "\<\"\[RuleDelayed]\"\>", ",", "\<\"0\"\>"}], "}"}],
"]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"ss_\"\>", ",", "\<\"\[RuleDelayed]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"StringLength\"\>", ",", "\<\"[\"\>",
",", "\<\"ss\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"}\"\>"}], "}"}],
"]"}]}], "}"}], "]"}], ",", "\<\")\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\",\"\>",
",", "\<\"\[Infinity]\"\>"}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\"=!=\"\>",
",", "\<\"0\"\>"}], "}"}], "]"}], ",", "\<\"&\"\>"}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",", "\<\"2\"\>", ",", "\<\"}\"\>"}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}]], "Output",
CellChangeTimes->{3.537994840295961*^9, 3.5387495154003906`*^9,
3.5391591382910156`*^9, 3.5391878947128906`*^9, 3.5398770142666016`*^9,
3.540401748653556*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes3"}]}]], "Input",
CellChangeTimes->{{3.537994851579164*^9, 3.5379948516924458`*^9},
3.5398770192978516`*^9, 3.540387641684276*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "maxLen", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"maxLen", "[", "boxes_", "]"}], ":=", "\n", "\t",
RowBox[{"Max", "[", "\n", "\t", "\t",
RowBox[{"Total", "[", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Split", "[", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Cases", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{"boxes", ",", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
"s_String", "\[RuleDelayed]", "\n", "\t", "\t", "\t", "\t", "\t",
"\t",
RowBox[{"(",
RowBox[{"s", "/.", "\[VeryThinSpace]",
RowBox[{"{",
RowBox[{
RowBox[{"\"\<\\t\>\"", "\[Rule]", "4"}], ",",
RowBox[{"\"\<\\n\>\"", "\[RuleDelayed]", "0"}], ",",
RowBox[{"ss_", "\[RuleDelayed]",
RowBox[{"StringLength", "[", "ss", "]"}]}]}], "}"}]}],
")"}]}], ",", "\n", "\t", "\t", "\t", "\t", "\t",
"\[Infinity]"}], "\n", "\t", "\t", "\t", "\t", "]"}], ",", "\n",
"\t", "\t", "\t", "\t",
RowBox[{
RowBox[{"#1", "=!=", "0"}], "&"}]}], "\n", "\t", "\t", "\t", "]"}],
",", "\n", "\t", "\t", "\t",
RowBox[{"{", "2", "}"}]}], "\n", "\t", "\t", "]"}], "\n", "\t",
"]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.540401749796222*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes3"}]}]], "Input",
CellChangeTimes->{{3.5398773299970703`*^9, 3.5398773312001953`*^9},
3.540387641726947*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"Clear", "[", "maxLen", "]"}], ";"}], "\n",
RowBox[{
RowBox[{"maxLen", "[", "boxes_", "]"}], ":=", "\n", "\t",
RowBox[{"Max", "[", "\n", "\t", "\t",
RowBox[{"Total", "[", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Split", "[", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{
"Cases", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{"boxes", ",", "\n", "\t", "\t", "\t", "\t", "\t",
RowBox[{
"s_String", "\[RuleDelayed]", "\n", "\t", "\t", "\t", "\t", "\t",
"\t",
RowBox[{"(",
RowBox[{"s", "/.", "\[InvisibleSpace]",
RowBox[{"{",
RowBox[{
RowBox[{"\"\<\\t\>\"", "\[Rule]", "4"}], ",",
RowBox[{"\"\<\\n\>\"", "\[RuleDelayed]", "0"}], ",",
RowBox[{"ss_", "\[RuleDelayed]",
RowBox[{"StringLength", "[", "ss", "]"}]}]}], "}"}]}],
")"}]}], ",", "\n", "\t", "\t", "\t", "\t", "\t",
"\[Infinity]"}], "]"}], ",", "\n", "\t", "\t", "\t", "\t",
RowBox[{
RowBox[{"#1", "=!=", "0"}], "&"}]}], "]"}], ",", "\n", "\t", "\t",
"\t",
RowBox[{"{", "2", "}"}]}], "]"}], "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.539877331810547*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example6", "Subsubsection",
CellChangeTimes->{{3.539159154192383*^9, 3.5391591550751953`*^9},
3.540401566654604*^9}],
Cell[BoxData[
RowBox[{"(*", "\[IndentingNewLine]",
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@",
RowBox[{"MakeBoxes", "[",
RowBox[{
RowBox[{"SetAttributes", "[",
RowBox[{"CleanUp", ",", "HoldAll"}], "]"}], ";", "\[IndentingNewLine]",
RowBox[{
RowBox[{"CleanUp", "[",
RowBox[{"expr_", ",", "cleanup_"}], "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"exprFn", ",", "result", ",",
RowBox[{"abort", "=", "False"}], ",",
RowBox[{"rethrow", "=", "True"}], ",", "seq"}], "}"}], ",",
RowBox[{
RowBox[{
RowBox[{"exprFn", "[", "]"}], ":=", "expr"}], ";",
RowBox[{"result", "=",
RowBox[{"CheckAbort", "[",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"result", "=",
RowBox[{"exprFn", "[", "]"}]}], ";",
RowBox[{"rethrow", "=", "False"}], ";", "result"}], "]"}],
",", "_", ",",
RowBox[{
RowBox[{"seq", "[", "##1", "]"}], "&"}]}], "]"}], ",",
RowBox[{"abort", "=", "True"}]}], "]"}]}], ";", "cleanup", ";",
RowBox[{"If", "[",
RowBox[{"abort", ",",
RowBox[{"Abort", "[", "]"}]}], "]"}], ";",
RowBox[{"If", "[",
RowBox[{"rethrow", ",",
RowBox[{"Throw", "[",
RowBox[{"result", "/.",
RowBox[{"seq", "\[Rule]", "Sequence"}]}], "]"}]}], "]"}], ";",
"result"}]}], "]"}]}]}], "]"}]}]}], "\[IndentingNewLine]",
"*)"}]], "Input",
CellChangeTimes->{{3.540396896060979*^9, 3.540396925984738*^9}}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes2", " ", "=", " ", "\[IndentingNewLine]",
RowBox[{"MakeBoxes", "[",
RowBox[{
RowBox[{"SetAttributes", "[",
RowBox[{"CleanUp", ",", "HoldAll"}], "]"}], ";",
RowBox[{
RowBox[{"CleanUp", "[",
RowBox[{"expr_", ",", "cleanup_"}], "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"exprFn", ",", "result", ",",
RowBox[{"abort", "=", "False"}], ",",
RowBox[{"rethrow", "=", "True"}], ",", "seq"}], "}"}], ",",
RowBox[{
RowBox[{
RowBox[{"exprFn", "[", "]"}], ":=", "expr"}], ";",
RowBox[{"result", "=",
RowBox[{"CheckAbort", "[",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"result", "=",
RowBox[{"exprFn", "[", "]"}]}], ";",
RowBox[{"rethrow", "=", "False"}], ";", "result"}], "]"}], ",",
"_", ",",
RowBox[{
RowBox[{"seq", "[", "##1", "]"}], "&"}]}], "]"}], ",",
RowBox[{"abort", "=", "True"}]}], "]"}]}], ";", "cleanup", ";",
RowBox[{"If", "[",
RowBox[{"abort", ",",
RowBox[{"Abort", "[", "]"}]}], "]"}], ";",
RowBox[{"If", "[",
RowBox[{"rethrow", ",",
RowBox[{"Throw", "[",
RowBox[{"result", "/.", "\[InvisibleSpace]",
RowBox[{"seq", "\[Rule]", "Sequence"}]}], "]"}]}], "]"}], ";",
"result"}]}], "]"}]}]}], "]"}]}]], "Input"],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"SetAttributes\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"CleanUp\"\>", ",", "\<\",\"\>",
",", "\<\"HoldAll\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"CleanUp\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"expr_\"\>", ",", "\<\",\"\>",
",", "\<\"cleanup_\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"exprFn\"\>", ",", "\<\",\"\>",
",", "\<\"result\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"abort\"\>", ",", "\<\"=\"\>",
",", "\<\"False\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"rethrow\"\>", ",", "\<\"=\"\>",
",", "\<\"True\"\>"}], "}"}], "]"}], ",", "\<\",\"\>",
",", "\<\"seq\"\>"}], "}"}], "]"}], ",", "\<\"}\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"exprFn\"\>", ",", "\<\"[\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>",
",", "\<\"expr\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"result\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"CheckAbort\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Catch\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Catch\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"result\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"exprFn\"\>", ",", "\<\"[\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"rethrow\"\>", ",", "\<\"=\"\>",
",", "\<\"False\"\>"}], "}"}], "]"}], ",", "\<\";\"\>",
",", "\<\"result\"\>"}], "}"}], "]"}], ",", "\<\"]\"\>"}],
"}"}], "]"}], ",", "\<\",\"\>", ",", "\<\"_\"\>",
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"seq\"\>", ",", "\<\"[\"\>",
",", "\<\"##1\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\"&\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"abort\"\>", ",", "\<\"=\"\>",
",", "\<\"True\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>", ",", "\<\"cleanup\"\>", ",", "\<\";\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"abort\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Abort\"\>", ",", "\<\"[\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"rethrow\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Throw\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"result\"\>", ",", "\<\"/.\"\>",
",", "\<\"\[InvisibleSpace]\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"seq\"\>", ",", "\<\"\[Rule]\"\>",
",", "\<\"Sequence\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>",
",", "\<\"result\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}]], "Output",
CellChangeTimes->{3.5379949530352187`*^9, 3.5387495280566406`*^9,
3.539159165388672*^9, 3.539198592041664*^9, 3.5398773494902344`*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes2"}]}]], "Input",
CellChangeTimes->{{3.5379949606338515`*^9, 3.537994960757875*^9}, {
3.539877354588867*^9, 3.539877360645508*^9}, 3.540387641769716*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"SetAttributes", "[",
RowBox[{"CleanUp", ",", "HoldAll"}], "]"}], ";"}], "\n",
RowBox[{
RowBox[{"CleanUp", "[",
RowBox[{"expr_", ",", "cleanup_"}], "]"}], ":=", "\n", "\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"exprFn", ",", "result", ",",
RowBox[{"abort", "=", "False"}], ",",
RowBox[{"rethrow", "=", "True"}], ",", "seq"}], "}"}], ",", "\t",
"\t", "\n", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"exprFn", "[", "]"}], ":=", "\n", "\t", "\t", "\t", "expr"}],
";", "\n", "\t", "\t",
RowBox[{"result", "=", "\n", "\t", "\t", "\t",
RowBox[{
"CheckAbort", "[", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t",
RowBox[{
RowBox[{
"Catch", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"result", "=",
RowBox[{"exprFn", "[", "]"}]}], ";",
RowBox[{"rethrow", "=", "False"}], ";", "result"}], "]"}], ",",
"\n", "\t", "\t", "\t", "\t", "\t", "_", ",", "\n", "\t", "\t",
"\t", "\t", "\t",
RowBox[{
RowBox[{"seq", "[", "##1", "]"}], "&"}]}], "\n", "\t", "\t",
"\t", "\t", "]"}], ",", "\n", "\t", "\t", "\t", "\t",
RowBox[{"abort", "=", "True"}]}], "\n", "\t", "\t", "\t", "]"}]}],
";", "\n", "\t", "\t", "cleanup", ";", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{"abort", ",",
RowBox[{"Abort", "[", "]"}]}], "]"}], ";", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{"rethrow", ",",
RowBox[{"Throw", "[",
RowBox[{"result", "/.", "\[InvisibleSpace]",
RowBox[{"seq", "\[Rule]", "Sequence"}]}], "]"}]}], "]"}], ";",
"\n", "\t", "\t", "result"}]}], "\n", "\t", "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398773704003906`*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes2"}]}]], "Input",
CellChangeTimes->{{3.5398773825722656`*^9, 3.539877383732422*^9},
3.540387641811932*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{
RowBox[{"SetAttributes", "[",
RowBox[{"CleanUp", ",", "HoldAll"}], "]"}], ";"}], "\n",
RowBox[{
RowBox[{"CleanUp", "[",
RowBox[{"expr_", ",", "cleanup_"}], "]"}], ":=", "\n", "\t",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"exprFn", ",", "result", ",",
RowBox[{"abort", "=", "False"}], ",",
RowBox[{"rethrow", "=", "True"}], ",", "seq"}], "}"}], ",", "\t",
"\t", "\n", "\t", "\t",
RowBox[{
RowBox[{
RowBox[{"exprFn", "[", "]"}], ":=", "\n", "\t", "\t", "\t", "expr"}],
";", "\n", "\t", "\t",
RowBox[{"result", "=", "\n", "\t", "\t", "\t",
RowBox[{
"CheckAbort", "[", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t",
RowBox[{
RowBox[{
"Catch", "[", "\t", "\t", "\t", "\t", "\t", "\n", "\t", "\t", "\t",
"\t", "\t",
RowBox[{
RowBox[{"Catch", "[",
RowBox[{
RowBox[{"result", "=",
RowBox[{"exprFn", "[", "]"}]}], ";",
RowBox[{"rethrow", "=", "False"}], ";", "result"}], "]"}], ",",
"\n", "\t", "\t", "\t", "\t", "\t", "_", ",", "\n", "\t", "\t",
"\t", "\t", "\t",
RowBox[{
RowBox[{"seq", "[", "##1", "]"}], "&"}]}], "]"}], ",", "\n",
"\t", "\t", "\t", "\t",
RowBox[{"abort", "=", "True"}]}], "]"}]}], ";", "\n", "\t", "\t",
"cleanup", ";", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{"abort", ",",
RowBox[{"Abort", "[", "]"}]}], "]"}], ";", "\n", "\t", "\t",
RowBox[{"If", "[",
RowBox[{"rethrow", ",",
RowBox[{"Throw", "[",
RowBox[{"result", "/.", "\[InvisibleSpace]",
RowBox[{"seq", "\[Rule]", "Sequence"}]}], "]"}]}], "]"}], ";",
"\n", "\t", "\t", "result"}]}], "]"}]}]}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398773844414062`*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example7", "Subsubsection",
CellChangeTimes->{{3.539159194254883*^9, 3.5391591951679688`*^9},
3.540401567380342*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"testBoxes", " ", "=", " ",
RowBox[{"MakeBoxes", "@", "\[IndentingNewLine]",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"a", ",", "b"}], "}"}], ",",
RowBox[{
RowBox[{"a", "=", "1"}], ";",
RowBox[{"Block", "[",
RowBox[{
RowBox[{"{",
RowBox[{"c", ",", "d"}], "}"}], ",",
RowBox[{
RowBox[{"c", "=",
RowBox[{"a", "+", "1"}]}], ";",
RowBox[{"d", "=",
RowBox[{"b", "+", "2"}]}]}]}], "]"}], ";", "b"}]}],
"]"}]}]}]], "Input",
CellChangeTimes->{{3.5398774636591797`*^9, 3.539877468645508*^9}}],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"a\"\>", ",", "\<\",\"\>", ",", "\<\"b\"\>"}], "}"}],
"]"}], ",", "\<\"}\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"a\"\>", ",", "\<\"=\"\>", ",", "\<\"1\"\>"}], "}"}],
"]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Block\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"c\"\>", ",", "\<\",\"\>", ",", "\<\"d\"\>"}],
"}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"c\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"a\"\>", ",", "\<\"+\"\>", ",", "\<\"1\"\>"}],
"}"}], "]"}]}], "}"}], "]"}], ",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"d\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"b\"\>", ",", "\<\"+\"\>", ",", "\<\"2\"\>"}],
"}"}], "]"}]}], "}"}], "]"}]}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\";\"\>",
",", "\<\"b\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]], "Output",
CellChangeTimes->{3.537995051552797*^9, 3.538749543763672*^9,
3.539159201376953*^9, 3.53987740371875*^9, 3.539877469296875*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "testBoxes"}]}]], "Input",
CellChangeTimes->{
3.537995063959047*^9, {3.5398774149160156`*^9, 3.539877416786133*^9},
3.540387641866953*^9}],
Cell[BoxData[
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"a", ",", "b"}], "}"}], ",", "\t", "\n", "\t",
RowBox[{
RowBox[{"a", "=", "1"}], ";", "\t", "\n", "\t",
RowBox[{"Block", "[",
RowBox[{
RowBox[{"{",
RowBox[{"c", ",", "d"}], "}"}], ",", "\n", "\t", "\t",
RowBox[{
RowBox[{"c", "=",
RowBox[{"a", "+", "1"}]}], ";",
RowBox[{"d", "=",
RowBox[{"b", "+", "2"}]}]}]}], "\n", "\t", "]"}], ";", "\n", "\t",
"b"}]}], "\n", "]"}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398774711435547`*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "testBoxes"}]}]], "Input",
CellChangeTimes->{{3.539877427086914*^9, 3.5398774284140625`*^9},
3.54038764191775*^9}],
Cell[BoxData[
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"a", ",", "b"}], "}"}], ",", "\t", "\n", "\t",
RowBox[{
RowBox[{"a", "=", "1"}], ";", "\t", "\n", "\t",
RowBox[{"Block", "[",
RowBox[{
RowBox[{"{",
RowBox[{"c", ",", "d"}], "}"}], ",", "\n", "\t", "\t",
RowBox[{
RowBox[{"c", "=",
RowBox[{"a", "+", "1"}]}], ";",
RowBox[{"d", "=",
RowBox[{"b", "+", "2"}]}]}]}], "]"}], ";", "\n", "\t", "b"}]}],
"]"}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398774290585938`*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example8", "Subsubsection",
CellChangeTimes->{{3.5391592149648438`*^9, 3.5391592159570312`*^9},
3.540401577008524*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes7", " ", "=", " ",
RowBox[{"MakeBoxes", "[",
RowBox[{
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"ln", "=",
RowBox[{"Length", "@", "#"}]}], ",", "x"}], "}"}], ",",
RowBox[{
RowBox[{"x", "=",
RowBox[{
RowBox[{"#", "[",
RowBox[{"[", " ",
RowBox[{";;",
RowBox[{"Ceiling", "[",
RowBox[{"ln", "/", "2`"}], "]"}]}], "]"}], "]"}], "+",
RowBox[{"#", "[",
RowBox[{"[",
RowBox[{
RowBox[{"-", "1"}], ";;",
RowBox[{
RowBox[{"Floor", "[",
RowBox[{"ln", "/", "2`"}], "]"}], "+", "1"}], ";;",
RowBox[{"-", "1"}]}], "]"}], "]"}]}]}], ";",
"\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"OddQ", "@", "ln"}], ",",
RowBox[{
RowBox[{"x", "[",
RowBox[{"[",
RowBox[{"-", "1"}], "]"}], "]"}], "/=", "2"}]}], "]"}], ";",
"\[IndentingNewLine]", "x"}]}], "]"}], "&"}], "]"}]}]], "Input"],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"ln\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"#1\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\",\"\>", ",", "\<\"x\"\>"}], "}"}],
"]"}], ",", "\<\"}\"\>"}], "}"}], "]"}], ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"x\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\"\[LeftDoubleBracket]\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"1\"\>", ",", "\<\";;\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Ceiling\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"FractionBox", "[",
RowBox[{"\<\"ln\"\>", ",", "\<\"2.`\"\>"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"+\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"#1\"\>", ",", "\<\"\[LeftDoubleBracket]\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"-\"\>", ",", "\<\"1\"\>"}], "}"}], "]"}],
",", "\<\";;\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Floor\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"FractionBox", "[",
RowBox[{"\<\"ln\"\>", ",", "\<\"2.`\"\>"}], "]"}],
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\"+\"\>",
",", "\<\"1\"\>"}], "}"}], "]"}], ",", "\<\";;\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"-\"\>", ",", "\<\"1\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"\[RightDoubleBracket]\"\>"}],
"}"}], "]"}]}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\";\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"OddQ\"\>", ",", "\<\"[\"\>",
",", "\<\"ln\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"x\"\>", ",", "\<\"\[LeftDoubleBracket]\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"-\"\>", ",", "\<\"1\"\>"}], "}"}], "]"}],
",", "\<\"\[RightDoubleBracket]\"\>"}], "}"}], "]"}],
",", "\<\"/=\"\>", ",", "\<\"2\"\>"}], "}"}], "]"}]}],
"}"}], "]"}], ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\";\"\>", ",", "\<\"x\"\>"}], "}"}], "]"}]}], "}"}],
"]"}], ",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\"&\"\>"}], "}"}],
"]"}]], "Output",
CellChangeTimes->{3.5379951049199843`*^9, 3.5387495529335938`*^9,
3.539159221930664*^9, 3.5398774887890625`*^9}]
}, Open ]],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormat", "@", "boxes7"}]}]], "Input",
CellChangeTimes->{
3.5379951187871723`*^9, {3.539877493857422*^9, 3.539877495448242*^9},
3.540387641963473*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"ln", "=",
RowBox[{"Length", "[", "#1", "]"}]}], ",", "x"}], "}"}], ",", "\t",
"\n", "\t",
RowBox[{
RowBox[{"x", "=",
RowBox[{
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{"1", ";;",
RowBox[{"Ceiling", "[",
FractionBox["ln", "2.`"], "]"}]}], "\[RightDoubleBracket]"}], "+",
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{
RowBox[{"-", "1"}], ";;",
RowBox[{
RowBox[{"Floor", "[",
FractionBox["ln", "2.`"], "]"}], "+", "1"}], ";;",
RowBox[{"-", "1"}]}], "\[RightDoubleBracket]"}]}]}], ";", "\n",
"\t",
RowBox[{"If", "[",
RowBox[{
RowBox[{"OddQ", "[", "ln", "]"}], ",",
RowBox[{
RowBox[{"x", "\[LeftDoubleBracket]",
RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], "/=", "2"}]}], "]"}],
";", "\n", "\t", "x"}]}], "\n", "]"}], "&"}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.539877497241211*^9}],
Cell[BoxData[
RowBox[{"prn", "@",
RowBox[{"FullCodeFormatCompact", "@", "boxes7"}]}]], "Input",
CellChangeTimes->{{3.5398775082802734`*^9, 3.53987750934375*^9},
3.540387642008209*^9}],
Cell[BoxData[
RowBox[{"\n",
RowBox[{
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{
RowBox[{"ln", "=",
RowBox[{"Length", "[", "#1", "]"}]}], ",", "x"}], "}"}], ",", "\t",
"\n", "\t",
RowBox[{
RowBox[{"x", "=",
RowBox[{
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{"1", ";;",
RowBox[{"Ceiling", "[",
FractionBox["ln", "2.`"], "]"}]}], "\[RightDoubleBracket]"}], "+",
RowBox[{"#1", "\[LeftDoubleBracket]",
RowBox[{
RowBox[{"-", "1"}], ";;",
RowBox[{
RowBox[{"Floor", "[",
FractionBox["ln", "2.`"], "]"}], "+", "1"}], ";;",
RowBox[{"-", "1"}]}], "\[RightDoubleBracket]"}]}]}], ";", "\n",
"\t",
RowBox[{"If", "[",
RowBox[{
RowBox[{"OddQ", "[", "ln", "]"}], ",",
RowBox[{
RowBox[{"x", "\[LeftDoubleBracket]",
RowBox[{"-", "1"}], "\[RightDoubleBracket]"}], "/=", "2"}]}], "]"}],
";", "\n", "\t", "x"}]}], "]"}], "&"}]}]], "Input",
GeneratedCell->True,
CellAutoOverwrite->True,
CellChangeTimes->{3.5398775100722656`*^9}]
}, Closed]],
Cell[CellGroupData[{
Cell["Example9", "Subsubsection",
CellChangeTimes->{{3.5391592768847656`*^9, 3.5391592778564453`*^9},
3.540401577696081*^9}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"boxes8", " ", "=", " ", "\[IndentingNewLine]",
RowBox[{"MakeBoxes", "[",
RowBox[{
RowBox[{"symSum", "[", "li_List", "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"k2", "=",
RowBox[{"Ceiling", "[",
RowBox[{
RowBox[{"Length", "[", "li", "]"}], "/", "2"}], "]"}]}], "}"}], ",",
RowBox[{"Total", "[",
RowBox[{"MapAt", "[",
RowBox[{"Reverse", ",",
RowBox[{
RowBox[{
RowBox[{"If", "[",
RowBox[{
RowBox[{"Apply", "[",
RowBox[{"Equal", ",",
RowBox[{"Length", "/@", "#"}]}], "]"}], ",", "#", ",",
RowBox[{"MapAt", "[",
RowBox[{
RowBox[{"Function", "[",
RowBox[{"l", ",",
RowBox[{"PadLeft", "[",
RowBox[{"l", ",", "k2"}], "]"}]}], "]"}], ",", "#", ",",
RowBox[{"{", "2", "}"}]}], "]"}]}], "]"}], "&"}], "[",
RowBox[{"Partition", "[",
RowBox[{"li", ",", "k2", ",", "k2", ",",
RowBox[{"{",
RowBox[{"1", ",", "1"}], "}"}], ",",
RowBox[{"{", "}"}]}], "]"}], "]"}], ",",
RowBox[{"{", "2", "}"}]}], "]"}], "]"}]}], "]"}]}], "]"}]}]], "Input"],
Cell[BoxData[
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"symSum\"\>", ",", "\<\"[\"\>", ",", "\<\"li_List\"\>",
",", "\<\"]\"\>"}], "}"}], "]"}], ",", "\<\":=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Module\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"{\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"k2\"\>", ",", "\<\"=\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Ceiling\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"FractionBox", "[",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"[\"\>",
",", "\<\"li\"\>", ",", "\<\"]\"\>"}], "}"}], "]"}],
",", "\<\"2\"\>"}], "]"}], ",", "\<\"]\"\>"}], "}"}],
"]"}]}], "}"}], "]"}], ",", "\<\"}\"\>"}], "}"}], "]"}],
",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Total\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"MapAt\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Reverse\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"(\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"If\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Equal\"\>", ",", "\<\"@@\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Length\"\>", ",", "\<\"/@\"\>",
",", "\<\"#1\"\>"}], "}"}], "]"}]}], "}"}], "]"}],
",", "\<\",\"\>", ",", "\<\"#1\"\>", ",", "\<\",\"\>",
",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"MapAt\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"Function\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"l\"\>", ",", "\<\",\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"PadLeft\"\>", ",", "\<\"[\"\>", ",",
RowBox[{"RowBox", "[",
RowBox[{"{",
RowBox[{"\<\"l\"\>", ",", "\<\",\"\>",
",", "\<\"k2\"\>"}], "