diff - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

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, ...), ....})




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



The diff command computes total or partial derivatives (with respect to t at a fixed ft) 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 Lt,qt with respect to t, at a fixed point qt, 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, fx,y,z 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.


- the Physics diff command, when the derivand involves anticommutative objects or the differentiation variable is of type function (the display of the Physics diff is the same as that of the standard diff).


- D, otherwise.


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 user-defined 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.






diff can differentiate with respect to functions.




Different formats for derivatives, such as diff and D, are recognized as mathematically equal.










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.





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




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 qt, then qt in general, and finally,ⅆqⅆt.










Now assign a value to L(Q), without using mappings.




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.










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


Defined objects with tensor properties



So now the derivative of Aμ with respect to Aν is 0 if μν, and gμ,μ summed over μ, that is the dimension of spacetime when ν=μ.




If the indices are repeated, then the sum rule for them is automatically applied.




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:


Not defined as a tensor within the framework of the Physics package


and so the derivative of Bμ with respect to Bν is just zero.




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


Defined objects with tensor properties






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.


Error, (in Physics:-diff) found B with 2 spacetime indices, [mu, alpha], contradicting a previous definition with 1 such indices. You can use Define with the 'clear' or 'redo' options to discard the previous definition.

See Also

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



Cheb-Terrab, E.S. "Maple procedures for partial and functional derivatives." Computer Physics Communications, Vol. 79. (1994): 409-424.