DF Operator
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 7.8 DF Operator

The operator DF is used to represent partial diﬀerentiation with respect to one or more variables. It is used with the syntax:

DF(⟨EXPRN:algebraic⟩[,⟨VAR:kernel⟩ <,⟨NUM:integer⟩ >]) : algebraic.

The ﬁrst argument is the expression to be diﬀerentiated. The remaining arguments specify the diﬀerentiation variables and the number of times they are applied.

The number NUM may be omitted if it is 1. For example,

The evaluation of df(y,x) proceeds as follows: ﬁrst, the values of Y and X are found. Let us assume that X has no assigned value, so its value is X. Each term or other part of the value of Y that contains the variable X is diﬀerentiated by the standard rules. If Z is another variable, not X itself, then its derivative with respect to X is taken to be 0, unless Z has previously been declared to DEPEND on X, in which case the derivative is reported as the symbol df(z,x).

#### 7.8.1 Switches inﬂuencing diﬀerentiation

Consider df(u,x,y,z), assuming u depends on each of x,y,z in some way. If none of x,y,z is equal to u then the order of diﬀerentiation is commuted into a canonical form, unless the switch NOCOMMUTEDF is turned on (default is oﬀ). If at least one of x,y,z is equal to u then the order of diﬀerentiation is not fully commuted and the derivative is not simpliﬁed to zero, unless the switch COMMUTEDF is turned on. It is oﬀ by default.

If COMMUTEDF is oﬀ and the switch SIMPNONCOMDF is on then simplify as follows:

DF(U,X,U) -> DF(U,X,2) / DF(U,X)
DF(U,X,N,U) -> DF(U,X,N+1) / DF(U,X)

provided U depends only on the one variable X. This simpliﬁcation removes the non-commutative aspect of the derivative.

If the switch EXPANDDF is turned on then REDUCE uses the chain rule to expand symbolic derivatives of indirectly dependent variables provided the result is unambiguous, i.e. provided there is no direct dependence. It is oﬀ by default. Thus, for example, given

DEPEND F,U,V; DEPEND {U,V},X;
ON EXPANDDF;
DF(F,X) -> DF(F,U)*DF(U,X) + DF(F,V)*DF(V,X)

whereas after

DEPEND F,X;

DF(F,X) does not expand at all (since the result would be ambiguous and the algorithm would loop).

Turning on the switch ALLOWDFINT allows “diﬀerentiation under the integral sign”, i.e.

DF(INT(Y, X), V) -> INT(DF(Y, V), X)

if this results in a simpliﬁcation. If the switch DFINT is also turned on then this happens regardless of whether the result simpliﬁes. Both switches are oﬀ by default.

#### 7.8.2 Adding Diﬀerentiation Rules

The LET statement can be used to introduce rules for diﬀerentiation of user-deﬁned operators. Its general form is

FOR ALL ⟨var1⟩,…,⟨varn⟩
LET DF(⟨operator⟩⟨varlist⟩,⟨vari⟩)=⟨expression⟩

where

⟨varlist⟩ ::= (⟨var1⟩,…,⟨varn⟩),

and ⟨var1⟩,…,⟨varn⟩ are the dummy variable arguments of ⟨operator⟩.

An analogous form applies to inﬁx operators.

Examples:

for all x let df(tan x,x)= 1 + tan(x)^2;

(This is how the tan diﬀerentiation rule appears in the REDUCE source.)

for all x,y let df(f(x,y),x)=2*f(x,y),
df(f(x,y),y)=x*f(x,y);

Notice that all dummy arguments of the relevant operator must be declared arbitrary by the FOR ALL command, and that rules may be supplied for operators with any number of arguments. If no diﬀerentiation rule appears for an argument in an operator, the diﬀerentiation routines will return as result an expression in terms of DF. For example, if the rule for the diﬀerentiation with respect to the second argument of F is not supplied, the evaluation of df(f(x,z),z) would leave this expression unchanged. (No DEPEND declaration is needed here, since f(x,z) obviously “depends on” Z.)

Once such a rule has been deﬁned for a given operator, any future diﬀerentiation rules for that operator must be deﬁned with the same number of arguments for that operator, otherwise we get the error message

Incompatible DF rule argument length for <operator>

#### 7.8.3 Options controlling display of derivatives

If the switch DFPRINT is turned on (it is oﬀ by default) then derivatives are displayed using subscripts, as illustrated below. In graphical environments with typeset mathematics enabled, the (shared) variable FANCY_PRINT_DF can be set to one of the values PARTIAL, TOTAL or INDEXED to control the display of derivatives. The default value is PARTIAL. However, if the switch DFPRINT is on then FANCY_PRINT_DF is ignored. For example, with the following settings, derivatives are displayed as follows (assuming DEPEND F,X,Y and OPERATOR G):

Setting | df(f,x,2,y) | df(g(x,y),x,2,y)
fancy_print_df:=partial |  |
fancy_print_df:=total |  |
fancy_print_df:=indexed |  |
on dfprint |  |

Up | Next | Prev | PrevTail | Front