Physics[diff]  evaluate total and partial derivatives, with respect to commutative and noncommutative variables, functions, tensors, or tensor functions, using the sum rule for repeated indices

Calling Sequence


diff(expression, x, t, ... )
diff(expression, x, t, ..., {f1(x, ...), f2(t, ...), ....})


Parameters


expression



any mathematical expression or relation between expressions

x, t, ...



the derivation variables; (tensorial or not) names or functions, commutative or anticommutative

{f(x, ...), ...}



(optional) to compute the derivative with respect to x at fixed f(x, ...), and in this way compute true partial derivatives





Description


•

The diff command computes total or partial derivatives (with respect to $t$ at a fixed $f\left(t\right)$) of algebraic expressions with respect to commutative or anticommutative variables or functions, commonly used in physics and in formulations based on variational principles. diff accepts an indexed tensor function as its differentiation variable, in which case its symmetry properties and the sum rule for repeated indices are taken into account when computing the derivative. To define an indexed object as a tensor function, see Define.

•

Diff and %diff are the inert forms of diff; that is, they represent the same mathematical operation while displaying the operation unevaluated. To evaluate the operation, use the value command.

•

For details regarding differentiation with respect to anticommutative objects, see diff, anticommutative; the rest of this help page discusses the case of differentiation with respect to commutative objects.

•

In order to evaluate "partial derivatives," for instance, the partial derivative of $L\left(t\,q\left(t\right)\right)$ with respect to $t$, at a fixed point $q\left(t\right)$, an indication of which functions depending on the differentiation variable must be fixed is required. This indication is always given to diff as the last argument, and must be in a set (enclosed by { }). The functions of $t$ indicated inside the braces, as well as their derivatives, are fixed (considered as not depending on $t$) during the calculation of the partial derivative.

•

If the algebraic expression (derivand) is given with the functional dependence indicated but in implicit form (for example, $f\left(x\,y\,z\right)$ with unknown form for $f$), then the result returned by diff is expressed by using:


 the standard diff command (not the Physics diff), when all of the mathematical objects involved in the derivand are commutative and the differentiation variable is of type name.


When the output is returned in terms of D (that is, it involves D derivatives of unknown functions), this result can be transformed into one free of D derivatives by using the convert(expr, diff) command after defining the explicit form of the functions entering the derivand through a direct assignment, not requiring the use of mappings (see the Examples section).

•

Special rules for the evaluation of partial derivatives of userdefined functions can be stated by indicating the differentiation rule to the standard Maple diff command as usual.

•

It makes no difference whether you use the :diff, :Diff, or D command in the arguments passed to the Physics[diff] command; it takes into account the mathematical equivalence between them. For example, diff(L, diff(q(t),t)), diff(L, Diff(q(t),t)), and diff(L, D(q)(t)) all return the same result.

•

As a rule, diff always tries not to change the format (diff, Diff, or D) of derivatives appearing in the input. Nevertheless, when more than one of these formats is present and representing the same mathematical object, the format used in the output will be that of the derivatives found in the "differentiation variable." If the latter does not involve derivatives and the derivand uses more than one format to represent the same mathematical object, the result is returned using the D format for that object.

•

When a mathematical formulation involving diff or D can be expressed in terms of the other differentiation operator or their inert versions, that conversion can be achieved by using the convert command, as in convert(expr, diff_command), where diff_command is diff or D.



Examples


>

$\mathrm{with}\left(\mathrm{Physics}\right)\:$

>

$\mathrm{Setup}\left(\mathrm{mathematicalnotation}=\mathrm{true}\right)$

$\left[{\mathrm{mathematicalnotation}}{=}{\mathrm{true}}\right]$
 (1) 
diff can differentiate with respect to functions.
>

$\mathrm{diff}\left(\mathrm{cos}\left(q\left(t\right)\right)\,q\left(t\right)\right)$

${}{\mathrm{sin}}{}\left({q}{}\left({t}\right)\right)$
 (2) 
Different formats for derivatives, such as diff and D, are recognized as mathematically equal.
>

$\mathrm{diff}\left({\mathrm{diff}\left(q\left(t\right)\,t\right)}^{\frac{1}{2}}\,\mathrm{D}\left(q\right)\left(t\right)\right)$

$\frac{{1}}{{2}{}\sqrt{{\mathrm{D}}{}\left({q}\right){}\left({t}\right)}}$
 (3) 
>

