(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.0' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 11916, 490]*) (*NotebookOutlinePosition[ 12551, 512]*) (* CellTagsIndexPosition[ 12507, 508]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Number bases", "Subtitle"], Cell["\<\ I. Cnop Vrije Universiteit Brussel icnop@vub.ac.be\ \>", "Subsubtitle"], Cell[CellGroupData[{ Cell["An example of List programming.", "Section"], Cell[TextData[{ "We present a simple example of list programming in ", StyleBox["Mathematica", FontSlant->"Italic"], " ." }], "Text"], Cell[CellGroupData[{ Cell["List programming a change of basis.", "Subsection"], Cell["Take the decimal representation of a large number ", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(t = 3\^200\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \(265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001\)], "Output"] }, Closed]], Cell["\<\ The of the logaritm tells us how many digits we have (after \ rounding upwards)\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Log[10. , t]\)], "Input"], Cell[BoxData[ \(95.42425094393248`\)], "Output"] }, Closed]], Cell["This one has a simple expression in base 3 form:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(BaseForm[t, 3]\)], "Input"], Cell[BoxData[ TagBox[ InterpretationBox[\(\ "10000000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000"\_"3"\), 2656139888758747693387813220357796268292334526533944959745749617390924\ 90901302182994384699044001, Editable->False], (BaseForm[ #, 3]&)]], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Log[3, t]\)], "Input"], Cell[BoxData[ \(200\)], "Output"] }, Closed]], Cell["with 200 zeroes. It gets shorter if we use a bigger basis:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(BaseForm[t, 17]\)], "Input"], Cell[BoxData[ TagBox[ InterpretationBox[\(\ "4d53gee78e356ffg4d4310dc1c3f6gb76a6a4ga27f848gg47383f682gbd5ca367b8e400a7113a\ g"\_"17"\), 2656139888758747693387813220357796268292334526533944959745749617390924\ 90901302182994384699044001, Editable->False], (BaseForm[ #, 17]&)]], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(Log[17. , t]\)], "Input"], Cell[BoxData[ \(77.55238700769802`\)], "Output"] }, Closed]], Cell["with only 78 digits, and less in larger basis forms.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(BaseForm[t, 35]\)], "Input"], Cell[BoxData[ TagBox[ InterpretationBox[\(\ "h7rqjripui98d3c9eefiyhvcm325aclcqfc7b6ct72oep7mu6ojn8tkd9md8gg"\_"35"\), 2656139888758747693387813220357796268292334526533944959745749617390924\ 90901302182994384699044001, Editable->False], (BaseForm[ #, 35]&)]], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(BaseForm[t, 47]\)], "Input"], Cell[BoxData[ \(BaseForm::"basf" \(\(:\)\(\ \)\) "Requested base \!\(\"47\"\) should be between 2 and \!\(\"36\"\)."\)], \ "Message"], Cell[BoxData[ \(BaseForm[ 265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001, 47]\)], "Output"] }, Closed]], Cell["\<\ We no longer have a sufficient number of characters at our disposal \ to represent all 47 digits, since the maximum is (10 + 26).\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(BaseForm[t, 243]\)], "Input"], Cell[BoxData[ \(BaseForm::"basf" \(\(:\)\(\ \)\) "Requested base \!\(\"243\"\) should be between 2 and \ \!\(\"36\"\)."\)], "Message"], Cell[BoxData[ \(BaseForm[ 265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001, 243]\)], "Output"] }, Closed]], Cell["\<\ Here we now the answer by hand: it should be a 1 followed by 40 \ zeroes. (Why?)\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Conversion to a new \"basis\"", "Subsection"], Cell[CellGroupData[{ Cell[BoxData[ \(basis = 17\)], "Input"], Cell[BoxData[ \(17\)], "Output"] }, Closed]], Cell[BoxData[ \(Clear[nextentry]\)], "Input"], Cell[BoxData[ \(nextentry[{l_List, m_Integer}] := \n\t If[m == 0, {l, m}, \n\t\t{Prepend[l, Mod[m, basis]], \((m - Mod[m, basis])\)/ basis}]\)], "Input", CellAutoOverwrite->False], Cell["\<\ The first remainder is recorded and we continue with the quotient\ \ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[{{}, t}]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{16}, 156243522868161629022812542373988015781902030972584997632102918670054406\ 41253069587904982296705}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[nextentry[{{}, t}]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{10, 16}, 919079546283303700134191425729341269305306064544617633130017168647378861\ 250180563994410723335}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[nextentry[nextentry[{{}, t}]]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{3, 10, 16}, 540635027225472764784818485723141923120768273261539784194127746263164036\ 02951797882024160196}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[nextentry[nextentry[nextentry[{{}, t}]]]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{1, 3, 10, 16}, 318020604250278096932246168072436425365157807800905755408310438978331785\ 8997164581295538835}\)], "Output"] }, Closed]], Cell["\<\ The expected length of the final result is the logarithm up to one \ more nextentry:\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(message = First[Nest[nextentry, {{}, t}, IntegerPart[Log[basis, t]] + 1]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \(General::"spell1" \(\(:\)\(\ \)\) "Possible spelling error: new symbol name \"\!\(message\)\" is similar \ to existing symbol \"\!\(Message\)\"."\)], "Message"], Cell[BoxData[ \({4, 13, 5, 3, 16, 14, 14, 7, 8, 14, 3, 5, 6, 15, 15, 16, 4, 13, 4, 3, 1, 0, 13, 12, 1, 12, 3, 15, 6, 16, 11, 7, 6, 10, 6, 10, 4, 16, 10, 2, 7, 15, 8, 4, 8, 16, 16, 4, 7, 3, 8, 3, 15, 6, 8, 2, 16, 11, 13, 5, 12, 10, 3, 6, 7, 11, 8, 14, 4, 0, 0, 10, 7, 1, 1, 3, 10, 16}\)], "Output"] }, Closed]], Cell["\<\ Instead of using logarithms we could also build a If structure to \ end the computiation.\ \>", "Text"], Cell[CellGroupData[{ Cell["Control", "Subsubsection"], Cell[CellGroupData[{ Cell[BoxData[ \(basis\^Range[0, Length[%] - 1] . Reverse[message]\)], "Input"], Cell[BoxData[ \(265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(% == t\)], "Input"], Cell[BoxData[ \(True\)], "Output"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Try this", "Subsection"], Cell[CellGroupData[{ Cell["basis=47", "Subsubsection", Evaluatable->True], Cell[BoxData[ \(47\)], "Output"], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[{{}, t}]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{32}, 565136146544414402848470897948467291126028622666796799945904173912962746\ 5985152829667759554127}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(message = First[Nest[nextentry, {{}, t}, IntegerPart[Log[basis, t]] + 1]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({1, 14, 9, 24, 40, 26, 39, 46, 11, 3, 3, 43, 18, 4, 14, 3, 1, 12, 45, 35, 41, 43, 4, 10, 23, 29, 44, 35, 38, 28, 33, 0, 13, 17, 43, 32, 3, 4, 20, 40, 42, 7, 25, 43, 10, 24, 38, 21, 22, 28, 44, 11, 34, 2, 26, 0, 43, 32}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(basis\^Range[0, Length[%] - 1] . Reverse[message]\)], "Input"], Cell[BoxData[ \(265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001\)], "Output"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["basis=243", "Subsubsection", Evaluatable->True], Cell[BoxData[ \(243\)], "Output"], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[{{}, t}]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{0}, 109306168261676859810198074911843467830960268581643825503940313472877568\ 2721408160470718926107}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(message = First[Nest[nextentry, {{}, t}, IntegerPart[Log[basis, t]] + 1]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(basis\^Range[0, Length[%] - 1] . Reverse[message]\)], "Input"], Cell[BoxData[ \(265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001\)], "Output"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["basis=1234567890123456789", "Subsubsection", Evaluatable->True], Cell[BoxData[ \(1234567890123456789\)], "Output"], Cell[CellGroupData[{ Cell[BoxData[ \(nextentry[{{}, t}]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({{661478062934349342}, 215147332925784559692257981041767276427539347245111888494473521451978429\ 227831}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(message = First[Nest[nextentry, {{}, t}, IntegerPart[Log[basis, t]] + 1]]\)], "Input", CellAutoOverwrite->False], Cell[BoxData[ \({92613, 1080836537295918344, 5166532231134628, 176563874993238558, 584193204873457312, 661478062934349342}\)], "Output"] }, Closed]], Cell[CellGroupData[{ Cell[BoxData[ \(basis\^Range[0, Length[%] - 1] . Reverse[message]\)], "Input"], Cell[BoxData[ \(265613988875874769338781322035779626829233452653394495974574961739092490\ 901302182994384699044001\)], "Output"] }, Closed]] }, Closed]] }, Closed]] }, Open ]] }, Open ]] }, FrontEndVersion->"5.0 for Macintosh", ScreenRectangle->{{0, 1115}, {0, 746}}, WindowSize->{888, 632}, WindowMargins->{{1, Automatic}, {Automatic, 1}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 32, 0, 52, "Subtitle"], Cell[1811, 55, 81, 4, 64, "Subsubtitle"], Cell[CellGroupData[{ Cell[1917, 63, 50, 0, 69, "Section"], Cell[1970, 65, 144, 5, 32, "Text"], Cell[CellGroupData[{ Cell[2139, 74, 57, 0, 38, "Subsection"], Cell[2199, 76, 66, 0, 30, "Text"], Cell[CellGroupData[{ Cell[2290, 80, 71, 2, 29, "Input"], Cell[2364, 84, 132, 2, 27, "Output"] }, Closed]], Cell[2511, 89, 103, 3, 30, "Text"], Cell[CellGroupData[{ Cell[2639, 96, 45, 1, 27, "Input"], Cell[2687, 99, 52, 1, 27, "Output"] }, Closed]], Cell[2754, 103, 66, 0, 30, "Text"], Cell[CellGroupData[{ Cell[2845, 107, 47, 1, 27, "Input"], Cell[2895, 110, 441, 9, 55, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[3373, 124, 42, 1, 27, "Input"], Cell[3418, 127, 37, 1, 27, "Output"] }, Closed]], Cell[3470, 131, 76, 0, 30, "Text"], Cell[CellGroupData[{ Cell[3571, 135, 48, 1, 27, "Input"], Cell[3622, 138, 318, 8, 40, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[3977, 151, 45, 1, 27, "Input"], Cell[4025, 154, 52, 1, 27, "Output"] }, Closed]], Cell[4092, 158, 68, 0, 30, "Text"], Cell[CellGroupData[{ Cell[4185, 162, 48, 1, 27, "Input"], Cell[4236, 165, 300, 7, 40, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[4573, 177, 48, 1, 27, "Input"], Cell[4624, 180, 144, 3, 21, "Message"], Cell[4771, 185, 153, 3, 39, "Output"] }, Closed]], Cell[4939, 191, 154, 3, 30, "Text"], Cell[CellGroupData[{ Cell[5118, 198, 49, 1, 27, "Input"], Cell[5170, 201, 145, 3, 21, "Message"], Cell[5318, 206, 154, 3, 39, "Output"] }, Closed]], Cell[5487, 212, 104, 3, 30, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5628, 220, 51, 0, 30, "Subsection"], Cell[CellGroupData[{ Cell[5704, 224, 43, 1, 27, "Input"], Cell[5750, 227, 36, 1, 27, "Output"] }, Closed]], Cell[5801, 231, 49, 1, 27, "Input"], Cell[5853, 234, 214, 5, 59, "Input"], Cell[6070, 241, 91, 3, 30, "Text"], Cell[CellGroupData[{ Cell[6186, 248, 79, 2, 27, "Input"], Cell[6268, 252, 146, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[6451, 260, 90, 2, 27, "Input"], Cell[6544, 264, 148, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[6729, 272, 101, 2, 27, "Input"], Cell[6833, 276, 150, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[7020, 284, 112, 2, 27, "Input"], Cell[7135, 288, 152, 3, 27, "Output"] }, Closed]], Cell[7302, 294, 108, 3, 30, "Text"], Cell[CellGroupData[{ Cell[7435, 301, 152, 4, 27, "Input"], Cell[7590, 307, 187, 3, 21, "Message"], Cell[7780, 312, 322, 4, 59, "Output"] }, Closed]], Cell[8117, 319, 113, 3, 30, "Text"], Cell[CellGroupData[{ Cell[8255, 326, 32, 0, 42, "Subsubsection"], Cell[CellGroupData[{ Cell[8312, 330, 82, 1, 29, "Input"], Cell[8397, 333, 132, 2, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[8566, 340, 39, 1, 27, "Input"], Cell[8608, 343, 38, 1, 27, "Output"] }, Closed]] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[8707, 351, 30, 0, 30, "Subsection"], Cell[CellGroupData[{ Cell[8762, 355, 54, 1, 28, "Subsubsection", Evaluatable->True], Cell[8819, 358, 36, 1, 27, "Output"], Cell[CellGroupData[{ Cell[8880, 363, 79, 2, 27, "Input"], Cell[8962, 367, 145, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[9144, 375, 152, 4, 27, "Input"], Cell[9299, 381, 273, 4, 43, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[9609, 390, 82, 1, 29, "Input"], Cell[9694, 393, 132, 2, 27, "Output"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[9875, 401, 55, 1, 28, "Subsubsection", Evaluatable->True], Cell[9933, 404, 37, 1, 27, "Output"], Cell[CellGroupData[{ Cell[9995, 409, 79, 2, 27, "Input"], Cell[10077, 413, 144, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[10258, 421, 152, 4, 27, "Input"], Cell[10413, 427, 164, 2, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[10614, 434, 82, 1, 29, "Input"], Cell[10699, 437, 132, 2, 27, "Output"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[10880, 445, 71, 1, 42, "Subsubsection", Evaluatable->True], Cell[10954, 448, 53, 1, 27, "Output"], Cell[CellGroupData[{ Cell[11032, 453, 79, 2, 27, "Input"], Cell[11114, 457, 145, 3, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[11296, 465, 152, 4, 27, "Input"], Cell[11451, 471, 147, 2, 27, "Output"] }, Closed]], Cell[CellGroupData[{ Cell[11635, 478, 82, 1, 29, "Input"], Cell[11720, 481, 132, 2, 27, "Output"] }, Closed]] }, Closed]] }, Closed]] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)