(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of 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[ 11687, 338]*) (*NotebookOutlinePosition[ 12399, 363]*) (* CellTagsIndexPosition[ 12355, 359]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[StyleBox[ "Plots of Miscellaneous Functions on Integers", "Title", FontFamily->"Times New Roman", FontSlant->"Italic", FontColor->RGBColor[1, 0, 1]]], "Section"], Cell[CellGroupData[{ Cell["Initialization", "Section", GeneratedCell->True, CellAutoOverwrite->True], Cell[BoxData[ \(<< \ Graphics`Polyhedra`\)], "Input"], Cell[BoxData[{ \(n1\ = \ 4; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*\ Machine\ word\ size\ for\ most\ plots\ 1, \ must\ be\ \(even . \)\ *) \n n2\ = \ 7; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*\ Machine\ word\ size\ for\ most\ plots\ 2\ \(\((must\ be\ \[GreaterEqual] \ n1)\) . \)\ *) \nn3\ = \ 6; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*\ Machine\ word\ size\ near\ n2, \ must\ be\ \(even . \)\ *) \nn4\ = \ 8; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (*\ Another\ machine\ word\ size, \ must\ be\ \(even . \)\ *) \nnn1\ = \ 2^n1; \nnn2\ = \ 2^n2; \n nn3\ = \ 2^n3; \nnn4\ = \ 2^n4; \n tn1\ = \ Table[i, \ {i, \ 0, \ n1, \ Ceiling[n1/4]}]; \n tn2\ = \ Table[i, \ {i, \ 0, \ n2, \ Ceiling[n2/4]}]; \n tn3\ = \ Table[i, \ {i, \ 0, \ n3, \ Ceiling[n3/4]}]; \n tn4\ = \ Table[i, \ {i, \ 0, \ n4, \ Ceiling[n4/4]}]; \n Off[General::spell]\), \(tnn1\ = \ Table[i, \ {i, \ 0, \ nn1, \ nn1/4}]; \n tnn2\ = \ Table[i, \ {i, \ 0, \ nn2, \ nn2/4}]; \n tnn3\ = \ Table[i, \ {i, \ 0, \ nn3, \ nn3/4}]; \n tnn4\ = \ Table[i, \ {i, \ 0, \ nn4, \ nn4/4}]; \)}], "Input"], Cell[BoxData[ \(\(\(SetOptions[Graphics3D, \ \ Axes -> True, \ AxesEdge -> {Automatic, \ {\(-1\), \ \(-1\)}, \ None}, \ AxesLabel -> {"\", \ "\", \ "\<\>"}, \ Boxed -> False, \ \ LightSources -> {{{1, 0, 1}, RGBColor[1, 0, 0]}, \ {{1, 1, 1}, RGBColor[0, 1, 0]}, \ {{0, 1, 1}, RGBColor[0, 0, 1]}\ , \ {{\(-2\), \(-1\), 1}, RGBColor[ .5, .5, 0]}}, \ PlotRange -> All, \ ViewPoint -> {\(-1.4\), \ \(-2.4\), 1.6}]; \)\ \)\)], "Input"], Cell[BoxData[ \(\(SetOptions[Plot, \ DisplayFunction -> Identity, \ PlotPoints -> 2\ nn2]; \)\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Bitwise XOR Function", "Section"], Cell[BoxData[ \(bxor[x_, \ y_]\ := \ FromDigits[ \((IntegerDigits[x, \ 2, \ n2]\ - \ IntegerDigits[y, \ 2, \ n2]) \)^2, \ 2]\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Gray Code Function", "Section"], Cell[BoxData[ \(Gray[x_]\ := \ bxor[Floor[x], \ Floor[x/2]]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[Gray[x], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[Gray[x], \ {x, \ 0, \ nn2 - .01}, \ Ticks -> {tnn2, \ tnn2}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"], Cell[BoxData[ \(StylePrint["\", \ "\"]\)], "Input"], Cell[BoxData[ \(Yarg[x_]\ := \ Module[{y\ = \ Floor[x], \ s\ = \ 1, \ t}, \n\t\t\ \ \ While[True, \n\t\t\t\ \ \ t\ = \ Floor[y/\((2^s)\)]; \n\t\t\t\t If\ [t\ == \ 0, \ Return[y]]; \n\t\t\t\ty\ = \ bxor[y, \ t]; \n \t\t\t\ts\ = \ 2 s]\n\t]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[Yarg[x], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, tnn1}]; \n p2\ = \ Plot[Yarg[x], \ {x, \ 0, \ nn2 - .01}, \ Ticks -> {tnn2, tnn2}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"], Cell[BoxData[ \(StylePrint[ "\", \ "\"]\)], "Input"], Cell[BoxData[ \(ntz[x_, \ n_]\ := Module[{k = 0}, \n\t\t Do\ [\n\t\t\tIf\ [EvenQ[Floor[x/\((2^i)\)]], \ k = k + 1, Break[]], \n \t\t\t{i, 0, n - 1}]; \n\t\tReturn[k]\n\t]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[ntz[x, \ n1], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tn1}]; \np2\ = \ Plot[ntz[x, \ n2], \ {x, \ 0, \ nn2 - .01}, \ Ticks -> {tnn2, \ tn2}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"], Cell[BoxData[ \(StylePrint["\", \ "\"]\)], "Input"], Cell[BoxData[ \(pop[x_]\ := Module[{k = 0, \ y = Floor[x]}, \n\t\t While\ [\(! \((y\ == \ 0)\)\), \n\t\t\tIf\ [OddQ[y], \ k = k + 1]; \n \t\t\ \ \ y\ = \ Floor[y/2]]; \n\t\tReturn[k]\n\t]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[pop[x], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tn1}]; \n p2\ = \ Plot[pop[x], \ {x, \ 0, \ nn2 - .01}, \ Ticks -> {tnn2, \ tn2}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Bit Reversal Function", "Section"], Cell[BoxData[ \(rev[x_, \ n_]\ := \ FromDigits[Reverse[IntegerDigits[Floor[x], 2, n]], \ 2]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[rev[x, \ n1], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[rev[x, \ n2], \ {x, \ 0, \ nn2 - .01}, \ Ticks -> {tnn2, \ tnn2}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Outer Perfect Shuffle Function", "Section"], Cell[BoxData[ \(oshuf[x_, \ n_]\ := \ If[EvenQ[Floor[x]], \ Floor[x/2], \ Floor[\((x - 1 + n)\)/2]]\)], "Input"], Cell[BoxData[ \(m\ = \ nn1; \n p1\ = \ Plot[oshuf[x, \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[oshuf[oshuf[x, \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p3\ = \ Plot[oshuf[oshuf[oshuf[x, \ m], \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n Show[GraphicsArray[{\ p1, \ p2, \ p3}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Inner Perfect Shuffle Function", "Section"], Cell[BoxData[ \(ishuf[x_, \ n_]\ := \ If[EvenQ[Floor[x]], \ Floor[\((x + n)\)/2], \ Floor[\((x - 1)\)/2]]\)], "Input"], Cell[BoxData[ \(m\ = \ nn1; \n p1\ = \ Plot[ishuf[x, \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[ishuf[ishuf[x, \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p3\ \ = Plot[ishuf[ishuf[ishuf[x, \ m], \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n Show[GraphicsArray[{\ p1, \ p2, \ p3}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Outer Perfect Unshuffle Function", "Section"], Cell[BoxData[ \(ounshuf[x_, \ n_]\ := \ If[x < \ n/2, 2\ Floor[x], \ 2 Floor[x] - n + 1]\)], "Input"], Cell[BoxData[ \(m\ = \ nn1; \n p1\ = \ Plot[ounshuf[x, \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[ounshuf[ounshuf[x, \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p3\ = \ Plot[ounshuf[ounshuf[ounshuf[x, \ m], \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n Show[GraphicsArray[{\ p1, \ p2, \ p3}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Inner Perfect Unshuffle Function", "Section"], Cell[BoxData[ \(iunshuf[x_, \ n_]\ := \ If[x < \ n/2, 2\ Floor[x] + 1, \ 2 Floor[x] - n]\)], "Input"], Cell[BoxData[ \(m\ = \ nn1; \n p1\ = \ Plot[iunshuf[x, \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[iunshuf[iunshuf[x, \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p3\ = \ Plot[iunshuf[iunshuf[iunshuf[x, \ m], \ m], \ m], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n Show[GraphicsArray[{\ p1, \ p2, \ p3}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Outer Perfect Shuffle Bits Function", "Section"], Cell["\<\ By the 'shuffle bits' function we mean the shuffle function applied to the \ bits of an integer (that's represented in binary), and the resulting shuffled \ bit string reinterpreted as an integer. Informally,\ \>", "Text", GeneratedCell->True, CellAutoOverwrite->True], Cell["shufflebits(x, n) = AsInteger(shuffle(bits(x, n)))", "Text", GeneratedCell->True, CellAutoOverwrite->True, TextAlignment->Center], Cell[BoxData[ \(oshufbits[x_, \ n_]\ := \ Module[{b, \ r}, \[IndentingNewLine]b\ = \ IntegerDigits[Floor[x], \ 2, \ n]; \[IndentingNewLine]r\ = \ b; \[IndentingNewLine]Do[r[\([2 i - 1]\)]\ = \ b[\([i]\)]; \[IndentingNewLine]r[\([2 i]\)]\ = \ b[\([i + n/2]\)], \[IndentingNewLine]{i, \ 1, \ n/2}]; \[IndentingNewLine]Return[FromDigits[r, \ 2]]\[IndentingNewLine]]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[oshufbits[x, \ n1], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[oshufbits[x, \ n4], \ {x, \ 0, \ nn4 - .01}, \ Ticks -> {tnn4, \ tnn4}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plots of the Inner Perfect Shuffle Bits Function", "Section"], Cell[BoxData[ \(ishufbits[x_, \ n_]\ := \ Module[{b, \ r}, \[IndentingNewLine]b\ = \ IntegerDigits[Floor[x], \ 2, \ n]; \[IndentingNewLine]r\ = \ b; \[IndentingNewLine]Do[r[\([2 i - 1]\)]\ = \ b[\([i + n/2]\)]; \[IndentingNewLine]r[\([2 i]\)]\ = \ b[\([i]\)], \[IndentingNewLine]{i, \ 1, \ n/2}]; \[IndentingNewLine]Return[FromDigits[r, \ 2]]\[IndentingNewLine]]\)], "Input"], Cell[BoxData[ \(p1\ = \ Plot[ishufbits[x, \ n1], \ {x, \ 0, \ nn1 - .01}, \ Ticks -> {tnn1, \ tnn1}]; \n p2\ = \ Plot[ishufbits[x, \ n4], \ {x, \ 0, \ nn4 - .01}, \ Ticks -> {tnn4, \ tnn4}]; \nShow[GraphicsArray[{\ p1, \ p2}]]; \)], "Input"] }, Open ]] }, FrontEndVersion->"Microsoft Windows 3.0", ScreenRectangle->{{0, 1280}, {0, 943}}, WindowSize->{636, 673}, WindowMargins->{{17, Automatic}, {Automatic, 9}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic} ] (*********************************************************************** 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[1709, 49, 181, 4, 118, "Section"], Cell[CellGroupData[{ Cell[1915, 57, 83, 2, 53, "Section"], Cell[2001, 61, 57, 1, 30, "Input"], Cell[2061, 64, 1180, 21, 350, "Input"], Cell[3244, 87, 509, 9, 110, "Input"], Cell[3756, 98, 117, 2, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[3910, 105, 39, 0, 53, "Section"], Cell[3952, 107, 170, 4, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4159, 116, 50, 0, 53, "Section"], Cell[4212, 118, 77, 1, 30, "Input"], Cell[4292, 121, 250, 5, 70, "Input"], Cell[4545, 128, 114, 2, 30, "Input"], Cell[4662, 132, 299, 5, 150, "Input"], Cell[4964, 139, 246, 5, 70, "Input"], Cell[5213, 146, 136, 3, 30, "Input"], Cell[5352, 151, 213, 4, 130, "Input"], Cell[5568, 157, 258, 5, 70, "Input"], Cell[5829, 164, 113, 2, 30, "Input"], Cell[5945, 168, 232, 4, 130, "Input"], Cell[6180, 174, 246, 5, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6463, 184, 53, 0, 53, "Section"], Cell[6519, 186, 116, 2, 30, "Input"], Cell[6638, 190, 269, 6, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6944, 201, 62, 0, 53, "Section"], Cell[7009, 203, 127, 3, 30, "Input"], Cell[7139, 208, 427, 8, 130, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7603, 221, 62, 0, 53, "Section"], Cell[7668, 223, 133, 3, 30, "Input"], Cell[7804, 228, 427, 8, 130, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8268, 241, 64, 0, 53, "Section"], Cell[8335, 243, 114, 2, 30, "Input"], Cell[8452, 247, 439, 8, 130, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8928, 260, 64, 0, 53, "Section"], Cell[8995, 262, 114, 2, 30, "Input"], Cell[9112, 266, 439, 8, 130, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[9588, 279, 67, 0, 53, "Section"], Cell[9658, 281, 283, 6, 52, "Text"], Cell[9944, 289, 141, 3, 33, "Text"], Cell[10088, 294, 454, 9, 170, "Input"], Cell[10545, 305, 281, 6, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10863, 316, 67, 0, 53, "Section"], Cell[10933, 318, 454, 9, 170, "Input"], Cell[11390, 329, 281, 6, 70, "Input"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)