${\mathrm{diff}\left(q\left(t\right)\,t\right)}^{\frac{1}{2}}+{\mathrm{D}\left(q\right)\left(t\right)}^{3}$

$\sqrt{\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)}{+}{{\mathrm{D}}{}\left({q}\right){}\left({t}\right)}^{{3}}$
 (4) 
>

$\mathrm{diff}\left(\,\mathrm{diff}\left(q\left(t\right)\,t\right)\right)$

$\frac{{1}}{{2}{}\sqrt{\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)}}{+}{3}{}{\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)}^{{2}}$
 (5) 
Regarding the choice of format (diff or D) in the output above, see the Description section of this page.
Set an alias for this generic functionality.
>

$Q=\left(t\,q\left(t\right)\,\mathrm{diff}\left(q\left(t\right)\,t\right)\right)$

${Q}{=}\left({t}{\,}{q}{}\left({t}\right){\,}\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)\right)$
 (6) 
>

$\mathrm{alias}\left(\right)\:$

The total derivative with respect to $t$ of a function of Q is given by:
>

$\mathrm{dL\_dt}\u2254\mathrm{diff}\left(L\left(Q\right)\,t\right)$

${\mathrm{dL\_dt}}{\u2254}{{\mathrm{D}}}_{{1}}{}\left({L}\right){}\left({Q}\right){+}{{\mathrm{D}}}_{{2}}{}\left({L}\right){}\left({Q}\right){}\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right){+}{{\mathrm{D}}}_{{3}}{}\left({L}\right){}\left({Q}\right){}\stackrel{{\mathbf{..}}}{{q}}{}\left({t}\right)$
 (7) 
Now in typical frameworks, Q is a function of three variables (for example, time, position, and velocity), and you want to compute the partial derivatives of Q with respect to each of the three variables. First, compute the partial derivative with respect to $t$ at fixed $q\left(t\right)$, then $q\left(t\right)$ in general, and finally,$\frac{\ⅆq}{\ⅆt}$.
>

$\mathrm{pdL\_dt}\u2254\mathrm{diff}\left(L\left(Q\right)\,t\,\left\{q\left(t\right)\right\}\right)$

${\mathrm{pdL\_dt}}{\u2254}{{\mathrm{D}}}_{{1}}{}\left({L}\right){}\left({Q}\right)$
 (8) 
>

$\mathrm{pdL\_dq}\u2254\mathrm{diff}\left(L\left(Q\right)\,q\left(t\right)\right)$

${\mathrm{pdL\_dq}}{\u2254}{{\mathrm{D}}}_{{2}}{}\left({L}\right){}\left({Q}\right)$
 (9) 
>

$\mathrm{pdL\_ddq}\u2254\mathrm{diff}\left(L\left(Q\right)\,\mathrm{diff}\left(q\left(t\right)\,t\right)\right)$

${\mathrm{pdL\_ddq}}{\u2254}{{\mathrm{D}}}_{{3}}{}\left({L}\right){}\left({Q}\right)$
 (10) 
Now assign a value to L(Q), without using mappings.
>

$L\left(Q\right)\u2254\frac{1}{2}{\mathrm{diff}\left(q\left(t\right)\,t\right)}^{2}\frac{1}{2}k{q\left(t\right)}^{2}\mathrm{cos}\left(wt\right)$

${L}{}\left({Q}\right){\u2254}\frac{{\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)}^{{2}}}{{2}}{}\frac{{k}{}{{q}{}\left({t}\right)}^{{2}}}{{2}}{}{\mathrm{cos}}{}\left({w}{}{t}\right)$
 (11) 
Each of the three partial derivatives computed above (when L(Q) was still unassigned) can be transformed into concrete results by using the convert, diff command.
>

$\mathrm{convert}\left(\mathrm{pdL\_dt}\,\mathrm{diff}\right)$

${w}{}{\mathrm{sin}}{}\left({w}{}{t}\right)$
 (12) 
>

$\mathrm{convert}\left(\mathrm{pdL\_dq}\,\mathrm{diff}\right)$

${}{k}{}{q}{}\left({t}\right)$
 (13) 
>

$\mathrm{convert}\left(\mathrm{pdL\_ddq}\,\mathrm{diff}\right)$

$\stackrel{{\mathbf{.}}}{{q}}{}\left({t}\right)$
 (14) 
Consider now an indexed object representing a spacetime tensor, so one for which the sum rule for repeated indices should be applied when computing derivatives. Spacetime tensors are defined as such by using the Define command
>

