(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; keywords = "CForm, FortranForm, TeXForm, FullForm, TreeForm, InputForm, Short, TableForm, MatrixForm, Files`writing, File`reading, File`output, File`append, File`display, Save, Encode, Get, Files`finding, Files`manipulating, Directory, SetDirectory, FileNames, Copy, ReNameFile, DeleteFile, FileDate, FindList, Files`reading`data, ReadList, Files`splicing, Splice, Date, TimeZone, AbsoluteTime, SessionTime, TimeUsed, Timing, Strings`manipulating, StringLength, StringJoin, StringReverse, StringTake, StringDrop, StringInsert, StringPosition, StringReplace, Characters, Sort, Strings`searching, Strings`reading, Character, Word"; fontset = title, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeTitle, M7, bold, e8, 24, "Helvetica"; fontset = subtitle, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeTitle, M7, bold, italic, e6, 24, "Helvetica"; fontset = subsubtitle, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeTitle, M7, italic, e50, 24, "Helvetica"; fontset = section, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeSection, blackBox, M22, bold, a20, 18, "Helvetica"; fontset = subsection, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeSection, grayBox, M19, bold, a15, 14, "Helvetica"; fontset = subsubsection, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakBelow, nohscroll, noKeepOnOnePage, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Helvetica"; fontset = text, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M17, 14, "Times"; fontset = smalltext, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M61, 14, "Times"; fontset = input, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, N23, bold, B65535, 12, "Courier"; fontset = output, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, N23, R17381, G28866, B53247, L-5, 12, "Courier"; fontset = message, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = print, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = info, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, evaluateAsCurrentKernel, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l37, w282, h287, 12, "Courier"; fontset = name, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; fontset = header, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, right, M7, 12, "Palatino"; fontset = leftheader, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, nohscroll, L2, 12, "Palatino"; fontset = footer, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, 12, "Palatino"; fontset = leftfooter, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, center, L2, 12, "Palatino"; fontset = help, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Geneva"; fontset = clipboard, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "New York"; fontset = completions, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Courier"; fontset = special1, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, grayDot, M19, N7, bold, 12, "Helvetica"; fontset = special2, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M18, bold, 12, "Courier"; fontset = special3, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M18, bold, 12, "Helvetica"; fontset = special4, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Palatino"; fontset = special5, Text, formatAsCurrentKernel, evaluateAsCurrentKernel, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Palatino"; paletteColors = 128; automaticGrouping; ] :[font = title; inactive; preserveAspect; startGroup] System Operations :[font = section; inactive; Cclosed; preserveAspect; startGroup] Index :[font = text; inactive; dontPreserveAspect] This index gives a list of keywords that are associated with various cells in this Notebook. If you Command-Double-click one of the keywords below, Mathematica will find the cell associated with that keyword, select it, and display it in the center of your window. ;[s] 3:0,0;149,1;160,0;268,-1; 2:2,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = smalltext; inactive; preserveAspect; endGroup] AbsoluteTime CForm Character Characters Copy Date DeleteFile Directory Encode File`append File`display File`output File`reading FileDate FileNames Files`finding Files`manipulating Files`reading`data Files`splicing Files`writing FindList FortranForm FullForm Get InputForm MatrixForm ReadList ReNameFile Save SessionTime SetDirectory Short Sort Splice StringDrop StringInsert StringJoin StringLength StringPosition StringReplace StringReverse Strings`manipulating Strings`reading Strings`searching StringTake TableForm TeXForm TimeUsed TimeZone Timing TreeForm Word :[font = section; inactive; Cclosed; preserveAspect; startGroup] Special Output Forms :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see pages 182 and 343) :[font = special2; inactive; preserveAspect; keywords = "CForm"] CForm :[font = smalltext; inactive; preserveAspect] CForm[expr ] writes out expr in a form that can be used in a C program. ;[s] 7:0,1;6,2;10,0;11,1;12,0;24,2;28,0;73,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "FortranForm"] FortranForm :[font = smalltext; inactive; preserveAspect] FortranForm[expr ]writes out expr for Fortran. ;[s] 7:0,1;12,2;16,0;17,1;18,0;29,2;33,0;48,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "TeXForm"] TeXForm :[font = smalltext; inactive; preserveAspect] TeXForm[expr ] writes out expr in TeX input form. ;[s] 7:0,1;8,2;12,0;13,1;14,0;26,2;30,0;51,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "FullForm"] FullForm :[font = smalltext; inactive; preserveAspect] FullForm[expr ] gives the explicit form of expr in functional notation. ;[s] 7:0,1;9,2;13,0;14,1;15,0;44,2;48,0;74,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "TreeForm"] TreeForm :[font = smalltext; inactive; preserveAspect] TreeForm[expr ] gives a representation of the expression tree for expr. ;[s] 7:0,1;9,2;13,0;14,1;15,0;66,2;70,0;72,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "InputForm"] InputForm :[font = smalltext; inactive; preserveAspect] InputForm[expr ] gives a one-dimensional form suitable for input to Mathematica. ;[s] 7:0,2;10,1;14,0;15,2;16,0;68,1;79,0;81,-1; 3:3,16,12,Times,0,14,0,0,0;2,16,12,Times,2,14,0,0,0;2,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Short"] Short :[font = smalltext; inactive; preserveAspect] Short[expr ] shows a one-line outline of expr. ;[s] 7:0,1;6,2;10,0;11,1;12,0;41,2;45,0;47,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "TableForm"] TableForm :[font = smalltext; inactive; preserveAspect] TableForm[list ] prints the list in tabular form. ;[s] 4:0,1;10,2;15,1;16,0;50,-1; 3:1,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "MatrixForm"] MatrixForm :[font = smalltext; inactive; preserveAspect; endGroup] MatrixForm[list ] prints the list in matrix form. ;[s] 5:0,1;11,2;15,0;16,1;17,0;50,-1; 3:2,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using TeXForm ;[s] 3:0,0;6,1;13,0;14,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] TeXForm[ x^5 / 7 + y^3 - Log[y] ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] {{{x^5}}\over 7} + {y^3} - \log (y) ;[o] {{{x^5}}\over 7} + {y^3} - \log (y) :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using CForm ;[s] 3:0,0;6,1;11,0;12,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] CForm[ x^5 / 7 + y^3 - Log[y] ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] Power(x,5)/7 + Power(y,3) - Log(y) ;[o] Power(x,5)/7 + Power(y,3) - Log(y) :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using FortranForm ;[s] 3:0,0;6,1;17,0;18,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] FortranForm[ x^5 / 7 + y^3 - Log[y] ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] x**5/7 + y**3 - Log(y) ;[o] x**5/7 + y**3 - Log(y) :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using FullForm ;[s] 3:0,0;6,1;14,0;15,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] FullForm[ x^2 / 3 + 1 / y^2 ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] FullForm[x^2/3 + y^(-2)] ;[o] Plus[Times[Rational[1, 3], Power[x, 2]], Power[y, -2]] :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using TreeForm ;[s] 3:0,0;6,1;14,0;15,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] TreeForm[ x^2 / 3 + 1 / y^2 ] :[font = output; output; inactive; preserveAspect; fontLeading = 0; endGroup; endGroup] TreeForm[x^2/3 + y^(-2)] ;[o] Plus[| , | ] Times[| , | ] Power[y, -2] Rational[1, 3] Power[x, 2] :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] A Note on FullForm and TreeForm ;[s] 5:0,0;10,1;18,0;23,1;31,0;32,-1; 2:3,14,10,Helvetica,1,12,0,0,0;2,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect; endGroup] In most output formats, the way Mathematica prints a particular expression often bears little relation to the way in which it stores that expression internally. For most purposes, you never need to know exactly how an expression is stored. But if you want to manipulate the structure of an expression, particularly as part of a progam, you may need to see what its internal form is. You can do this using an output format such as FullForm or TreeForm. ;[s] 7:0,0;32,1;43,0;433,2;441,0;445,2;453,0;455,-1; 3:4,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;2,13,10,Courier,1,12,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using InputForm ;[s] 3:0,0;6,1;15,0;16,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] InputForm allows you to generate a textual form for any Mathematica expression, suitable for editing or other kinds of textual manipulation. Note that in a Mathematica notebook you can typically switch between output form and input form versions of a particular cell by choosing the "formatted" and "unformatted" options for the cell. ;[s] 6:0,2;9,0;56,1;67,0;157,1;168,0;337,-1; 3:3,16,12,Times,0,14,0,0,0;2,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] x^4 / 4 + 1 / y^2 :[font = output; output; inactive; preserveAspect; endGroup] x^4/4 + y^(-2) ;[o] 4 x -2 -- + y 4 :[font = input; Cclosed; preserveAspect; startGroup] InputForm[%] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] InputForm[x^4/4 + y^(-2)] ;[o] x^4/4 + y^(-2) :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using Short ;[s] 3:0,0;6,1;11,0;12,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] The second input shows how to use Short in a "postfix form". ;[s] 3:0,0;34,1;39,0;61,-1; 2:2,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] Short[ Expand[(1 + x + y)^12]] :[font = output; output; inactive; preserveAspect; endGroup] Short["<<>>"] ;[o] 2 12 1 + 12 x + 66 x + <<87>> + y :[font = input; Cclosed; preserveAspect; startGroup] Expand[(1 + x + y)^12] // Short :[font = output; output; inactive; preserveAspect; endGroup; endGroup] Short["<<>>"] ;[o] 2 12 1 + 12 x + 66 x + <<87>> + y :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using TableForm ;[s] 3:0,0;6,1;15,0;16,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; preserveAspect] tab = Table[(i + 45)^j, {i, 3}, {j, 3}]; :[font = input; Cclosed; preserveAspect; startGroup] TableForm[tab] :[font = output; output; inactive; preserveAspect; fontLeading = 0; endGroup; endGroup] TableForm[{{46, 2116, 97336}, {47, 2209, 103823}, {48, 2304, 110592}}] ;[o] 46 2116 97336 47 2209 103823 48 2304 110592 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using MatrixForm ;[s] 3:0,0;6,1;16,0;17,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] MatrixForm displays the list as a matrix, in which each "cell" has the same size. ;[s] 2:0,1;10,0;82,-1; 2:1,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; preserveAspect] tab = Table[(i + 45)^j, {i, 3}, {j, 3}]; :[font = input; Cclosed; preserveAspect; startGroup] MatrixForm[tab] :[font = output; output; inactive; preserveAspect; fontLeading = 0; endGroup; endGroup; endGroup] MatrixForm[{{46, 2116, 97336}, {47, 2209, 103823}, {48, 2304, 110592}}] ;[o] 46 2116 97336 47 2209 103823 48 2304 110592 :[font = section; inactive; Cclosed; preserveAspect; startGroup] Working with External Files :[font = text; inactive; preserveAspect; fontSize = 12] Note: Some of these examples are for demonstration purposes only; they are machine-specific, and will yield different output (or none) on your computer. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; keywords = "Files`writing"] Reading and Writing Mathematica Files ;[s] 3:0,0;20,1;31,0;39,-1; 2:2,15,11,Helvetica,1,14,0,0,0;1,15,11,Helvetica,3,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see pages 178 and 477) :[font = special3; inactive; preserveAspect; keywords = "File`reading"] Read in a File :[font = smalltext; inactive; preserveAspect] <> filename outputs expr to a file as plain text. ;[s] 8:0,1;4,0;6,2;8,0;9,1;17,0;29,1;33,0;60,-1; 3:4,16,12,Times,0,14,0,0,0;3,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special3; inactive; preserveAspect; keywords = "File`append"] Append a File :[font = smalltext; inactive; preserveAspect] expr >>> filename appends expr to a file. ;[s] 8:0,1;4,0;6,2;9,0;10,1;18,0;30,1;34,0;47,-1; 3:4,16,12,Times,0,14,0,0,0;3,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special3; inactive; preserveAspect; keywords = "File`display"] Display a File :[font = smalltext; inactive; preserveAspect] !!filename displays the contents of a plain text file. ;[s] 3:0,2;2,1;10,0;58,-1; 3:1,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Save"] Save :[font = smalltext; inactive; preserveAspect] Save["filename ", f, g, ...] saves definitions for variables or functions in a file. ;[s] 12:0,2;6,1;15,2;17,0;18,1;19,2;20,0;21,1;22,2;23,0;27,2;28,0;87,-1; 3:4,16,12,Times,0,14,0,0,0;3,16,12,Times,2,14,0,0,0;5,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Encode, Get"] Encode :[font = smalltext; inactive; preserveAspect] Encode["source ","dest "] writes an encoded version of the file source to the file dest . ;[s] 10:0,2;8,1;14,0;15,2;18,1;22,0;23,2;25,0;85,1;90,0;92,-1; 3:4,16,12,Times,0,14,0,0,0;3,16,12,Times,2,14,0,0,0;3,13,10,Courier,1,12,0,0,0; :[font = smalltext; inactive; preserveAspect] <> tmp :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] !!tmp :[font = print; inactive; wordwrap; preserveAspect; endGroup] x^3 + 3*x^2*y + 3*x*y^2 + y^3 :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] <>> tmp :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] !!tmp :[font = print; inactive; wordwrap; preserveAspect; endGroup; endGroup] x^3 + 3*x^2*y + 3*x*y^2 + y^3 x^4 + 4*x^3*y + 6*x^2*y^2 + 4*x*y^3 + y^4 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Input from a File :[font = text; inactive; preserveAspect] It is sometimes useful to prepare input in an external file using a text editor and then read in the file. The first line shows the contents of the file gdef and the second line inputs this file into Mathematica. ;[s] 6:0,0;153,2;157,1;158,0;200,1;211,0;213,-1; 3:3,16,12,Times,0,14,0,0,0;2,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] !!gdef :[font = print; inactive; preserveAspect; endGroup] g[x_] := Cos[x^2] + Sin[x^3]/Tan[7*x] :[font = input; wordwrap; preserveAspect] <> tmp2 :[font = input; wordwrap; preserveAspect] Encode["tmp2", "tmp2.x"] :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] !!tmp2.x :[font = print; inactive; wordwrap; preserveAspect; endGroup] (*!1N!*)mcm _QZ9tcI1cfre*Wo8:) P :[font = input; Cclosed; wordwrap; preserveAspect; startGroup] < True] reads numbers from a file, making a separate list for each line in the file. ;[s] 6:0,1;10,2;19,1;21,0;22,1;50,0;128,-1; 3:2,16,12,Times,0,14,0,0,0;3,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Reading a List of Numbers :[font = text; inactive; preserveAspect] The first line displays the contents of the file numbers.data. ;[s] 3:0,0;49,1;61,0;63,-1; 2:2,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] !!numbers.data :[font = print; inactive; preserveAspect; endGroup] 56.5 -23 14 23 78 12.78 :[font = input; Cclosed; preserveAspect; startGroup] ReadList["numbers.data", Number] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] ;[o] {56.5, -23, 14, 23, 78, 12.78} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Reading Pairs of Numbers :[font = input; Cclosed; preserveAspect; startGroup] ReadList["numbers.data", {Number, Number}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] ;[o] {{56.5, -23}, {14, 23}, {78, 12.78}} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Making Each Line a Separate List :[font = input; Cclosed; preserveAspect; startGroup] ReadList["numbers.data", Number, RecordLists -> True ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup] ;[o] {{56.5, -23, 14}, {23, 78, 12.78}} :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; keywords = "Files`splicing"] Splicing into External Files :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see pages 184 :[font = smalltext; inactive; preserveAspect; endGroup; keywords = "Splice"] Splice["infile ", "outfile "] splices Mathematica output into infile , sending the output to outfile . ;[s] 16:0,2;8,1;14,0;15,2;17,3;18,2;19,1;26,0;27,2;29,0;38,1;49,0;63,1;70,0;94,1;102,0;105,-1; 4:6,16,12,Times,0,14,0,0,0;5,16,12,Times,2,14,0,0,0;4,13,10,Courier,1,12,0,0,0;1,13,9,Times,0,12,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using Splice ;[s] 2:0,0;6,1;13,-1; 2:1,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] The file extension .mtex causes the Mathematica output to be put in a form suitable for input into the TeX typesetting system (see note below). ;[s] 5:0,0;20,2;26,0;37,1;48,0;147,-1; 3:3,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] !!paper.mtex :[font = print; inactive; preserveAspect; endGroup] if we compute <* Integrate[Sin[x]^2, x] *> we see that .... :[font = input; Cclosed; preserveAspect; startGroup] Splice["paper.mtex"] :[font = output; output; inactive; preserveAspect; endGroup] ;[o] paper.mtex :[font = input; Cclosed; preserveAspect; startGroup] !!paper.tex :[font = print; inactive; preserveAspect; endGroup; endGroup] if we compute {x\over 2} - {{\sin (2\,x)}\over 4} we see that .... :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] A Note on Splice :[font = text; inactive; preserveAspect; endGroup; endGroup; endGroup] Text in the input file not enclosed between <* and *> is copied without change to the output file. Text between <* and *> is treated as Mathematica input and is evaluated. The default format for Mathematica output is determined by the extension of the input file name: name .mc gives output formated by CForm, name .mf by FortranForm, and name .mtex by TeXForm. ;[s] 31:0,0;45,3;47,0;52,2;53,3;55,0;116,3;118,0;124,3;126,0;142,1;153,0;202,1;213,0;277,1;282,3;285,0;311,3;316,0;318,1;322,4;323,3;326,0;330,3;341,0;347,1;351,4;352,3;357,0;362,3;369,0;371,-1; 5:13,16,12,Times,0,14,0,0,0;5,16,12,Times,2,14,0,0,0;1,15,11,Courier,1,14,0,0,0;10,13,10,Courier,1,12,0,0,0;2,13,10,Courier,3,12,0,0,0; :[font = section; inactive; Cclosed; preserveAspect; startGroup] Date and Time Functions :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see page 523) :[font = special2; inactive; preserveAspect; keywords = "Date"] Date :[font = smalltext; inactive; preserveAspect] Date[ ] gives the current local date and time in the form {year, month, day, hour, minute, second }. ;[s] 22:0,1;7,0;63,1;64,2;68,1;69,0;70,2;75,1;76,0;77,2;80,1;81,0;82,2;86,1;87,0;88,2;94,1;95,0;96,2;102,0;103,1;104,0;106,-1; 3:8,16,12,Times,0,14,0,0,0;8,13,10,Courier,1,12,0,0,0;6,16,12,Times,2,14,0,0,0; :[font = smalltext; inactive; preserveAspect] Date[z ] gives the current date and time in time zone z . ;[s] 7:0,1;5,2;6,0;7,1;8,0;54,2;56,0;58,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "TimeZone"] TimeZone :[font = smalltext; inactive; preserveAspect] TimeZone[ ] gives the time zone assumed by your computer. ;[s] 2:0,1;11,0;58,-1; 2:1,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "AbsoluteTime"] AbsoluteTime :[font = smalltext; inactive; preserveAspect] AbsoluteTime[ ] gives the total number of seconds since the beginning of January 1, 1900. ;[s] 2:0,1;15,0;90,-1; 2:1,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "SessionTime"] SessionTime :[font = smalltext; inactive; preserveAspect] SessionTime[ ] gives the total number of seconds elapsed since the beginning of your Mathematica session. ;[s] 4:0,2;14,0;85,1;96,0;107,-1; 3:2,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "TimeUsed"] TimeUsed :[font = smalltext; inactive; preserveAspect] TimeUsed[ ] gives the total number of seconds used in your current Mathematica session. ;[s] 4:0,2;11,0;67,1;78,0;89,-1; 3:2,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Timing"] Timing :[font = smalltext; inactive; preserveAspect; endGroup] Timing[expr ] evaluates expr , and returns a list of the CPU time needed, together with the result obtained. ;[s] 7:0,1;7,2;11,0;12,1;13,0;24,2;29,0;109,-1; 3:3,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using Date ;[s] 3:0,0;6,1;10,0;12,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] Date[ ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] {1993, 6, 1, 13, 5, 50} ;[o] {1993, 6, 1, 13, 5, 50} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using TimeZone ;[s] 3:0,0;6,1;14,0;15,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] TimeZone[ ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] -5 ;[o] -5 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] The Date in Another Time Zone :[font = text; inactive; preserveAspect] This gives the current time and date in time zone +9, the time zone for Japan. :[font = input; Cclosed; preserveAspect; startGroup] Date[9] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] {1993, 6, 2, 3, 10, 38} ;[o] {1993, 6, 2, 3, 10, 38} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using AbsoluteTime ;[s] 3:0,0;6,1;18,0;19,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] AbsoluteTime[ ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] 2.947929047190995*10^9 ;[o] 9 2.947929047190995 10 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using SessionTime ;[s] 3:0,0;6,1;17,0;18,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] SessionTime[ ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] 7743.854195 ;[o] 7743.854195 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using TimeUsed ;[s] 3:0,0;6,1;14,0;15,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] TimeUsed[ ] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] 99.6 ;[o] 99.6 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using Timing ;[s] 3:0,0;6,1;12,0;13,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that the semicolon causes the result of the calculation to be given as Null. ;[s] 3:0,0;76,1;80,0;82,-1; 2:2,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] Timing[ 1000!;] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup] {0.3166666666666629*Second, Null} ;[o] {0.316667 Second, Null} :[font = section; inactive; Cclosed; preserveAspect; startGroup] Operations on Strings :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; keywords = "Strings`manipulating"] Manipulating Strings :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see page 376) :[font = special2; inactive; preserveAspect; keywords = "StringLength"] StringLength :[font = smalltext; inactive; preserveAspect] StringLength[s ] gives the number of characters in a string. ;[s] 5:0,1;13,2;14,0;15,1;16,0;61,-1; 3:2,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringJoin"] StringJoin :[font = smalltext; inactive; preserveAspect] s1 <> s2 <> ... or StringJoin[s1, s2, ...] joins several strings together. ;[s] 17:0,2;2,0;4,1;7,0;8,2;10,0;12,1;14,0;24,1;35,2;37,1;38,0;39,2;41,1;42,0;46,1;47,0;82,-1; 3:7,16,12,Times,0,14,0,0,0;6,13,10,Courier,1,12,0,0,0;4,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringReverse"] StringReverse :[font = smalltext; inactive; preserveAspect] StringReverse[s ] reverses the characters in a string. ;[s] 5:0,1;14,2;15,0;16,1;18,0;56,-1; 3:2,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringTake"] StringTake :[font = smalltext; inactive; preserveAspect] StringTake[s, n ] makes a string by taking the first n characters from s . ;[s] 12:0,1;11,2;12,1;13,0;14,2;15,0;16,1;17,0;55,2;56,0;74,2;75,0;78,-1; 3:5,16,12,Times,0,14,0,0,0;3,13,10,Courier,1,12,0,0,0;4,16,12,Times,2,14,0,0,0; :[font = smalltext; inactive; preserveAspect] StringTake[s, {n }] takes the n th character of s . ;[s] 13:0,1;11,2;12,1;13,0;14,1;15,2;16,0;17,1;19,0;32,2;33,0;50,2;51,0;54,-1; 3:5,16,12,Times,0,14,0,0,0;4,13,10,Courier,1,12,0,0,0;4,16,12,Times,2,14,0,0,0; :[font = smalltext; inactive; preserveAspect] StringTake[s, {n1, n2 }] takes characters n1 to n2 . ;[s] 16:0,1;11,2;12,1;13,0;14,1;15,2;17,1;18,0;19,2;21,0;22,1;24,0;44,2;46,0;51,2;53,0;56,-1; 3:6,16,12,Times,0,14,0,0,0;5,13,10,Courier,1,12,0,0,0;5,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringDrop"] StringDrop :[font = smalltext; inactive; preserveAspect] StringDrop[s, n ] makes a string by dropping the first n characters in s . ;[s] 12:0,1;11,2;12,1;13,0;14,2;15,0;16,1;17,0;58,2;59,0;75,2;77,0;79,-1; 3:5,16,12,Times,0,14,0,0,0;3,13,10,Courier,1,12,0,0,0;4,16,12,Times,2,14,0,0,0; :[font = smalltext; inactive; preserveAspect] StringDrop[ s, {n1, n2 }] drops characters n1 through n2 . ;[s] 17:0,1;11,0;12,2;13,1;14,0;15,1;16,2;18,1;19,0;20,2;22,0;23,1;25,0;44,2;46,0;56,2;58,0;61,-1; 3:7,16,12,Times,0,14,0,0,0;5,13,10,Courier,1,12,0,0,0;5,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringInsert"] StringInsert :[font = smalltext; inactive; preserveAspect] StringInsert[s, snew, n] inserts the string snew at position n . ;[s] 14:0,1;13,2;14,1;15,0;16,2;20,1;21,0;22,2;23,1;24,0;44,2;48,0;61,2;62,0;65,-1; 3:5,16,12,Times,0,14,0,0,0;4,13,10,Courier,1,12,0,0,0;5,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringPosition"] StringPosition :[font = smalltext; inactive; preserveAspect] StringPosition[s, sub ] gives a list of the starting and ending positions at which sub appears as a substring of s . ;[s] 12:0,1;15,2;16,1;17,0;18,2;21,0;22,1;23,0;85,2;88,0;116,2;117,0;120,-1; 3:5,16,12,Times,0,14,0,0,0;3,13,10,Courier,1,12,0,0,0;4,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "StringReplace"] StringReplace :[font = smalltext; inactive; preserveAspect] StringReplace[s, {s1 -> sp1, s2 -> sp2, ...}] replaces the si by the corresponding spi whenever they occur as substrings of s . ;[s] 27:0,1;14,2;15,1;16,0;17,1;18,2;20,0;21,1;23,0;24,2;27,1;28,0;29,2;31,0;32,1;34,0;35,2;38,1;39,0;43,1;45,0;60,2;62,0;85,2;89,0;127,2;129,0;131,-1; 3:11,16,12,Times,0,14,0,0,0;8,13,10,Courier,1,12,0,0,0;8,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Characters"] Characters :[font = smalltext; inactive; preserveAspect] Characters[s ] gives a list of the characters in a string. ;[s] 5:0,1;11,2;12,0;13,1;14,0;59,-1; 3:2,16,12,Times,0,14,0,0,0;2,13,10,Courier,1,12,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "Sort"] Sort :[font = smalltext; inactive; preserveAspect; endGroup] Sort[{s1, s2, ...}] sorts a list of strings into standard "dictionary" order. ;[s] 9:0,1;6,2;8,1;9,0;10,2;12,1;13,0;17,1;19,0;80,-1; 3:3,16,12,Times,0,14,0,0,0;4,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Joining Strings :[font = input; Cclosed; preserveAspect; startGroup] "aaaa" <> "bbbbb" <> "ccccc" :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "aaaabbbbbccccc" ;[o] aaaabbbbbccccc :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringLength ;[s] 3:0,0;6,1;18,0;19,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" :[font = output; output; inactive; preserveAspect; endGroup] "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;[o] ABCDEFGHIJKLMNOPQRSTUVWXYZ :[font = input; Cclosed; preserveAspect; startGroup] StringLength[alpha] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] 26 ;[o] 26 :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringReverse ;[s] 3:0,0;6,1;19,0;20,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that alpha was defined in the previous example. ;[s] 3:0,0;10,1;15,0;53,-1; 2:2,16,12,Times,0,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] StringReverse[alpha] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "ZYXWVUTSRQPONMLKJIHGFEDCBA" ;[o] ZYXWVUTSRQPONMLKJIHGFEDCBA :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringTake ;[s] 3:0,0;6,1;16,0;17,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that negative positions are counted from the end of the string. :[font = input; Cclosed; preserveAspect; startGroup] StringTake[alpha, 5] :[font = output; output; inactive; preserveAspect; endGroup] "ABCDE" ;[o] ABCDE :[font = input; Cclosed; preserveAspect; startGroup] StringTake[alpha, {5}] :[font = output; output; inactive; preserveAspect; endGroup] "E" ;[o] E :[font = input; Cclosed; preserveAspect; startGroup] StringTake[alpha, {-10, -2}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "QRSTUVWXY" ;[o] QRSTUVWXY :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringDrop ;[s] 3:0,0;6,1;16,0;17,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that negative positions are counted from the end of the string. :[font = input; Cclosed; preserveAspect; startGroup] StringDrop[alpha, 5] :[font = output; output; inactive; preserveAspect; endGroup] "FGHIJKLMNOPQRSTUVWXYZ" ;[o] FGHIJKLMNOPQRSTUVWXYZ :[font = input; Cclosed; preserveAspect; startGroup] StringDrop[alpha, -5] :[font = output; output; inactive; preserveAspect; endGroup] "ABCDEFGHIJKLMNOPQRSTU" ;[o] ABCDEFGHIJKLMNOPQRSTU :[font = input; Cclosed; preserveAspect; startGroup] StringDrop[alpha, {10, 15}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "ABCDEFGHIPQRSTUVWXYZ" ;[o] ABCDEFGHIPQRSTUVWXYZ :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringInsert ;[s] 3:0,0;6,1;18,0;19,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that negative positions are counted from the end of the string. :[font = input; Cclosed; preserveAspect; startGroup] StringInsert[alpha, "XXX", 3] :[font = output; output; inactive; preserveAspect; endGroup] "ABXXXCDEFGHIJKLMNOPQRSTUVWXYZ" ;[o] ABXXXCDEFGHIJKLMNOPQRSTUVWXYZ :[font = input; Cclosed; preserveAspect; startGroup] StringInsert[alpha, "XXX", -3] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "ABCDEFGHIJKLMNOPQRSTUVWXXXXYZ" ;[o] ABCDEFGHIJKLMNOPQRSTUVWXXXXYZ :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringPosition ;[s] 3:0,0;6,1;20,0;21,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] newstr = "abcdabcdaabcabcd" :[font = output; output; inactive; preserveAspect; endGroup] "abcdabcdaabcabcd" ;[o] abcdabcdaabcabcd :[font = input; Cclosed; preserveAspect; startGroup] StringPosition[newstr, "abc"] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] {{1, 3}, {5, 7}, {10, 12}, {13, 15}} ;[o] {{1, 3}, {5, 7}, {10, 12}, {13, 15}} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Using StringReplace ;[s] 3:0,0;6,1;19,0;20,-1; 2:2,14,10,Helvetica,1,12,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect] Note that newstr was defined in the previous example. ;[s] 4:0,0;10,2;16,1;17,0;54,-1; 3:2,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0;1,13,10,Courier,1,12,0,0,0; :[font = input; Cclosed; preserveAspect; startGroup] StringReplace[newstr, {"a" -> "XX", "bc" -> "Y"}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "XXYdXXYdXXXXYXXYd" ;[o] XXYdXXYdXXXXYXXYd :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Converting a String to a List :[font = text; inactive; preserveAspect] In doing some kinds of string manipulation, you may find it useful to convert strings into lists of characters, and then perform operations on these lists. :[font = input; Cclosed; preserveAspect; startGroup] Characters["abcdefg"] :[font = output; output; inactive; preserveAspect; endGroup] {"a", "b", "c", "d", "e", "f", "g"} ;[o] {a, b, c, d, e, f, g} :[font = input; Cclosed; preserveAspect; startGroup] RotateLeft[%] :[font = output; output; inactive; preserveAspect; endGroup] {"b", "c", "d", "e", "f", "g", "a"} ;[o] {b, c, d, e, f, g, a} :[font = input; Cclosed; preserveAspect; startGroup] StringJoin[%] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] "bcdefga" ;[o] bcdefga :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Sorting a String :[font = input; Cclosed; preserveAspect; startGroup] Sort[{"cat", "fish", "catfish", "Cat"}] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup] {"cat", "Cat", "catfish", "fish"} ;[o] {cat, Cat, catfish, fish} :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; keywords = "Strings`searching, Strings`reading"] Searching and Reading Strings :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Syntax (see pages 494 and 504) :[font = special2; inactive; preserveAspect; keywords = "ReadList, Character, Word"] ReadList :[font = smalltext; inactive; preserveAspect] ReadList[file, Character] reads a sequence of characters from a file, and puts them in a Mathematica list. ;[s] 8:0,2;9,1;13,2;14,0;15,2;25,0;91,1;102,0;110,-1; 3:3,16,12,Times,0,14,0,0,0;2,16,12,Times,2,14,0,0,0;3,13,10,Courier,1,12,0,0,0; :[font = smalltext; inactive; preserveAspect] ReadList[file, Word] reads a sequence of words from a file, and puts them in a Mathematica list. ;[s] 8:0,2;9,1;13,2;14,0;15,2;20,0;81,1;92,0;100,-1; 3:3,16,12,Times,0,14,0,0,0;2,16,12,Times,2,14,0,0,0;3,13,10,Courier,1,12,0,0,0; :[font = special2; inactive; preserveAspect; keywords = "FindList"] FindList :[font = smalltext; inactive; preserveAspect; endGroup] FindList["file ", "text "] gives a list of all lines in a file that contain the specified text. ;[s] 6:0,1;10,2;15,1;19,2;24,1;26,0;98,-1; 3:1,16,12,Times,0,14,0,0,0;3,13,10,Courier,1,12,0,0,0;2,16,12,Times,2,14,0,0,0; :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Reading Characters from a File :[font = text; inactive; preserveAspect] The first line displays the contents of the file strings. :[font = input; Cclosed; preserveAspect; startGroup] !!strings :[font = print; inactive; preserveAspect; endGroup] Here is some text. And some more. A little more is possible. :[font = input; Cclosed; preserveAspect; startGroup] ReadList["strings", Character] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] ;[o] {H, e, r, e, , i, s, , s, o, m, e, , t, e, x, t, ., , A, n, d, , s, o, m, e, , m, o, r, e, ., , A, , l, i, t, t, l, e, , m, o, r, e, , i, s, , p, o, s, s, i, b, l, e, ., } :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Reading Words from a File :[font = input; Cclosed; preserveAspect; startGroup] ReadList["strings", Word] :[font = output; output; inactive; preserveAspect; endGroup; endGroup] ;[o] {Here, is, some, text., And, some, more., A, little, more, is, possible.} :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Finding Strings in a File :[font = input; Cclosed; preserveAspect; startGroup] FindList["strings", "is"] :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup; endGroup; endGroup] ;[o] {Here is some text., A little more is possible.} ^*)