(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 12902, 456] NotebookOptionsPosition[ 9950, 352] NotebookOutlinePosition[ 10806, 383] CellTagsIndexPosition[ 10639, 376] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Project - An Integer Sequence", "Title", CellChangeTimes->{{3.4496813196580153`*^9, 3.449681342612208*^9}}], Cell[TextData[StyleBox["This is a project which deals with discrete \ mathematics and sequences that are defined via a recurrence. You are to \ examine the long-term behavior of these sequences.", FontWeight->"Bold"]], "Text"], Cell[CellGroupData[{ Cell["Overview", "Subsection"], Cell[TextData[{ "Take any positive integer, say 57. Square the individual digits and add \ them to get a new integer:\n\n\t", Cell[BoxData[ FormBox[ RowBox[{ RowBox[{ SuperscriptBox["5", "2"], "+", SuperscriptBox["7", "2"]}], "=", RowBox[{ RowBox[{"25", "+", "47"}], "=", "74."}]}], TraditionalForm]]], "\n\nNow repeat the procedure. What will happen? Will the sequence converge \ (i.e., settle down to a single value)? Will it cycle through a sequence of \ values? Does each starting number produce a different behavior?\n\nYou are to \ answer these questions for the integers from 1 to 100." }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Details", "Subsection"], Cell[CellGroupData[{ Cell["Step 1", "Subsubsection"], Cell["\<\ Write a function which computes the next integer in the sequence from the \ given one, i.e.,\ \>", "Text"], Cell[BoxData[ RowBox[{"nextval", "[", "57", "]"}]], "Input", Active->True], Cell[BoxData["74"], "Input", Active->True], Cell[TextData[{ "Make sure this function checks for positive integers. You will need to use \ the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["IntegerDigits", FontWeight->"Bold"], ", which returns a list of the individual digits of any integer n." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"?", "IntegerDigits"}]], "Input"], Cell[BoxData[ RowBox[{"\<\"IntegerDigits[n] gives a list of the decimal digits in the \ integer n. IntegerDigits[n, b] gives a list of the base-b digits in the \ integer n. IntegerDigits[n, b, len] pads the list on the left with zeros to \ give a list of length len.\"\>", " ", ButtonBox[ StyleBox["More\[Ellipsis]", "SR"], Active->True, BaseStyle->"RefGuideLink", ButtonData:>"IntegerDigits"]}]], "Print", CellTags->"Info3231262317-6084397"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"IntegerDigits", "[", "14258934", "]"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{ "1", ",", "4", ",", "2", ",", "5", ",", "8", ",", "9", ",", "3", ",", "4"}], "}"}]], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Step 2", "Subsubsection"], Cell[TextData[{ "Write a function which will detect whether a given sequence converges, has \ a cycle, or does not settle down into a regular behavior (within the first \ 200 steps). You should do this using a ", StyleBox["Do", FontWeight->"Bold"], " or ", StyleBox["While ", FontWeight->"Bold"], "loop, checking whether the newly computed value has already occurred in the \ sequence. If the new value repeats the value just before it, then there is \ convergence, otherwise there is a cycle. To check for repeated values, use \ the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["FreeQ", FontWeight->"Bold"], ", which checks whether an expression (in this case a list) is free of a \ specific form (in this case a value)." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"?", "FreeQ"}]], "Input"], Cell[BoxData[ RowBox[{"\<\"FreeQ[expr, form] yields True if no subexpression in expr \ matches form, and yields False otherwise. FreeQ[expr, form, levelspec] tests \ only those parts of expr on levels specified by levelspec.\"\>", " ", ButtonBox[ StyleBox["More\[Ellipsis]", "SR"], Active->True, BaseStyle->"RefGuideLink", ButtonData:>"FreeQ"]}]], "Print", CellTags->"Info3231262882-9543063"] }, Open ]], Cell["Here are some examples for FreeQ.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "5", ",", "6", ",", "9"}], "}"}], ",", "4"}], "]"}]], "Input"], Cell[BoxData["True"], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"FreeQ", "[", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "2", ",", "5", ",", "6", ",", "9"}], "}"}], ",", "2"}], "]"}]], "Input"], Cell[BoxData["False"], "Output"] }, Open ]], Cell[TextData[{ "Once you have found convergence or a cycle, your function should return the \ values between the repeated ones, including the repeated values. For example, \ your function should return\n\n\t{2, 2} for a sequence \ converging to 2\n\t{3, 4, 7, 2, 3} for the cycle consisting of the \ repeated values 3, 4, 7, 2.\n\nYou can use the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", StyleBox["Position", FontWeight->"Bold"], " to find the positions of the repeated values, then use ", StyleBox["Take", FontWeight->"Bold"], " or ", StyleBox["Drop", FontWeight->"Bold"], " to return only the cyclic part of the sequence." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"?", "Position"}]], "Input"], Cell[BoxData[ RowBox[{"\<\"Position[expr, pattern] gives a list of the positions at which \ objects matching pattern appear in expr. Position[expr, pattern, levspec] \ finds only objects that appear on levels specified by levspec. Position[expr, \ pattern, levspec, n] gives the positions of the first n objects found.\"\>", " ", ButtonBox[ StyleBox["More\[Ellipsis]", "SR"], Active->True, BaseStyle->"RefGuideLink", ButtonData:>"Position"]}]], "Print", CellTags->"Info3231263105-5889946"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Position", "[", RowBox[{ RowBox[{"{", RowBox[{ "1", ",", "2", ",", "3", ",", " ", "5", ",", "6", ",", "9", ",", "3"}], "}"}], ",", "3"}], "]"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"{", "3", "}"}], ",", RowBox[{"{", "7", "}"}]}], "}"}]], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Step 3", "Subsubsection"], Cell["\<\ In order to compare the cycles of different starting values, you would want \ to \"standardize\" the cycles. For example, the three different sequences \ below all reference the same cycle, except we are focusing on a different \ area in the repeated sequence.\ \>", "Text"], Cell[BoxData[ RowBox[{"{", RowBox[{"4", ",", " ", "6", ",", " ", "8", ",", " ", "7", ",", " ", "4"}], "}"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{"6", ",", " ", "8", ",", " ", "7", ",", " ", "4", ",", "6"}], "}"}]], "Input"], Cell[BoxData[ RowBox[{"{", RowBox[{"7", ",", " ", "4", ",", " ", "6", ",", " ", "8", ",", " ", "7"}], "}"}]], "Input"], Cell["\<\ To find a \"canonical\" or \"standardized\" form, we identify the minimal \ element in the list, and then write the cycle with that element as the first \ one. Write a function that produces the standard cycle from a given \ (possibly) non-standard one. In the example given above, the standard cycle \ would be \ \>", "Text"], Cell[BoxData[ RowBox[{"{", RowBox[{"4", ",", " ", "6", ",", " ", "8", ",", " ", "7", ",", " ", "4"}], "}"}]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Step 4", "Subsubsection"], Cell[TextData[{ "Put all the previous steps together to produce a table for the integers \ form 1 to 100 (in general from 1 to ", StyleBox["n ", FontSlant->"Italic"], "or from ", StyleBox["m", FontSlant->"Italic"], " to ", StyleBox["n", FontSlant->"Italic"], ") which lists the integers together with their cycles or the statement \ \"other\". \n\n\t1\t{1, 1}\n\t2\t{4, 16, 37, 58, 89, 145, 42, 20, 4}\n\t\ \[VerticalEllipsis]\t\t\[VerticalEllipsis]\n\t100\t{1, 1}\n\t\nYou might want \ to think about which numbers have the same behavior (such as 1 and 100, since \ 0s do not change a thing!) How many different behaviors do you expect at \ most??" }], "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Step 5", "Subsubsection"], Cell["\<\ Finally, create a visual display of the information given in the table of \ Step 4. One possibility is to display the integers on the horizontal axis, \ and the sequence values on the vertical axis (or vice versa). Display cycles \ that are the same in the same color - you will be surprised by the graph (not \ really, since you have already looked at the table). You may also think of \ any other type of plot which summarizes the table visually - be creative! \ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Step 6", "Subsubsection"], Cell[TextData[{ "Put all the pieces together in a function whose input is the value", StyleBox[" n", FontSlant->"Italic"], " to create the table and graph for the integers from 1 to ", StyleBox["n ", FontSlant->"Italic"], "(or you can have values ", StyleBox["m", FontSlant->"Italic"], " and ", StyleBox["n", FontSlant->"Italic"], ", and then the integers for which the table and graph are created are the \ integers from ", StyleBox["m", FontSlant->"Italic"], " to ", StyleBox["n", FontSlant->"Italic"], ".) Write a usage statement for your function, and if needed, an error \ statement. Test you function to answer the question posed for the integers \ from 1 to 100." }], "Text"] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{751, 448}, WindowMargins->{{90, Automatic}, {Automatic, 14}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, FrontEndVersion->"6.0 for Mac OS X PowerPC (32-bit) (April 20, 2007)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{ "Info3231262317-6084397"->{ Cell[2379, 89, 459, 10, 51, "Print", CellTags->"Info3231262317-6084397"]}, "Info3231262882-9543063"->{ Cell[4027, 146, 409, 9, 51, "Print", CellTags->"Info3231262882-9543063"]}, "Info3231263105-5889946"->{ Cell[5747, 209, 509, 11, 66, "Print", CellTags->"Info3231263105-5889946"]} } *) (*CellTagsIndex CellTagsIndex->{ {"Info3231262317-6084397", 10317, 364}, {"Info3231262882-9543063", 10426, 367}, {"Info3231263105-5889946", 10535, 370} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 114, 1, 76, "Title"], Cell[707, 26, 227, 3, 41, "Text"], Cell[CellGroupData[{ Cell[959, 33, 30, 0, 34, "Subsection"], Cell[992, 35, 638, 15, 134, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1667, 55, 29, 0, 34, "Subsection"], Cell[CellGroupData[{ Cell[1721, 59, 31, 0, 25, "Subsubsection"], Cell[1755, 61, 116, 3, 26, "Text"], Cell[1874, 66, 76, 2, 27, "Input"], Cell[1953, 70, 43, 1, 27, "Input"], Cell[1999, 73, 296, 9, 41, "Text"], Cell[CellGroupData[{ Cell[2320, 86, 56, 1, 27, "Input"], Cell[2379, 89, 459, 10, 51, "Print", CellTags->"Info3231262317-6084397"] }, Open ]], Cell[CellGroupData[{ Cell[2875, 104, 73, 1, 27, "Input"], Cell[2951, 107, 139, 4, 27, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3139, 117, 31, 0, 25, "Subsubsection"], Cell[3173, 119, 778, 20, 86, "Text"], Cell[CellGroupData[{ Cell[3976, 143, 48, 1, 27, "Input"], Cell[4027, 146, 409, 9, 51, "Print", CellTags->"Info3231262882-9543063"] }, Open ]], Cell[4451, 158, 49, 0, 26, "Text"], Cell[CellGroupData[{ Cell[4525, 162, 163, 5, 27, "Input"], Cell[4691, 169, 31, 0, 27, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[4759, 174, 163, 5, 27, "Input"], Cell[4925, 181, 32, 0, 27, "Output"] }, Open ]], Cell[4972, 184, 696, 18, 131, "Text"], Cell[CellGroupData[{ Cell[5693, 206, 51, 1, 27, "Input"], Cell[5747, 209, 509, 11, 66, "Print", CellTags->"Info3231263105-5889946"] }, Open ]], Cell[CellGroupData[{ Cell[6293, 225, 198, 6, 27, "Input"], Cell[6494, 233, 121, 4, 27, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[6664, 243, 31, 0, 25, "Subsubsection"], Cell[6698, 245, 284, 5, 41, "Text"], Cell[6985, 252, 125, 3, 27, "Input"], Cell[7113, 257, 120, 3, 27, "Input"], Cell[7236, 262, 125, 3, 27, "Input"], Cell[7364, 267, 337, 6, 56, "Text"], Cell[7704, 275, 125, 3, 27, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7866, 283, 31, 0, 25, "Subsubsection"], Cell[7900, 285, 674, 17, 161, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[8611, 307, 31, 0, 25, "Subsubsection"], Cell[8645, 309, 487, 8, 86, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[9169, 322, 31, 0, 25, "Subsubsection"], Cell[9203, 324, 707, 23, 71, "Text"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)