(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. 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[ 24212, 774]*) (*NotebookOutlinePosition[ 24947, 800]*) (* CellTagsIndexPosition[ 24903, 796]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "The LocalPatterns package\n", StyleBox["By Ted Ersek\n ersektr@navair.navy.mil", FontSize->12] }], "Subtitle"], Cell[TextData[{ "One must be careful about using (lhs=rhs), (lhs\[Rule]rhs), (lhs^=rhs), or \ (f/:lhs=rhs) if a named pattern is in (lhs) and the pattern name is needed in \ (rhs). Named patterns can include (x_), (x__), (opts___), (m_:4) \ (j_Integer), (t_?Positive), (n_.) and many other forms. Methods of avoiding \ problems with ", Cell[BoxData[ \(TraditionalForm\`\((lhs = rhs)\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((lhs \[Rule] rhs)\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((lhs ^= rhs)\)\)]], ", ", Cell[BoxData[ \(TraditionalForm\`\((f /: lhs = rhs)\)\)]], " are presented below. One method of avoiding problems is to use functions \ RightArrow, DotEqual, HumpEqual, and LocalTagSet defined in the \ (LocalPatterns.m) package. Each of these functions are demonstrated below, \ but first you should put the LocalPatterns.m package in the ", Cell[BoxData[ \(TraditionalForm\`\(\(\\\)\(AddOns\)\)\\ExtraPackages\)]], " folder and evaluate the next cell." }], "Text", CellFrame->{{0, 0}, {0, 0.5}}], Cell[BoxData[ \(<< LocalPatterns.m\)], "Input"], Cell[CellGroupData[{ Cell["The BasicInput2 palette", "Subsubsection"], Cell[TextData[{ "The LocalPatterns package uses the special symbols (\[LongRightArrow] \ \[DotEqual] \[HumpEqual] \[VerticalSeparator] ). To assist with entering \ these symbols the BasicInput palette was modified to include a new row with \ buttons for these symbols. Below the row of buttons for ", Cell[BoxData[ \(TraditionalForm\`\((\(\(\[Equal]\)\(\ \ \)\(\[NotEqual]\)\(\ \ \)\(\ \[LessEqual]\)\(\ \ \)\(\[GreaterEqual]\)\)\(\ \ \)\(\[Element]\))\)\)]], " you will find a row of buttons for ", Cell[BoxData[ \(TraditionalForm\`\((\(\(\[LongRightArrow]\)\(\ \ \ \)\(\(\[DotEqual]\)\(\ \ \)\(\[HumpEqual]\)\)\)\ \ \[VerticalSeparator] \ \ \ \[Implies] )\)\)]], ". You can also move the mouse over many of the buttons in the BasicInput2 \ palette and the status area at the bottom of the palette will show the alias \ for the symbol the button would produce. Hence the palette can be used as a \ quick reference for the aliases of many symbols. Keep in mind a number of \ symbols have more than one alias, but I programmed the palette to show only \ one alias for each symbol. For example the status area shows that the alias \ for \[Eta] is \[EscapeKey]eta\[EscapeKey], but \[EscapeKey]et\[EscapeKey] \ and \[EscapeKey]h\[EscapeKey] are valid aliases for the same symbol. It may \ be that you prefer a different alias than the one I decided to display, and \ you can modify the source code for the BasicInput2 palette with a text editor \ if you like. If you store the BasicInput2 palette in the folder ", Cell[BoxData[ \(TraditionalForm\`\(\(\(/\)\(SystemFiles\)\)/FrontEnd\)/Palettes\)]], " you will be able to access it with the menu selection ", Cell[BoxData[ \(TraditionalForm\`\((File \[RightTriangle] Palettes)\)\)]], ". If you are sure you like the BasicInput2 palette better than the \ BasicInput palette, you can replace the original palette with the modified \ palette." }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Set and DotEqual with named patterns", "Subsubsection", CellFrame->{{0, 0}, {0, 0.5}}], Cell["\<\ In the next cell (=) has (x_) on the left and (x) on the right. This attempt \ to define the function doesn't work because the global value of (x) is \ substituted in the integral before the integral is evaluated. You could use \ delayed assignment (:=) instead, but that would be very inefficient because \ the symbolic integral would be derived each time (f) is evaluated.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(ClearAll[f]; x = 53.34;\), "\[IndentingNewLine]", \(f[x_] = Integrate[Log[\@x + 1], x]\)}], "Input"], Cell[BoxData[ \(Integrate::"ilim" \(\(:\)\(\ \)\) "Invalid integration variable or limit(s) in \!\(53.34`\) ."\)], \ "Message"], Cell[BoxData[ \(\[Integral]2.1166679423455217` \[DifferentialD]53.34`\)], "Output"] }, Open ]], Cell[TextData[{ "In practice you might assign a value to (x) early in a ", StyleBox["Mathematica", FontSlant->"Italic"], " session and forget about it. A practical solution to this problem is to \ clear any variables that might cause problems as in the next cell. This \ obviously requires a little thought in that the variables used for pattern \ names shouldn't have values that you care about." }], "Text"], Cell[BoxData[{ \(\(Clear[x];\)\), "\[IndentingNewLine]", \(\(f[x_] = Integrate[Log[\@x + 1], x];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?f\)\)], "Input"], Cell[BoxData[ \("Global`f"\)], "Print"], Cell[BoxData[ InterpretationBox[GridBox[{ {GridBox[{ {\(f[x_] = \@x - x\/2 - Log[1 + \@x] + x\ Log[1 + \@x]\)} }, GridBaseline->{Baseline, {1, 1}}, ColumnWidths->0.999, ColumnAlignments->{Left}]} }, GridBaseline->{Baseline, {1, 1}}, ColumnAlignments->{Left}], Definition[ f], Editable->False]], "Print"] }, Open ]], Cell["\<\ Instead of using the solution above you can load the package \ (LocalPatterns.m) and use the function DotEqual which gives the desired \ result without clearing the values of any variables. The cells below show \ the usage message of DotEqual, and demonstrate that it stores the intended \ definition for (f) without clearing the global value of x.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?DotEqual\)\)], "Input"], Cell[BoxData[ \("lhs\[DotEqual]rhs evaluates rhs using a local environment for any \ variable used as a pattern in lhs. From then on lhs is replaced by the \ result of evaluating rhs whenever lhs appears. The infix operator \[DotEqual] \ is entered as \\[DotEqual]. The expression lhs\[DotEqual]rhs, has an \ equivalent form LocalSet[lhs,rhs]."\)], "Print"] }, Open ]], Cell[BoxData[{ \(\(Clear[f];\)\), "\[IndentingNewLine]", \(\(x = 53.54;\)\), "\[IndentingNewLine]", \(f[x_] \[DotEqual] Integrate[Log[\@x + 1], x]\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?f\)\)], "Input"], Cell[BoxData[ \("Global`f"\)], "Print"], Cell[BoxData[ InterpretationBox[GridBox[{ {GridBox[{ {\(f[x_] := \@x - x\/2 - Log[1 + \@x] + x\ Log[1 + \@x]\)} }, GridBaseline->{Baseline, {1, 1}}, ColumnWidths->0.999, ColumnAlignments->{Left}]} }, GridBaseline->{Baseline, {1, 1}}, ColumnAlignments->{Left}], Definition[ f], Editable->False]], "Print"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\)], "Input"], Cell[BoxData[ \(53.54`\)], "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["Rule and LongRightArrow with named patterns", "Subsubsection", CellFrame->{{0, 0}, {0, 0.5}}], Cell["\<\ The next cell shows an attempt to define a replacement rule called (g2). In \ this case (\[Rule]) has (x_) on the left and (x) on the right, and the rule \ doesn't work at all because the global value of (x) is substituted on the \ right side of (\[Rule]) before the integral evaluates. As we saw in the last \ problem the substitution is made before the integral evaluates, and Integrate \ gets arguments it can't work with. You could use RuleDelayed \ (\[RuleDelayed]) instead but that would be inefficient because the symbolic \ integral would evaluate each time the rule is used.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(x = 4;\)\), "\[IndentingNewLine]", \(\(g2 = g[x_] \[Rule] Integrate[Log[\@x + 1], x];\)\)}], "Input"], Cell[BoxData[ \(Integrate::"ilim" \(\(:\)\(\ \)\) "Invalid integration variable or limit(s) in \!\(4\) ."\)], "Message"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Exp[2\ a]\ g[a + 2] /. g2\)], "Input"], Cell[BoxData[ \(\[ExponentialE]\^\(2\ a\)\ \(\[Integral]Log[ 3] \[DifferentialD]4\)\)], "Output"] }, Open ]], Cell[TextData[{ "Here again you may have assigned a value to (x) early in the ", StyleBox["Mathematica", FontSlant->"Italic"], " session and forgot about it. You can get the desired result by clearing \ any variables that might cause problems as in the next cell. Of course the \ variables used for pattern names shouldn't have values that you care about." }], "Text"], Cell[BoxData[{ \(\(Clear[x];\)\), "\[IndentingNewLine]", \(\(g2 = g[x_] \[Rule] Integrate[Log[\@x + 1], x];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Exp[2\ a]\ g[a + 2] /. g2\)], "Input"], Cell[BoxData[ \(\[ExponentialE]\^\(2\ a\)\ \((1\/2\ \((\(-2\) - a)\) + \@\(2 + a\) - Log[1 + \@\(2 + a\)] + \((2 + a)\)\ Log[ 1 + \@\(2 + a\)])\)\)], "Output"] }, Open ]], Cell["\<\ Instead of using the solution above you can load the package \ (LocalPatterns.m) and use the function LongRightArrow which gives the desired \ result without clearing the values of any variables. The cells below show \ the usage message of LongRightArrow, and demonstrate that it makes the right \ replacement without clearing the value of x.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?LongRightArrow\)\)], "Input"], Cell[BoxData[ \("lhs\[LongRightArrow]rhs represents a rule where rhs is evaluated \ immediately using a local environment for any variable used as a pattern in \ lhs. The infix operator \[LongRightArrow] is entered as \\[LongRightArrow]. \ The expression lhs\[LongRightArrow]rhs has an equivalent form \ LocalRule[lhs,rhs]."\)], "Print"] }, Open ]], Cell[BoxData[{ \(\(x = 34/7;\)\), "\[IndentingNewLine]", \(\(g2 = g[x_]\[LongRightArrow]Integrate[Log[\@x + 1], x];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Exp[3\ a]\ g[a + 2] /. g2\)], "Input"], Cell[BoxData[ \(\[ExponentialE]\^\(3\ a\)\ \((1\/2\ \((\(-2\) - a)\) + \@\(2 + a\) - Log[1 + \@\(2 + a\)] + \((2 + a)\)\ Log[ 1 + \@\(2 + a\)])\)\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\)], "Input"], Cell[BoxData[ \(34\/7\)], "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell["UpSet and HumpEqual with named patterns", "Subsubsection", CellFrame->{{0, 0}, {0, 0.5}}], Cell["\<\ The cells below add definitions to Sinh and Cosh, so they should be \ unprotected using the next cell before proceeding.\ \>", "Text"], Cell[BoxData[ \(\(Unprotect[Sinh, Cosh];\)\)], "Input"], Cell["\<\ In the next cell (^=) has (x_) on the left and (x) on the right. This \ doesn't give the intended result because the global value of (x) is \ substituted on the right side of (^=) before the series expansion is derived. \ You could use UpSetDelayed (^:=) instead but then the series expansion will \ be derived each time the UpValue is used.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Clear[Sinh, Cosh];\)\), "\[IndentingNewLine]", \(\(x = 4;\)\), "\[IndentingNewLine]", \(\(Sinh[x_] + Cosh[x_] ^= Normal[Series[Exp[x], {x, 0, 7}]];\)\)}], "Input"], Cell[BoxData[ \(General::"ivar" \(\(:\)\(\ \)\) "\!\(4\) is not a valid variable."\)], "Message"] }, Open ]], Cell["\<\ The attempted definition in the previous cell is stored in UpValues[Sinh] and \ UpValues[Cosh]. Below we see the wrong definition was stored.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[ Cosh[x_] + Sinh[x_]] \[RuleDelayed] \[ExponentialE]\^4}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Cosh]\)], "Input"], Cell[BoxData[ \({HoldPattern[ Cosh[x_] + Sinh[x_]] \[RuleDelayed] \[ExponentialE]\^4}\)], "Output"] }, Open ]], Cell[TextData[{ "Once again you may have assigned a value to (x) early in the ", StyleBox["Mathematica", FontSlant->"Italic"], " session and forgot about it. As with use of (=) and (\[Rule]) you can \ get the desired result by clearing any variables that might cause problems as \ in the next cell. As before the variables used for pattern names shouldn't \ have values that you care about." }], "Text"], Cell[BoxData[{ \(\(Clear[x, y];\)\), "\[IndentingNewLine]", \(\(Sinh[x_] + Cosh[x_] ^= Normal[Series[Exp[x], {x, 0, 7}]];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Cosh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040}\)], "Output"] }, Open ]], Cell["\<\ Instead of using the solution above you can load the package \ (LocalPatterns.m) and use the function HumpEqual which gives the desired \ result without clearing the values of any variables. The cells below show \ the usage message of HumpEqual, and demonstrate that it stores the right \ definition without clearing the value of x.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?HumpEqual\)\)], "Input"], Cell[BoxData[ \("lhs\[HumpEqual]rhs represents an UpValue where rhs is evaluated \ immediately using a local environment for any variable used as a pattern in \ lhs. The infix operator \[HumpEqual] is entered as \\[HumpEqual]. The \ expression lhs\[HumpEqual]rhs is equivalent to LocalUpSet[lhs,rhs]."\)], \ "Print"] }, Open ]], Cell[BoxData[{ \(\(Clear[Sinh, Cosh];\)\), "\[IndentingNewLine]", \(\(x = 4;\)\), "\[IndentingNewLine]", \(\(Sinh[x_] + Cosh[x_] \[HumpEqual] Normal[Series[Exp[x], {x, 0, 7}]];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Cosh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\)], "Input"], Cell[BoxData[ \(4\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Sinh[z + 7] + Cosh[z + 7]\)], "Input"], Cell[BoxData[ \(8 + z + 1\/2\ \((7 + z)\)\^2 + 1\/6\ \((7 + z)\)\^3 + 1\/24\ \((7 + z)\)\^4 + 1\/120\ \((7 + z)\)\^5 + 1\/720\ \((7 + z)\)\^6 + \((7 + z)\)\^7\/5040\)], "Output"] }, Open ]], Cell["Evaluating the next cell will remove the definitions above.", "Text"], Cell[BoxData[{ \(Clear[Sinh, Cosh]\), "\[IndentingNewLine]", \(\(Protect[Sinh, Cosh];\)\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["TagSet and LocalTagSet with named patterns on the left side", \ "Subsubsection", CellFrame->{{0, 0}, {0, 0.5}}], Cell["\<\ The cells below will add a definition to Sinh, so it should be unprotected \ using the next cell before proceeding.\ \>", "Text"], Cell[BoxData[ \(\(Unprotect[Sinh];\)\)], "Input"], Cell[TextData[{ "In the next cell (=) has (x_) is on the left and (x) on the right. This \ attempt to make a definition for Sinh doesn't give the intended result \ because the global value of (x) is substituted on the right side of (=) \ before the series expansion is derived. You could use TagSetDelayed ", Cell[BoxData[ \(TraditionalForm\`\((f /: lhs := rhs)\)\)]], " instead, but then the series expansion will be derived each time the \ UpValue is used." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Clear[Sinh];\)\), "\[IndentingNewLine]", \(\(x = 4;\)\), "\n", \(\(Sinh /: Sinh[x_] + Cosh[x_] = Normal[Series[Exp[x], {x, 0, 7}]];\)\)}], "Input"], Cell[BoxData[ \(General::"ivar" \(\(:\)\(\ \)\) "\!\(4\) is not a valid variable."\)], "Message"] }, Open ]], Cell["\<\ The attempted definition in the previous cell is stored in UpValues[Sinh]. \ Below we see the wrong definition was stored. Recall the cell above stores a \ definition in UpValues[Sinh] but not in UpValues[Cosh].\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[ Cosh[x_] + Sinh[x_]] \[RuleDelayed] \[ExponentialE]\^4}\)], "Output"] }, Open ]], Cell[TextData[{ "Once again you may have assigned a value to (x) early in the ", StyleBox["Mathematica", FontSlant->"Italic"], " session and forgot about it. As with use of (=) and (\[Rule]) you can \ get the desired result by clearing any variables that might cause problems as \ demonstrated in the next cell. As before the variables used for pattern \ names shouldn't have any values that you care about." }], "Text"], Cell[BoxData[{ \(\(Clear[x];\)\), "\[IndentingNewLine]", \(\(Sinh /: Sinh[x_] + Cosh[x_] = Normal[Series[Exp[x], {x, 0, 8}]];\)\)}], "Input"], Cell["\<\ In the next cell we see that the intended definition is stored in \ UpValues[Sinh].\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040 + x\^8\/40320}\)], "Output"] }, Open ]], Cell["\<\ Instead of using the solution above you can load the package \ (LocalPatterns.m) and use the function LocalTagSet which gives the desired \ result without clearing the values of any variables. The cells below show \ the usage message of LocalTagSet and demonstrate that it stores the right \ definition without clearing the value of x.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?LocalTagSet\)\)], "Input"], Cell[BoxData[ \("LocalTagSet[f,lhs,rhs] uses a local environment for any variable used \ as a pattern in lhs, and assigns rhs to be the value of lhs, and associates \ the assignment with the symbol f. The expression LocalTagSet[f,lhs,rhs] can \ be entered as f \[EscapeKey]|\[EscapeKey] lhs \\[HumpEqual] rhs."\)], "Print"] }, Open ]], Cell[BoxData[{ \(\(Clear[Sinh];\)\), "\[IndentingNewLine]", \(\(x = 4;\)\), "\[IndentingNewLine]", \(\(Sinh \[VerticalSeparator] Sinh[x_] + Cosh[x_] \[HumpEqual] Normal[Series[Exp[x], {x, 0, 7}]];\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(UpValues[Sinh]\)], "Input"], Cell[BoxData[ \({HoldPattern[Cosh[x_] + Sinh[x_]] \[RuleDelayed] 1 + x + x\^2\/2 + x\^3\/6 + x\^4\/24 + x\^5\/120 + x\^6\/720 + x\^7\/5040}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\)], "Input"], Cell[BoxData[ \(4\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Sinh[z + 7] + Cosh[z + 7]\)], "Input"], Cell[BoxData[ \(8 + z + 1\/2\ \((7 + z)\)\^2 + 1\/6\ \((7 + z)\)\^3 + 1\/24\ \((7 + z)\)\^4 + 1\/120\ \((7 + z)\)\^5 + 1\/720\ \((7 + z)\)\^6 + \((7 + z)\)\^7\/5040\)], "Output"] }, Open ]], Cell["Evaluating the next cell will remove the definitions above.", "Text"], Cell[BoxData[{ \(Clear[Sinh]\), "\[IndentingNewLine]", \(\(Protect[Sinh];\)\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["A function called PatternNames", "Subsubsection", CellFrame->{{0, 0}, {0, 0.5}}], Cell["\<\ PatternsNames is a utility function included in the LocalPatterns.m package. \ The definitions of DotEqual, LongRightArrow, HumpEqual, LocalTagSet call on \ PatternNames, and it might prove useful in other situations. The usage \ message below explains the PatternNames function.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?PatternNames\)\)], "Input"], Cell[BoxData[ \("PatternNames[expr] returns a list of the names of patterns included in \ expr. The list returned is wrapped in Hold. PatternNames does not consider \ patterns that appear inside Verbatim. Example:\n \ PatternNames[foo[a_,b_:1,c_?NumericQ,d,e]] returns \n Hold[{a,b,c}]."\)], \ "Print"] }, Open ]], Cell[TextData[{ "Early versions of the LocalPatterns.m package didn't include a separate \ function to do what PatternNames does. Robby Villegas (of Wolfram Research) \ recommended use of a separate function and provided an elegant \ implementation. The code Robby Villagas provided was modified slightly to \ ensure ", Cell[BoxData[ \(TraditionalForm\`Hold[{}]\)]], " is returned when no named patterns are present. This change wasn't \ necessary, but was made to ensure the result always has the same form. \n\n\ An example is given in the next cell where the pattern names include (x, y). \ Notice the output doesn't include (a,b) and (x,y) don't evaluate to (6,3)." }], "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(x = 6;\)\), "\n", \(\(y = 3;\)\), "\n", \(PatternNames[Sin[a + b + x_ + y_]]\)}], "Input"], Cell[BoxData[ \(Hold[{x, y}]\)], "Output"] }, Open ]], Cell["\<\ In the next cell PatternNames returns the symbols used for other patterns.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(PatternNames[f[x_Rational, y_?Positive]]\)], "Input"], Cell[BoxData[ \(Hold[{x, y}]\)], "Output"] }, Open ]], Cell["\<\ In the next cell PatternNames returns the symbols used for more complicated \ patterns.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(mtrx = {{2, 0}, {0, \(-1\)}};\)\), "\[IndentingNewLine]", \(\(n = 23;\)\), "\[IndentingNewLine]", \(PatternNames[f_[mtrx : {{__Real} .. }, \ n_Integer: 4]]\)}], "Input"], Cell[BoxData[ \(Hold[{f, mtrx, n}]\)], "Output"] }, Open ]], Cell["\<\ The patterns in the next example aren't named, and PatternNames returns an \ empty list wrapped in Hold.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(PatternNames[f[_?Positive, _Integer]]\)], "Input"], Cell[BoxData[ \(Hold[{}]\)], "Output"] }, Open ]] }, Closed]] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 800}, {0, 527}}, WindowSize->{792, 500}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, Magnification->1.25 ] (*********************************************************************** 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[1739, 51, 140, 4, 118, "Subtitle"], Cell[1882, 57, 1079, 25, 154, "Text"], Cell[2964, 84, 51, 1, 35, "Input"], Cell[CellGroupData[{ Cell[3040, 89, 48, 0, 51, "Subsubsection"], Cell[3091, 91, 1957, 32, 269, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[5085, 128, 94, 1, 43, "Subsubsection"], Cell[5182, 131, 400, 6, 80, "Text"], Cell[CellGroupData[{ Cell[5607, 141, 126, 2, 61, "Input"], Cell[5736, 145, 138, 3, 30, "Message"], Cell[5877, 150, 87, 1, 51, "Output"] }, Open ]], Cell[5979, 154, 421, 8, 80, "Text"], Cell[6403, 164, 121, 2, 61, "Input"], Cell[CellGroupData[{ Cell[6549, 170, 39, 1, 35, "Input"], Cell[6591, 173, 43, 1, 30, "Print"], Cell[6637, 176, 429, 12, 36, "Print"] }, Open ]], Cell[7081, 191, 373, 6, 80, "Text"], Cell[CellGroupData[{ Cell[7479, 201, 46, 1, 35, "Input"], Cell[7528, 204, 363, 5, 114, "Print"] }, Open ]], Cell[7906, 212, 174, 3, 82, "Input"], Cell[CellGroupData[{ Cell[8105, 219, 39, 1, 35, "Input"], Cell[8147, 222, 43, 1, 30, "Print"], Cell[8193, 225, 430, 12, 36, "Print"] }, Open ]], Cell[CellGroupData[{ Cell[8660, 242, 34, 1, 35, "Input"], Cell[8697, 245, 40, 1, 35, "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[8786, 252, 101, 1, 43, "Subsubsection"], Cell[8890, 255, 610, 9, 122, "Text"], Cell[CellGroupData[{ Cell[9525, 268, 129, 2, 61, "Input"], Cell[9657, 272, 131, 2, 30, "Message"] }, Open ]], Cell[CellGroupData[{ Cell[9825, 279, 58, 1, 35, "Input"], Cell[9886, 282, 113, 2, 51, "Output"] }, Open ]], Cell[10014, 287, 380, 7, 80, "Text"], Cell[10397, 296, 132, 2, 61, "Input"], Cell[CellGroupData[{ Cell[10554, 302, 58, 1, 35, "Input"], Cell[10615, 305, 188, 3, 49, "Output"] }, Open ]], Cell[10818, 311, 367, 6, 80, "Text"], Cell[CellGroupData[{ Cell[11210, 321, 52, 1, 35, "Input"], Cell[11265, 324, 342, 5, 93, "Print"] }, Open ]], Cell[11622, 332, 140, 2, 61, "Input"], Cell[CellGroupData[{ Cell[11787, 338, 58, 1, 35, "Input"], Cell[11848, 341, 188, 3, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[12073, 349, 34, 1, 35, "Input"], Cell[12110, 352, 39, 1, 49, "Output"] }, Open ]] }, Closed]], Cell[CellGroupData[{ Cell[12198, 359, 97, 1, 43, "Subsubsection"], Cell[12298, 362, 144, 3, 38, "Text"], Cell[12445, 367, 59, 1, 35, "Input"], Cell[12507, 370, 367, 6, 80, "Text"], Cell[CellGroupData[{ Cell[12899, 380, 205, 4, 77, "Input"], Cell[13107, 386, 108, 2, 30, "Message"] }, Open ]], Cell[13230, 391, 166, 3, 59, "Text"], Cell[CellGroupData[{ Cell[13421, 398, 47, 1, 35, "Input"], Cell[13471, 401, 113, 2, 35, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[13621, 408, 47, 1, 35, "Input"], Cell[13671, 411, 113, 2, 35, "Output"] }, Open ]], Cell[13799, 416, 415, 8, 80, "Text"], Cell[14217, 426, 155, 3, 56, "Input"], Cell[CellGroupData[{ Cell[14397, 433, 47, 1, 35, "Input"], Cell[14447, 436, 177, 3, 52, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[14661, 444, 47, 1, 35, "Input"], Cell[14711, 447, 177, 3, 52, "Output"] }, Open ]], Cell[14903, 453, 357, 6, 80, "Text"], Cell[CellGroupData[{ Cell[15285, 463, 47, 1, 35, "Input"], Cell[15335, 466, 322, 5, 93, "Print"] }, Open ]], Cell[15672, 474, 215, 4, 77, "Input"], Cell[CellGroupData[{ Cell[15912, 482, 47, 1, 35, "Input"], Cell[15962, 485, 177, 3, 52, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[16176, 493, 47, 1, 35, "Input"], Cell[16226, 496, 177, 3, 52, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[16440, 504, 34, 1, 35, "Input"], Cell[16477, 507, 35, 1, 35, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[16549, 513, 58, 1, 35, "Input"], Cell[16610, 516, 196, 3, 52, "Output"] }, Open ]], Cell[16821, 522, 75, 0, 38, "Text"], Cell[16899, 524, 110, 2, 56, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[17046, 531, 119, 2, 43, "Subsubsection"], Cell[17168, 535, 139, 3, 38, "Text"], Cell[17310, 540, 53, 1, 35, "Input"], Cell[17366, 543, 484, 9, 101, "Text"], Cell[CellGroupData[{ Cell[17875, 556, 189, 4, 77, "Input"], Cell[18067, 562, 108, 2, 30, "Message"] }, Open ]], Cell[18190, 567, 237, 4, 59, "Text"], Cell[CellGroupData[{ Cell[18452, 575, 47, 1, 35, "Input"], Cell[18502, 578, 113, 2, 35, "Output"] }, Open ]], Cell[18630, 583, 432, 8, 80, "Text"], Cell[19065, 593, 159, 3, 56, "Input"], Cell[19227, 598, 107, 3, 38, "Text"], Cell[CellGroupData[{ Cell[19359, 605, 47, 1, 35, "Input"], Cell[19409, 608, 191, 3, 77, "Output"] }, Open ]], Cell[19615, 614, 360, 6, 80, "Text"], Cell[CellGroupData[{ Cell[20000, 624, 49, 1, 35, "Input"], Cell[20052, 627, 328, 4, 93, "Print"] }, Open ]], Cell[20395, 634, 246, 5, 77, "Input"], Cell[CellGroupData[{ Cell[20666, 643, 47, 1, 35, "Input"], Cell[20716, 646, 177, 3, 52, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[20930, 654, 34, 1, 35, "Input"], Cell[20967, 657, 35, 1, 35, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[21039, 663, 58, 1, 35, "Input"], Cell[21100, 666, 196, 3, 52, "Output"] }, Open ]], Cell[21311, 672, 75, 0, 38, "Text"], Cell[21389, 674, 98, 2, 56, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[21524, 681, 88, 1, 43, "Subsubsection"], Cell[21615, 684, 306, 5, 80, "Text"], Cell[CellGroupData[{ Cell[21946, 693, 50, 1, 35, "Input"], Cell[21999, 696, 309, 5, 114, "Print"] }, Open ]], Cell[22323, 704, 700, 12, 164, "Text"], Cell[CellGroupData[{ Cell[23048, 720, 123, 3, 77, "Input"], Cell[23174, 725, 46, 1, 35, "Output"] }, Open ]], Cell[23235, 729, 98, 2, 38, "Text"], Cell[CellGroupData[{ Cell[23358, 735, 73, 1, 35, "Input"], Cell[23434, 738, 46, 1, 35, "Output"] }, Open ]], Cell[23495, 742, 111, 3, 38, "Text"], Cell[CellGroupData[{ Cell[23631, 749, 203, 3, 77, "Input"], Cell[23837, 754, 52, 1, 35, "Output"] }, Open ]], Cell[23904, 758, 128, 3, 38, "Text"], Cell[CellGroupData[{ Cell[24057, 765, 70, 1, 35, "Input"], Cell[24130, 768, 42, 1, 35, "Output"] }, Open ]] }, Closed]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)