       Re: RE:? D[f,{x,n}]

• To: mathgroup at smc.vnet.net
• Subject: [mg25576] Re: [mg25559] RE:[mg25495] ? D[f,{x,n}]
• From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
• Date: Mon, 9 Oct 2000 01:16:41 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```I must make a correction to my earlier message (this is also related, I
think, to Allan Hayes's latest message in this thread).  First of all,
contrary to what I wrote,  Derivative[n][f][x] is computed by nesting
Derivative's  in Mathematica 4.0. Look at the following example:

In:=
f /: f' = g
Out=
g
In:=
f''[x]
Out=
g'[x]

In fact this was not the case in Mathematica 3.0 (but was true in earlier
Maeder's "Programming in Mathematica", Third edition (see p. 225) and
assumed it must still be the case. Clearly the original behaviour was
considered desirable and restored in v.4.

However, what is relevant to the example below is this interesting
behaviour:

In:=
flag = True;

In:=
f'/;flag=g

Out=
g

In:=
f'[x]

Out=
g[x]

In:=
f''[x]

Out=
f''[x]

In other words, when f'' is evaluated, Derivative is nested but the
conditional value of f' is not used.

Andrzej

--
Andrzej Kozlowski
Toyama International University, JAPAN

For Mathematica related links and resources try:
<http://www.sstreams.com/Mathematica/>

on 00.10.7 11:37 PM, Andrzej Kozlowski at andrzej at tuins.ac.jp wrote:

> on 10/7/00 4:36 PM, Ersek, Ted R at ErsekTR at navair.navy.mil wrote:
>
>> seems to prove that D[f, {x, n}]  evaluates
>> Nest[ D[#, x]&, f, n ]
>> or something equivalent.
>> -----------------------------
>
> I think the point is (as already has been pointed out by Carl Woll)  that:
>
> In:=
> MatchQ[Unevaluated[D[f, {x, n}]], Unevaluated[D[f_, y_]]]
> Out=
> True
>
> We can see what happens in your case simply by looking at Trace:
>
> In:=
> Trace[D[(x + 2)^4, {x, 2}]]
>
> Out=
> {{{HoldForm[x + 2], HoldForm[2 + x]}, HoldForm[(2 + x)^4]}, HoldForm[D[(2 +
> x)^4, {x, 2}]], {HoldForm[flag], HoldForm[True]}, HoldForm[Block[{flag},
> D[Expand[(2 + x)^4], {x, 2}]]], {{HoldForm[Expand[(2 + x)^4]], HoldForm[16 +
> 32*x + 24*x^2 + 8*x^3 + x^4]}, HoldForm[D[16 + 32*x + 24*x^2 + 8*x^3 + x^4,
> {x, 2}]], HoldForm[48 + 48*x + 12*x^2]}, HoldForm[48 + 48*x + 12*x^2]}
>
> As you can see,  D[(2 + x) , {x, 2}] was found to match the rule for
> D[f_,x_]/;flag and the rule was simply applied. There was need to use Nest,
> and so on. This is just a case of pattern matching doing its job.
>
> A similar approach can be used to show that when Mathematica evaluates
> Derivative[n][f] it does not do actually do this by nesting Derivative's.
>
> Here is a rule for Derivative that is, essentially, equivalent to the above
> one for D (note that there is no need to use Unprotect as Derivative does not
> have the Protected Attribute!):
>
> In:=
> Derivative[Function[p_]] /; flag :=
> Block[{flag}, Derivative[Function @@ {Expand[p] }]]
>
> In:=
> flag = True;
>
> This works just as above:
>
>
> In:=
> (# + 2)^3 &'[x]
>
> Out=
> 2
> 12 + 12 x + 3 x
>
> But:
>
> In:=
> ((# + 2)^3 &)''[x]
>
> Out=
> 6 (2 + x)
>
> While on the other hand
>
> In:=
> ((# + 2)^3 &')'[x]
>
> Out=
> 12 + 6 x
>
>
> Of course what one should do is use a  more general pattern:
>
> In:=
> Derivative[n_][Function[p_]] /; flag :=
> Block[{flag}, Derivative[n][Function @@ {Expand[p] }]]
>
>
> so that:
>
> In:=
> ((# + 2)^5 &)'''[x]
>
> Out=
> 2
> 240 + 240 x + 60 x
>

```

• Prev by Date: Re: problem with nonlinearfit
• Next by Date: Tangent on 3d cubic spline
• Previous by thread: Re: RE:? D[f,{x,n}]
• Next by thread: Exporting multiple page graphics