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⁡t) 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⁡t,q⁡t with respect to t, at a fixed point q⁡t, 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⁡x,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.
Examples
with⁡Physics:
Setup⁡mathematicalnotation=true
mathematicalnotation=true
diff can differentiate with respect to functions.
diff⁡cos⁡q⁡t,q⁡t
−sin⁡q⁡t
Different formats for derivatives, such as diff and D, are recognized as mathematically equal.
diff⁡diff⁡q⁡t,t12,D⁡q⁡t
12⁢D⁡q⁡t
diff⁡q⁡t,t12+D⁡q⁡t3
q.⁡t+D⁡q⁡t3
diff⁡,diff⁡q⁡t,t
12⁢q.⁡t+3⁢q.⁡t2
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=t,q⁡t,diff⁡q⁡t,t
Q=t,q⁡t,q.⁡t
alias⁡:
The total derivative with respect to t of a function of Q is given by:
dL_dt≔diff⁡L⁡Q,t
dL_dt≔D1⁡L⁡Q+D2⁡L⁡Q⁢q.⁡t+D3⁡L⁡Q⁢q..⁡t
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⁡t, then q⁡t in general, and finally,ⅆqⅆt.
pdL_dt≔diff⁡L⁡Q,t,q⁡t
pdL_dt≔D1⁡L⁡Q
pdL_dq≔diff⁡L⁡Q,q⁡t
pdL_dq≔D2⁡L⁡Q
pdL_ddq≔diff⁡L⁡Q,diff⁡q⁡t,t
pdL_ddq≔D3⁡L⁡Q
Now assign a value to L(Q), without using mappings.
L⁡Q≔12⁢diff⁡q⁡t,t2−12⁢k⁢q⁡t2−cos⁡w⁢t
L⁡Q≔q.⁡t22−k⁢q⁡t22−cos⁡w⁢t
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.
convert⁡pdL_dt,diff
w⁢sin⁡w⁢t
convert⁡pdL_dq,diff
−k⁢q⁡t
convert⁡pdL_ddq,diff
q.⁡t
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
Define⁡A
Defined objects with tensor properties
A,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
So now the derivative of Aμ with respect to Aν is 0 if μ≠ν, and gμ,μ summed over μ, that is the dimension of spacetime when ν=μ.
diff⁡Aμ,Aν
δμνμν
If the indices are repeated, then the sum rule for them is automatically applied.
diff⁡Aμ,Aμ
4
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:
Define⁡B,query
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.
diff⁡Bμ,Bν
0
If you now define it as a tensor, a result as with A is returned.
Define⁡B
B,Aμ,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
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.
diff⁡Bμ,α,Bν,β
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
References
Cheb-Terrab, E.S. "Maple procedures for partial and functional derivatives." Computer Physics Communications, Vol. 79. (1994): 409-424.
Download Help Document