ToC

This comes from Lie.scm.

(defn- vector-field-Lie-derivative [X]
(let [freeze-X (g/freeze X)
op-name `(~'Lie-derivative ~freeze-X)]
(-> (fn rec [Y]
(cond (f/function? Y) (X Y)
(vf/vector-field? Y) (o/commutator X Y)
(ff/form-field? Y)
(let [k (ff/get-rank Y)
op (fn [& vectors]
(let [vectors (into [] vectors)]
(assert (= k (count vectors))
`(~'≠ ~k ~(count vectors)
~@vectors
~@(map meta vectors)))
(g/- ((g/Lie-derivative X) (apply Y vectors))
(ua/generic-sum
(fn [i]
(let [xs (update vectors i (g/Lie-derivative X))]
(apply Y xs)))
0 k))))
name `((~'Lie-derivative ~freeze-X) ~(g/freeze Y))]
(ff/procedure->nform-field op k name))
(s/structure? Y)
(s/mapr (vector-field-Lie-derivative X) Y)
:else (u/unsupported "Bad argument: Lie Derivative")))
(o/make-operator op-name))))
#object[emmy.calculus.covariant$vector_field_Lie_derivative 0x6e5b35a "
emmy.calculus.covariant$vector_field_Lie_derivative@6e5b35a"
]
(defmethod g/Lie-derivative [::vf/vector-field] [V]
(vector-field-Lie-derivative V))
#object[clojure.lang.MultiFn 0xd31ac27 "
clojure.lang.MultiFn@d31ac27"
]

From ODE.scm:

Let (sigma t) be the state of a system at time t. Let the (first-order) system of differential equations governing the evolution of this state be:

((D sigma) t) = (R (sigma t)) or (D sigma) = (compose R sigma)

i.e. R is a system derivative.

Let F be any function of state, then a differential equation for the evolution of F, as it is dragged along the integral curve sigma is:

(D (compose F sigma)) = (* (compose (D F) sigma) (D sigma)) = (compose (* (D F) R) sigma)

Let's call this operation Lie-D (the Lie derivative for coordinates):

(defn Lie-D
"Takes a system derivative `R` and returns a operator that takes a function `F`
of coordinatized state and performs the operation described below, from
ODE.scm in scmutils:
Let `(sigma t)` be the state of a system at time `t`. Let the
(first-order) system of differential equations governing the evolution of
this state be:
```clojure
((D sigma) t) = (R (sigma t))
```
```clojure
(D sigma) = (compose R sigma)
```
i.e. `R` is a system derivative.
Let `F` be any function of state, then a differential equation for the
evolution of `F`, as it is dragged along the integral curve sigma is:
```clojure
(D (compose F sigma)) = (* (compose (D F) sigma) (D sigma))
= (compose (* (D F) R) sigma)
```
Let's call this operation `Lie-D` (the Lie derivative for coordinates)."
[R]
(-> (fn [F]
(g/* (D F) R))
(o/make-operator
(list 'Lie-D (g/freeze R)))))
#object[emmy.calculus.covariant$Lie_D 0x663897fb "
emmy.calculus.covariant$Lie_D@663897fb"
]

Interior Product, from interior-product.scm

(defn interior-product [X]
(assert (vf/vector-field? X))
(fn ix [alpha]
(assert (ff/form-field? alpha))
(let [p (ff/get-rank alpha)]
(assert (> p 0)
"Rank of form not greater than zero: interior-product")
(ff/procedure->nform-field
(fn the-product [& vectors]
(assert (= (dec p) (count vectors)))
(apply alpha X vectors))
(dec p)
`((~'interior-product ~(g/freeze X))
~(g/freeze alpha))))))
#object[emmy.calculus.covariant$interior_product 0x66b303a8 "
emmy.calculus.covariant$interior_product@66b303a8"
]

Covariant Derivative, from covariant-derivative.scm

