(*********************************************************************** 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[ 6534, 220]*) (*NotebookOutlinePosition[ 7375, 247]*) (* CellTagsIndexPosition[ 7331, 243]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Advanced Topic: Upvalues", "Section"], Cell[TextData[{ "When you define a function or transformation rule in the normal way, you \ are storing a definition to be applied to the head of that function or rule. \ Most of the time this is what you want. But suppose instead you want to \ define rules for what happens when you add two or more of this object up. \ Then the head of the expression is ", StyleBox["Plus", FontFamily->"Courier", FontWeight->"Bold"], ", a built-in symbol. While in theory you can modify most built-in symbols, \ it is not advisable to do so! What is required is an ", StyleBox["Upvalue", FontWeight->"Bold"], ", which creates a definition for your symbol, not the more general \ symbols. " }], "Text"], Cell[CellGroupData[{ Cell["An Example: Lag Operator", "Subsubsection"], Cell[BoxData[ \(Clear[\[DoubleStruckCapitalL]]\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL][x_[t_]] := x[t - 1]\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL]\ /: \[DoubleStruckCapitalL]*x_[t_] := \[DoubleStruckCapitalL][x[t]]\)], "Input"], Cell[TextData[{ "Because upvalues can only apply if the object in question is only \ \[OpenCurlyDoubleQuote]one layer deep\[CloseCurlyDoubleQuote] in the \ expression, and because ", Cell[BoxData[ \(TraditionalForm \`\[DoubleStruckCapitalL]\^4 = \ \[DoubleStruckCapitalL]\[Times]\[DoubleStruckCapitalL]\[Times]\ \[DoubleStruckCapitalL]\[Times]\[DoubleStruckCapitalL]\)]], " which could cause infinite iteration, you can\[CloseCurlyQuote]t define \ upvalues for things like ", Cell[BoxData[ FormBox[ StyleBox[ \(Times[\[DoubleStruckCapitalL]\^a, \[DoubleStruckCapitalL]\^b] := \ \[DoubleStruckCapitalL]\^\(a + b\)\), FontWeight->"Bold"], TraditionalForm]]], ". The FullForm makes this clear: ", StyleBox[ "Times[Power[\[DoubleStruckCapitalL],a],Power[\[DoubleStruckCapitalL],b]]", FontFamily->"Courier", FontWeight->"Bold"], ". Instead, we define an auxiliary variable to handle the \ \[OpenCurlyDoubleQuote]powers\[CloseCurlyDoubleQuote]." }], "Text"], Cell[BoxData[ \(\[DoubleStruckCapitalL]\ /: \[DoubleStruckCapitalL]\^i_Integer := \[DoubleStruckCapitalL][p, i]\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(\[DoubleStruckCapitalL]\^2\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL][p, 2]\)], "Output"] }, Open ]], Cell[BoxData[ \(\(\[DoubleStruckCapitalL]\ /: \[DoubleStruckCapitalL][p, i_Integer]\ x_Symbol[t_] := Nest[\[DoubleStruckCapitalL], x[t], i]\ /; \ i \[GreaterEqual] 0\ \)\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL]\ /: \ \[DoubleStruckCapitalL][p, a_Integer]* \[DoubleStruckCapitalL][p, b_Integer] := \ \[DoubleStruckCapitalL][p, a + b]\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL]\ /: \ \ \[DoubleStruckCapitalL][p, a_Integer]\/\[DoubleStruckCapitalL][p, b_Integer] := \ \[DoubleStruckCapitalL][p, a - b]\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL] /: \ \[DoubleStruckCapitalL][p, a_Integer]\^b_Integer := \ \[DoubleStruckCapitalL][p, a\ b]\)], "Input"], Cell["\<\ Strictly speaking, you could also use a different way to set \ upvalues:\ \>", "Text"], Cell[BoxData[ \(\[DoubleStruckCapitalL][p, 0]\ x_[t_] ^:= x[t]\)], "Input"], Cell[TextData[{ "which is called ", StyleBox["UpSetDelayed", FontFamily->"Courier", FontWeight->"Bold"], ", as opposed to the other examples which use ", StyleBox["TagSetDelayed", FontFamily->"Courier", FontWeight->"Bold"], ", but you get the same result and ", StyleBox["TagSet/TagSetDelayed", FontFamily->"Courier", FontWeight->"Bold"], " is easier to read." }], "Text"], Cell["Here is the Lag Operator in action.", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\[DoubleStruckCapitalL]\ \[Theta][\[Tau]]\)], "Input"], Cell[BoxData[ \(\[Theta][\(-1\) + \[Tau]]\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Times\ @@\ Table[\[DoubleStruckCapitalL], {4}]\)], "Input"], Cell[BoxData[ \(\[DoubleStruckCapitalL][p, 4]\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(\(\[DoubleStruckCapitalL]\^3\) y[t]\)], "Input"], Cell[BoxData[ \(y[\(-3\) + t]\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(\[DoubleStruckCapitalL]\ \ \[DoubleStruckCapitalL]\ \[ScriptY][t]\)], "Input"], Cell[BoxData[ \(\[ScriptY][\(-2\) + t]\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(\[DoubleStruckCapitalL]\^4/\[DoubleStruckCapitalL]\^4\ *\ z[t]\)], "Input"], Cell[BoxData[ \(z[t]\)], "Output"] }, Open ]] }, Open ]] }, Open ]] }, FrontEndVersion->"Macintosh 3.0", ScreenRectangle->{{0, 1152}, {0, 850}}, WindowSize->{520, 365}, WindowMargins->{{28, Automatic}, {30, Automatic}}, MacintoshSystemPageSetup->"\<\ 00<0001804P000000`d26_oQon@3:`8g0dL5N`?P0080001804P000000]P2:001 0000I00000400`<30?l00BL?00400@0000000000000006P801T1T00000000000 00000000004000000000000000000000\>" ] (*********************************************************************** 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[1731, 51, 43, 0, 50, "Section"], Cell[1777, 53, 712, 15, 112, "Text"], Cell[CellGroupData[{ Cell[2514, 72, 49, 0, 41, "Subsubsection"], Cell[2566, 74, 63, 1, 27, "Input"], Cell[2632, 77, 76, 1, 27, "Input"], Cell[2711, 80, 132, 2, 27, "Input"], Cell[2846, 84, 1047, 24, 97, "Text"], Cell[3896, 110, 136, 2, 29, "Input"], Cell[CellGroupData[{ Cell[4057, 116, 59, 1, 29, "Input"], Cell[4119, 119, 63, 1, 26, "Output"] }, Open ]], Cell[4197, 123, 207, 4, 43, "Input"], Cell[4407, 129, 201, 4, 27, "Input"], Cell[4611, 135, 199, 3, 44, "Input"], Cell[4813, 140, 162, 3, 29, "Input"], Cell[4978, 145, 96, 3, 30, "Text"], Cell[5077, 150, 79, 1, 27, "Input"], Cell[5159, 153, 410, 14, 64, "Text"], Cell[5572, 169, 51, 0, 30, "Text"], Cell[CellGroupData[{ Cell[5648, 173, 74, 1, 27, "Input"], Cell[5725, 176, 59, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[5821, 182, 79, 1, 27, "Input"], Cell[5903, 185, 63, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6003, 191, 68, 1, 29, "Input"], Cell[6074, 194, 47, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6158, 200, 101, 2, 27, "Input"], Cell[6262, 204, 56, 1, 26, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6355, 210, 98, 2, 29, "Input"], Cell[6456, 214, 38, 1, 26, "Output"] }, Open ]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)