(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 13.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 302599, 7288] NotebookOptionsPosition[ 142963, 4236] NotebookOutlinePosition[ 285474, 6926] CellTagsIndexPosition[ 283665, 6876] WindowTitle->SelectPermutations | Definition Notebook WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["SelectPermutations", "Title", CellTags->{"Name", "TemplateCell", "Title"}, CellID->480373133], Cell["Get permutations that satisfy a certain criterion", "Text", CellTags->{"Description", "TemplateCell"}, CellID->587508207], Cell[CellGroupData[{ Cell[TextData[{ "Definition", Cell[BoxData[ PaneSelectorBox[{True-> TemplateBox[{"Function", Cell[ BoxData[ FrameBox[ Cell[ "Define your function using the name you gave in the Title line \ above. You can add input cells and extra code to define additional input \ cases or prerequisites. All definitions, including dependencies, will be \ included in the generated resource function.\n\nThis section should be \ evaluated before creating the Examples section below.", "MoreInfoText"], Background -> GrayLevel[0.95], FrameMargins -> 20, FrameStyle -> GrayLevel[0.9], RoundingRadius -> 5, ImageSize -> { Scaled[0.65], Automatic}]], "MoreInfoText", Deletable -> True, CellTags -> {"SectionMoreInfoFunction"}, CellMargins -> {{66, 66}, {15, 15}}]}, "MoreInfoOpenerButtonTemplate"]}, Dynamic[ CurrentValue[ EvaluationNotebook[], {TaggingRules, "ResourceCreateNotebook"}]], ImageSize->Automatic]]] }], "Section", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Function"}, DefaultNewCellStyle->"Input", CellTags->{"Definition", "Function", "TemplateCellGroup"}, CellID->72845326], Cell[BoxData[{ RowBox[{"ClearAll", "[", RowBox[{"iSelectPermutations", ",", "SelectPermutations"}], "]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"iSelectPermutations", "[", RowBox[{"list_", ",", "nlist_List", ",", "crit_", ",", RowBox[{"m_", ":", "\[Infinity]"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"vars", ",", "its", ",", RowBox[{"len", "=", RowBox[{"Length", "[", "list", "]"}]}], ",", "begin", ",", "end", ",", "val", ",", RowBox[{"found", "=", "0"}], ",", "result", ",", RowBox[{"broken", "=", "False"}], ",", "rules", ",", "minindex"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"result", "=", RowBox[{"Reap", "[", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"!", "broken"}], ",", "\[IndentingNewLine]", RowBox[{"Which", "[", RowBox[{ RowBox[{"numvar", ">", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"vars", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"Unique", "[", "\"\\"", "]"}], ",", "numvar"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"begin", "=", RowBox[{"ConstantArray", "[", RowBox[{"1", ",", RowBox[{"Length", "[", "vars", "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"end", "=", RowBox[{"ConstantArray", "[", RowBox[{"len", ",", RowBox[{"Length", "[", "vars", "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"its", "=", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"vars", ",", "begin", ",", "end"}], "}"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"minindex", "=", RowBox[{"GatherBy", "[", RowBox[{ RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{ RowBox[{"List", "@@", "list"}], ",", RowBox[{"Range", "[", RowBox[{"Length", "[", "list", "]"}], "]"}]}], "}"}], "]"}], ",", "First"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"minindex", "=", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"#", "[", RowBox[{"[", RowBox[{"1", ",", "1"}], "]"}], "]"}], ",", RowBox[{"#", "[", RowBox[{"[", RowBox[{"All", ",", "2"}], "]"}], "]"}]}], "}"}], "&"}], "/@", "minindex"}]}], ";", "\[IndentingNewLine]", RowBox[{"minindex", "=", RowBox[{"Association", "[", RowBox[{"Rule", "@@@", "minindex"}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"DuplicateFreeQ", "[", "list", "]"}], ",", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{ "optimize", " ", "for", " ", "lists", " ", "that", " ", "are", " ", "duplicate"}], "-", "free"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"Unequal", "@@", "vars"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"val", "=", RowBox[{"Part", "[", RowBox[{"list", ",", "vars"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"TrueQ", "[", RowBox[{"crit", "[", "val", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"found", "++"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"found", ">", "m"}], ",", RowBox[{ RowBox[{"broken", "=", "True"}], ";", RowBox[{"Break", "[", "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Sow", "[", "val", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"Evaluate", "[", RowBox[{"Sequence", "@@", "its"}], "]"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"Do", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"Unequal", "@@", "vars"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"val", "=", RowBox[{"Part", "[", RowBox[{"list", ",", "vars"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"rules", "=", RowBox[{"Transpose", "[", RowBox[{"{", RowBox[{"vars", ",", RowBox[{"List", "@@", "val"}]}], "}"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"rules", "=", RowBox[{"GatherBy", "[", RowBox[{"rules", ",", "Last"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"rules", "=", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"#", "[", RowBox[{"[", RowBox[{"1", ",", "2"}], "]"}], "]"}], ",", RowBox[{"#", "[", RowBox[{"[", RowBox[{"All", ",", "1"}], "]"}], "]"}]}], "}"}], "&"}], "/@", "rules"}]}], ";", "\[IndentingNewLine]", RowBox[{"rules", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Take", "[", RowBox[{ RowBox[{"minindex", "[", "#1", "]"}], ",", RowBox[{"UpTo", "[", RowBox[{"Length", "[", "#2", "]"}], "]"}]}], "]"}], "===", "#2"}], ")"}], "&"}], "@@@", "rules"}]}], ";", "\[IndentingNewLine]", RowBox[{"rules", "=", RowBox[{"And", "@@", "rules"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"rules", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"TrueQ", "[", RowBox[{"crit", "[", "val", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"found", "++"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"found", ">", "m"}], ",", RowBox[{ RowBox[{"broken", "=", "True"}], ";", RowBox[{"Break", "[", "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Sow", "[", "val", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"Evaluate", "[", RowBox[{"Sequence", "@@", "its"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"numvar", "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"val", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"TrueQ", "[", RowBox[{"crit", "[", "val", "]"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"found", "++"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"found", ">", "m"}], ",", RowBox[{ RowBox[{"broken", "=", "True"}], ";", RowBox[{"Break", "[", "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Sow", "[", "val", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"numvar", ",", "nlist"}], "}"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"First", "[", RowBox[{ RowBox[{"result", "[", RowBox[{"[", "2", "]"}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"list", ":", RowBox[{"_", "[", "___", "]"}]}], ",", "crit_"}], "]"}], ":=", RowBox[{"iSelectPermutations", "[", RowBox[{"list", ",", RowBox[{"{", RowBox[{"Length", "[", "list", "]"}], "}"}], ",", "crit"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"list", ":", RowBox[{"_", "[", "___", "]"}]}], ",", RowBox[{"n_Integer", "?", "NonNegative"}], ",", "crit_", ",", RowBox[{"m_", ":", "\[Infinity]"}]}], "]"}], ":=", RowBox[{"iSelectPermutations", "[", RowBox[{"list", ",", RowBox[{"Range", "[", "n", "]"}], ",", "crit", ",", "m"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"list", ":", RowBox[{"_", "[", "___", "]"}]}], ",", RowBox[{"{", RowBox[{"n_Integer", "?", "NonNegative"}], "}"}], ",", "crit_", ",", RowBox[{"m_", ":", "\[Infinity]"}]}], "]"}], ":=", RowBox[{"iSelectPermutations", "[", RowBox[{"list", ",", RowBox[{"{", "n", "}"}], ",", "crit", ",", "m"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"list", ":", RowBox[{"_", "[", "___", "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"nmin_Integer", "?", "NonNegative"}], ",", RowBox[{"nmax_Integer", "?", "NonNegative"}]}], "}"}], ",", "crit_", ",", RowBox[{"m_", ":", "\[Infinity]"}]}], "]"}], ":=", RowBox[{"iSelectPermutations", "[", RowBox[{"list", ",", RowBox[{"Range", "[", RowBox[{"nmin", ",", "nmax"}], "]"}], ",", "crit", ",", "m"}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"list", ":", RowBox[{"_", "[", "___", "]"}]}], ",", RowBox[{"{", RowBox[{ RowBox[{"nmin_Integer", "?", "NonNegative"}], ",", RowBox[{"nmax_Integer", "?", "NonNegative"}], ",", "dstep_Integer"}], "}"}], ",", "crit_", ",", RowBox[{"m_", ":", "\[Infinity]"}]}], "]"}], ":=", RowBox[{"iSelectPermutations", "[", RowBox[{"list", ",", RowBox[{"Range", "[", RowBox[{"nmin", ",", "nmax", ",", "dstep"}], "]"}], ",", "crit", ",", "m"}], "]"}]}]}], "Input", CellChangeTimes->CompressedData[" 1:eJwd0VtIUwEAxvGpaw8Lhw1dZDNdFloqjDlQDKXhZKCFu5nBjNGx0dRQYw4p FbuIxAwvEOuYPjQKklIxxOXCIhxZCrOlsWwT53zwfjmSLnQqne88fPxevre/ iKhSG8JZLFYKPSg2VdmUonXZV0fGR5jhr/kBVRz7L6h0HgRgtdG8AIPa24tw wSvYgOSIdBv6/GHHVPjtbwrgn4rx07BncOYc5HUnn4fBxi+X4dP7ZxSQfJ5Y AK0h2RX42TOrh8VzOaXQp1wzwhk7xRiXPXoHclzTJji20lYHY6/ONsMpd0QL bD3b0AElEyESTq++sUF3l6wHZk52Mv7z9h3B/fRPjOUWZ4SaNt8aw4btJRN8 GD58KhpeDBBCqBI/Ziy/lH0BHpC/U+EJoTQd3koRSaFcwsmCrmV/LkywOhRQ 93MrH+pPmosgGXirg/wCAwG5qX8Z05SeV5B43d4HvcKR93B0XuyCkfYjN8zR zflgi75pFRbd6GUUNqRR0H7NsgP79XKuhvZD7t5xGHzBLW2kfTlkZLzeyamA S1NUJWTv5plgKKG3BlYOhu7BJzzJQ1hG8J7B/sOxLkgNtNngcJRlANYXG1UP 0JufpIbaccqQlEh3qW0tg1r3zUO4ufyOUTD5XZNM+8gRXQK/xRfehQqP0wT/ A9tXP30= "], CellLabel->"In[6]:=", CellID->747980014] }, Open ]], Cell[CellGroupData[{ Cell["Documentation", "Section", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Documentation"}, CellTags->{"Documentation", "TemplateSection"}, CellID->429741307], Cell[CellGroupData[{ Cell[TextData[{ "Usage", Cell[BoxData[ PaneSelectorBox[{True-> TemplateBox[{"Usage", Cell[ BoxData[ FrameBox[ Cell[ TextData[{ "Document input usage cases by first typing an input structure, \ then pressing ", Cell[ BoxData[ StyleBox[ DynamicBox[ ToBoxes[ If[$OperatingSystem === "MacOSX", "\[ReturnKey]", "\[EnterKey]"], StandardForm], SingleEvaluation -> True, Evaluator -> "System"], ShowStringCharacters -> False]]], " to add a brief explanation of the function\[CloseCurlyQuote]s \ behavior for that structure. Pressing ", Cell[ BoxData[ StyleBox[ DynamicBox[ ToBoxes[ If[$OperatingSystem === "MacOSX", "\[ReturnKey]", "\[EnterKey]"], StandardForm], SingleEvaluation -> True, Evaluator -> "System"], ShowStringCharacters -> False]]], " repeatedly will create new cases as needed. Every input usage \ case defined above should be demonstrated explicitly here.\n\nSee existing \ documentation pages for examples."}], "MoreInfoText"], Background -> GrayLevel[0.95], FrameMargins -> 20, FrameStyle -> GrayLevel[0.9], RoundingRadius -> 5, ImageSize -> { Scaled[0.65], Automatic}]], "MoreInfoText", Deletable -> True, CellTags -> {"SectionMoreInfoUsage"}, CellMargins -> {{66, 66}, {15, 15}}]}, "MoreInfoOpenerButtonTemplate"]}, Dynamic[ CurrentValue[ EvaluationNotebook[], {TaggingRules, "ResourceCreateNotebook"}]], ImageSize->Automatic]]] }], "Subsection", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Usage"}, DefaultNewCellStyle->{"UsageInputs", FontFamily -> "Source Sans Pro"}, CellTags->{"TemplateCellGroup", "Usage"}, CellID->542419310], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", StyleBox["crit", "TI"]}], "]"}]], "UsageInputs", FontFamily->"Source Sans Pro", CellID->437220591], Cell[TextData[{ "generates a list of all possible permutations of the elements in ", Cell[BoxData[ StyleBox["list", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " satisfying ", Cell[BoxData[ StyleBox["crit", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], "." }], "UsageDescription", CellID->365605240] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", StyleBox["n", "TI"], ",", StyleBox["crit", "TI"]}], "]"}]], "UsageInputs", FontFamily->"Source Sans Pro", CellID->589654059], Cell[TextData[{ "gives all permutations containing at most ", Cell[BoxData[ StyleBox["n", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " elements satisfying ", Cell[BoxData[ StyleBox["crit", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], "." }], "UsageDescription", CellID->80019109] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", RowBox[{"{", StyleBox["n", "TI"], "}"}], ",", StyleBox["crit", "TI"]}], "]"}]], "UsageInputs", FontFamily->"Source Sans Pro", CellID->337664785], Cell[TextData[{ "gives all permutations containing exactly ", Cell[BoxData[ StyleBox["n", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " elements satisfying ", Cell[BoxData[ StyleBox["crit", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], "." }], "UsageDescription", CellID->612556996] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{"\[Ellipsis]", ",", StyleBox["crit", "TI"], ",", StyleBox["m", "TI"]}], "]"}]], "UsageInputs", FontFamily->"Source Sans Pro", CellID->48665361], Cell[TextData[{ "gives at most ", Cell[BoxData[ StyleBox["m", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " results." }], "UsageDescription", CellID->499080552] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Details & Options", Cell[BoxData[ PaneSelectorBox[{True-> TemplateBox[{"Notes", Cell[ BoxData[ FrameBox[ Cell[ "Give a detailed explanation of how the function is used and \ configured (e.g. acceptable input types, result formats, options \ specifications, background information). This section may include multiple \ cells, bullet lists, tables, hyperlinks and additional styles/structures as \ needed.\n\nAdd any other information that may be relevant, such as when the \ function was first discovered or how and why it is used within a given field. \ Include all relevant background or contextual information related to the \ function, its development, and its usage.", "MoreInfoText"], Background -> GrayLevel[0.95], FrameMargins -> 20, FrameStyle -> GrayLevel[0.9], RoundingRadius -> 5, ImageSize -> { Scaled[0.65], Automatic}]], "MoreInfoText", Deletable -> True, CellTags -> {"SectionMoreInfoNotes"}, CellMargins -> {{66, 66}, {15, 15}}]}, "MoreInfoOpenerButtonTemplate"]}, Dynamic[ CurrentValue[ EvaluationNotebook[], {TaggingRules, "ResourceCreateNotebook"}]], ImageSize->Automatic]]] }], "Subsection", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Notes"}, DefaultNewCellStyle->"Notes", CellTags->{"Details & Options", "Notes", "TemplateCellGroup"}, CellID->908801236], Cell[TextData[{ "There are ", Cell[BoxData[ RowBox[{ StyleBox["n", "TI"], "!"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " permutations of a list of ", Cell[BoxData[ StyleBox["n", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " distinct elements." }], "Notes", CellTags->"TabNext", CellID->895736812], Cell["Repeated elements are treated as identical.", "Notes", CellID->109739069], Cell[TextData[{ "The object ", Cell[BoxData[ StyleBox["list", "TI"]], "InlineFormula", FontFamily->"Source Sans Pro"], " need not have head ", Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["List", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.8549, 0.39608, 0.1451]}, {"Link"}]], ButtonData->"paclet:ref/List", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], "." }], "Notes", CellID->563477289], Cell[TextData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " is effectively equivalent to ", Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", RowBox[{"{", RowBox[{ TagBox[ ButtonBox[ StyleBox["Length", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Length", ContentPadding->False], MouseAppearanceTag["LinkHand"]], "[", StyleBox["list", "TI"], "]"}], "}"}], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], "." }], "Notes", CellID->28431049], Cell[TextData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", RowBox[{"{", RowBox[{ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]], ",", SubscriptBox[ StyleBox["n", "TI"], StyleBox["max", "TI"]]}], "}"}], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " gives permutations of between ", Cell[BoxData[ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " and ", Cell[BoxData[ SubscriptBox[ StyleBox["n", "TI"], StyleBox["max", "TI"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " elements." }], "Notes", CellID->470464428], Cell[TextData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", RowBox[{"{", RowBox[{ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]], ",", SubscriptBox[ StyleBox["n", "TI"], StyleBox["max", "TI"]], ",", StyleBox["dn", "TI"]}], "}"}], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " gives permutations ", Cell[BoxData[ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]]], "InlineFormula", FontFamily->"Source Sans Pro"], ", ", Cell[BoxData[ RowBox[{ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]], "+", StyleBox["dn", "TI"]}]], "InlineFormula", FontFamily->"Source Sans Pro"], ", ", Cell[BoxData[ RowBox[{ SubscriptBox[ StyleBox["n", "TI"], StyleBox["min", "TI"]], "+", RowBox[{"2", StyleBox["dn", "TI"]}]}]], "InlineFormula", FontFamily->"Source Sans Pro"], " \[Ellipsis] and ", Cell[BoxData[ SubscriptBox[ StyleBox["n", "TI"], StyleBox["max", "TI"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " elements." }], "Notes", CellID->420286189] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Examples", Cell[BoxData[ PaneSelectorBox[{True-> TemplateBox[{"Examples", Cell[ BoxData[ FrameBox[ Cell[ TextData[{ "Demonstrate the function\[CloseCurlyQuote]s usage, starting with \ the most basic use case and describing each example in a preceding text cell.\ \n\nWithin a group, individual examples can be delimited by inserting page \ breaks between them (either using ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"[Right-click]\"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontColor -> GrayLevel[0.286275], FontSize -> 14, StripOnInput -> False], StyleBox[ "\" \[FilledRightTriangle] \"", FontFamily -> "Source Sans Pro", FontSize -> 13.86, FontColor -> GrayLevel[0.5], StripOnInput -> False], StyleBox[ "\"Insert Page Break\"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontColor -> GrayLevel[0.286275], FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], " between cells or through the menu using ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"Insert\"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontColor -> GrayLevel[0.286275], FontSize -> 14, StripOnInput -> False], StyleBox[ "\" \[FilledRightTriangle] \"", FontFamily -> "Source Sans Pro", FontSize -> 13.86, FontColor -> GrayLevel[0.5], StripOnInput -> False], StyleBox[ "\"Page Break\"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontColor -> GrayLevel[0.286275], FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], ").\n\nExamples should be grouped into Subsection and \ Subsubsection cells similarly to existing documentation pages. Here are some \ typical Subsection names and the types of examples they normally contain:\n \ ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Basic Examples: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "most basic function usage\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Scope: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "input and display conventions, standard computational attributes \ (e.g. threading over lists)\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Options: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "available options and parameters for the function\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Applications: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "standard industry or academic applications\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Properties and Relations: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "how the function relates to other functions\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Possible Issues: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "limitations or unexpected behavior a user might experience\n ", Cell[ BoxData[ StyleBox[ TemplateBox[{ StyleBox[ "\"\[FilledSmallSquare] \"", FontColor -> RGBColor[0.8, 0.043, 0.008], StripOnInput -> False], StyleBox[ "\"Neat Examples: \"", FontFamily -> "Source Sans Pro", FontWeight -> "SemiBold", FontSize -> 14, StripOnInput -> False]}, "RowDefault"], ShowStringCharacters -> False]]], "particularly interesting, unconventional, or otherwise unique \ usage"}], "MoreInfoText"], Background -> GrayLevel[0.95], FrameMargins -> 20, FrameStyle -> GrayLevel[0.9], RoundingRadius -> 5, ImageSize -> { Scaled[0.65], Automatic}]], "MoreInfoText", Deletable -> True, CellTags -> {"SectionMoreInfoExamples"}, CellMargins -> {{66, 66}, {15, 15}}]}, "MoreInfoOpenerButtonTemplate"]}, Dynamic[ CurrentValue[ EvaluationNotebook[], {TaggingRules, "ResourceCreateNotebook"}]], ImageSize->Automatic]]] }], "Section", Editable->False, Deletable->False, TaggingRules->{"TemplateGroupName" -> "Examples"}, CellTags->{"Examples", "TemplateCellGroup"}, CellID->530638011], Cell[CellGroupData[{ Cell["Basic Examples", "Subsection", TaggingRules->{}, CellID->904125756], Cell["\<\ Select from the list {5,6,7,8,9} those permutations that form a prime when \ concatenating the digits: \ \>", "Text", TaggingRules->{}, CellChangeTimes->{{3.775568205955653*^9, 3.775568227320828*^9}, { 3.775568257522637*^9, 3.775568284776268*^9}, {3.775568406638788*^9, 3.7755684078891897`*^9}}, CellID->123284224], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "7", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"PrimeQ", "@*", "FromDigits"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775568168324977*^9, 3.775568246840334*^9}, { 3.775568343294755*^9, 3.7755683487998447`*^9}, {3.775568398156794*^9, 3.775568423898609*^9}, {3.776529126287918*^9, 3.77652913001302*^9}}, CellLabel->"In[13]:=", CellID->841619866], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "8", ",", "9", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "7", ",", "6", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "6", ",", "7", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "9", ",", "6", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "5", ",", "7", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "7", ",", "5", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "8", ",", "5", ",", "9", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "9", ",", "8", ",", "5", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "5", ",", "6", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "5", ",", "8", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "8", ",", "5", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "6", ",", "5", ",", "7", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "9", ",", "5", ",", "6", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "9", ",", "6", ",", "5", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "6", ",", "5", ",", "8", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "6", ",", "8", ",", "5", ",", "7"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.775568183396497*^9, 3.775568201638604*^9}, { 3.775568255076702*^9, 3.775568263439975*^9}, {3.775568380685358*^9, 3.775568424252521*^9}, 3.7756595100280657`*^9, {3.776529095525774*^9, 3.776529130338461*^9}, 3.776529313866888*^9, 3.777914407196706*^9}, CellLabel->"Out[13]=", CellID->428895306] }, Open ]], Cell["Select permutations of length 3:", "Text", TaggingRules->{}, CellChangeTimes->{{3.77556848444596*^9, 3.7755685001038637`*^9}}, CellID->837471449], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "7", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", "3", "}"}], ",", RowBox[{"PrimeQ", "@*", "FromDigits"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.7755684786907463`*^9, 3.7755684795515823`*^9}}, CellLabel->"In[14]:=", CellID->724085147], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "5", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "5", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "5", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "6", ",", "7"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.7755684799271097`*^9, 3.775568497623534*^9}, 3.775659511887641*^9, 3.7765291338475637`*^9, 3.77652931593814*^9, 3.777914412861889*^9}, CellLabel->"Out[14]=", CellID->417779462] }, Open ]], Cell["Select permutations with length 3\[LongDash]4:", "Text", TaggingRules->{}, CellChangeTimes->{{3.77556848444596*^9, 3.775568509805202*^9}, { 3.775568557163394*^9, 3.775568581141801*^9}}, CellID->733329592], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "7", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "4"}], "}"}], ",", RowBox[{"PrimeQ", "@*", "FromDigits"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.7755684786907463`*^9, 3.7755684795515823`*^9}, { 3.7755685117029343`*^9, 3.775568514832704*^9}, {3.775568548776168*^9, 3.775568573740428*^9}}, CellLabel->"In[15]:=", CellID->472360365], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"5", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "5", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "5", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "5", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "6", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "6", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "6", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "6", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "7", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "8", ",", "9", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"5", ",", "9", ",", "8", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"6", ",", "8", ",", "5", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "5", ",", "8", ",", "9"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "5", ",", "9", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "5", ",", "8", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"9", ",", "8", ",", "5", ",", "7"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.7755684799271097`*^9, 3.775568515310902*^9}, { 3.7755685510649137`*^9, 3.775568573972561*^9}, 3.77565951429523*^9, 3.7765291361641808`*^9, 3.77652931673779*^9, 3.777914421493857*^9}, CellLabel->"Out[15]=", CellID->914008324] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[Cell["\t", "ExampleDelimiter"], $Line = 0; Null]], "ExampleDelimiter", TaggingRules->{}, CellID->14107562], Cell["\<\ Select permutations for which the first two elements and the last elements \ add up to the same value:\ \>", "Text", TaggingRules->{}, CellChangeTimes->{{3.775568615672393*^9, 3.775568642910595*^9}}, CellID->979377819], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "3", ",", "4"}], "}"}], ",", RowBox[{ RowBox[{ RowBox[{"Total", "[", RowBox[{"#", "[", RowBox[{"[", RowBox[{"1", ";;", "2"}], "]"}], "]"}], "]"}], "==", RowBox[{"Total", "[", RowBox[{"#", "[", RowBox[{"[", RowBox[{"3", ";;", "4"}], "]"}], "]"}], "]"}]}], "&"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775568591553537*^9, 3.7755686112570133`*^9}}, CellLabel->"In[72]:=", CellID->174898405], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "4", ",", "2", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "4", ",", "3", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "1", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "3", ",", "4", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "2", ",", "1", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "2", ",", "4", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", "1", ",", "2", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"4", ",", "1", ",", "3", ",", "2"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{3.775568611591529*^9, 3.775568644008772*^9, 3.775659516424469*^9, 3.7765291414916773`*^9, 3.77652931856979*^9}, CellLabel->"Out[72]=", CellID->350299350] }, Open ]] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Scope", "Subsection", TaggingRules->{}, CellID->204653245], Cell["\<\ Select the first ten permutations of length 4 for which the elements add up \ to an odd number:\ \>", "Text", TaggingRules->{}, CellChangeTimes->{{3.775568753645933*^9, 3.775568812706834*^9}}, CellID->559719523], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6"}], "}"}], ",", RowBox[{"{", "4", "}"}], ",", RowBox[{"OddQ", "@*", "Total"}], ",", "10"}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{ 3.775568390327188*^9, {3.775568657121542*^9, 3.775568658024325*^9}, { 3.7755687157418547`*^9, 3.7755687754639063`*^9}}, CellLabel->"In[73]:=", CellID->359245144], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "3", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2", ",", "4", ",", "6"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2", ",", "5", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "2", ",", "6", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "2", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "4", ",", "5"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "5", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "5", ",", "4"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "5", ",", "6"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "3", ",", "6", ",", "5"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.7755687038053503`*^9, 3.7755688138863287`*^9}, 3.7756595189226503`*^9, 3.776529143745932*^9, 3.7765293197019567`*^9}, CellLabel->"Out[73]=", CellID->115709028] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Applications", "Subsection", TaggingRules->{}, CellID->605265931], Cell[TextData[{ "Select polynomials for which the slope is 1 at ", Cell[BoxData[ RowBox[{ StyleBox["x", "TI"], "=", "0"}]], "InlineFormula", FontFamily->"Source Sans Pro"], ":" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775568978297995*^9, 3.775568990453267*^9}, 3.7779148648834963`*^9}, CellID->306011383], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"out", "=", RowBox[{"Total", "/@", RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"x", ",", RowBox[{"4", "x"}], ",", "1", ",", RowBox[{ RowBox[{"(", RowBox[{"x", "-", "2"}], ")"}], "^", "2"}]}], "}"}], ",", "4", ",", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"D", "[", RowBox[{ RowBox[{"Total", "[", "#", "]"}], ",", "x"}], "]"}], ")"}], "/.", RowBox[{"x", "\[Rule]", "0"}]}], ")"}], "\[Equal]", "1"}], "&"}]}], "]"}]}]}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.7755690066041317`*^9, 3.775569013725047*^9}}, CellLabel->"In[74]:=", CellID->884651642], Cell[BoxData[ RowBox[{"{", RowBox[{"x", ",", RowBox[{"1", "+", "x"}], ",", RowBox[{"1", "+", "x"}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{ SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}], ",", RowBox[{"1", "+", SuperscriptBox[ RowBox[{"(", RowBox[{ RowBox[{"-", "2"}], "+", "x"}], ")"}], "2"], "+", RowBox[{"5", " ", "x"}]}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.775568996876224*^9, 3.775569014097753*^9}, 3.775659522403158*^9, 3.7756596276060133`*^9, 3.776529146850255*^9, 3.776529321528561*^9}, CellLabel->"Out[74]=", CellID->681404123] }, Open ]], Cell[TextData[{ "Confirm that the slope is indeed unity at ", Cell[BoxData[ RowBox[{ StyleBox["x", "TI"], "=", "0"}]], "InlineFormula", FontFamily->"Source Sans Pro"], ":" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775569032362935*^9, 3.775569042022148*^9}, 3.7779148702157297`*^9}, CellID->700662694], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{ RowBox[{"D", "[", RowBox[{"#", ",", "x"}], "]"}], "/.", RowBox[{"x", "\[Rule]", "0"}]}], "&"}], "/@", "out"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775569008779991*^9, 3.775569029774448*^9}}, CellLabel->"In[75]:=", CellID->70632808], Cell[BoxData[ RowBox[{"{", RowBox[{ "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1", ",", "1"}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.775569024986065*^9, 3.77556903028509*^9}, 3.775659524049831*^9, 3.7756596295261593`*^9, 3.776529148801647*^9, 3.776529322629979*^9}, CellLabel->"Out[75]=", CellID->437861425] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Properties and Relations", "Subsection", TaggingRules->{}, CellID->232113220], Cell["Duplicated items are treated the same:", "Text", TaggingRules->{}, CellChangeTimes->{{3.7756596329305153`*^9, 3.775659640189417*^9}}, CellID->444986081], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"{", RowBox[{"6", ",", "7", ",", "7", ",", "7", ",", "8"}], "}"}], ",", RowBox[{"{", "2", "}"}], ",", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Total", "[", "#", "]"}], "\[Equal]", "14"}], ")"}], "&"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775658730148959*^9, 3.775658747520253*^9}, { 3.7756590438565607`*^9, 3.775659044412951*^9}, {3.7756596525277853`*^9, 3.7756596527056847`*^9}}, CellLabel->"In[76]:=", CellID->991815813], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"6", ",", "8"}], "}"}], ",", RowBox[{"{", RowBox[{"7", ",", "7"}], "}"}], ",", RowBox[{"{", RowBox[{"8", ",", "6"}], "}"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{ 3.775658748232149*^9, 3.775658894579425*^9, 3.775658982885504*^9, { 3.77565902072548*^9, 3.775659044907261*^9}, {3.7756591949370537`*^9, 3.775659233580648*^9}, {3.7756593450669947`*^9, 3.775659400072006*^9}, 3.7756595071964903`*^9, 3.7756596532496367`*^9, 3.77652915012943*^9, 3.776529324231215*^9}, CellLabel->"Out[76]=", CellID->167671158] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[Cell["\t", "ExampleDelimiter"], $Line = 0; Null]], "ExampleDelimiter", TaggingRules->{}, CellID->14107563], Cell[TextData[{ "The main difference between ", Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ StyleBox["list", "TI"], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " and ", Cell[BoxData[ RowBox[{ TagBox[ ButtonBox[ StyleBox["Select", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Select", ContentPadding->False], MouseAppearanceTag["LinkHand"]], "[", RowBox[{ RowBox[{ TagBox[ ButtonBox[ StyleBox["Permutations", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Permutations", ContentPadding->False], MouseAppearanceTag["LinkHand"]], "[", StyleBox["list", "TI"], "]"}], ",", StyleBox["crit", "TI"]}], "]"}]], "InlineFormula", FontFamily->"Source Sans Pro"], " is the memory usage:" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775659692231538*^9, 3.775659737034504*^9}, { 3.777915104180867*^9, 3.7779151337974873`*^9}}, CellID->771301361], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MaxMemoryUsed", "[", RowBox[{ RowBox[{"result1", "=", RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"Range", "[", RowBox[{"3", ",", "13"}], "]"}], ",", "6", ",", RowBox[{ RowBox[{ RowBox[{"Total", "[", "#", "]"}], "\[Equal]", "24"}], "&"}]}], "]"}]}], ";"}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.7756597419331837`*^9, 3.775659859377911*^9}, 3.775659965227964*^9}, CellLabel->"In[77]:=", CellID->535666113], Cell[BoxData["75936"], "Output", TaggingRules->{}, CellChangeTimes->{{3.77565978044046*^9, 3.775659822081428*^9}, { 3.775659853998701*^9, 3.775659866096383*^9}, 3.775659977992035*^9, 3.7756600199457493`*^9, 3.776529154597158*^9, 3.776529328657302*^9}, CellLabel->"Out[77]=", CellID->759417183] }, Open ]], Cell[TextData[{ "Using ", Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["Select", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Select", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " and ", Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["Permutations", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Permutations", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " uses 500 times more memory:" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775659958690896*^9, 3.775660003727075*^9}, { 3.777914890455714*^9, 3.777914892938813*^9}}, CellID->444708281], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"MaxMemoryUsed", "[", RowBox[{ RowBox[{"result2", "=", RowBox[{"Select", "[", RowBox[{ RowBox[{"Permutations", "[", RowBox[{ RowBox[{"Range", "[", RowBox[{"3", ",", "13"}], "]"}], ",", "6"}], "]"}], ",", RowBox[{ RowBox[{ RowBox[{"Total", "[", "#", "]"}], "\[Equal]", "24"}], "&"}]}], "]"}]}], ";"}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775659826770007*^9, 3.775659862367159*^9}, 3.775659967831942*^9}, CellLabel->"In[78]:=", CellID->887464862], Cell[BoxData["37562680"], "Output", TaggingRules->{}, CellChangeTimes->{{3.775659833819317*^9, 3.775659867629966*^9}, 3.775659978889728*^9, 3.775660020843718*^9, 3.776529158151636*^9, 3.776529329564918*^9}, CellLabel->"Out[78]=", CellID->789170819] }, Open ]], Cell["Verify that the results are identical:", "Text", TaggingRules->{}, CellChangeTimes->{{3.775660014046246*^9, 3.775660019525916*^9}}, CellID->486162817], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"result1", "\[Equal]", "result2"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775659839679294*^9, 3.775659844204294*^9}}, CellLabel->"In[79]:=", CellID->615462631], Cell[BoxData["True"], "Output", TaggingRules->{}, CellChangeTimes->{{3.775659844726769*^9, 3.775659872379087*^9}, 3.775660021901587*^9, 3.7765291614553967`*^9, 3.776529330743194*^9}, CellLabel->"Out[79]=", CellID->573023320] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ InterpretationBox[Cell["\t", "ExampleDelimiter"], $Line = 0; Null]], "ExampleDelimiter", TaggingRules->{}, CellID->14107564], Cell[TextData[{ Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["Head", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Head", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], " does not have to be ", Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["List", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/List", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], ":" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775659940349708*^9, 3.77565995308701*^9}, 3.77791491092492*^9}, CellID->177535240], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"f", "[", RowBox[{"1", ",", "2", ",", "3", ",", "4", ",", "5"}], "]"}], ",", RowBox[{"{", "2", "}"}], ",", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"Plus", "@@", "#"}], ")"}], "\[Equal]", "6"}], "&"}], ")"}]}], "]"}]], "Input", TaggingRules->{}, CellChangeTimes->{{3.775564501355146*^9, 3.77556453064013*^9}, { 3.775564595079977*^9, 3.775564596369431*^9}, {3.775564628426854*^9, 3.775564631573576*^9}}, CellLabel->"In[80]:=", CellID->661797484], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"f", "[", RowBox[{"1", ",", "5"}], "]"}], ",", RowBox[{"f", "[", RowBox[{"2", ",", "4"}], "]"}], ",", RowBox[{"f", "[", RowBox[{"4", ",", "2"}], "]"}], ",", RowBox[{"f", "[", RowBox[{"5", ",", "1"}], "]"}]}], "}"}]], "Output", TaggingRules->{}, CellChangeTimes->{{3.77556451988704*^9, 3.77556463182666*^9}, 3.7755676679041758`*^9, 3.775567712707305*^9, 3.775567818332111*^9, 3.77565941046673*^9, 3.776529163330064*^9, 3.776529331852521*^9}, CellLabel->"Out[80]=", CellID->931706464] }, Open ]] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Possible Issues", "Subsection", TaggingRules->{}, CellID->158766396], Cell[TextData[{ Cell[BoxData["SelectPermutations"], "InlineFormula", FontFamily->"Source Sans Pro"], " might take longer as it is written in higher-level code as compared to the \ implementation of ", Cell[BoxData[ TagBox[ ButtonBox[ StyleBox["Permutations", "SymbolsRefLink", ShowStringCharacters->True, FontFamily->"Source Sans Pro"], BaseStyle->Dynamic[ FEPrivate`If[ CurrentValue["MouseOver"], { "Link", FontColor -> RGBColor[0.854902, 0.396078, 0.145098]}, { "Link"}]], ButtonData->"paclet:ref/Permutations", ContentPadding->False], MouseAppearanceTag["LinkHand"]]], "InlineFormula", FontFamily->"Source Sans Pro"], ":" }], "Text", TaggingRules->{}, CellChangeTimes->{{3.775660090968472*^9, 3.775660098838415*^9}, { 3.7756601400967207`*^9, 3.7756601913190613`*^9}, {3.775660772370102*^9, 3.775660773132094*^9}, 3.777914921223103*^9}, CellID->445973593], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{"MaxMemoryUsed", "[", RowBox[{"time", "=", RowBox[{ RowBox[{"AbsoluteTiming", "[", RowBox[{ RowBox[{"result1", "=", RowBox[{"SelectPermutations", "[", RowBox[{ RowBox[{"Range", "[", RowBox[{"3", ",", "13"}], "]"}], ",", "6", ",", RowBox[{ RowBox[{ RowBox[{"Total", "[", "#", "]"}], "\[Equal]", "24"}], "&"}]}], "]"}]}], ";"}], "]"}], "[", RowBox[{"[", "1", "]"}], "]"}]}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{"Grid", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"\"\