Lie derivative and Lie bracket
ad(X, g) differentiates along a vector field
using OptimalControlLie derivative
The Lie derivative of a function
For the harmonic oscillator,
X(x) = [x[2], -x[1]]
f(x) = x[1]^2 + x[2]^2
Xf = ad(X, f)
Xf([1.0, 2.0])0.0Lie bracket
The Lie bracket of two vector fields
where
Y(x) = [x[1]^2, x[2]^2]
Z = ad(X, Y)
Z([1.0, 2.0])2-element Vector{Float64}:
0.0
-3.0Typed operands and nested brackets
On VectorFields, ad returns a VectorField, which can be bracketed again. The bracket
XV = VectorField(x -> [x[2], -x[1]])
YV = VectorField(x -> [x[1]^2, x[2]^2])
ZV = ad(XV, YV)
ZV isa VectorField, ad(ZV, YV)([1.0, 2.0])(true, [4.0, -2.0])The macro @Lie writes the same bracket @Lie [[XV, YV], YV].
Time and variable
The derivatives are taken with respect to is_autonomous=false. With
Xt(t, x) = [t + x[2], -x[1]]
ft(t, x) = t + x[1]^2 + x[2]^2
ad(Xt, ft; is_autonomous=false)(1.0, [1.0, 2.0])2.0For a vector field is_variable=true. With
Xv(x, v) = [x[2] + v, -x[1]]
fv(x, v) = x[1]^2 + x[2]^2 + v
ad(Xv, fv; is_variable=true)([1.0, 2.0], 1.0)2.0Typed operands carry these traits, and must agree:
julia> Xa = VectorField(x -> [x[2], -x[1]]);
julia> Xb = VectorField((t, x) -> [t + x[2], -x[1]]; is_autonomous=false);
julia> ad(Xa, Xb)
PreconditionError → top-level scope, REPL[3]:2
│
│ ad: TD/VD mismatch between X and Y
│
│ Reason X: CTBase.Traits.Autonomous/CTBase.Traits.Fixed ≠ Y: CTBase.Traits.NonAutonomous/CTBase.Traits.Fixed — both arguments must share the same TimeDependence and VariableDependence
│
│ Context ad on AbstractVectorField
│ Hint Ensure both vector fields have the same time and variable dependence traits
└─Partial time derivative
For a function ∂ₜ(f) computes the partial derivative with respect to time:
With
g(t, x) = t^2 + x[1] * x[2]
dg = ∂ₜ(g)
dg(3.0, [1.0, 2.0])6.0∂ₜ also applies to a VectorField or a Hamiltonian. Its result always depends on time, even when the input does not, and is then zero:
dXV = ∂ₜ(XV)
dXV(1.0, [1.0, 2.0])2-element Vector{Float64}:
0.0
0.0Together with the Poisson bracket, ∂ₜ gives the time derivative of a function along an extremal (see Poisson bracket).
Errors
| Situation | Exception |
|---|---|
a Hamiltonian given to ad | IncorrectArgument, pointing to Poisson |
| operands with different dependences on time or on the variable | PreconditionError |
an in-place VectorField | NotImplemented |
a HamiltonianVectorField | NotImplemented |
julia> H = Hamiltonian((x, p) -> x[1] + p[1]);
julia> ad(H, x -> x)
IncorrectArgument → top-level scope, REPL[2]:2
│
│ ad is not defined for AbstractHamiltonian operands
│
│ Context ad on AbstractHamiltonian
│ Hint Use Poisson(H, G) for the Poisson bracket of Hamiltonians
└─julia> Xip = VectorField((dx, x) -> (dx .= [x[2], -x[1]]); is_inplace=true);
julia> ad(Xip, x -> x[1]^2)
NotImplemented → top-level scope, REPL[2]:2
│
│ ad is not implemented for InPlace vector fields
│
│ Method Use an OutOfPlace VectorField
│
│ Context ad on AbstractVectorField
│ Hint Reconstruct the VectorField without in-place flag
└─See also
Poisson bracket: the bracket of Hamiltonians, and
.The
@Liemacro: the bracket notation.AD backend: how the derivatives are computed.