$\mathrm{Define}\left(A\right)$

$\mathrm{Defined\; objects\; with\; tensor\; properties}$
 
$\left\{{A}{\,}{{\mathrm{\gamma}}}_{{\mathrm{\mu}}}{\,}{{\mathrm{\sigma}}}_{{\mathrm{\mu}}}{\,}{{\partial}}_{{\mathrm{\mu}}}{\,}{{g}}_{{\mathrm{\mu}}{,}{\mathrm{\nu}}}{\,}{{\mathrm{\epsilon}}}_{{\mathrm{\alpha}}{,}{\mathrm{\beta}}{,}{\mathrm{\mu}}{,}{\mathrm{\nu}}}\right\}$
 (15) 
So now the derivative of ${A}_{\mathrm{\mu}}$ with respect to ${A}_{\mathrm{\nu}}$ is $0$ if $\mathrm{\mu}\ne \mathrm{\nu}$, and ${\mathrm{g\_}}_{\mathrm{\mu},\mathrm{\mu}}$ summed over $\mathrm{\mu}$, that is the dimension of spacetime when $\mathrm{\nu}=\mathrm{\mu}$.
>

$\mathrm{diff}\left(A\left[\mathrm{\mu}\right]\,A\left[\mathrm{\nu}\right]\right)$

${{\mathrm{g\_}}}_{{\mathrm{\mu}}\phantom{{\mathrm{\nu}}}}^{\phantom{{\mathrm{\mu}}}{\mathrm{\nu}}}$
 (16) 
If the indices are repeated, then the sum rule for them is automatically applied.
>

$\mathrm{diff}\left(A\left[\mathrm{\mu}\right]\,A\left[\mathrm{\mu}\right]\right)$

Note that the behavior above does not happen when the differentiation variable was not defined as an object with tensorial properties (that is, having tensor properties with respect to its indices) by the Define command. For example, so far $B$ is not a tensor:
>

$\mathrm{Define}\left(B\,\mathrm{query}\right)$

$\mathrm{Not\; defined\; as\; a\; tensor\; within\; the\; framework\; of\; the\; Physics\; package}$
 (18) 
and so the derivative of ${B}_{\mathrm{\mu}}$ with respect to ${B}_{\mathrm{\nu}}$ is just zero.
>

$\mathrm{diff}\left(B\left[\mathrm{\mu}\right]\,B\left[\mathrm{\nu}\right]\right)$

If you now define it as a tensor, a result as with $A$ is returned.
>

$\mathrm{Define}\left(B\right)$

$\mathrm{Defined\; objects\; with\; tensor\; properties}$
 
$\left\{{B}{\,}{{A}}_{{\mathrm{\mu}}}{\,}{{\mathrm{\gamma}}}_{{\mathrm{\mu}}}{\,}{{\mathrm{\sigma}}}_{{\mathrm{\mu}}}{\,}{{\partial}}_{{\mathrm{\mu}}}{\,}{{g}}_{{\mathrm{\mu}}{,}{\mathrm{\nu}}}{\,}{{\mathrm{\epsilon}}}_{{\mathrm{\alpha}}{,}{\mathrm{\beta}}{,}{\mathrm{\mu}}{,}{\mathrm{\nu}}}\right\}$
 (20) 
>

$\mathrm{diff}\left(B\left[\mathrm{\mu}\right]\,B\left[\mathrm{\nu}\right]\right)$

${{\mathrm{g\_}}}_{{\mathrm{\mu}}\phantom{{\mathrm{\nu}}}}^{\phantom{{\mathrm{\mu}}}{\mathrm{\nu}}}$
 (21) 
Note also that the information on $B$ has been updated in the background: now the system knows that $B$ is a tensor with only one index, so an error interruption will occur if it is used with more indices.
>

$\mathrm{diff}\left(B\left[\mathrm{\mu},\mathrm{\alpha}\right]\,B\left[\mathrm{\nu},\mathrm{\beta}\right]\right)$



See Also


Define, diff and D notations and conversions, Physics, Physics conventions, Physics examples, Physics Updates, Tensors  a complete guide, MiniCourse Computer Algebra for Physicists, Physics,diff,anticommutative, Setup


References



ChebTerrab, E.S. "Maple procedures for partial and functional derivatives." Computer Physics Communications, Vol. 79. (1994): 409424.


