Re: What is the purpose of the Defer Command?

*To*: mathgroup at smc.vnet.net*Subject*: [mg82083] Re: What is the purpose of the Defer Command?*From*: Chris Chiasson <chris.chiasson at gmail.com>*Date*: Thu, 11 Oct 2007 00:26:38 -0400 (EDT)*References*: <fe4uhp$155$1@smc.vnet.net><fei1u1$pmv$1@smc.vnet.net>

On Oct 10, 3:19 am, Chris Chiasson <chris.chias... at gmail.com> wrote: > On Oct 9, 4:34 am, "DavidPark" <djmp... at comcast.net> wrote: > > > > > Still, my question is: "What is the purpose of theDeferCommand?" > > > The only potential purpose that I can see is for didactic purposes, to show > > preliminary expressions before they are automatically evaluated. But the > > only way to getDeferto evaluate is by copying and pasting and then > > evaluating, by using Shift-Ctrl-L and then evaluating, or by evaluating in > > place. All of these operations leave no record of the steps taken. That goes > > contrary to any didactic purpose. > > > -- > > DavidPark > > djmp... at comcast.nethttp://home.comcast.net/~djmpark/ > > > "DavidPark" <djmp... at comcast.net> wrote in message > > >news:fe4uhp$155$1 at smc.vnet.net... > > > >I do not understand the utility of the newDeferstatement in Mathematica > > > Version 6. Also, it seems to me to be similar to, but not as good as, the > > > HoldTemporary command introduced by Ted Ersek on MathSource a few years > > > ago. > > > > The help forDefersays: "Defer[expr] yields an object that displays as > > > the > > > unevaluated form of expr, but which is evaluated if it is explicitly given > > > as Mathematica input." What does 'given as Mathematica input' mean? The > > > examples seem to only involve copying and pasting, which I don't consider > > > a > > > great method for doing mathematics, or evaluation in place. > > > > I would like to understand howDefermight be used in expository notebooks > > > to clarify some piece of mathematics. The problem is that it requires an > > > interactive action, which would be invisible to a reader of a notebook. I > > > think the idea of 'modification in place' is poor in technical > > > communication > > > because it destroys the record of what was done. > > > > (In the examples below, whenever an output resulted in an expression that > > > copied as a box structure, I converted to InputForm to simplify the > > > posting.) > > > > Here is a simple example: > > > > y =Defer[1 + 1] > > > 1 + y giving > > > > 1 + 1 > > > > 1 + (1 + 1) > > > > I would prefer that theDeferexpression would have evaluated in the > > > second > > > statement but I guess it is logical that it didn't. If I write: > > > > 1 + y > > > > then select the y and Evaluate In Place I obtain the following, which must > > > then be further evaluated to obtain 3. > > > > 1 + 1 + 1 > > > > 3 > > > > A second example. I want to show an integral without evaluation and then > > > the > > > evaluated result. I have to write the following expression, then select > > > the > > > second line of output, evaluate in place, and then I obtain the result - > > > but > > > as an Input cell. This is certainly a place where HoldForm would be > > > better. > > > >Defer[Integrate[x^2 Exp[-x], {x, 0, 1}]] > > > % > > > giving > > > > Integrate[x^2/E^x, {x, 0, 1}] > > > > 2 - 5/\[ExponentialE] (which is an Input cell) > > > > Here is third example.Deferdoes not evaluate and we obtain an error > > > message. > > > > numb =Defer[2^67 - 1] > > > FactorInteger[numb] giving > > > > 2^67 - 1 > > > > FactorInteger::"exact" : "\"Argument \!\(\*SuperscriptBox[\"2\", \ > > > \"67\"]\) - 1 in FactorInteger[\!\(\*SuperscriptBox[\"2\", \"67\"]\) \ > > > - 1] is not an exact number\"" > > > > FactorInteger[2^67 - 1] > > > > But it works if I copy and paste into FactorInteger. > > > > Now, look at the behavior of Ted's MathSource package. > > > > Needs["Enhancements`HoldTemporary`"] > > > > y = HoldTemporary[1 + 1] > > > 1 + y giving > > > > 1 + 1 > > > > 3 > > > > The expression is evaluated if it is an argument of some function. > > > > HoldTemporary[Integrate[x^2 Exp[-x], {x, 0, 1}]] > > > Identity[%] > > > giving > > > > Integrate[x^2/E^x, {x, 0, 1}] > > > > 2 - 5/\[ExponentialE] (which is an Output cell) > > > > numb = HoldTemporary[2^67 - 1] > > > FactorInteger[numb] giving > > > > 2^67 - 1 > > > > {{193707721, 1}, {761838257287, 1}} > > > > Much better. I might be missing the point, but I don't think thatDeferis > > > at all well designed. > > > > There is another Hold that is very useful. This is one that holds an > > > operation but evaluates the arguments. We have a HoldOp statement in the > > > Tensorial package. > > > > Needs["TensorCalculus4V6`Tensorial`"] > > > > ?HoldOp > > > > HoldOp[operation][expr] will prevent the given operation from being > > > evaluated in expr. Nevertheless, other operations within expr will be > > > evaluated. Operation may be a pattern, including alternatives, that > > > represents heads of expressions. The HoldOp can be removed with > > > ReleaseHold. > > > > One reason we want the arguments to evaluate is that the arguments often > > > contain tensor shortcut expressions and we want them evaluated to show the > > > full tensor expression inside some operation. However, there are many > > > other > > > uses. > > > > f[x_] := Sin[x] \[ExponentialE]^x > > > > We would like f[x] to be evaluated inside the Integrate statement, but > > > hold > > > the actual itegration. > > > > Integrate[f[x], {x, 0, \[Pi]}] // HoldOp[Integrate] > > > % // ReleaseHold > > > giving > > > > HoldForm[Integrate[E^x*Sin[x], {x, 0, Pi}]] > > > > 1/2 (1 + \[ExponentialE]^\[Pi]) > > > > For exposition purposes we might want to keep the following expression in > > > the input order. > > > > \[Pi] Sin[x] \[ExponentialE]^x // HoldOp[Times] > > > % // ReleaseHold > > > giving > > > > HoldForm[Pi*Sin[x]*E^x] > > > > \[ExponentialE]^x \[Pi] Sin[x] > > > > Often we will have cases where some operation has automatic built-in > > > rules, > > > such as linear and Leibnizian breakouts with differentiation. Again, for > > > exposition purposes, we might want to show the expression before these > > > rules > > > are applied. > > > > g[x_] := x^2 > > > > D[a f[x] g[x], x] // HoldOp[D] > > > % // ReleaseHold giving > > > > HoldForm[D[a*E^x*x^2*Sin[x], x]] > > > > a \[ExponentialE]^x x^2 Cos[x] + 2 a \[ExponentialE]^x x Sin[x] + > > > a \[ExponentialE]^x x^2 Sin[x] > > > > -- > > > DavidPark > > > djmp... at comcast.net > > >http://home.comcast.net/~djmpark/ > > You have quite obviously missed the point. Without Defer, we might > actually have to type ReleaseHold. Furthermore, symbols like Defer are > only afforded by keeping the System context free of useless symbols > such as AxesInFront and GridLinesInFront. Stick that in your pipe and > smoke it. > > Sincerely, > > --http://chris.chiasson.name/ I have received at least one email that reprimanded me for my email above. I feel compelled to note that the email above is a joke and actually refers to this previous thread: http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/c5d2ee609ba69bbc It is meant to highlight changes that, from the outside, seem capricious and wrong, while taking the sting out of the criticism - criticism that is meant for WRI, not the esteemed Mr. Park.

**Re: "dereference" variable**

**Re: Re: creating a palette of characters**

**Re: What is the purpose of the Defer Command?**

**Re: What is the purpose of the Defer Command?**