(defn make-Cartan
[forms basis]
{:type ::Cartan
:forms forms
:basis basis})
#object[emmy.calculus.covariant$make_Cartan 0x6297dcaa "
emmy.calculus.covariant$make_Cartan@6297dcaa"
]
(defn Cartan? [x]
(= (v/kind x) ::Cartan))
#object[emmy.calculus.covariant$Cartan_QMARK_ 0x4943ccc1 "
emmy.calculus.covariant$Cartan_QMARK_@4943ccc1"
]
(defn Cartan->forms [C]
(:forms C))
#object[emmy.calculus.covariant$Cartan__GT_forms 0x6be61d5d "
emmy.calculus.covariant$Cartan__GT_forms@6be61d5d"
]
(defn Cartan->basis [C]
(:basis C))
#object[emmy.calculus.covariant$Cartan__GT_basis 0x1536edca "
emmy.calculus.covariant$Cartan__GT_basis@1536edca"
]
(defn make-Christoffel
"Returns a data structure representing [Christoffel symbols of the second
kind](https://en.wikipedia.org/wiki/Christoffel_symbols#Christoffel_symbols_of_the_second_kind_(symmetric_definition))."
[symbols basis]
{:type ::Christoffel
:symbols symbols
:basis basis})
#object[emmy.calculus.covariant$make_Christoffel 0x4998014a "
emmy.calculus.covariant$make_Christoffel@4998014a"
]
(defn Christoffel? [x]
(= (v/kind x) ::Christoffel))
#object[emmy.calculus.covariant$Christoffel_QMARK_ 0x1e6ae97c "
emmy.calculus.covariant$Christoffel_QMARK_@1e6ae97c"
]
(defn Christoffel->symbols [C]
(:symbols C))
#object[emmy.calculus.covariant$Christoffel__GT_symbols 0x45bd0319 "
emmy.calculus.covariant$Christoffel__GT_symbols@45bd0319"
]
(defn Christoffel->basis [C]
(:basis C))
#object[emmy.calculus.covariant$Christoffel__GT_basis 0x67c7eed9 "
emmy.calculus.covariant$Christoffel__GT_basis@67c7eed9"
]
(defn Cartan->Christoffel [Cartan]
{:pre [(Cartan? Cartan)]}
(let [basis (Cartan->basis Cartan)
forms (Cartan->forms Cartan)]
(make-Christoffel
(s/mapr forms (b/basis->vector-basis basis))
basis)))
#object[emmy.calculus.covariant$Cartan__GT_Christoffel 0x6edc213a "
emmy.calculus.covariant$Cartan__GT_Christoffel@6edc213a"
]
(defn Christoffel->Cartan [Christoffel]
{:pre [(Christoffel? Christoffel)]}
(let [basis (Christoffel->basis Christoffel)
symbols (Christoffel->symbols Christoffel)]
(make-Cartan
(g/* symbols (b/basis->oneform-basis basis))
basis)))
#object[emmy.calculus.covariant$Christoffel__GT_Cartan 0x27341494 "
emmy.calculus.covariant$Christoffel__GT_Cartan@27341494"
]
(defn symmetrize-Christoffel [G]
(let [s (Christoffel->symbols G)]
(make-Christoffel
(g/* (g// 1 2)
(g/+ s (s/transpose-outer s)))
(Christoffel->basis G))))
#object[emmy.calculus.covariant$symmetrize_Christoffel 0xa3c7ea0 "
emmy.calculus.covariant$symmetrize_Christoffel@a3c7ea0"
]
(defn symmetrize-Cartan [Cartan]
(Christoffel->Cartan
(symmetrize-Christoffel
(Cartan->Christoffel Cartan))))
#object[emmy.calculus.covariant$symmetrize_Cartan 0x52d5f818 "
emmy.calculus.covariant$symmetrize_Cartan@52d5f818"
]
(defn Cartan-transform
[cartan basis-prime]
(let [basis (Cartan->basis cartan) ;; tuple of basis vectors
forms (Cartan->forms cartan)
prime-dual-basis (b/basis->oneform-basis basis-prime)
prime-vector-basis (b/basis->vector-basis basis-prime)
vector-basis (b/basis->vector-basis basis)
oneform-basis (b/basis->oneform-basis basis)
J-inv (s/mapr oneform-basis prime-vector-basis)
J (s/mapr prime-dual-basis vector-basis)
omega-prime-forms (ff/procedure->oneform-field
(fn [u]
(g/+
(g/* J (u J-inv))
(g/* J (g/* (forms u) J-inv))))
'omega-prime-forms)]
(make-Cartan omega-prime-forms basis-prime)))
#object[emmy.calculus.covariant$Cartan_transform 0x5d0fc689 "
emmy.calculus.covariant$Cartan_transform@5d0fc689"
]
(defn Cartan->Cartan-over-map [Cartan map]
(let [basis (cm/basis->basis-over-map
map (Cartan->basis Cartan))
forms (s/mapr (cm/form-field->form-field-over-map map)
(Cartan->forms Cartan))]
(make-Cartan forms basis)))
#object[emmy.calculus.covariant$Cartan__GT_Cartan_over_map 0x5a18f908 "
emmy.calculus.covariant$Cartan__GT_Cartan_over_map@5a18f908"
]

Covariant Vector Definition

(defn- covariant-derivative-vector [Cartan]
(let [basis (Cartan->basis Cartan)
Cartan-forms (Cartan->forms Cartan)
vector-basis (b/basis->vector-basis basis)
oneform-basis (b/basis->oneform-basis basis)]
(fn [V]
(let [CV (Cartan-forms V)]
(fn [U]
(let [u-components (oneform-basis U)
deriv-components (g/+ (V u-components)
(g/* CV u-components))]
(vf/procedure->vector-field
(fn the-derivative [f]
(g/* (vector-basis f) deriv-components))
`((~'nabla ~(g/freeze V))
~(g/freeze U)))))))))
#object[emmy.calculus.covariant$covariant_derivative_vector 0x33b84595 "
emmy.calculus.covariant$covariant_derivative_vector@33b84595"
]
(defn- covariant-derivative-form [Cartan]
(fn [V]
(fn [tau]
(let [k (ff/get-rank tau)
nabla_V ((covariant-derivative-vector Cartan) V)
op (fn [& vectors]
(let [vectors (into [] vectors)]
(assert (= k (count vectors)))
(g/- (V (apply tau vectors))
(ua/generic-sum
(fn [i]
(let [xs (update vectors i nabla_V)]
(apply tau xs)))
0 k))))
name `((~'nabla ~(g/freeze V))
~(g/freeze tau))]
(ff/procedure->nform-field op k name)))))
#object[emmy.calculus.covariant$covariant_derivative_form 0x4ed06ec2 "
emmy.calculus.covariant$covariant_derivative_form@4ed06ec2"
]
(defn- covariant-derivative-argument-types
"NOTE: Returns a derivative with the same argument types as the original input
function."
[Cartan]
(let [basis (Cartan->basis Cartan)
vector-basis (b/basis->vector-basis basis)
oneform-basis (b/basis->oneform-basis basis)
Cartan-forms (Cartan->forms Cartan)]
(fn [V]
(let [CV (Cartan-forms V)]
(fn [T]
(let [arg-types (ci/argument-types T)]
(assert
(every? (fn [t]
(or (isa? t ::vf/vector-field)
(isa? t ::ff/oneform-field)))
arg-types))
(letfn [(lp [types args targs factors]
(if (empty? types)
(g/* (V (apply T targs))
(apply g/* factors))
(b/contract
(fn [e w]
(cond (isa? (first types) ::vf/vector-field)
(do (assert (vf/vector-field? (first args)))
(lp (rest types)
(rest args)
(conj targs e)
(conj factors (w (first args)))))
(isa? (first types) ::ff/oneform-field)
(do (assert (ff/oneform-field? (first args)))
(lp (rest types)
(rest args)
(conj targs w)
(conj factors ((first args) e))))))
basis)))
(the-derivative [& args]
(assert (= (count args)
(count arg-types)))
(let [argv (into [] args)
VT (lp arg-types argv [] [])
corrections (ua/generic-sum
(map-indexed
(fn [i type]
(cond
;; positive
(isa? type ::ff/oneform-field)
(g/*
(g/* (s/mapr (fn [e]
((nth argv i) e))
vector-basis)
CV)
(s/mapr
(fn [w]
(apply T (assoc argv i w)))
oneform-basis))
;; negative
(isa? type ::vf/vector-field)
(g/negate
(g/*
(s/mapr
(fn [e]
(apply T (assoc argv i e)))
vector-basis)
(g/* CV (s/mapr
(fn [w]
(w (nth argv i)))
oneform-basis))))))
arg-types))]
(g/+ VT corrections)))]
(ci/with-argument-types
the-derivative
arg-types))))))))
#object[emmy.calculus.covariant$covariant_derivative_argument_types 0x6d48d21f "
emmy.calculus.covariant$covariant_derivative_argument_types@6d48d21f"
]
(defn- covariant-derivative-function [Cartan]
(fn [X]
(fn [f]
(fn [& args]
(let [types (apply v/argument-kind args)]
(cond (and (= (count args) 1)
(manifold/manifold-point? (first args)))
(let [f (ci/with-argument-types f types)]
((X f) (first args)))
(every? (fn [arg] ;; either a vector field or oneform.
(or (vf/vector-field? arg)
(ff/oneform-field? arg)))
args)
(let [f (ci/with-argument-types f types)]
(apply (((covariant-derivative-argument-types Cartan) X) f)
args))
:else
(u/illegal "Bad function or arguments to covariant derivative")))))))
#object[emmy.calculus.covariant$covariant_derivative_function 0x7005a607 "
emmy.calculus.covariant$covariant_derivative_function@7005a607"
]
(defn- covariant-derivative-ordinary [Cartan]
{:pre [(Cartan? Cartan)]}
(fn [X]
(let [op (fn nabla_X [V]
(cond (vf/vector-field? V)
(((covariant-derivative-vector Cartan) X) V)
(ff/form-field? V)
(((covariant-derivative-form Cartan) X) V)
(ci/has-argument-types? V)
(((covariant-derivative-argument-types Cartan) X) V)
(f/function? V)
(((covariant-derivative-function Cartan) X) V)
(s/structure? V)
(s/mapr nabla_X V)
:else
(u/unsupported
(str "Can't do this kind of covariant derivative yet "
(g/freeze X) " @ " (g/freeze V)))))
name `(~'nabla
~(g/freeze X))]
(o/make-operator op name))))
#object[emmy.calculus.covariant$covariant_derivative_ordinary 0x160d17f "
emmy.calculus.covariant$covariant_derivative_ordinary@160d17f"
]
(defn covariant-derivative
([Cartan]
(covariant-derivative-ordinary Cartan))
([Cartan map]
(let [mapped (Cartan->Cartan-over-map Cartan map)]
(covariant-derivative-ordinary
(make-Cartan (f/compose (Cartan->forms mapped)
(cm/differential map))
(Cartan->basis mapped))))))
#object[emmy.calculus.covariant$covariant_derivative 0x4c0b19ef "
emmy.calculus.covariant$covariant_derivative@4c0b19ef"
]
(defn covariant-differential [Cartan]
(fn [V]
(fn [X]
(((covariant-derivative Cartan) X) V))))
#object[emmy.calculus.covariant$covariant_differential 0x6778e25b "
emmy.calculus.covariant$covariant_differential@6778e25b"
]
(defn geodesic-equation
[source-coordsys target-coordsys Cartan-on-target]
(fn [gamma]
(fn [source-m]
{:pre [(= 1 (:dimension
(manifold/manifold source-coordsys)))]}
(let [e (vf/coordinate-system->vector-basis source-coordsys)]
(((((covariant-derivative Cartan-on-target gamma)
e)
((cm/differential gamma) e))
(manifold/chart target-coordsys))
source-m)))))
#object[emmy.calculus.covariant$geodesic_equation 0x3a10552d "
emmy.calculus.covariant$geodesic_equation@3a10552d"
]
(defn parallel-transport-equation
[source-coordsys target-coordsys Cartan-on-target]
(fn [gamma]
(fn [vector-over-gamma]
(fn [source-m]
{:pre [(= 1 (:dimension
(manifold/manifold source-coordsys)))]}
(let [e (vf/coordinate-system->vector-basis source-coordsys)]
(((((covariant-derivative Cartan-on-target gamma)
e) ;; d/dt
vector-over-gamma)
(manifold/chart target-coordsys))
source-m))))))
#object[emmy.calculus.covariant$parallel_transport_equation 0x3d7c8039 "
emmy.calculus.covariant$parallel_transport_equation@3d7c8039"
]