anchor.diff:          | D(ap, at, ai), D(bp, bt, bi) when ai < bi -> D(atan2 a bp, -(a * bt) / (a * a + bp * bp), bi)
           | D(ap, at, ai), D(bp, bt, bi) when ai = bi -> D(atan2 ap bp, (at * bp - ap * bt) / (ap * ap + bp * bp), ai)
           | D(ap, at, ai), D(bp, bt, bi) when ai > bi -> D(atan2 ap b, (at * b) / (ap * ap + b * b), ai)
  +    // D - float binary operations
       static member (+) (a:D, b:float) =
           match a with
           | Df(a) -> Df(a + b)
  
positive.code:         match b with
          | Df(b) -> Df(atan2 a b)
          | D(bp, bt, bi) -> D(D.Atan2(a, bp), -(a * bt) / (a * a + bp * bp), bi)
      static member Log (a:D) =
          if (float a) <= 0. then invalidArgLog()
          match a with
  
negative.code:                                         <| xd.[j])
          (x |> Array.map dual |> f, Array.sumBy tangent a)
  
      /// Laplacian of a vector-to-scalar function `f`, at point `x`
      let inline laplacian f x =
          laplacian' f x |> snd
  
      /// Original value and Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`
      let inline jacobianv' f x v =
          let i = GlobalTagger.Next
          Array.map2 (dualIPT i) x v |> f |> Array.map tuple |> Array.unzip
  
      /// Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`
      let inline jacobianv f x v =
          jacobianv' f x v |> snd
  
      /// Original value and transposed Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobianT' f (x:_[]) =
          let a = Array.init x.Length (fun i -> jacobianv' f x (standardBasis x.Length i))
          (fst a.[0], array2D (Array.map snd a))
  
      /// Transposed Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobianT f x =
          jacobianT' f x |> snd
  
      /// Original value and Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobian' f x =
          jacobianT' f x |> fun (r, j) -> (r, transpose j)
  
      /// Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobian f x =
          jacobian' f x |> snd
  
      /// Gradient and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline gradhessian f x =
          jacobian' (grad f) x
  
      /// Original value, gradient, and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline gradhessian' f x =
          let g, h = gradhessian f x
          (x |> Array.map dual |> f, g, h)
  
      /// Hessian of a vector-to-scalar function `f`, at point `x`
      let inline hessian f x =
          jacobian (grad f) x
  
      /// Original value and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline hessian' f x =
          (x |> Array.map dual |> f, hessian f x)
  
      /// Original value and curl of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curl' f x =
          let v, j = jacobianT' f x
          if (Array2D.length1 j, Array2D.length2 j) <> (3, 3) then invalidArgCurl()
          v, [|j.[1, 2] - j.[2, 1]; j.[2, 0] - j.[0, 2]; j.[0, 1] - j.[1, 0]|]
  
      /// Curl of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curl f x =
          curl' f x |> snd
  
      /// Original value and divergence of a vector-to-vector function `f`, at point `x`. Defined only for functions with a square Jacobian matrix.
      let inline div' f x =
          let v, j = jacobianT' f x
          if Array2D.length1 j <> Array2D.length2 j then invalidArgDiv()
          v, trace j
  
      /// Divergence of a vector-to-vector function `f`, at point `x`. Defined only for functions with a square Jacobian matrix.
      let inline div f x =
          div' f x |> snd
  
      /// Original value, curl, and divergence of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curldiv' f x =
          let v, j = jacobianT' f x
          if (Array2D.length1 j, Array2D.length2 j) <> (3, 3) then invalidArgCurlDiv()
          v, [|j.[1, 2] - j.[2, 1]; j.[2, 0] - j.[0, 2]; j.[0, 1] - j.[1, 0]|], trace j
  
      /// Curl and divergence of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curldiv f x =
          curldiv' f x |> sndtrd
  
  
  module Vector =
      /// Original value and first derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diff' (f:D->D) x = ForwardOps.diff' f x
      /// First derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diff (f:D->D) x = ForwardOps.diff f x
      /// Original value and second derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diff2' (f:D->D) x = ForwardOps.diff2' f x
      /// Second derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diff2 (f:D->D) x = ForwardOps.diff2 f x
      /// Original value, first derivative, and second derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diff2'' (f:D->D) x = ForwardOps.diff2'' f x
      /// Original value and the `n`-th derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diffn' (n:int) (f:D->D) x = ForwardOps.diffn' n f x
      /// `n`-th derivative of a scalar-to-scalar function `f`, at point `x`
      let inline diffn (n:int) (f:D->D) x = ForwardOps.diffn n f x
      /// Original value and directional derivative of a vector-to-scalar function `f`, at point `x`, along vector `v`
      let inline gradv' (f:Vector<D>->D) x v = ForwardOps.gradv' (vector >> f) (Vector.toArray x) (Vector.toArray v)
      /// Directional derivative of a vector-to-scalar function `f`, at point `x`, along vector `v`
      let inline gradv (f:Vector<D>->D) x v = ForwardOps.gradv (vector >> f) (Vector.toArray x) (Vector.toArray v)
      /// Original value and gradient of a vector-to-scalar function `f`, at point `x`
      let inline grad' (f:Vector<D>->D) x = ForwardOps.grad' (vector >> f) (Vector.toArray x) |> fun (a, b) -> (a, vector b)
      /// Gradient of a vector-to-scalar function `f`, at point `x`
      let inline grad (f:Vector<D>->D) x = ForwardOps.grad (vector >> f) (Vector.toArray x) |> vector
      /// Original value and Laplacian of a vector-to-scalar function `f`, at point `x`
      let inline laplacian' (f:Vector<D>->D) x = ForwardOps.laplacian' (vector >> f) (Vector.toArray x)
      /// Laplacian of a vector-to-scalar function `f`, at point x
      let inline laplacian (f:Vector<D>->D) x = ForwardOps.laplacian (vector >> f) (Vector.toArray x)
      /// Original value and transposed Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobianT' (f:Vector<D>->Vector<_>) x = ForwardOps.jacobianT' (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b) -> (vector a, Matrix.ofArray2D b)
      /// Transposed Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobianT (f:Vector<D>->Vector<_>) x = ForwardOps.jacobianT (vector >> f >> Vector.toArray) (Vector.toArray x) |> Matrix.ofArray2D
      /// Original value and Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobian' (f:Vector<D>->Vector<_>) x = ForwardOps.jacobian' (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b) -> (vector a, Matrix.ofArray2D b)
      /// Jacobian of a vector-to-vector function `f`, at point `x`
      let inline jacobian (f:Vector<D>->Vector<_>) x = ForwardOps.jacobian (vector >> f >> Vector.toArray) (Vector.toArray x) |> Matrix.ofArray2D
      /// Original value and Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`
      let inline jacobianv' (f:Vector<D>->Vector<D>) x v = ForwardOps.jacobianv' (vector >> f >> Vector.toArray) (Vector.toArray x) (Vector.toArray v) |> fun (a, b) -> (vector a, vector b)
      /// Jacobian-vector product of a vector-to-vector function `f`, at point `x`, along vector `v`
      let inline jacobianv (f:Vector<D>->Vector<D>) x v = ForwardOps.jacobianv (vector >> f >> Vector.toArray) (Vector.toArray x) (Vector.toArray v) |> vector
      /// Hessian of a vector-to-scalar function `f`, at point `x`
      let inline hessian (f:Vector<D>->D) x = ForwardOps.hessian (vector >> f) (Vector.toArray x) |> Matrix.ofArray2D
      /// Original value and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline hessian' (f:Vector<D>->D) x = ForwardOps.hessian' (vector >> f) (Vector.toArray x) |> fun (a, b) -> (a, Matrix.ofArray2D b)
      /// Original value, gradient, and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline gradhessian' (f:Vector<D>->D) x = ForwardOps.gradhessian' (vector >> f) (Vector.toArray x) |> fun (a, b, c) -> (a, vector b, Matrix.ofArray2D c)
      /// Gradient and Hessian of a vector-to-scalar function `f`, at point `x`
      let inline gradhessian (f:Vector<D>->D) x = ForwardOps.gradhessian (vector >> f) (Vector.toArray x) |> fun (a, b) -> (vector a, Matrix.ofArray2D b)
      /// Original value and curl of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curl' (f:Vector<D>->Vector<D>) x = ForwardOps.curl' (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b) -> (vector a, vector b)
      /// Curl of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curl (f:Vector<D>->Vector<D>) x = ForwardOps.curl (vector >> f >> Vector.toArray) (Vector.toArray x) |> vector
      /// Original value and divergence of a vector-to-vector function `f`, at point `x`. Defined only for functions with a square Jacobian matrix.
      let inline div' (f:Vector<D>->Vector<D>) x = ForwardOps.div' (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b) -> (vector a, b)
      /// Divergence of a vector-to-vector function `f`, at point `x`. Defined only for functions with a square Jacobian matrix.
      let inline div (f:Vector<D>->Vector<D>) x = ForwardOps.div (vector >> f >> Vector.toArray) (Vector.toArray x)
      /// Original value, curl, and divergence of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curldiv' (f:Vector<D>->Vector<D>) x = ForwardOps.curldiv' (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b, c) -> (vector a, vector b, c)
      /// Curl and divergence of a vector-to-vector function `f`, at point `x`. Supported only for functions with a three-by-three Jacobian matrix.
      let inline curldiv (f:Vector<D>->Vector<D>) x = ForwardOps.curldiv (vector >> f >> Vector.toArray) (Vector.toArray x) |> fun (a, b) -> (vector a, b)