       Re: Derivative

• To: MathGroup at yoda.physics.unc.edu
• Subject: Re: Derivative
• From: villegas
• Date: Thu, 30 Jul 92 18:30:46 CDT

```Hi Trott,

Concerning the outcome of:

Derivative[n_][F]:=FU[n]

Derivative[n_][G][x_]:=GU[n][x]

{F''[y], G''[y] }

We can see what happens if we freeze the expressions F''[y] and G''[y]
immediately after Mathematica parses them but before it starts to evaluate them
in the normal manner.  We define a general function to tell us how Mathematica
understands an expression we type in as input:

Attributes[ParsedForm] = HoldFirst

ParsedForm[expr_] := FullForm[expr] //HoldForm

FullForm is a display format for an expression; it causes the internal stored
form of an expression to be displayed in full.  HoldForm prevents 'expr'
(whatever it happens to be) from being evaluated, but the FullForm, being simply
a display formatter, still takes effect inside HoldForm.

Here is an excerpt of a Mathematica session, with comments:

_________________________________________________________________________
In:= Attributes[ParsedForm] = HoldFirst

Out= HoldFirst

In:= ParsedForm[expr_] := FullForm[expr] //HoldForm

In:= Derivative[n_][F]:=FU[n]

In:= Derivative[n_][G][x_]:=GU[n][x]

The following should tell us how any second derivative, written in the
"double-prime" form that we used, will be understood:

In:= ParsedForm[ H''[x] ]

Out= Derivative[Derivative[H]][x]

As expected, using F and G for H gives the same form:

In:= ParsedForm[ F''[x] ]

Out= Derivative[Derivative[F]][x]

In:= ParsedForm[ G''[x] ]

Out= Derivative[Derivative[G]][x]

So the special-input form  H''  stands for the first derivative of the first
derivative of H, not the second derivative straight off.  Now that we know what
expressions the Mathematica evaluator starts with (the parsing stage being
complete), we can use some general principles of evaluation of expressions:
first evaluate the head and then the elements in turn.

The head of the parsed form of F''[x] shown above is

Derivative[Derivative[F]],

which is itself an expression with head Derivative and element
Derivative[F].  The element Derivative[F] can be evaluated because we told
the kernel what to do:

In:= Derivative[F]

Out= FU

Then it applies the head Derivative to this and gets:

In:= Derivative[%]

Out= (FU)'

This is applied to the symbol 'x' to give the final result of the evaluation.

The evaluation of the parsed form of G proceeds differently.  It starts the same

Derivative[Derivative[G]]

This time the element Derivative[G] can _not_ be evaluated, because we
provided no rule for the derivative operator acting on G unless there is an
argument present as well.  That's where the different assignments for F and G
comes in, and we get:

In:= Derivative[Derivative[G]]

Out= G''

In:= FullForm[%]

Out//FullForm= Derivative[G]

When this acts on x, the rule for G comes into play:

In:= %[x]

Out= GU[x]

So the result is that we get:

In:= {F''[x], G''[x]}

Out= {(FU)'[x], GU[x]}

Robby Villegas

```

• Prev by Date: why does this crash the kernel
• Next by Date: Excell <-> MMa