-- |
-- Module      : Data.Function.Differentiable
-- Copyright   : (c) Justus Sagemüller 2015
-- License     : GPL v3
-- 
-- Maintainer  : (@) jsag $ hvl.no
-- Stability   : experimental
-- Portability : portable
-- 

{-# LANGUAGE FlexibleInstances        #-}
{-# LANGUAGE UndecidableInstances     #-}
{-# LANGUAGE TypeFamilies             #-}
{-# LANGUAGE FunctionalDependencies   #-}
{-# LANGUAGE FlexibleContexts         #-}
{-# LANGUAGE LiberalTypeSynonyms      #-}
{-# LANGUAGE GADTs                    #-}
{-# LANGUAGE RankNTypes               #-}
{-# LANGUAGE TupleSections            #-}
{-# LANGUAGE ConstraintKinds          #-}
{-# LANGUAGE PatternGuards            #-}
{-# LANGUAGE TypeOperators            #-}
{-# LANGUAGE TypeApplications         #-}
{-# LANGUAGE UnicodeSyntax            #-}
{-# LANGUAGE MultiWayIf               #-}
{-# LANGUAGE LambdaCase               #-}
{-# LANGUAGE ScopedTypeVariables      #-}
{-# LANGUAGE RecordWildCards          #-}
{-# LANGUAGE CPP                      #-}


module Data.Function.Differentiable (
            -- * Everywhere differentiable functions
              Differentiable
            -- * Region-wise defined diff'able functions
            , RWDiffable
            -- ** Operators for piecewise definition
            -- $definitionRegionOps
            , (?->), (?>), (?<), (?|:), backupRegions
            -- * Regions within a manifold
            , Region
            , smoothIndicator
            -- * Evaluation of differentiable functions
            , discretisePathIn
            , discretisePathSegs
            , continuityRanges
            , regionOfContinuityAround
            , analyseLocalBehaviour
            , intervalImages
            ) where
    


import Data.List
import Data.Maybe
import Data.Semigroup
import Data.Embedding
import Data.MemoTrie (HasTrie)

import Data.VectorSpace
import Math.LinearMap.Category
import Data.AffineSpace
import Data.Function.Differentiable.Data
import Data.Function.Affine
import Data.Basis
import Data.Tagged
import Data.Manifold.Types.Primitive
import Data.Manifold.PseudoAffine
import Data.Manifold.WithBoundary
import Data.Manifold.WithBoundary.Class
import Data.Manifold.Atlas

import qualified Prelude
import qualified Control.Applicative as Hask

import Control.Category.Constrained.Prelude hiding ((^))
import Control.Arrow.Constrained
import Control.Monad.Constrained
import Data.Foldable.Constrained



type RealDimension s
       = ( RealFloat' s, Manifold s, SimpleSpace s, Atlas' s
         , s ~ Needle s, s ~ Scalar s, s ~ DualVector s )


discretisePathIn :: (WithField  Manifold y, SimpleSpace (Needle y))
      => Int                        -- ^ Limit the number of steps taken in either direction. Note this will not cap the resolution but /length/ of the discretised path.
      -> ℝInterval                  -- ^ Parameter interval of interest.
      -> (RieMetric , RieMetric y) -- ^ Inaccuracy allowance /ε/.
      -> (Differentiable   y)     -- ^ Path specification.
      -> [(,y)]                    -- ^ Trail of points along the path, such that a linear interpolation deviates nowhere by more as /ε/.
discretisePathIn :: Int
-> ℝInterval
-> (RieMetric ℝ, RieMetric y)
-> Differentiable ℝ ℝ y
-> [(ℝ, y)]
discretisePathIn Int
nLim (xl, xr) (RieMetric ℝ
mx,RieMetric y
my) (Differentiable ℝ -> (y, Needle ℝ +> Needle y, LinDevPropag ℝ y)
f)
         = [(ℝ, y)] -> [(ℝ, y)]
forall a. [a] -> [a]
reverse ([(ℝ, y)] -> [(ℝ, y)]
forall a. [a] -> [a]
tail ([(ℝ, y)] -> [(ℝ, y)])
-> ([(ℝ, y)] -> [(ℝ, y)]) -> [(ℝ, y)] -> [(ℝ, y)]
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Int -> [(ℝ, y)] -> [(ℝ, y)]
forall a. Int -> [a] -> [a]
take Int
nLim ([(ℝ, y)] -> [(ℝ, y)]) -> [(ℝ, y)] -> [(ℝ, y)]
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ ℝ -> ℝ -> ℝ -> [(ℝ, y)]
traceFwd xl xm (-1))
          [(ℝ, y)] -> [(ℝ, y)] -> [(ℝ, y)]
forall a. [a] -> [a] -> [a]
++ Int -> [(ℝ, y)] -> [(ℝ, y)]
forall a. Int -> [a] -> [a]
take Int
nLim (ℝ -> ℝ -> ℝ -> [(ℝ, y)]
traceFwd xr xm 1)
 where traceFwd :: ℝ -> ℝ -> ℝ -> [(ℝ, y)]
traceFwd xlim x₀ dir
         | ℝ -> ℝ
forall a. Num a => a -> a
signum (x₀ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-xlim) ℝ -> ℝ -> Bool
forall a. Eq a => a -> a -> Bool
== ℝ -> ℝ
forall a. Num a => a -> a
signum dir = [(xlim, y
fxlim)]
         | Bool
otherwise                      = (x₀, y
fx₀) (ℝ, y) -> [(ℝ, y)] -> [(ℝ, y)]
forall a. a -> [a] -> [a]
: ℝ -> ℝ -> ℝ -> [(ℝ, y)]
traceFwd xlim (x₀ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+xstep) dir
        where (y
fx₀, LinearMap ℝ ℝ (Needle y)
jf, Norm (Needle y) -> Seminorm ℝ
δx²) = ℝ -> (y, Needle ℝ +> Needle y, LinDevPropag ℝ y)
f x₀
              εx :: Norm (Needle y)
εx = RieMetric y
my y
fx₀ Norm (Needle y) -> [Needle y] -> Norm (Needle y)
forall v. SimpleSpace v => Norm v -> [v] -> Norm v
`relaxNorm` [LinearMap ℝ ℝ (Needle y)
jf LinearMap ℝ ℝ (Needle y) -> ℝ -> Needle y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Seminorm ℝ -> ℝ
forall s. RealFrac' s => Norm s -> s
normalLength (Seminorm ℝ -> ℝ) -> Seminorm ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ RieMetric ℝ
mx x₀]
              χ :: Scalar ℝ
χ = Norm (Needle y) -> Seminorm ℝ
δx² Norm (Needle y)
εx Seminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 1
              xstep :: ℝ
xstep = dir ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
min (ℝ -> ℝ
forall a. Num a => a -> a
abs x₀ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+1) (ℝ -> ℝ
forall a. Fractional a => a -> a
recip ℝ
Scalar ℝ
χ)
              (y
fxlim, LinearMap ℝ ℝ (Needle y)
_, Norm (Needle y) -> Seminorm ℝ
_) = ℝ -> (y, Needle ℝ +> Needle y, LinDevPropag ℝ y)
f xlim
       xm :: ℝ
xm = (xr ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ xl) ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ 2
                      
type ℝInterval = (,)

continuityRanges :: WithField  Manifold y
      => Int                        -- ^ Max number of exploration steps per region
      -> RieMetric                 -- ^ Needed resolution of boundaries
      -> RWDiffable   y           -- ^ Function to investigate
      -> ([ℝInterval], [ℝInterval]) -- ^ Subintervals on which the function is guaranteed continuous.
continuityRanges :: Int
-> RieMetric ℝ -> RWDiffable ℝ ℝ y -> ([ℝInterval], [ℝInterval])
continuityRanges Int
nLim RieMetric ℝ
δbf (RWDiffable ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
f)
  | (PreRegion ℝ ℝ
GlobalRegion, Maybe (Differentiable ℝ ℝ y)
_) <- ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
f xc
                 = ([], [(-huge,huge)])
  | Bool
otherwise    = [ℝInterval] -> [ℝInterval] -> ([ℝInterval], [ℝInterval])
forall a b. Eq a => [(a, a)] -> [(a, b)] -> ([(a, a)], [(a, b)])
glueMid (ℝ -> ℝ -> [ℝInterval]
go xc (-1)) (ℝ -> ℝ -> [ℝInterval]
go xc 1)
 where go :: ℝ -> ℝ -> [ℝInterval]
go x₀ dir
         | yq₀ ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<= ℝ -> ℝ
forall a. Num a => a -> a
abs ((LinearMap ℝ ℝ ℝ
jq₀LinearMap ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$1) ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* step₀)
                      = ℝ -> ℝ -> [ℝInterval]
go (x₀ ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ step₀ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/2) dir
         | RealSubray S⁰_ ℝ
PositiveHalfSphere xl' <- PreRegion ℝ ℝ
rangeHere
                      = let stepl' :: ℝ
stepl' = dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/(RieMetric ℝ
δbf xl'Seminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 2)
                        in if dirℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>0
                            then if Bool
definedHere then [(ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
max (xl'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stepl') x₀, huge)]
                                                else []
                            else if Bool
definedHere Bool -> Bool -> Bool
&& x₀ ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
> xl'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stepl'
                                  then (xl'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stepl',x₀) ℝInterval -> [ℝInterval] -> [ℝInterval]
forall a. a -> [a] -> [a]
: ℝ -> ℝ -> [ℝInterval]
go (xl'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stepl') dir
                                  else ℝ -> ℝ -> [ℝInterval]
go (xl'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stepl') dir
         | RealSubray S⁰_ ℝ
NegativeHalfSphere xr' <- PreRegion ℝ ℝ
rangeHere
                      = let stepr' :: ℝ
stepr' = dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/(RieMetric ℝ
δbf xr'Seminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 2)
                        in if dirℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<0
                            then if Bool
definedHere then [(-huge, ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
min (xr'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stepr') x₀)]
                                                else []
                            else if Bool
definedHere Bool -> Bool -> Bool
&& x₀ ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
< xr'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stepr'
                                  then (x₀,xr'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stepr') ℝInterval -> [ℝInterval] -> [ℝInterval]
forall a. a -> [a] -> [a]
: ℝ -> ℝ -> [ℝInterval]
go (xr'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stepr') dir
                                  else ℝ -> ℝ -> [ℝInterval]
go (xr'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stepr') dir
         | Bool
otherwise  = Int -> ℝ -> ℝ -> [ℝInterval]
exit Int
nLim dir x₀
        where (PreRegion ℝ ℝ
rangeHere, Maybe (Differentiable ℝ ℝ y)
fq₀) = ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
f x₀
              (PreRegion (Differentiable ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
r₀)) = PreRegion ℝ ℝ -> PreRegion ℝ ℝ
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion ℝ ℝ
rangeHere
              (yq₀, LinearMap ℝ ℝ ℝ
jq₀, Seminorm ℝ -> Seminorm ℝ
δyq₀) = ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
r₀ x₀
              step₀ :: ℝ
step₀ = dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/(RieMetric ℝ
δbf x₀Seminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 1)
              exit :: Int -> ℝ -> ℝ -> [ℝInterval]
exit Int
0 _ xq
                | Bool -> Bool
not Bool
definedHere  = []
                | xq ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
< xc          = [(xq,x₀)]
                | Bool
otherwise        = [(x₀,xq)]
              exit Int
nLim' dir' xq
                | yq₁ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<0 Bool -> Bool -> Bool
|| LinDevPropag ℝ ℝ -> ℝ -> ℝ
forall a. RealDimension a => LinDevPropag a a -> a -> a
as_devεδ Seminorm ℝ -> Seminorm ℝ
LinDevPropag ℝ ℝ
δyq yq₁ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<ℝ -> ℝ
forall a. Num a => a -> a
abs stepp
                                      = Int -> ℝ -> ℝ -> [ℝInterval]
exit (Int
nLim'Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) (dir'ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/2) xq
                | yq₂ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<0
                , LinDevPropag ℝ ℝ -> ℝ -> ℝ
forall a. RealDimension a => LinDevPropag a a -> a -> a
as_devεδ Seminorm ℝ -> Seminorm ℝ
LinDevPropag ℝ ℝ
δyq (-yq₂)ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>=ℝ -> ℝ
forall a. Num a => a -> a
abs stepp
                , ℝ -> ℝ
resoHere steppℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<1    = (if Bool
definedHere
                                          then ((ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
min x₀ xq₁, ℝ -> ℝ -> ℝ
forall a. Ord a => a -> a -> a
max x₀ xq₁)ℝInterval -> [ℝInterval] -> [ℝInterval]
forall a. a -> [a] -> [a]
:)
                                          else [ℝInterval] -> [ℝInterval]
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) ([ℝInterval] -> [ℝInterval]) -> [ℝInterval] -> [ℝInterval]
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ ℝ -> ℝ -> [ℝInterval]
go xq₂ dir
                | Bool
otherwise           = Int -> ℝ -> ℝ -> [ℝInterval]
exit (Int
nLim'Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) dir xq₁
               where (yq, LinearMap ℝ ℝ ℝ
jq, Seminorm ℝ -> Seminorm ℝ
δyq) = ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
r₀ xq
                     xq₁ :: ℝ
xq₁ = xq ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ stepp
                     xq₂ :: ℝ
xq₂ = xq₁ ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ stepp
                     yq₁ :: ℝ
yq₁ = yq ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ f'xℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*stepp
                     yq₂ :: ℝ
yq₂ = yq₁ ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ f'xℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*stepp
                     f'x :: ℝ
f'x = LinearMap ℝ ℝ ℝ
jq LinearMap ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ 1
                     stepp :: ℝ
stepp | f'xℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*dir ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
< 0  = -0.9 ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* ℝ -> ℝ
forall a. Num a => a -> a
abs dir' ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* yqℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/f'x
                           | Bool
otherwise    = dir' ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* LinDevPropag ℝ ℝ -> ℝ -> ℝ
forall a. RealDimension a => LinDevPropag a a -> a -> a
as_devεδ Seminorm ℝ -> Seminorm ℝ
LinDevPropag ℝ ℝ
δyq yq -- TODO: memoise in `exit` recursion
                     resoHere :: ℝ -> ℝ
resoHere = Seminorm ℝ -> ℝ -> ℝ
forall v. LSpace v => Seminorm v -> v -> Scalar v
normSq (Seminorm ℝ -> ℝ -> ℝ) -> Seminorm ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ RieMetric ℝ
δbf xq
                     resoStep :: ℝ
resoStep = dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ℝ -> ℝ
forall a. Floating a => a -> a
sqrt(ℝ -> ℝ
resoHere 1)
              definedHere :: Bool
definedHere = case Maybe (Differentiable ℝ ℝ y)
fq₀ of
                              Just Differentiable ℝ ℝ y
_  -> Bool
True
                              Maybe (Differentiable ℝ ℝ y)
Nothing -> Bool
False
       glueMid :: [(a, a)] -> [(a, b)] -> ([(a, a)], [(a, b)])
glueMid ((a
l,a
le):[(a, a)]
ls) ((a
re,b
r):[(a, b)]
rs) | a
lea -> a -> Bool
forall a. Eq a => a -> a -> Bool
==a
re  = ([(a, a)]
ls, (a
l,b
r)(a, b) -> [(a, b)] -> [(a, b)]
forall a. a -> [a] -> [a]
:[(a, b)]
rs)
       glueMid [(a, a)]
l [(a, b)]
r = ([(a, a)]
l,[(a, b)]
r)
       huge :: ℝ
huge = ℝ -> ℝ
forall a. Floating a => a -> a
exp (ℝ -> ℝ) -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Int -> ℝ
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nLim
       xc :: ℝ
xc = 0

discretisePathSegs :: (WithField  Manifold y, SimpleSpace (Needle y))
      => Int              -- ^ Maximum number of path segments and/or points per segment.
      -> ( RieMetric 
         , RieMetric y )  -- ^ Inaccuracy allowance /δ/ for arguments
                          --   (mostly relevant for resolution of discontinuity boundaries –
                          --   consider it a “safety margin from singularities”),
                          --   and /ε/ for results in the target space.
      -> RWDiffable   y -- ^ Path specification. It is recommended that this
                          --   function be limited to a compact interval (e.g. with
                          --   '?>', '?<' and '?->'). For many functions the discretisation
                          --   will even work on an infinite interval: the point density
                          --   is exponentially decreased towards the infinities. But
                          --   this is still pretty bad for performance.
      -> ([[(,y)]], [[(,y)]]) -- ^ Discretised paths: continuous segments in either direction
discretisePathSegs :: Int
-> (RieMetric ℝ, RieMetric y)
-> RWDiffable ℝ ℝ y
-> ([[(ℝ, y)]], [[(ℝ, y)]])
discretisePathSegs Int
nLim (RieMetric ℝ
mx,RieMetric y
my) f :: RWDiffable ℝ ℝ y
f@(RWDiffable ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
ff)
                            = ( (ℝInterval -> [(ℝ, y)]) -> [ℝInterval] -> [[(ℝ, y)]]
forall a b. (a -> b) -> [a] -> [b]
map ℝInterval -> [(ℝ, y)]
discretise [ℝInterval]
ivsL, (ℝInterval -> [(ℝ, y)]) -> [ℝInterval] -> [[(ℝ, y)]]
forall a b. (a -> b) -> [a] -> [b]
map ℝInterval -> [(ℝ, y)]
discretise [ℝInterval]
ivsR )
 where ([ℝInterval]
ivsL, [ℝInterval]
ivsR) = Int
-> RieMetric ℝ -> RWDiffable ℝ ℝ y -> ([ℝInterval], [ℝInterval])
forall y.
WithField ℝ Manifold y =>
Int
-> RieMetric ℝ -> RWDiffable ℝ ℝ y -> ([ℝInterval], [ℝInterval])
continuityRanges Int
nLim RieMetric ℝ
mx RWDiffable ℝ ℝ y
f
       discretise :: ℝInterval -> [(ℝ, y)]
discretise rng :: ℝInterval
rng@(l,r) = Int
-> ℝInterval
-> (RieMetric ℝ, RieMetric y)
-> Differentiable ℝ ℝ y
-> [(ℝ, y)]
forall y.
(WithField ℝ Manifold y, SimpleSpace (Needle y)) =>
Int
-> ℝInterval
-> (RieMetric ℝ, RieMetric y)
-> Differentiable ℝ ℝ y
-> [(ℝ, y)]
discretisePathIn Int
nLim ℝInterval
rng (RieMetric ℝ
mx,RieMetric y
my) Differentiable ℝ ℝ y
fr
        where (PreRegion ℝ ℝ
_, Just Differentiable ℝ ℝ y
fr) = ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
ff (ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y)))
-> ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ y))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (lℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+r)ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/2

              
analyseLocalBehaviour ::
     RWDiffable   
  ->                       -- ^ /x/₀ value.
  -> Maybe ( (,)
           , ->Maybe  ) -- ^ /f/ /x/₀, derivative (i.e. Taylor-1-coefficient),
                           --   and reverse propagation of /O/ (/δ/²) bound.
analyseLocalBehaviour :: RWDiffable ℝ ℝ ℝ -> ℝ -> Maybe (ℝInterval, ℝ -> Maybe ℝ)
analyseLocalBehaviour (RWDiffable ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
f) x₀ = case ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
f x₀ of
       (PreRegion ℝ ℝ
r, Just (Differentiable ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
fd))
           | PreRegion ℝ ℝ -> ℝ -> Bool
forall a m. (Ord a, Num a) => PreRegion a m -> m -> Bool
inRegion PreRegion ℝ ℝ
r x₀ -> (ℝInterval, ℝ -> Maybe ℝ) -> Maybe (ℝInterval, ℝ -> Maybe ℝ)
forall (m :: * -> *) a. Monad m (->) => a -> m a
return ((ℝInterval, ℝ -> Maybe ℝ) -> Maybe (ℝInterval, ℝ -> Maybe ℝ))
-> (ℝInterval, ℝ -> Maybe ℝ) -> Maybe (ℝInterval, ℝ -> Maybe ℝ)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
              let (fx, LinearMap ℝ ℝ ℝ
j, Seminorm ℝ -> Seminorm ℝ
δf) = ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
fd x₀
                  epsprop :: ℝ -> Maybe ℝ
epsprop ε
                    | εℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>0  = case (Seminorm ℝ -> Seminorm ℝ
δf (Seminorm ℝ -> Seminorm ℝ) -> Seminorm ℝ -> Seminorm ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [DualVector ℝ] -> Seminorm ℝ
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [ℝ -> ℝ
forall a. Fractional a => a -> a
recip ε])Seminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 1 of
                               Scalar ℝ
0  -> Maybe ℝ
forall (f :: * -> *) a. Alternative f => f a
empty
                               Scalar ℝ
δ' -> ℝ -> Maybe ℝ
forall (m :: * -> *) a. Monad m (->) => a -> m a
return (ℝ -> Maybe ℝ) -> ℝ -> Maybe ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ ℝ -> ℝ
forall a. Fractional a => a -> a
recip ℝ
Scalar ℝ
δ'
                    | Bool
otherwise  = ℝ -> Maybe ℝ
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure 0
              in ((fx, LinearMap ℝ ℝ ℝ
j LinearMap ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ 1), ℝ -> Maybe ℝ
epsprop)
       (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
_ -> Maybe (ℝInterval, ℝ -> Maybe ℝ)
forall (f :: * -> *) a. Alternative f => f a
empty
 where                                    -- This check shouldn't really be necessary,
                                          -- because the initial value lies by definition
       inRegion :: PreRegion a m -> m -> Bool
inRegion PreRegion a m
GlobalRegion m
_ = Bool
True     -- in its domain.
       inRegion (PreRegion (Differentiable m -> (a, Needle m +> Needle a, LinDevPropag m a)
rf)) m
x
         | (a
yr,Needle m +> Needle a
_,LinDevPropag m a
_) <- m -> (a, Needle m +> Needle a, LinDevPropag m a)
rf m
x   = a
yra -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0
       inRegion (RealSubray S⁰_ ℝ
PositiveHalfSphere a
xl) m
x = m
xm -> m -> Bool
forall a. Ord a => a -> a -> Bool
>m
a
xl
       inRegion (RealSubray S⁰_ ℝ
NegativeHalfSphere a
xr) m
x = m
xm -> m -> Bool
forall a. Ord a => a -> a -> Bool
<m
a
xr

-- | Represent a 'Region' by a smooth function which is positive within the region,
--   and crosses zero at the boundary.
smoothIndicator :: (LocallyScalable  q, Manifold q, Atlas' q, SimpleSpace (Needle q))
                       => Region  q -> Differentiable  q 
smoothIndicator :: Region ℝ q -> Differentiable ℝ q ℝ
smoothIndicator (Region q
_ PreRegion ℝ q
r₀) = let (PreRegion Differentiable ℝ q ℝ
r) = PreRegion ℝ q -> PreRegion ℝ q
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion ℝ q
r₀
                                in  Differentiable ℝ q ℝ
r

regionOfContinuityAround :: RWDiffable  q x -> q -> Region  q
regionOfContinuityAround :: RWDiffable ℝ q x -> q -> Region ℝ q
regionOfContinuityAround (RWDiffable q -> (PreRegion ℝ q, Maybe (Differentiable ℝ q x))
f) q
q = q -> PreRegion ℝ q -> Region ℝ q
forall s m. m -> PreRegion s m -> Region s m
Region q
q (PreRegion ℝ q -> Region ℝ q)
-> (q -> PreRegion ℝ q) -> q -> Region ℝ q
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (PreRegion ℝ q, Maybe (Differentiable ℝ q x)) -> PreRegion ℝ q
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst ((PreRegion ℝ q, Maybe (Differentiable ℝ q x)) -> PreRegion ℝ q)
-> (q -> (PreRegion ℝ q, Maybe (Differentiable ℝ q x)))
-> q
-> PreRegion ℝ q
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. q -> (PreRegion ℝ q, Maybe (Differentiable ℝ q x))
f (q -> Region ℝ q) -> q -> Region ℝ q
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ q
q
              

intervalImages ::
         Int                         -- ^ Max number of exploration steps per region
      -> (RieMetric , RieMetric )  -- ^ Needed resolution in (x,y) direction
      -> RWDiffable               -- ^ Function to investigate
      -> ( [(ℝInterval,ℝInterval)]
         , [(ℝInterval,ℝInterval)] ) -- ^ (XInterval, YInterval) rectangles in which
                                     --   the function graph lies.
intervalImages :: Int
-> (RieMetric ℝ, RieMetric ℝ)
-> RWDiffable ℝ ℝ ℝ
-> ([(ℝInterval, ℝInterval)], [(ℝInterval, ℝInterval)])
intervalImages Int
nLim (RieMetric ℝ
mx,RieMetric ℝ
my) f :: RWDiffable ℝ ℝ ℝ
f@(RWDiffable ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
fd)
                  = ((ℝInterval -> (ℝInterval, ℝInterval))
-> [ℝInterval] -> [(ℝInterval, ℝInterval)]
forall a b. (a -> b) -> [a] -> [b]
map (ℝInterval -> ℝInterval
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id(ℝInterval -> ℝInterval)
-> (ℝInterval -> ℝInterval) -> ℝInterval -> (ℝInterval, ℝInterval)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&ℝInterval -> ℝInterval
ivimg) [ℝInterval]
domsL, (ℝInterval -> (ℝInterval, ℝInterval))
-> [ℝInterval] -> [(ℝInterval, ℝInterval)]
forall a b. (a -> b) -> [a] -> [b]
map (ℝInterval -> ℝInterval
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id(ℝInterval -> ℝInterval)
-> (ℝInterval -> ℝInterval) -> ℝInterval -> (ℝInterval, ℝInterval)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&ℝInterval -> ℝInterval
ivimg) [ℝInterval]
domsR)
 where ([ℝInterval]
domsL, [ℝInterval]
domsR) = Int
-> RieMetric ℝ -> RWDiffable ℝ ℝ ℝ -> ([ℝInterval], [ℝInterval])
forall y.
WithField ℝ Manifold y =>
Int
-> RieMetric ℝ -> RWDiffable ℝ ℝ y -> ([ℝInterval], [ℝInterval])
continuityRanges Int
nLim RieMetric ℝ
mx RWDiffable ℝ ℝ ℝ
f
       ivimg :: ℝInterval -> ℝInterval
ivimg (xl,xr) = ℝ -> ℝ -> ℝInterval -> ℝInterval
go xl 1 ℝInterval
i₀ ℝInterval -> ℝInterval -> ℝInterval
forall a b. (Ord a, Ord b) => (a, b) -> (a, b) -> (a, b)
 ℝ -> ℝ -> ℝInterval -> ℝInterval
go xr (-1) ℝInterval
i₀
        where (PreRegion ℝ ℝ
_, Just fdd :: Differentiable ℝ ℝ ℝ
fdd@(Differentiable ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
fddd))
                    = (Maybe (Differentiable ℝ ℝ ℝ) -> Maybe (Differentiable ℝ ℝ ℝ))
-> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
-> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
forall (a :: * -> * -> *) d b c.
(Morphism a, ObjectPair a d b, ObjectPair a d c) =>
a b c -> a (d, b) (d, c)
second ((Differentiable ℝ ℝ ℝ -> Differentiable ℝ ℝ ℝ)
-> Maybe (Differentiable ℝ ℝ ℝ) -> Maybe (Differentiable ℝ ℝ ℝ)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Differentiable ℝ ℝ ℝ -> Differentiable ℝ ℝ ℝ
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable) ((PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
 -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ)))
-> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
-> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ ℝ -> (PreRegion ℝ ℝ, Maybe (Differentiable ℝ ℝ ℝ))
fd xc
              xc :: ℝ
xc = (xlℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+xr)ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/2
              i₀ :: ℝInterval
i₀ = [ℝ] -> ℝ
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum([ℝ] -> ℝ) -> ([ℝ] -> ℝ) -> [ℝ] -> ℝInterval
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&[ℝ] -> ℝ
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([ℝ] -> ℝInterval) -> [ℝ] -> ℝInterval
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [Differentiable ℝ ℝ ℝ
fddDifferentiable ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$xl, Differentiable ℝ ℝ ℝ
fddDifferentiable ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$xc, Differentiable ℝ ℝ ℝ
fddDifferentiable ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$xr]
              go :: ℝ -> ℝ -> ℝInterval -> ℝInterval
go x dir (a,b)
                 | dirℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>0 Bool -> Bool -> Bool
&& xℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>xc   = (a,b)
                 | dirℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<0 Bool -> Bool -> Bool
&& xℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
<xc   = (a,b)
                 | ℝ
Scalar ℝ
χ ℝ -> ℝ -> Bool
forall a. Eq a => a -> a -> Bool
== 0          = (y ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ (xℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-xl)ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*y', y ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ (xℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-xr)ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*y')
                 | y ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
< aℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+resoHere  = ℝ -> ℝ -> ℝInterval -> ℝInterval
go (x ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ℝ
Scalar ℝ
χ) dir (y,b)
                 | y ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
> bℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-resoHere  = ℝ -> ℝ -> ℝInterval -> ℝInterval
go (x ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ dirℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/ℝ
Scalar ℝ
χ) dir (a,y)
                 | Bool
otherwise       = ℝ -> ℝ -> ℝInterval -> ℝInterval
go (x ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+ ℝ -> ℝ
safeStep stepOut₀) dir (a,b)
               where (y, LinearMap ℝ ℝ ℝ
j, Seminorm ℝ -> Seminorm ℝ
δε) = ℝ -> (ℝ, Needle ℝ +> Needle ℝ, LinDevPropag ℝ ℝ)
fddd x
                     y' :: ℝ
y' = LinearMap ℝ ℝ ℝ
j LinearMap ℝ ℝ ℝ -> ℝ -> ℝ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ 1
                     εx :: Metric ℝ
εx = RieMetric ℝ
my y
                     resoHere :: ℝ
resoHere = Seminorm ℝ -> ℝ
forall s. RealFrac' s => Norm s -> s
normalLength Seminorm ℝ
Metric ℝ
εx
                     χ :: Scalar ℝ
χ = Seminorm ℝ -> Seminorm ℝ
δε Seminorm ℝ
Metric ℝ
εxSeminorm ℝ -> ℝ -> Scalar ℝ
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$| 1
                     safeStep :: ℝ -> ℝ
safeStep s₀
                         | LinDevPropag ℝ ℝ -> ℝ -> ℝ
forall a. RealDimension a => LinDevPropag a a -> a -> a
as_devεδ Seminorm ℝ -> Seminorm ℝ
LinDevPropag ℝ ℝ
δε (ℝ -> ℝ
safetyMarg s₀) ℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
> ℝ -> ℝ
forall a. Num a => a -> a
abs s₀  = s₀
                         | Bool
otherwise                             = ℝ -> ℝ
safeStep (s₀ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*0.5)
                     stepOut₀ :: ℝ
stepOut₀ | y'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*dirℝ -> ℝ -> Bool
forall a. Ord a => a -> a -> Bool
>0   = 0.5 ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* (bℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-y)ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/y'
                              | Bool
otherwise  = -0.5 ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
* (yℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-a)ℝ -> ℝ -> ℝ
forall a. Fractional a => a -> a -> a
/y'
                     safetyMarg :: ℝ -> ℝ
safetyMarg stp = [ℝ] -> ℝ
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum [yℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-a, yℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
+stpℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*y'ℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-a, bℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-y, bℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-yℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
-stpℝ -> ℝ -> ℝ
forall a. Num a => a -> a -> a
*y']
       infixl 3 
       (a
a,b
b) ∪ :: (a, b) -> (a, b) -> (a, b)
 (a
c,b
d) = (a -> a -> a
forall a. Ord a => a -> a -> a
min a
a a
c, b -> b -> b
forall a. Ord a => a -> a -> a
max b
b b
d)


hugeℝVal :: 
hugeℝVal :: ℝ
hugeℝVal = 1e+100



showℝ :: RealFloat r => r -> String
showℝ :: r -> String
showℝ r
x = ℝ -> String
forall a. Show a => a -> String
show (r -> ℝ
forall a b. (Real a, Fractional b) => a -> b
realToFrac r
x :: Double)


unsafe_dev_ε_δ ::  a . RealDimension a
                => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ :: String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ = case ( LinearManifoldWitness a
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness a
                      , ClosedScalarWitness a
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness a ) of
 (LinearManifoldWitness a
LinearManifoldWitness, ClosedScalarWitness a
ClosedScalarWitness) -> \String
errHint a -> a
f Metric a
d
           -> let ε'² :: Scalar a
ε'² = Seminorm a -> a -> Scalar a
forall v. LSpace v => Seminorm v -> v -> Scalar v
normSq Seminorm a
Metric a
d a
1
              in if a
Scalar a
ε'²a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0
                  then let δ :: a
δ = a -> a
f (a -> a) -> (a -> a) -> a -> a
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. a -> a
forall a. Floating a => a -> a
sqrt (a -> a) -> a -> a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a -> a
forall a. Fractional a => a -> a
recip a
Scalar a
ε'²
                       in if a
δ a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0
                           then [DualVector a] -> Seminorm a
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [a -> a
forall a. Fractional a => a -> a
recip a
δ]
                           else String -> Seminorm a
forall a. HasCallStack => String -> a
error (String -> Seminorm a) -> String -> Seminorm a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ String
"ε-δ propagator function for "
                                    String -> String -> String
forall a. [a] -> [a] -> [a]
++String
errHintString -> String -> String
forall a. [a] -> [a] -> [a]
++String
", with ε="
                                    String -> String -> String
forall a. [a] -> [a] -> [a]
++a -> String
forall r. RealFloat r => r -> String
showℝ (a -> a
forall a. Floating a => a -> a
sqrt (a -> a) -> a -> a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a -> a
forall a. Fractional a => a -> a
recip a
Scalar a
ε'²)
                                    String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" gives non-positive δ="
                                    String -> String -> String
forall a. [a] -> [a] -> [a]
++ℝ -> String
forall r. RealFloat r => r -> String
showℝ (a -> ℝ
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
δ)String -> String -> String
forall a. [a] -> [a] -> [a]
++String
"."
                  else Metric a
forall a. Monoid a => a
mempty
dev_ε_δ ::  a . RealDimension a
         => (a -> a) -> Metric a -> Maybe (Metric a)
dev_ε_δ :: (a -> a) -> Metric a -> Maybe (Metric a)
dev_ε_δ = case ( LinearManifoldWitness a
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness a
                      , ClosedScalarWitness a
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness a ) of
 (LinearManifoldWitness a
LinearManifoldWitness, ClosedScalarWitness a
ClosedScalarWitness) -> \a -> a
f Metric a
d
           -> let ε'² :: Scalar a
ε'² = Seminorm a -> a -> Scalar a
forall v. LSpace v => Seminorm v -> v -> Scalar v
normSq Seminorm a
Metric a
d a
1
              in if a
Scalar a
ε'²a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0
                  then let δ :: a
δ = a -> a
f (a -> a) -> (a -> a) -> a -> a
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. a -> a
forall a. Floating a => a -> a
sqrt (a -> a) -> a -> a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a -> a
forall a. Fractional a => a -> a
recip a
Scalar a
ε'²
                       in if a
δ a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0
                           then Seminorm a -> Maybe (Seminorm a)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ([DualVector a] -> Seminorm a
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [a -> a
forall a. Fractional a => a -> a
recip a
δ])
                           else Maybe (Metric a)
forall (f :: * -> *) a. Alternative f => f a
empty
                  else Seminorm a -> Maybe (Seminorm a)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Seminorm a
forall a. Monoid a => a
mempty

as_devεδ ::  a . RealDimension a => LinDevPropag a a -> a -> a
as_devεδ :: LinDevPropag a a -> a -> a
as_devεδ = LinearManifoldWitness a
-> ClosedScalarWitness a -> LinDevPropag a a -> a -> a
asdevεδ LinearManifoldWitness a
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness ClosedScalarWitness a
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness where
 asdevεδ :: LinearManifoldWitness a -> ClosedScalarWitness a -> LinDevPropag a a -> a -> a
 asdevεδ :: LinearManifoldWitness a
-> ClosedScalarWitness a -> LinDevPropag a a -> a -> a
asdevεδ LinearManifoldWitness a
LinearManifoldWitness ClosedScalarWitness a
ClosedScalarWitness
         LinDevPropag a a
ldp a
ε | a
εa -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0
               , Scalar a
δ'² <- Seminorm a -> a -> Scalar a
forall v. LSpace v => Seminorm v -> v -> Scalar v
normSq (Seminorm a -> Seminorm a
LinDevPropag a a
ldp (Seminorm a -> Seminorm a) -> Seminorm a -> Seminorm a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [DualVector a] -> Seminorm a
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [a -> a
forall a. Fractional a => a -> a
recip a
ε]) a
1
               , a
Scalar a
δ'² a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
0
                    = a -> a
forall a. Floating a => a -> a
sqrt (a -> a) -> a -> a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a -> a
forall a. Fractional a => a -> a
recip a
Scalar a
δ'²
               | Bool
otherwise  = a
0


genericiseDifferentiable :: (LocallyScalable s d, LocallyScalable s c)
                    => Differentiable s d c -> Differentiable s d c
genericiseDifferentiable :: Differentiable s d c -> Differentiable s d c
genericiseDifferentiable (AffinDiffable DiffableEndoProof d c
_ Affine s d c
af)
     = (d
 -> (c, LinearMap (Scalar (Needle d)) (Needle d) (Needle c),
     Norm (Needle c) -> Norm (Needle d)))
-> Differentiable s d c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((d
  -> (c, LinearMap (Scalar (Needle d)) (Needle d) (Needle c),
      Norm (Needle c) -> Norm (Needle d)))
 -> Differentiable s d c)
-> (d
    -> (c, LinearMap (Scalar (Needle d)) (Needle d) (Needle c),
        Norm (Needle c) -> Norm (Needle d)))
-> Differentiable s d c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \d
x -> let (c
y₀, LinearMap (Scalar (Needle d)) (Needle d) (Needle c)
ϕ) = Affine s d c -> d -> (c, LinearMap s (Needle d) (Needle c))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine s d c
af d
x
                              in (c
y₀, LinearMap (Scalar (Needle d)) (Needle d) (Needle c)
ϕ, Norm (Needle d) -> Norm (Needle c) -> Norm (Needle d)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle d)
forall a. Monoid a => a
mempty)
genericiseDifferentiable Differentiable s d c
f = Differentiable s d c
f


instance RealFrac' s => Category (Differentiable s) where
  type Object (Differentiable s) o = ( Manifold o, Atlas' o
                                     , LocallyScalable s o, SimpleSpace (Needle o) )
  id :: Differentiable s a a
id = (a
 -> (a, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
     Norm (Needle a) -> Norm (Needle a)))
-> Differentiable s a a
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((a
  -> (a, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
      Norm (Needle a) -> Norm (Needle a)))
 -> Differentiable s a a)
-> (a
    -> (a, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
        Norm (Needle a) -> Norm (Needle a)))
-> Differentiable s a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \a
x -> (a
x, LinearMap (Scalar (Needle a)) (Needle a) (Needle a)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle a)
forall a. Monoid a => a
mempty)
  Differentiable b -> (c, Needle b +> Needle c, LinDevPropag b c)
f . :: Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
. Differentiable a -> (b, Needle a +> Needle b, LinDevPropag a b)
g = (a
 -> (c, LinearMap (Scalar (Needle a)) (Needle a) (Needle c),
     Norm (Needle c) -> Norm (Needle a)))
-> Differentiable s a c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((a
  -> (c, LinearMap (Scalar (Needle a)) (Needle a) (Needle c),
      Norm (Needle c) -> Norm (Needle a)))
 -> Differentiable s a c)
-> (a
    -> (c, LinearMap (Scalar (Needle a)) (Needle a) (Needle c),
        Norm (Needle c) -> Norm (Needle a)))
-> Differentiable s a c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
     \a
x -> let (b
y, Needle a +> Needle b
g', LinDevPropag a b
devg) = a -> (b, Needle a +> Needle b, LinDevPropag a b)
g a
x
               (c
z, LinearMap (Scalar (Needle a)) (Needle b) (Needle c)
f', LinDevPropag b c
devf) = b -> (c, Needle b +> Needle c, LinDevPropag b c)
f b
y
               devfg :: Norm (Needle c) -> Norm (Needle a)
devfg Norm (Needle c)
δz = let δy :: Norm (Needle b)
δy = (Needle b +> Needle c) -> LinDevPropag b c
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap (Scalar (Needle a)) (Needle b) (Needle c)
Needle b +> Needle c
f' Norm (Needle c)
δz
                              εy :: Norm (Needle b)
εy = LinDevPropag b c
devf Norm (Needle c)
δz
                          in (Needle a +> Needle b) -> LinDevPropag a b
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm Needle a +> Needle b
g' Norm (Needle b)
εy Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall a. Semigroup a => a -> a -> a
<> LinDevPropag a b
devg Norm (Needle b)
δy Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall a. Semigroup a => a -> a -> a
<> LinDevPropag a b
devg Norm (Needle b)
εy
           in (c
z, LinearMap (Scalar (Needle a)) (Needle b) (Needle c)
f' LinearMap (Scalar (Needle a)) (Needle b) (Needle c)
-> (Needle a +> Needle b)
-> LinearMap (Scalar (Needle a)) (Needle a) (Needle c)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Needle a +> Needle b
g', Norm (Needle c) -> Norm (Needle a)
devfg)
  AffinDiffable DiffableEndoProof b c
ef Affine s b c
f . AffinDiffable DiffableEndoProof a b
eg Affine s a b
g = DiffableEndoProof a c -> Affine s a c -> Differentiable s a c
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable (DiffableEndoProof b c
ef DiffableEndoProof b c
-> DiffableEndoProof a b -> DiffableEndoProof a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. DiffableEndoProof a b
eg) (Affine s b c
f Affine s b c -> Affine s a b -> Affine s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Affine s a b
g)
  Differentiable s b c
f . Differentiable s a b
g = Differentiable s b c -> Differentiable s b c
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s b c
f Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b -> Differentiable s a b
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s a b
g


-- instance (RealDimension s) => EnhancedCat (Differentiable s) (Affine s) where
--   arr (Affine co ao sl) = actuallyAffineEndo (ao .-^ lapply sl co) sl
  
instance (RealDimension s) => EnhancedCat (->) (Differentiable s) where
  arr :: Differentiable s b c -> b -> c
arr (Differentiable b -> (c, Needle b +> Needle c, LinDevPropag b c)
f) b
x = let (c
y,LinearMap s (Needle b) (Needle c)
_,LinDevPropag b c
_) = b -> (c, Needle b +> Needle c, LinDevPropag b c)
f b
x in c
y
  arr (AffinDiffable DiffableEndoProof b c
_ Affine s b c
f) b
x = Affine s b c
f Affine s b c -> b -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b
x

instance (RealFrac'' s, SimpleSpace s) => Cartesian (Differentiable s) where
  type UnitObject (Differentiable s) = ZeroDim s
  swap :: Differentiable s (a, b) (b, a)
swap = ((a, b)
 -> ((b, a),
     LinearMap
       (Scalar (Needle a)) (Needle a, Needle b) (Needle b, Needle a),
     Norm (Needle b, Needle a) -> Norm (Needle a, Needle b)))
-> Differentiable s (a, b) (b, a)
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (((a, b)
  -> ((b, a),
      LinearMap
        (Scalar (Needle a)) (Needle a, Needle b) (Needle b, Needle a),
      Norm (Needle b, Needle a) -> Norm (Needle a, Needle b)))
 -> Differentiable s (a, b) (b, a))
-> ((a, b)
    -> ((b, a),
        LinearMap
          (Scalar (Needle a)) (Needle a, Needle b) (Needle b, Needle a),
        Norm (Needle b, Needle a) -> Norm (Needle a, Needle b)))
-> Differentiable s (a, b) (b, a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(a
x,b
y) -> ((b
y,a
x), LinearMap
  (Scalar (Needle a)) (Needle a, Needle b) (Needle b, Needle a)
forall (k :: * -> * -> *) a b.
(Cartesian k, ObjectPair k a b, ObjectPair k b a) =>
k (a, b) (b, a)
swap, Norm (Needle a, Needle b)
-> Norm (Needle b, Needle a) -> Norm (Needle a, Needle b)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle a, Needle b)
forall a. Monoid a => a
mempty)
  attachUnit :: Differentiable s a (a, unit)
attachUnit = (a
 -> ((a, ZeroDim s),
     LinearMap
       (Scalar (Needle a))
       (Needle a)
       (Needle a, ZeroDim (Scalar (Needle a))),
     Norm (Needle a, ZeroDim s) -> Norm (Needle a)))
-> Differentiable s a (a, unit)
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((a
  -> ((a, ZeroDim s),
      LinearMap
        (Scalar (Needle a))
        (Needle a)
        (Needle a, ZeroDim (Scalar (Needle a))),
      Norm (Needle a, ZeroDim s) -> Norm (Needle a)))
 -> Differentiable s a (a, unit))
-> (a
    -> ((a, ZeroDim s),
        LinearMap
          (Scalar (Needle a))
          (Needle a)
          (Needle a, ZeroDim (Scalar (Needle a))),
        Norm (Needle a, ZeroDim s) -> Norm (Needle a)))
-> Differentiable s a (a, unit)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \a
x -> ((a
x, ZeroDim s
forall s. ZeroDim s
Origin), LinearMap
  (Scalar (Needle a))
  (Needle a)
  (Needle a, ZeroDim (Scalar (Needle a)))
forall (k :: * -> * -> *) unit a.
(Cartesian k, unit ~ UnitObject k, ObjectPair k a unit) =>
k a (a, unit)
attachUnit, Norm (Needle a) -> Norm (Needle a, ZeroDim s) -> Norm (Needle a)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle a)
forall a. Monoid a => a
mempty)
  detachUnit :: Differentiable s (a, unit) a
detachUnit = ((a, ZeroDim s)
 -> (a,
     LinearMap
       (Scalar (Needle a))
       (Needle a, ZeroDim (Scalar (Needle a)))
       (Needle a),
     Norm (Needle a) -> Norm (Needle a, ZeroDim s)))
-> Differentiable s (a, unit) a
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (((a, ZeroDim s)
  -> (a,
      LinearMap
        (Scalar (Needle a))
        (Needle a, ZeroDim (Scalar (Needle a)))
        (Needle a),
      Norm (Needle a) -> Norm (Needle a, ZeroDim s)))
 -> Differentiable s (a, unit) a)
-> ((a, ZeroDim s)
    -> (a,
        LinearMap
          (Scalar (Needle a))
          (Needle a, ZeroDim (Scalar (Needle a)))
          (Needle a),
        Norm (Needle a) -> Norm (Needle a, ZeroDim s)))
-> Differentiable s (a, unit) a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(a
x, ZeroDim s
Origin) -> (a
x, LinearMap
  (Scalar (Needle a))
  (Needle a, ZeroDim (Scalar (Needle a)))
  (Needle a)
forall (k :: * -> * -> *) unit a.
(Cartesian k, unit ~ UnitObject k, ObjectPair k a unit) =>
k (a, unit) a
detachUnit, Norm (Needle a, ZeroDim s)
-> Norm (Needle a) -> Norm (Needle a, ZeroDim s)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle a, ZeroDim s)
forall a. Monoid a => a
mempty)
  regroup :: Differentiable s (a, (b, c)) ((a, b), c)
regroup = ((a, (b, c))
 -> (((a, b), c),
     LinearMap
       (Scalar (Needle a))
       (Needle a, (Needle b, Needle c))
       ((Needle a, Needle b), Needle c),
     Norm ((Needle a, Needle b), Needle c)
     -> Norm (Needle a, (Needle b, Needle c))))
-> Differentiable s (a, (b, c)) ((a, b), c)
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (((a, (b, c))
  -> (((a, b), c),
      LinearMap
        (Scalar (Needle a))
        (Needle a, (Needle b, Needle c))
        ((Needle a, Needle b), Needle c),
      Norm ((Needle a, Needle b), Needle c)
      -> Norm (Needle a, (Needle b, Needle c))))
 -> Differentiable s (a, (b, c)) ((a, b), c))
-> ((a, (b, c))
    -> (((a, b), c),
        LinearMap
          (Scalar (Needle a))
          (Needle a, (Needle b, Needle c))
          ((Needle a, Needle b), Needle c),
        Norm ((Needle a, Needle b), Needle c)
        -> Norm (Needle a, (Needle b, Needle c))))
-> Differentiable s (a, (b, c)) ((a, b), c)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(a
x,(b
y,c
z)) -> (((a
x,b
y),c
z), LinearMap
  (Scalar (Needle a))
  (Needle a, (Needle b, Needle c))
  ((Needle a, Needle b), Needle c)
forall (k :: * -> * -> *) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k (a, (b, c)) ((a, b), c)
regroup, Norm (Needle a, (Needle b, Needle c))
-> Norm ((Needle a, Needle b), Needle c)
-> Norm (Needle a, (Needle b, Needle c))
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle a, (Needle b, Needle c))
forall a. Monoid a => a
mempty)
  regroup' :: Differentiable s ((a, b), c) (a, (b, c))
regroup' = (((a, b), c)
 -> ((a, (b, c)),
     LinearMap
       (Scalar (Needle a))
       ((Needle a, Needle b), Needle c)
       (Needle a, (Needle b, Needle c)),
     Norm (Needle a, (Needle b, Needle c))
     -> Norm ((Needle a, Needle b), Needle c)))
-> Differentiable s ((a, b), c) (a, (b, c))
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((((a, b), c)
  -> ((a, (b, c)),
      LinearMap
        (Scalar (Needle a))
        ((Needle a, Needle b), Needle c)
        (Needle a, (Needle b, Needle c)),
      Norm (Needle a, (Needle b, Needle c))
      -> Norm ((Needle a, Needle b), Needle c)))
 -> Differentiable s ((a, b), c) (a, (b, c)))
-> (((a, b), c)
    -> ((a, (b, c)),
        LinearMap
          (Scalar (Needle a))
          ((Needle a, Needle b), Needle c)
          (Needle a, (Needle b, Needle c)),
        Norm (Needle a, (Needle b, Needle c))
        -> Norm ((Needle a, Needle b), Needle c)))
-> Differentiable s ((a, b), c) (a, (b, c))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \((a
x,b
y),c
z) -> ((a
x,(b
y,c
z)), LinearMap
  (Scalar (Needle a))
  ((Needle a, Needle b), Needle c)
  (Needle a, (Needle b, Needle c))
forall (k :: * -> * -> *) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k ((a, b), c) (a, (b, c))
regroup', Norm ((Needle a, Needle b), Needle c)
-> Norm (Needle a, (Needle b, Needle c))
-> Norm ((Needle a, Needle b), Needle c)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm ((Needle a, Needle b), Needle c)
forall a. Monoid a => a
mempty)


instance  s . (RealFrac'' s, SimpleSpace s) => Morphism (Differentiable s) where
  *** :: Differentiable s b c
-> Differentiable s b' c' -> Differentiable s (b, b') (c, c')
(***) = Differentiable s b c
-> Differentiable s b' c' -> Differentiable s (b, b') (c, c')
forall b b' c c'.
(ObjectPair (Differentiable s) b b',
 ObjectPair (Differentiable s) c c') =>
Differentiable s b c
-> Differentiable s b' c' -> Differentiable s (b, b') (c, c')
prll
   where prll ::  b β c γ . ( ObjectPair (Differentiable s) b β
                             , ObjectPair (Differentiable s) c γ )
                   => Differentiable s b c -> Differentiable s β γ
                        -> Differentiable s (b,β) (c,γ)
         prll :: Differentiable s b c
-> Differentiable s β γ -> Differentiable s (b, β) (c, γ)
prll (Differentiable b -> (c, Needle b +> Needle c, LinDevPropag b c)
f) (Differentiable β -> (γ, Needle β +> Needle γ, LinDevPropag β γ)
g) = ((b, β)
 -> ((c, γ), Needle (b, β) +> Needle (c, γ),
     LinDevPropag (b, β) (c, γ)))
-> Differentiable s (b, β) (c, γ)
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (b, β)
-> ((c, γ), LinearMap s (Needle b, Needle β) (Needle c, Needle γ),
    Norm (Needle c, Needle γ) -> Norm (Needle b, Needle β))
(b, β)
-> ((c, γ), Needle (b, β) +> Needle (c, γ),
    LinDevPropag (b, β) (c, γ))
h
          where h :: (b, β)
-> ((c, γ), LinearMap s (Needle b, Needle β) (Needle c, Needle γ),
    Norm (Needle c, Needle γ) -> Norm (Needle b, Needle β))
h (b
x,β
y) = ((c
fx, γ
gy), LinearMap s (Needle b) (Needle c)
f'LinearMap s (Needle b) (Needle c)
-> LinearMap s (Needle β) (Needle γ)
-> LinearMap s (Needle b, Needle β) (Needle c, Needle γ)
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
***LinearMap s (Needle β) (Needle γ)
g', Norm (Needle c, Needle γ) -> Norm (Needle b, Needle β)
devfg)
                 where (c
fx, LinearMap s (Needle b) (Needle c)
f', LinDevPropag b c
devf) = b -> (c, Needle b +> Needle c, LinDevPropag b c)
f b
x
                       (γ
gy, LinearMap s (Needle β) (Needle γ)
g', LinDevPropag β γ
devg) = β -> (γ, Needle β +> Needle γ, LinDevPropag β γ)
g β
y
                       devfg :: Norm (Needle c, Needle γ) -> Norm (Needle b, Needle β)
devfg Norm (Needle c, Needle γ)
δs = ((Needle b, Needle β) +> Needle b)
-> Norm (Needle b) -> Norm (Needle b, Needle β)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (Needle b, Needle β) +> Needle b
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst Norm (Needle b)
δx 
                                  Norm (Needle b, Needle β)
-> Norm (Needle b, Needle β) -> Norm (Needle b, Needle β)
forall a. Semigroup a => a -> a -> a
<> ((Needle b, Needle β) +> Needle β)
-> Norm (Needle β) -> Norm (Needle b, Needle β)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (Needle b, Needle β) +> Needle β
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd Norm (Needle β)
δy
                         where δx :: Norm (Needle b)
δx = LinDevPropag b c
devf LinDevPropag b c -> LinDevPropag b c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Needle c +> (Needle c, Needle γ))
-> Norm (Needle c, Needle γ) -> Norm (Needle c)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (LinearMap s (Needle c) (Needle c)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
idLinearMap s (Needle c) (Needle c)
-> LinearMap s (Needle c) (Needle γ)
-> LinearMap s (Needle c) (Needle c, Needle γ)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap s (Needle c) (Needle γ)
forall v. AdditiveGroup v => v
zeroV) Norm (Needle c, Needle γ)
δs
                               δy :: Norm (Needle β)
δy = LinDevPropag β γ
devg LinDevPropag β γ -> LinDevPropag β γ
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Needle γ +> (Needle c, Needle γ))
-> Norm (Needle c, Needle γ) -> Norm (Needle γ)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (LinearMap s (Needle γ) (Needle c)
forall v. AdditiveGroup v => v
zeroVLinearMap s (Needle γ) (Needle c)
-> LinearMap s (Needle γ) (Needle γ)
-> LinearMap s (Needle γ) (Needle c, Needle γ)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap s (Needle γ) (Needle γ)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) Norm (Needle c, Needle γ)
δs
         prll (AffinDiffable DiffableEndoProof b c
IsDiffableEndo Affine s b c
f) (AffinDiffable DiffableEndoProof β γ
IsDiffableEndo Affine s β γ
g)
                 = case ( Semimanifold b => SemimanifoldWitness b
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @b, Semimanifold β => SemimanifoldWitness β
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @β
                        , SemimanifoldWithBoundary b => SmfdWBoundWitness b
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @b, SemimanifoldWithBoundary β => SmfdWBoundWitness β
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @β
                        , LinearSpace (Needle b) => DualSpaceWitness (Needle b)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle b), LinearSpace (Needle β) => DualSpaceWitness (Needle β)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle β)
                        , SemimanifoldWithBoundary s => SmfdWBoundWitness s
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @s
                        ) of
           ( SemimanifoldWitness b
SemimanifoldWitness, SemimanifoldWitness β
SemimanifoldWitness
            ,SmfdWBoundWitness b
OpenManifoldWitness, SmfdWBoundWitness β
OpenManifoldWitness
            ,DualSpaceWitness (Needle b)
DualSpaceWitness, DualSpaceWitness (Needle β)
DualSpaceWitness
            ,SmfdWBoundWitness s
OpenManifoldWitness )
             -> ((LinearSpace (Needle (Boundary (Needle b))),
  Scalar (Needle (Boundary (Needle b)))
  ~ Scalar (Needle (Interior (Needle b)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle b)
                 ( ((LinearSpace (Needle (Boundary (Needle β))),
  Scalar (Needle (Boundary (Needle β)))
  ~ Scalar (Needle (Interior (Needle β)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle β)
                 ( DiffableEndoProof (b, β) (b, β)
-> Affine s (b, β) (b, β) -> Differentiable s (b, β) (b, β)
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof (b, β) (b, β)
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine s (b, β) (c, γ) -> Differentiable s (b, β) (c, γ))
-> Affine s (b, β) (c, γ) -> Differentiable s (b, β) (c, γ)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Affine s b c
f Affine s b c -> Affine s β γ -> Affine s (b, β) (c, γ)
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Affine s β γ
g ))
         prll (AffinDiffable DiffableEndoProof b c
_ Affine s b c
f) (AffinDiffable DiffableEndoProof β γ
_ Affine s β γ
g)
          = ((LinearSpace (Needle (Boundary (Needle β))),
  Scalar (Needle (Boundary (Needle β)))
  ~ Scalar (Needle (Interior (Needle β)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle β) (
             ((LinearSpace (Needle (Boundary (Needle γ))),
  Scalar (Needle (Boundary (Needle γ)))
  ~ Scalar (Needle (Interior (Needle γ)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle γ) (
              ((LinearSpace (Needle (Boundary (Needle b))),
  Scalar (Needle (Boundary (Needle b)))
  ~ Scalar (Needle (Interior (Needle b)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle b) (
               ((LinearSpace (Needle (Boundary (Needle c))),
  Scalar (Needle (Boundary (Needle c)))
  ~ Scalar (Needle (Interior (Needle c)))) =>
 Differentiable s (b, β) (c, γ))
-> Differentiable s (b, β) (c, γ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle c) (
              case ( Semimanifold β => SemimanifoldWitness β
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @β, Semimanifold γ => SemimanifoldWitness γ
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @γ
                   , Semimanifold b => SemimanifoldWitness b
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @b, Semimanifold c => SemimanifoldWitness c
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @c ) of
                 (SemimanifoldWitness β
SemimanifoldWitness, SemimanifoldWitness γ
SemimanifoldWitness
                  , SemimanifoldWitness b
SemimanifoldWitness, SemimanifoldWitness c
SemimanifoldWitness)
                   -> DiffableEndoProof (b, β) (c, γ)
-> Affine s (b, β) (c, γ) -> Differentiable s (b, β) (c, γ)
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof (b, β) (c, γ)
forall d c. DiffableEndoProof d c
NotDiffableEndo (Affine s (b, β) (c, γ) -> Differentiable s (b, β) (c, γ))
-> Affine s (b, β) (c, γ) -> Differentiable s (b, β) (c, γ)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Affine s b c
f Affine s b c -> Affine s β γ -> Affine s (b, β) (c, γ)
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Affine s β γ
g
             ))))
         prll Differentiable s b c
f Differentiable s β γ
g = Differentiable s b c -> Differentiable s b c
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s b c
f Differentiable s b c
-> Differentiable s β γ -> Differentiable s (b, β) (c, γ)
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Differentiable s β γ -> Differentiable s β γ
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s β γ
g


instance (RealFrac'' s, SimpleSpace s) => PreArrow (Differentiable s) where
  terminal :: Differentiable s b (UnitObject (Differentiable s))
terminal = (b
 -> (ZeroDim s,
     LinearMap (Scalar (Needle b)) (Needle b) (ZeroDim s),
     Norm (ZeroDim s) -> Norm (Needle b)))
-> Differentiable s b (ZeroDim s)
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((b
  -> (ZeroDim s,
      LinearMap (Scalar (Needle b)) (Needle b) (ZeroDim s),
      Norm (ZeroDim s) -> Norm (Needle b)))
 -> Differentiable s b (ZeroDim s))
-> (b
    -> (ZeroDim s,
        LinearMap (Scalar (Needle b)) (Needle b) (ZeroDim s),
        Norm (ZeroDim s) -> Norm (Needle b)))
-> Differentiable s b (ZeroDim s)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \b
_ -> (ZeroDim s
forall s. ZeroDim s
Origin, LinearMap (Scalar (Needle b)) (Needle b) (ZeroDim s)
forall v. AdditiveGroup v => v
zeroV, Norm (Needle b) -> Norm (ZeroDim s) -> Norm (Needle b)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle b)
forall a. Monoid a => a
mempty)
  fst :: Differentiable s (x, y) x
fst = ((x, y)
 -> (x,
     LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle x),
     Norm (Needle x) -> Norm (Needle x, Needle y)))
-> Differentiable s (x, y) x
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (((x, y)
  -> (x,
      LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle x),
      Norm (Needle x) -> Norm (Needle x, Needle y)))
 -> Differentiable s (x, y) x)
-> ((x, y)
    -> (x,
        LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle x),
        Norm (Needle x) -> Norm (Needle x, Needle y)))
-> Differentiable s (x, y) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(x
x,y
_) -> (x
x, LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle x)
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst, Norm (Needle x, Needle y)
-> Norm (Needle x) -> Norm (Needle x, Needle y)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle x, Needle y)
forall a. Monoid a => a
mempty)
  snd :: Differentiable s (x, y) y
snd = ((x, y)
 -> (y,
     LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle y),
     Norm (Needle y) -> Norm (Needle x, Needle y)))
-> Differentiable s (x, y) y
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable (((x, y)
  -> (y,
      LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle y),
      Norm (Needle y) -> Norm (Needle x, Needle y)))
 -> Differentiable s (x, y) y)
-> ((x, y)
    -> (y,
        LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle y),
        Norm (Needle y) -> Norm (Needle x, Needle y)))
-> Differentiable s (x, y) y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \(x
_,y
y) -> (y
y, LinearMap (Scalar (Needle x)) (Needle x, Needle y) (Needle y)
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd, Norm (Needle x, Needle y)
-> Norm (Needle y) -> Norm (Needle x, Needle y)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle x, Needle y)
forall a. Monoid a => a
mempty)
  Differentiable b -> (c, Needle b +> Needle c, LinDevPropag b c)
f &&& :: Differentiable s b c
-> Differentiable s b c' -> Differentiable s b (c, c')
&&& Differentiable b -> (c', Needle b +> Needle c', LinDevPropag b c')
g = (b
 -> ((c, c'), Needle b +> Needle (c, c'), LinDevPropag b (c, c')))
-> Differentiable s b (c, c')
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable b
-> ((c, c'), LinearMap s (Needle b) (Needle c, Needle c'),
    Norm (Needle c, Needle c') -> Norm (Needle b))
b -> ((c, c'), Needle b +> Needle (c, c'), LinDevPropag b (c, c'))
h
   where h :: b
-> ((c, c'), LinearMap s (Needle b) (Needle c, Needle c'),
    Norm (Needle c, Needle c') -> Norm (Needle b))
h b
x = ((c
fx, c'
gx), LinearMap s (Needle b) (Needle c)
f'LinearMap s (Needle b) (Needle c)
-> LinearMap s (Needle b) (Needle c')
-> LinearMap s (Needle b) (Needle c, Needle c')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap s (Needle b) (Needle c')
g', Norm (Needle c, Needle c') -> Norm (Needle b)
devfg)
          where (c
fx, LinearMap s (Needle b) (Needle c)
f', LinDevPropag b c
devf) = b -> (c, Needle b +> Needle c, LinDevPropag b c)
f b
x
                (c'
gx, LinearMap s (Needle b) (Needle c')
g', LinDevPropag b c'
devg) = b -> (c', Needle b +> Needle c', LinDevPropag b c')
g b
x
                devfg :: Norm (Needle c, Needle c') -> Norm (Needle b)
devfg Norm (Needle c, Needle c')
δs = (LinDevPropag b c
devf LinDevPropag b c -> LinDevPropag b c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Needle c +> (Needle c, Needle c'))
-> Norm (Needle c, Needle c') -> Norm (Needle c)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (LinearMap s (Needle c) (Needle c)
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
idLinearMap s (Needle c) (Needle c)
-> LinearMap s (Needle c) (Needle c')
-> LinearMap s (Needle c) (Needle c, Needle c')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap s (Needle c) (Needle c')
forall v. AdditiveGroup v => v
zeroV) Norm (Needle c, Needle c')
δs)
                           Norm (Needle b) -> Norm (Needle b) -> Norm (Needle b)
forall a. Semigroup a => a -> a -> a
<> (LinDevPropag b c'
devg LinDevPropag b c' -> LinDevPropag b c'
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (Needle c' +> (Needle c, Needle c'))
-> Norm (Needle c, Needle c') -> Norm (Needle c')
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm (LinearMap s (Needle c') (Needle c)
forall v. AdditiveGroup v => v
zeroVLinearMap s (Needle c') (Needle c)
-> LinearMap s (Needle c') (Needle c')
-> LinearMap s (Needle c') (Needle c, Needle c')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap s (Needle c') (Needle c')
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) Norm (Needle c, Needle c')
δs)
  Differentiable s b c
f &&& Differentiable s b c'
g = Differentiable s b c -> Differentiable s b c
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s b c
f Differentiable s b c
-> Differentiable s b c' -> Differentiable s b (c, c')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&& Differentiable s b c' -> Differentiable s b c'
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s b c'
g


instance (RealFrac'' s, SimpleSpace s) => WellPointed (Differentiable s) where
  unit :: CatTagged (Differentiable s) (UnitObject (Differentiable s))
unit = ZeroDim s
-> Tagged (Differentiable s (ZeroDim s) (ZeroDim s)) (ZeroDim s)
forall k (s :: k) b. b -> Tagged s b
Tagged ZeroDim s
forall s. ZeroDim s
Origin
  globalElement :: x -> Differentiable s (UnitObject (Differentiable s)) x
globalElement x
x = (ZeroDim s
 -> (x, LinearMap s (ZeroDim s) (Needle x),
     Norm (Needle x) -> Norm (ZeroDim s)))
-> Differentiable s (ZeroDim s) x
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((ZeroDim s
  -> (x, LinearMap s (ZeroDim s) (Needle x),
      Norm (Needle x) -> Norm (ZeroDim s)))
 -> Differentiable s (ZeroDim s) x)
-> (ZeroDim s
    -> (x, LinearMap s (ZeroDim s) (Needle x),
        Norm (Needle x) -> Norm (ZeroDim s)))
-> Differentiable s (ZeroDim s) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \ZeroDim s
Origin -> (x
x, LinearMap s (ZeroDim s) (Needle x)
forall v. AdditiveGroup v => v
zeroV, Norm (ZeroDim s) -> Norm (Needle x) -> Norm (ZeroDim s)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (ZeroDim s)
forall a. Monoid a => a
mempty)
  const :: x -> Differentiable s b x
const x
x = (b
 -> (x, LinearMap (Scalar (Needle b)) (Needle b) (Needle x),
     Norm (Needle x) -> Norm (Needle b)))
-> Differentiable s b x
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((b
  -> (x, LinearMap (Scalar (Needle b)) (Needle b) (Needle x),
      Norm (Needle x) -> Norm (Needle b)))
 -> Differentiable s b x)
-> (b
    -> (x, LinearMap (Scalar (Needle b)) (Needle b) (Needle x),
        Norm (Needle x) -> Norm (Needle b)))
-> Differentiable s b x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \b
_ -> (x
x, LinearMap (Scalar (Needle b)) (Needle b) (Needle x)
forall v. AdditiveGroup v => v
zeroV, Norm (Needle b) -> Norm (Needle x) -> Norm (Needle b)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm (Needle b)
forall a. Monoid a => a
mempty)



type DfblFuncValue s = GenericAgent (Differentiable s)

instance (RealFrac'' s) => HasAgent (Differentiable s) where
  alg :: (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a -> AgentVal (Differentiable s) q b)
-> Differentiable s a b
alg = (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a -> AgentVal (Differentiable s) q b)
-> Differentiable s a b
forall (k :: * -> * -> *) a b.
(HasAgent k, Object k a, Object k b) =>
(forall q. Object k q => GenericAgent k q a -> GenericAgent k q b)
-> k a b
genericAlg
  $~ :: Differentiable s b c
-> AgentVal (Differentiable s) a b
-> AgentVal (Differentiable s) a c
($~) = Differentiable s b c
-> AgentVal (Differentiable s) a b
-> AgentVal (Differentiable s) a c
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> GenericAgent k a b -> GenericAgent k a c
genericAgentMap
instance  s . (RealFloat'' s, SimpleSpace s) => CartesianAgent (Differentiable s) where
  alg1to2 :: (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> (AgentVal (Differentiable s) q b,
     AgentVal (Differentiable s) q c))
-> Differentiable s a (b, c)
alg1to2 = (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> (AgentVal (Differentiable s) q b,
     AgentVal (Differentiable s) q c))
-> Differentiable s a (b, c)
forall (k :: * -> * -> *) u a b c.
(PreArrow k, u ~ UnitObject k, Object k a, ObjectPair k b c) =>
(forall q.
 Object k q =>
 GenericAgent k q a -> (GenericAgent k q b, GenericAgent k q c))
-> k a (b, c)
genericAlg1to2
  alg2to1 :: (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> AgentVal (Differentiable s) q b
 -> AgentVal (Differentiable s) q c)
-> Differentiable s (a, b) c
alg2to1 = (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> AgentVal (Differentiable s) q b
 -> AgentVal (Differentiable s) q c)
-> Differentiable s (a, b) c
forall α β γ.
(Manifold α, Manifold β, Atlas' α, Atlas' β, ProjectableBoundary α,
 LocallyScalable s α, LocallyScalable s β) =>
(forall q.
 (LocallyScalable s q, Manifold q, Atlas q,
  Interior (Needle q) ~ Needle q,
  PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
  SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
 DfblFuncValue s q α -> DfblFuncValue s q β -> DfblFuncValue s q γ)
-> Differentiable s (α, β) γ
a2t1
   where a2t1 ::  α β γ . ( Manifold α, Manifold β
                           , Atlas' α, Atlas' β
                           , ProjectableBoundary α
                           , LocallyScalable s α, LocallyScalable s β
                           )
           => ( q . ( LocallyScalable s q, Manifold q, Atlas q
                     , Interior (Needle q) ~ Needle q
                     , PseudoAffineWithBoundary (Needle q)
                     , LinearManifold (Needle q)
                     , SimpleSpace (Needle q)
                     , HasTrie (ChartIndex q) )
               => DfblFuncValue s q α -> DfblFuncValue s q β -> DfblFuncValue s q γ )
           -> Differentiable s (α,β) γ
         a2t1 :: (forall q.
 (LocallyScalable s q, Manifold q, Atlas q,
  Interior (Needle q) ~ Needle q,
  PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
  SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
 DfblFuncValue s q α -> DfblFuncValue s q β -> DfblFuncValue s q γ)
-> Differentiable s (α, β) γ
a2t1 forall q.
(LocallyScalable s q, Manifold q, Atlas q,
 Interior (Needle q) ~ Needle q,
 PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
 SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
DfblFuncValue s q α -> DfblFuncValue s q β -> DfblFuncValue s q γ
f = case ( Semimanifold α => SemimanifoldWitness α
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @α, Semimanifold β => SemimanifoldWitness β
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @β
                       , LinearSpace (Needle α) => DualSpaceWitness (Needle α)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle α), LinearSpace (Needle β) => DualSpaceWitness (Needle β)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle β) ) of
            ( SemimanifoldWitness α
SemimanifoldWitness, SemimanifoldWitness β
SemimanifoldWitness
             ,DualSpaceWitness (Needle α)
DualSpaceWitness, DualSpaceWitness (Needle β)
DualSpaceWitness )
                -> (OpenManifold (Needle (Interior α)) => Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @α
                    ((OpenManifold (Needle (Interior β)) => Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @β
                      (((LinearSpace (Needle (Boundary α)),
  Scalar (Needle (Boundary α)) ~ Scalar (Needle (Interior α))) =>
 Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @α
                        (((LinearSpace (Needle (Boundary β)),
  Scalar (Needle (Boundary β)) ~ Scalar (Needle (Interior β))) =>
 Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @β
                          (((LinearSpace (Needle (Boundary (Needle α))),
  Scalar (Needle (Boundary (Needle α)))
  ~ Scalar (Needle (Interior (Needle α)))) =>
 Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle α)
                            (((LinearSpace (Needle (Boundary (Needle β))),
  Scalar (Needle (Boundary (Needle β)))
  ~ Scalar (Needle (Interior (Needle β)))) =>
 Differentiable s (α, β) γ)
-> Differentiable s (α, β) γ
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle β)
                              (Differentiable s (α, β) γ
forall a. HasCallStack => a
undefined -- genericAlg2to1 f
                                     ))))))
  alg2to2 :: (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> AgentVal (Differentiable s) q b
 -> (AgentVal (Differentiable s) q c,
     AgentVal (Differentiable s) q d))
-> Differentiable s (a, b) (c, d)
alg2to2 = (forall q.
 Object (Differentiable s) q =>
 AgentVal (Differentiable s) q a
 -> AgentVal (Differentiable s) q b
 -> (AgentVal (Differentiable s) q c,
     AgentVal (Differentiable s) q d))
-> Differentiable s (a, b) (c, d)
forall α β γ δ.
(Manifold α, Manifold β, Manifold γ, Manifold δ, Atlas' α,
 Atlas' β, Atlas' γ, Atlas' δ, LocallyScalable s α,
 LocallyScalable s β, LocallyScalable s γ, LocallyScalable s δ) =>
(forall q.
 (LocallyScalable s q, Manifold q, Atlas q,
  Interior (Needle q) ~ Needle q,
  PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
  SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
 DfblFuncValue s q α
 -> DfblFuncValue s q β
 -> (DfblFuncValue s q γ, DfblFuncValue s q δ))
-> Differentiable s (α, β) (γ, δ)
a2t1
   where a2t1 ::  α β γ δ . ( Manifold α, Manifold β, Manifold γ, Manifold δ
                             , Atlas' α, Atlas' β, Atlas' γ, Atlas' δ
                             , LocallyScalable s α, LocallyScalable s β
                             , LocallyScalable s γ, LocallyScalable s δ )
           => ( q . ( LocallyScalable s q, Manifold q, Atlas q
                     , Interior (Needle q) ~ Needle q
                     , PseudoAffineWithBoundary (Needle q)
                     , LinearManifold (Needle q)
                     , SimpleSpace (Needle q)
                     , HasTrie (ChartIndex q) )
               => DfblFuncValue s q α -> DfblFuncValue s q β
                     -> (DfblFuncValue s q γ, DfblFuncValue s q δ) )
           -> Differentiable s (α,β) (γ,δ)
         a2t1 :: (forall q.
 (LocallyScalable s q, Manifold q, Atlas q,
  Interior (Needle q) ~ Needle q,
  PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
  SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
 DfblFuncValue s q α
 -> DfblFuncValue s q β
 -> (DfblFuncValue s q γ, DfblFuncValue s q δ))
-> Differentiable s (α, β) (γ, δ)
a2t1 forall q.
(LocallyScalable s q, Manifold q, Atlas q,
 Interior (Needle q) ~ Needle q,
 PseudoAffineWithBoundary (Needle q), LinearManifold (Needle q),
 SimpleSpace (Needle q), HasTrie (ChartIndex q)) =>
DfblFuncValue s q α
-> DfblFuncValue s q β
-> (DfblFuncValue s q γ, DfblFuncValue s q δ)
f = case ( Semimanifold α => SemimanifoldWitness α
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @α, Semimanifold β => SemimanifoldWitness β
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @β
                       , Semimanifold γ => SemimanifoldWitness γ
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @γ, Semimanifold δ => SemimanifoldWitness δ
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @δ
                       , LinearSpace (Needle α) => DualSpaceWitness (Needle α)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle α), LinearSpace (Needle β) => DualSpaceWitness (Needle β)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle β)
                       , LinearSpace (Needle γ) => DualSpaceWitness (Needle γ)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle γ), LinearSpace (Needle δ) => DualSpaceWitness (Needle δ)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle δ) ) of
            ( SemimanifoldWitness α
SemimanifoldWitness, SemimanifoldWitness β
SemimanifoldWitness
             ,SemimanifoldWitness γ
SemimanifoldWitness, SemimanifoldWitness δ
SemimanifoldWitness
             ,DualSpaceWitness (Needle α)
DualSpaceWitness, DualSpaceWitness (Needle β)
DualSpaceWitness
             ,DualSpaceWitness (Needle γ)
DualSpaceWitness, DualSpaceWitness (Needle δ)
DualSpaceWitness )
                 -> (OpenManifold (Needle (Interior α)) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @α
                    ((OpenManifold (Needle (Interior β)) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @β
                     ((OpenManifold (Needle (Interior γ)) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @γ
                      ((OpenManifold (Needle (Interior δ)) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @δ
                       (((LinearSpace (Needle (Boundary α)),
  Scalar (Needle (Boundary α)) ~ Scalar (Needle (Interior α))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @α
                        (((LinearSpace (Needle (Boundary β)),
  Scalar (Needle (Boundary β)) ~ Scalar (Needle (Interior β))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @β
                         (((LinearSpace (Needle (Boundary γ)),
  Scalar (Needle (Boundary γ)) ~ Scalar (Needle (Interior γ))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @γ
                          (((LinearSpace (Needle (Boundary δ)),
  Scalar (Needle (Boundary δ)) ~ Scalar (Needle (Interior δ))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @δ
                           (((LinearSpace (Needle (Boundary (Needle α))),
  Scalar (Needle (Boundary (Needle α)))
  ~ Scalar (Needle (Interior (Needle α)))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle α)
                            (((LinearSpace (Needle (Boundary (Needle β))),
  Scalar (Needle (Boundary (Needle β)))
  ~ Scalar (Needle (Interior (Needle β)))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle β)
                             (((LinearSpace (Needle (Boundary (Needle γ))),
  Scalar (Needle (Boundary (Needle γ)))
  ~ Scalar (Needle (Interior (Needle γ)))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle γ)
                              (((LinearSpace (Needle (Boundary (Needle δ))),
  Scalar (Needle (Boundary (Needle δ)))
  ~ Scalar (Needle (Interior (Needle δ)))) =>
 Differentiable s (α, β) (γ, δ))
-> Differentiable s (α, β) (γ, δ)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @(Needle δ)
                               (Differentiable s (α, β) (γ, δ)
forall a. HasCallStack => a
undefined -- genericAlg2to2 f
                                 ))))))))))))
instance (RealFrac'' s, SimpleSpace s)
      => PointAgent (DfblFuncValue s) (Differentiable s) a x where
  point :: x -> DfblFuncValue s a x
point = x -> DfblFuncValue s a x
forall (k :: * -> * -> *) a x.
(WellPointed k, Object k a, ObjectPoint k x) =>
x -> GenericAgent k a x
genericPoint


actuallyLinearEndo :: (Object (Affine s) x, Object (LinearMap s) x)
            => (x+>x) -> Differentiable s x x
actuallyLinearEndo :: (x +> x) -> Differentiable s x x
actuallyLinearEndo = DiffableEndoProof x x -> Affine s x x -> Differentiable s x x
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof x x
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine s x x -> Differentiable s x x)
-> (LinearMap s x x -> Affine s x x)
-> LinearMap s x x
-> Differentiable s x x
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearMap s x x -> Affine s x x
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr

actuallyAffineEndo :: (Object (Affine s) x, Object (LinearMap s) x)
            => x -> (x+>Needle x) -> Differentiable s x x
actuallyAffineEndo :: x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo x
y₀ x +> Needle x
f = DiffableEndoProof x x -> Affine s x x -> Differentiable s x x
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof x x
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine s x x -> Differentiable s x x)
-> Affine s x x -> Differentiable s x x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ x -> LinearMap s x (Needle x) -> Affine s x x
forall x y s.
(LinearSpace x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar x, s ~ Scalar (Needle y)) =>
y -> LinearMap s x (Needle y) -> Affine s x y
fromOffsetSlope x
y₀ LinearMap s x (Needle x)
x +> Needle x
f


actuallyLinear :: ( Object (Affine s) x, Object (Affine s) y
                  , Object (LinearMap s) x, Object (LinearMap s) y )
            => (x+>y) -> Differentiable s x y
actuallyLinear :: (x +> y) -> Differentiable s x y
actuallyLinear = DiffableEndoProof x y -> Affine s x y -> Differentiable s x y
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof x y
forall d c. DiffableEndoProof d c
NotDiffableEndo (Affine s x y -> Differentiable s x y)
-> (LinearMap s x y -> Affine s x y)
-> LinearMap s x y
-> Differentiable s x y
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearMap s x y -> Affine s x y
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr

actuallyAffine :: ( Object (Affine s) x, Object (Affine s) y
                  , Object (LinearMap s) x, Object (LinearMap s) (Needle y) )
            => y -> (x+>Needle y) -> Differentiable s x y
actuallyAffine :: y -> (x +> Needle y) -> Differentiable s x y
actuallyAffine y
y₀ x +> Needle y
f = DiffableEndoProof x y -> Affine s x y -> Differentiable s x y
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof x y
forall d c. DiffableEndoProof d c
NotDiffableEndo (Affine s x y -> Differentiable s x y)
-> Affine s x y -> Differentiable s x y
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ y -> LinearMap s x (Needle y) -> Affine s x y
forall x y s.
(LinearSpace x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar x, s ~ Scalar (Needle y)) =>
y -> LinearMap s x (Needle y) -> Affine s x y
fromOffsetSlope y
y₀ LinearMap s x (Needle y)
x +> Needle y
f


-- affinPoint :: (WithField s LinearManifold c, WithField s LinearManifold d)
--                   => c -> DfblFuncValue s d c
-- affinPoint p = GenericAgent (AffinDiffable (const p))


dfblFnValsFunc ::  c c' d v v' ε s
     . ( Manifold c, Manifold d, Manifold c'
       , Atlas' c, Atlas' d, Atlas' c'
       , ProjectableBoundary s, ProjectableBoundary v'
       , ProjectableBoundary (Needle d)
       , SimpleSpace (Needle d)
       , LocallyScalable s c, LocallyScalable s c', LocallyScalable s d
       , v ~ Needle c, v' ~ Needle c'
       , ε ~ Norm v, ε ~ Norm v'
       , SimpleSpace v'
       , RealFrac'' s )
             => (c' -> (c, v'+>v, ε->ε)) -> DfblFuncValue s d c' -> DfblFuncValue s d c
dfblFnValsFunc :: (c' -> (c, v' +> v, ε -> ε))
-> DfblFuncValue s d c' -> DfblFuncValue s d c
dfblFnValsFunc c' -> (c, v' +> v, ε -> ε)
f = case ( TensorSpace s => ScalarSpaceWitness s
forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @s
                        , SemimanifoldWithBoundary s => SmfdWBoundWitness s
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @s
                        , Semimanifold d => SemimanifoldWitness d
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @d
                        , Semimanifold c' => SemimanifoldWitness c'
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @c' ) of
   ( ScalarSpaceWitness s
ScalarSpaceWitness, SmfdWBoundWitness s
OpenManifoldWitness
    ,SemimanifoldWitness d
SemimanifoldWitness, SemimanifoldWitness c'
SemimanifoldWitness )
        -> (OpenManifold (Needle (Interior c)) =>
 DfblFuncValue s d c' -> DfblFuncValue s d c)
-> DfblFuncValue s d c' -> DfblFuncValue s d c
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @c ((OpenManifold (Needle (Interior d)) =>
 DfblFuncValue s d c' -> DfblFuncValue s d c)
-> DfblFuncValue s d c' -> DfblFuncValue s d c
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @d ((c' -> (c, Needle c' +> Needle c, LinDevPropag c' c))
-> Differentiable s c' c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable c' -> (c, v' +> v, ε -> ε)
c' -> (c, Needle c' +> Needle c, LinDevPropag c' c)
f Differentiable s c' c
-> AgentVal (Differentiable s) d c'
-> AgentVal (Differentiable s) d c
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~))

dfblFnValsCombine :: forall d c c' c'' v v' v'' ε ε' ε'' s. 
         ( LocallyScalable s c,  LocallyScalable s c',  LocallyScalable s c''
         ,  LocallyScalable s d
         , v ~ Needle c, v' ~ Needle c', v'' ~ Needle c''
         , ε ~ Norm v  , ε' ~ Norm v'  , ε'' ~ Norm v'', ε~ε', ε~ε'' 
         , SimpleSpace (Needle d)
         , RealFrac' s )
       => (  c' -> c'' -> (c, (v',v'')+>v, ε -> (ε',ε''))  )
         -> DfblFuncValue s d c' -> DfblFuncValue s d c'' -> DfblFuncValue s d c
dfblFnValsCombine :: (c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> DfblFuncValue s d c'
-> DfblFuncValue s d c''
-> DfblFuncValue s d c
dfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb (GenericAgent (Differentiable d -> (c', Needle d +> Needle c', LinDevPropag d c')
f))
                      (GenericAgent (Differentiable d -> (c'', Needle d +> Needle c'', LinDevPropag d c'')
g)) 
    = Differentiable s d c -> DfblFuncValue s d c
forall k k1 (k2 :: k -> k1 -> *) (a :: k) (v :: k1).
k2 a v -> GenericAgent k2 a v
GenericAgent (Differentiable s d c -> DfblFuncValue s d c)
-> ((d
     -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
         ε -> Norm (Needle d)))
    -> Differentiable s d c)
-> (d
    -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
        ε -> Norm (Needle d)))
-> DfblFuncValue s d c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (d
 -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
     ε -> Norm (Needle d)))
-> Differentiable s d c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((d
  -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
      ε -> Norm (Needle d)))
 -> DfblFuncValue s d c)
-> (d
    -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
        ε -> Norm (Needle d)))
-> DfblFuncValue s d c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
        \d
d -> let (c'
c', LinearMap (Scalar (Needle d)) (Needle d) v''
jf, Norm v'' -> Norm (Needle d)
devf) = d -> (c', Needle d +> Needle c', LinDevPropag d c')
f d
d
                  (c''
c'', LinearMap (Scalar (Needle d)) (Needle d) v''
jg, Norm v'' -> Norm (Needle d)
devg) = d -> (c'', Needle d +> Needle c'', LinDevPropag d c'')
g d
d
                  (c
c, LinearMap (Scalar (Needle d)) (v'', v'') v''
jh, ε -> (ε', ε'')
devh) = c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb c'
c' c''
c''
                  jhl :: LinearMap (Scalar (Needle d)) v'' v''
jhl = LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
-> LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
idLinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) v'' v''
forall v. AdditiveGroup v => v
zeroV); jhr :: LinearMap (Scalar (Needle d)) v'' v''
jhr = LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
-> LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (LinearMap (Scalar (Needle d)) v'' v''
forall v. AdditiveGroup v => v
zeroVLinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
              in ( c
c
                 , LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) (Needle d) (v'', v'')
-> LinearMap (Scalar (Needle d)) (Needle d) v''
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< LinearMap (Scalar (Needle d)) (Needle d) v''
jfLinearMap (Scalar (Needle d)) (Needle d) v''
-> LinearMap (Scalar (Needle d)) (Needle d) v''
-> LinearMap (Scalar (Needle d)) (Needle d) (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) (Needle d) v''
jg
                 , \ε
εc -> let εc' :: Norm v''
εc' = (v'' +> v'') -> Norm v'' -> Norm v''
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm v'' +> v''
LinearMap (Scalar (Needle d)) v'' v''
jhl ε
Norm v''
εc
                              εc'' :: Norm v''
εc'' = (v'' +> v'') -> Norm v'' -> Norm v''
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm v'' +> v''
LinearMap (Scalar (Needle d)) v'' v''
jhr ε
Norm v''
εc
                              (ε'
δc',ε''
δc'') = ε -> (ε', ε'')
devh ε
εc 
                          in Norm v'' -> Norm (Needle d)
devf Norm v''
εc' Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> Norm v'' -> Norm (Needle d)
devg Norm v''
εc''
                               Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> LinearMap (Scalar (Needle d)) (Needle d) v''
-> Norm v'' -> Norm (Needle d)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap (Scalar (Needle d)) (Needle d) v''
jf ε'
Norm v''
δc'
                               Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> LinearMap (Scalar (Needle d)) (Needle d) v''
-> Norm v'' -> Norm (Needle d)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap (Scalar (Needle d)) (Needle d) v''
jg ε''
Norm v''
δc''
                 )
dfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb (GenericAgent Differentiable s d c'
fa) (GenericAgent Differentiable s d c''
ga) 
         = (c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> DfblFuncValue s d c'
-> DfblFuncValue s d c''
-> DfblFuncValue s d c
forall d c c' c'' v v' v'' ε ε' ε'' s.
(LocallyScalable s c, LocallyScalable s c', LocallyScalable s c'',
 LocallyScalable s d, v ~ Needle c, v' ~ Needle c',
 v'' ~ Needle c'', ε ~ Norm v, ε' ~ Norm v', ε'' ~ Norm v'', ε ~ ε',
 ε ~ ε'', SimpleSpace (Needle d), RealFrac' s) =>
(c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> DfblFuncValue s d c'
-> DfblFuncValue s d c''
-> DfblFuncValue s d c
dfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb (Differentiable s d c' -> DfblFuncValue s d c'
forall k k1 (k2 :: k -> k1 -> *) (a :: k) (v :: k1).
k2 a v -> GenericAgent k2 a v
GenericAgent (Differentiable s d c' -> DfblFuncValue s d c')
-> Differentiable s d c' -> DfblFuncValue s d c'
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s d c' -> Differentiable s d c'
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s d c'
fa)
                                 (Differentiable s d c'' -> DfblFuncValue s d c''
forall k k1 (k2 :: k -> k1 -> *) (a :: k) (v :: k1).
k2 a v -> GenericAgent k2 a v
GenericAgent (Differentiable s d c'' -> DfblFuncValue s d c'')
-> Differentiable s d c'' -> DfblFuncValue s d c''
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s d c'' -> Differentiable s d c''
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable s d c''
ga)





instance  v s a . ( LinearManifold v, Scalar v ~ s
                   , LocallyScalable s a, Manifold a, Atlas' a, Atlas' v
                   , SimpleSpace v, SimpleSpace (Needle a)
                   , RealFloat'' s )
    => AdditiveGroup (DfblFuncValue s a v) where
  zeroV :: DfblFuncValue s a v
zeroV = case ( TensorSpace v => LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @v, LinearSpace v => DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v
               , Semimanifold a => SemimanifoldWitness a
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @a
               ) of
     (LinearManifoldWitness v
LinearManifoldWitness, DualSpaceWitness v
DualSpaceWitness, SemimanifoldWitness a
SemimanifoldWitness)
         -> (OpenManifold (Needle (Interior a)) => DfblFuncValue s a v)
-> DfblFuncValue s a v
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a ((OpenManifold (Scalar (Needle (Interior a))) =>
 DfblFuncValue s a v)
-> DfblFuncValue s a v
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Scalar (Needle (Interior m))) => r) -> r
scalarIsOpenMfd @a
               ((ProjectableBoundary (Needle (Interior a)) => DfblFuncValue s a v)
-> DfblFuncValue s a v
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (v -> DfblFuncValue s a v
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point v
forall v. AdditiveGroup v => v
zeroV)))
  ^+^ :: DfblFuncValue s a v -> DfblFuncValue s a v -> DfblFuncValue s a v
(^+^) = (OpenManifold (Needle (Interior a)) =>
 DfblFuncValue s a v -> DfblFuncValue s a v -> DfblFuncValue s a v)
-> DfblFuncValue s a v
-> DfblFuncValue s a v
-> DfblFuncValue s a v
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a ( (ProjectableBoundary (Needle (Interior a)) =>
 DfblFuncValue s a v -> DfblFuncValue s a v -> DfblFuncValue s a v)
-> DfblFuncValue s a v
-> DfblFuncValue s a v
-> DfblFuncValue s a v
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a
               (case ( TensorSpace v => LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @v
                     , TensorSpace (Needle a) => LinearManifoldWitness (Needle a)
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @(Needle a)
                     , LinearSpace v => DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v
                     , LinearSpace (Needle a) => DualSpaceWitness (Needle a)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @(Needle a) ) of
     (LinearManifoldWitness v
LinearManifoldWitness, LinearManifoldWitness (Needle a)
LinearManifoldWitness
      ,DualSpaceWitness v
DualSpaceWitness, DualSpaceWitness (Needle a)
DualSpaceWitness)
         -> ((DfblFuncValue s a v, DfblFuncValue s a v) -> DfblFuncValue s a v)
-> DfblFuncValue s a v
-> DfblFuncValue s a v
-> DfblFuncValue s a v
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry (((DfblFuncValue s a v, DfblFuncValue s a v)
  -> DfblFuncValue s a v)
 -> DfblFuncValue s a v
 -> DfblFuncValue s a v
 -> DfblFuncValue s a v)
-> ((DfblFuncValue s a v, DfblFuncValue s a v)
    -> DfblFuncValue s a v)
-> DfblFuncValue s a v
-> DfblFuncValue s a v
-> DfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \case
        (GenericAgent (AffinDiffable DiffableEndoProof a v
ef Affine s a v
f), GenericAgent (AffinDiffable eg g))
              -> Differentiable s a v -> DfblFuncValue s a v
forall k k1 (k2 :: k -> k1 -> *) (a :: k) (v :: k1).
k2 a v -> GenericAgent k2 a v
GenericAgent (Differentiable s a v -> DfblFuncValue s a v)
-> Differentiable s a v -> DfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DiffableEndoProof a v -> Affine s a v -> Differentiable s a v
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable (DiffableEndoProof a v
efDiffableEndoProof a v
-> DiffableEndoProof a v -> DiffableEndoProof a v
forall a. Semigroup a => a -> a -> a
<>DiffableEndoProof a v
eg) (Affine s a v
fAffine s a v -> Affine s a v -> Affine s a v
forall v. AdditiveGroup v => v -> v -> v
^+^Affine s a v
g)
        (DfblFuncValue s a v
α,DfblFuncValue s a v
β) -> (v -> v -> (v, (v, v) +> v, Norm v -> (Norm v, Norm v)))
-> DfblFuncValue s a v
-> DfblFuncValue s a v
-> DfblFuncValue s a v
forall d c c' c'' v v' v'' ε ε' ε'' s.
(LocallyScalable s c, LocallyScalable s c', LocallyScalable s c'',
 LocallyScalable s d, v ~ Needle c, v' ~ Needle c',
 v'' ~ Needle c'', ε ~ Norm v, ε' ~ Norm v', ε'' ~ Norm v'', ε ~ ε',
 ε ~ ε'', SimpleSpace (Needle d), RealFrac' s) =>
(c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> DfblFuncValue s d c'
-> DfblFuncValue s d c''
-> DfblFuncValue s d c
dfblFnValsCombine (\v
a v
b -> (v
av -> v -> v
forall v. AdditiveGroup v => v -> v -> v
^+^v
b, LinearFunction s (v, v) v -> LinearMap s (v, v) v
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr LinearFunction s (v, v) v
forall w s. AdditiveGroup w => LinearFunction s (w, w) w
addV, (Norm v, Norm v) -> Norm v -> (Norm v, Norm v)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const (Norm v, Norm v)
forall a. Monoid a => a
mempty)) DfblFuncValue s a v
α DfblFuncValue s a v
β
    ))
  negateV :: DfblFuncValue s a v -> DfblFuncValue s a v
negateV = (OpenManifold (Needle (Interior a)) =>
 DfblFuncValue s a v -> DfblFuncValue s a v)
-> DfblFuncValue s a v -> DfblFuncValue s a v
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a (case ( TensorSpace v => LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @v, LinearSpace v => DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @v
                                     , Semimanifold a => SemimanifoldWitness a
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @a
                                     ) of
     (LinearManifoldWitness v
LinearManifoldWitness, DualSpaceWitness v
DualSpaceWitness, SemimanifoldWitness a
SemimanifoldWitness)
         -> (ProjectableBoundary (Needle (Interior a)) =>
 DfblFuncValue s a v -> DfblFuncValue s a v)
-> DfblFuncValue s a v -> DfblFuncValue s a v
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (\case
         (GenericAgent (AffinDiffable DiffableEndoProof a v
ef Affine s a v
f))
           -> Differentiable s a v -> DfblFuncValue s a v
forall k k1 (k2 :: k -> k1 -> *) (a :: k) (v :: k1).
k2 a v -> GenericAgent k2 a v
GenericAgent (Differentiable s a v -> DfblFuncValue s a v)
-> Differentiable s a v -> DfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ DiffableEndoProof a v -> Affine s a v -> Differentiable s a v
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof a v
ef (Affine s a v -> Affine s a v
forall v. AdditiveGroup v => v -> v
negateV Affine s a v
f)
         DfblFuncValue s a v
α -> (v -> (v, v +> v, Norm v -> Norm v))
-> DfblFuncValue s a v -> DfblFuncValue s a v
forall c c' d v v' ε s.
(Manifold c, Manifold d, Manifold c', Atlas' c, Atlas' d,
 Atlas' c', ProjectableBoundary s, ProjectableBoundary v',
 ProjectableBoundary (Needle d), SimpleSpace (Needle d),
 LocallyScalable s c, LocallyScalable s c', LocallyScalable s d,
 v ~ Needle c, v' ~ Needle c', ε ~ Norm v, ε ~ Norm v',
 SimpleSpace v', RealFrac'' s) =>
(c' -> (c, v' +> v, ε -> ε))
-> DfblFuncValue s d c' -> DfblFuncValue s d c
dfblFnValsFunc (\v
a -> (v -> v
forall v. AdditiveGroup v => v -> v
negateV v
a, (v +> v) -> v +> v
forall v. AdditiveGroup v => v -> v
negateV v +> v
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, Norm v -> Norm v -> Norm v
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const Norm v
forall a. Monoid a => a
mempty)) DfblFuncValue s a v
α
      )
    )
  
instance  n a . ( RealFloat'' n, Manifold a, LocallyScalable n a
                 , SimpleSpace (Needle a)
                 , Atlas' a, Atlas' n
                 )
            => Num (DfblFuncValue n a n) where
  fromInteger :: Integer -> DfblFuncValue n a n
fromInteger = case ( TensorSpace n => LinearManifoldWitness n
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @n, LinearSpace n => DualSpaceWitness n
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @n
                     , Semimanifold a => SemimanifoldWitness a
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @a, Num' n => ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness @n
                     ) of
     (LinearManifoldWitness n
LinearManifoldWitness, DualSpaceWitness n
DualSpaceWitness, SemimanifoldWitness a
SemimanifoldWitness, ClosedScalarWitness n
ClosedScalarWitness)
         -> (OpenManifold (Needle (Interior a)) =>
 Integer -> DfblFuncValue n a n)
-> Integer -> DfblFuncValue n a n
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a ((OpenManifold (Scalar (Needle (Interior a))) =>
 Integer -> DfblFuncValue n a n)
-> Integer -> DfblFuncValue n a n
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Scalar (Needle (Interior m))) => r) -> r
scalarIsOpenMfd @a
               ((ProjectableBoundary (Needle (Interior a)) =>
 Integer -> DfblFuncValue n a n)
-> Integer -> DfblFuncValue n a n
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (n -> DfblFuncValue n a n
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point (n -> DfblFuncValue n a n)
-> (Integer -> n) -> Integer -> DfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Integer -> n
forall a. Num a => Integer -> a
fromInteger)))
  + :: DfblFuncValue n a n -> DfblFuncValue n a n -> DfblFuncValue n a n
(+) = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
      ClosedScalarWitness n
ClosedScalarWitness -> DfblFuncValue n a n -> DfblFuncValue n a n -> DfblFuncValue n a n
forall v. AdditiveGroup v => v -> v -> v
(^+^)
  * :: DfblFuncValue n a n -> DfblFuncValue n a n -> DfblFuncValue n a n
(*) = case ( LinearManifoldWitness n
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness n
             , ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n ) of
      (LinearManifoldWitness n
LinearManifoldWitness, ClosedScalarWitness n
ClosedScalarWitness) -> (n
 -> n
 -> (n, LinearMap (Scalar n) (n, n) n, Norm n -> (Norm n, Norm n)))
-> DfblFuncValue n a n
-> DfblFuncValue n a n
-> DfblFuncValue n a n
forall d c c' c'' v v' v'' ε ε' ε'' s.
(LocallyScalable s c, LocallyScalable s c', LocallyScalable s c'',
 LocallyScalable s d, v ~ Needle c, v' ~ Needle c',
 v'' ~ Needle c'', ε ~ Norm v, ε' ~ Norm v', ε'' ~ Norm v'', ε ~ ε',
 ε ~ ε'', SimpleSpace (Needle d), RealFrac' s) =>
(c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> DfblFuncValue s d c'
-> DfblFuncValue s d c''
-> DfblFuncValue s d c
dfblFnValsCombine ((n
  -> n
  -> (n, LinearMap (Scalar n) (n, n) n, Norm n -> (Norm n, Norm n)))
 -> DfblFuncValue n a n
 -> DfblFuncValue n a n
 -> DfblFuncValue n a n)
-> (n
    -> n
    -> (n, LinearMap (Scalar n) (n, n) n, Norm n -> (Norm n, Norm n)))
-> DfblFuncValue n a n
-> DfblFuncValue n a n
-> DfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
          \n
a n
b -> ( n
an -> n -> n
forall a. Num a => a -> a -> a
*n
b
                  , LinearFunction n (n, n) n -> LinearMap (Scalar n) (n, n) n
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction n (n, n) n -> LinearMap (Scalar n) (n, n) n)
-> LinearFunction n (n, n) n -> LinearMap (Scalar n) (n, n) n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction n (n, n) n
forall w s. AdditiveGroup w => LinearFunction s (w, w) w
addV LinearFunction n (n, n) n
-> LinearFunction n (n, n) (n, n) -> LinearFunction n (n, n) n
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< (LinearFunction (Scalar n) n (LinearFunction n n n)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction (Scalar n) n (LinearFunction n n n)
-> n -> LinearFunction n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
a)LinearFunction n n n
-> LinearFunction n n n -> LinearFunction n (n, n) (n, n)
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
***(LinearFunction (Scalar n) n (LinearFunction n n n)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction (Scalar n) n (LinearFunction n n n)
-> n -> LinearFunction n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
b)
                  , String -> (n -> n) -> LinDevPropag n n
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(n -> String
forall r. RealFloat r => r -> String
showℝ n
aString -> String -> String
forall a. [a] -> [a] -> [a]
++String
"*"String -> String -> String
forall a. [a] -> [a] -> [a]
++n -> String
forall r. RealFloat r => r -> String
showℝ n
b) (n -> n
forall a. Floating a => a -> a
sqrt :: n->n)
                       (Norm n -> Norm n)
-> (Norm n -> (Norm n, Norm n)) -> Norm n -> (Norm n, Norm n)
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k a b -> k b c -> k a c
>>> \Norm n
d¹₂ -> (Norm n
d¹₂,Norm n
d¹₂)
                           -- ε δa δb = (a+δa)·(b+δb) - (a·b + (a·δa + b·δb)) 
                           --         = δa·δb
                           --   so choose δa = δb = √ε
                  )
  negate :: DfblFuncValue n a n -> DfblFuncValue n a n
negate = case ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness n of
     ClosedScalarWitness n
ClosedScalarWitness -> DfblFuncValue n a n -> DfblFuncValue n a n
forall v. AdditiveGroup v => v -> v
negateV
  abs :: DfblFuncValue n a n -> DfblFuncValue n a n
abs = (ProjectableBoundary (Needle (Interior a)) =>
 DfblFuncValue n a n -> DfblFuncValue n a n)
-> DfblFuncValue n a n -> DfblFuncValue n a n
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (
   case (TensorSpace n => LinearManifoldWitness n
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @n, Num' n => ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness @n) of
         (LinearManifoldWitness n
LinearManifoldWitness, ClosedScalarWitness n
ClosedScalarWitness) -> (n -> (n, n +> n, Norm n -> Norm n))
-> DfblFuncValue n a n -> DfblFuncValue n a n
forall c c' d v v' ε s.
(Manifold c, Manifold d, Manifold c', Atlas' c, Atlas' d,
 Atlas' c', ProjectableBoundary s, ProjectableBoundary v',
 ProjectableBoundary (Needle d), SimpleSpace (Needle d),
 LocallyScalable s c, LocallyScalable s c', LocallyScalable s d,
 v ~ Needle c, v' ~ Needle c', ε ~ Norm v, ε ~ Norm v',
 SimpleSpace v', RealFrac'' s) =>
(c' -> (c, v' +> v, ε -> ε))
-> DfblFuncValue s d c' -> DfblFuncValue s d c
dfblFnValsFunc n -> (n, n +> n, Norm n -> Norm n)
forall (k :: * -> * -> *) a a.
(Object k a, SemimanifoldWithBoundary (Scalar (Needle a)),
 SemimanifoldWithBoundary (Needle a), Category k,
 Empty (Boundary a), ProjectableBoundary a, FiniteDimensional a,
 FiniteDimensional (DualVector a), SemiInner a,
 SemiInner (DualVector a), HasTrie (ChartIndex a), Atlas a,
 InnerSpace (Scalar a), InnerSpace a, IEEE (Scalar a), IEEE a,
 Num' a, Num' (Scalar (Needle a)),
 LinearSpace (DualVector (Needle a)), LinearSpace (Needle a),
 AdditiveGroup (k a a), Scalar a ~ a, Needle a ~ a,
 DualVector a ~ a, Interior a ~ a) =>
a -> (a, k a a, Norm a -> Norm a)
dfblAbs
          where dfblAbs :: a -> (a, k a a, Norm a -> Norm a)
dfblAbs a
a
                 | a
aa -> a -> Bool
forall a. Ord a => a -> a -> Bool
>a
0        = (a
a, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String -> (a -> a) -> LinDevPropag a a
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"abs "String -> String -> String
forall a. [a] -> [a] -> [a]
++a -> String
forall r. RealFloat r => r -> String
showℝ a
a) ((a -> a) -> Norm a -> Norm a) -> (a -> a) -> Norm a -> Norm a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \a
ε -> a
a a -> a -> a
forall a. Num a => a -> a -> a
+ a
εa -> a -> a
forall a. Fractional a => a -> a -> a
/a
2) 
                 | a
aa -> a -> Bool
forall a. Ord a => a -> a -> Bool
<a
0        = (-a
a, k a a -> k a a
forall v. AdditiveGroup v => v -> v
negateV k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String -> (a -> a) -> LinDevPropag a a
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"abs "String -> String -> String
forall a. [a] -> [a] -> [a]
++a -> String
forall r. RealFloat r => r -> String
showℝ a
a)
                                       ((a -> a) -> Norm a -> Norm a) -> (a -> a) -> Norm a -> Norm a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \a
ε -> a
εa -> a -> a
forall a. Fractional a => a -> a -> a
/a
2 a -> a -> a
forall a. Num a => a -> a -> a
- a
a)
                 | Bool
otherwise  = (a
0, k a a
forall v. AdditiveGroup v => v
zeroV, Scalar a -> Norm a -> Norm a
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm (a -> a
forall a. Floating a => a -> a
sqrt a
0.5))
     )
  signum :: DfblFuncValue n a n -> DfblFuncValue n a n
signum = (ProjectableBoundary (Needle (Interior a)) =>
 DfblFuncValue n a n -> DfblFuncValue n a n)
-> DfblFuncValue n a n -> DfblFuncValue n a n
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (
   case (TensorSpace n => LinearManifoldWitness n
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @n, Num' n => ClosedScalarWitness n
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness @n) of
         (LinearManifoldWitness n
LinearManifoldWitness, ClosedScalarWitness n
ClosedScalarWitness) -> (n -> (n, n +> n, Norm n -> Norm n))
-> DfblFuncValue n a n -> DfblFuncValue n a n
forall c c' d v v' ε s.
(Manifold c, Manifold d, Manifold c', Atlas' c, Atlas' d,
 Atlas' c', ProjectableBoundary s, ProjectableBoundary v',
 ProjectableBoundary (Needle d), SimpleSpace (Needle d),
 LocallyScalable s c, LocallyScalable s c', LocallyScalable s d,
 v ~ Needle c, v' ~ Needle c', ε ~ Norm v, ε ~ Norm v',
 SimpleSpace v', RealFrac'' s) =>
(c' -> (c, v' +> v, ε -> ε))
-> DfblFuncValue s d c' -> DfblFuncValue s d c
dfblFnValsFunc n -> (n, n +> n, Norm n -> Norm n)
forall p a b.
(HasTrie (ChartIndex p), Atlas p, InnerSpace (Scalar p),
 InnerSpace p, IEEE (Scalar p), IEEE p, Num' (Scalar (Needle p)),
 Num' p, SemiInner (DualVector p), SemiInner p,
 FiniteDimensional (DualVector p), FiniteDimensional p,
 ProjectableBoundary p, Empty (Boundary p), Num a,
 SemimanifoldWithBoundary (Needle p),
 SemimanifoldWithBoundary (Scalar (Needle p)),
 LinearSpace (DualVector (Needle p)), LinearSpace (Needle p),
 AdditiveGroup b, Needle p ~ p, Scalar p ~ p, DualVector p ~ p,
 Interior p ~ p) =>
p -> (a, b, Norm (Needle p) -> Norm (Needle p))
dfblSgn
          where dfblSgn :: p -> (a, b, Norm (Needle p) -> Norm (Needle p))
dfblSgn p
a
                 | p
ap -> p -> Bool
forall a. Ord a => a -> a -> Bool
>p
0        = (a
1, b
forall v. AdditiveGroup v => v
zeroV, String -> (p -> p) -> Norm (Needle p) -> Norm (Needle p)
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"signum "String -> String -> String
forall a. [a] -> [a] -> [a]
++p -> String
forall r. RealFloat r => r -> String
showℝ p
a) ((p -> p) -> Norm (Needle p) -> Norm (Needle p))
-> (p -> p) -> Norm (Needle p) -> Norm (Needle p)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ p -> p -> p
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const p
a)
                 | p
ap -> p -> Bool
forall a. Ord a => a -> a -> Bool
<p
0        = (-a
1, b
forall v. AdditiveGroup v => v
zeroV, String -> (p -> p) -> Norm (Needle p) -> Norm (Needle p)
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"signum "String -> String -> String
forall a. [a] -> [a] -> [a]
++p -> String
forall r. RealFloat r => r -> String
showℝ p
a) ((p -> p) -> Norm (Needle p) -> Norm (Needle p))
-> (p -> p) -> Norm (Needle p) -> Norm (Needle p)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \p
_ -> -p
a)
                 | Bool
otherwise  = (a
0, b
forall v. AdditiveGroup v => v
zeroV, Norm p -> Norm (Needle p) -> Norm (Needle p)
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const (Norm p -> Norm (Needle p) -> Norm (Needle p))
-> Norm p -> Norm (Needle p) -> Norm (Needle p)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ [DualVector p] -> Norm p
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [DualVector p
1])
     )



-- VectorSpace instance is more problematic than you'd think: multiplication
-- requires the allowed-deviation backpropagators to be split as square
-- roots, but the square root of a nontrivial-vector-space metric requires
-- an eigenbasis transform, which we have not implemented yet.
-- 
-- instance (WithField s LinearManifold v, LocallyScalable s a, Floating s)
--       => VectorSpace (DfblFuncValue s a v) where
--   type Scalar (DfblFuncValue s a v) = DfblFuncValue s a (Scalar v)
--   (*^) = dfblFnValsCombine $ \μ v -> (μ*^v, lScl, \ε -> (ε ^* sqrt 2, ε ^* sqrt 2))
--       where lScl = linear $ uncurry (*^)


-- | Important special operator needed to compute intersection of 'Region's.
minDblfuncs ::  m s . (LocallyScalable s m, RealFloat'' s)
     => Differentiable s m s -> Differentiable s m s -> Differentiable s m s
minDblfuncs :: Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable m -> (s, Needle m +> Needle s, LinDevPropag m s)
f) (Differentiable m -> (s, Needle m +> Needle s, LinDevPropag m s)
g)
             = (m -> (s, Needle m +> Needle s, LinDevPropag m s))
-> Differentiable s m s
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((m -> (s, Needle m +> Needle s, LinDevPropag m s))
 -> Differentiable s m s)
-> (m -> (s, Needle m +> Needle s, LinDevPropag m s))
-> Differentiable s m s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearManifoldWitness s
-> ClosedScalarWitness s
-> m
-> (s, Needle m +> Needle s, LinDevPropag m s)
h LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness
 where h :: LinearManifoldWitness s -> ClosedScalarWitness s
             -> m -> (s, Needle m+>Needle s, LinDevPropag m s)
       h :: LinearManifoldWitness s
-> ClosedScalarWitness s
-> m
-> (s, Needle m +> Needle s, LinDevPropag m s)
h (LinearManifoldWitness s
LinearManifoldWitness) ClosedScalarWitness s
ClosedScalarWitness m
x
         | s
fx s -> s -> Bool
forall a. Ord a => a -> a -> Bool
< s
gx   = ( s
fx, LinearMap s (Needle m) s
Needle m +> Needle s
jf
                       , \Metric s
d -> Norm s -> Norm (Needle m)
devf Norm s
Metric s
d Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> Norm s -> Norm (Needle m)
devg Norm s
Metric s
d
                               Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> (Needle m +> s) -> Norm s -> Norm (Needle m)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap s (Needle m) s
Needle m +> s
δj
                                      ([DualVector s] -> Norm s
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [s -> s
forall a. Fractional a => a -> a
recip (s -> s) -> s -> s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s -> s
forall a. Fractional a => a -> a
recip(Norm s
Metric s
dNorm s -> s -> Scalar s
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$|s
1) s -> s -> s
forall a. Num a => a -> a -> a
+ s
gx s -> s -> s
forall a. Num a => a -> a -> a
- s
fx]) )
         | s
fx s -> s -> Bool
forall a. Ord a => a -> a -> Bool
> s
gx   = ( s
gx, LinearMap s (Needle m) s
Needle m +> Needle s
jg
                       , \Metric s
d -> Norm s -> Norm (Needle m)
devf Norm s
Metric s
d Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> Norm s -> Norm (Needle m)
devg Norm s
Metric s
d
                               Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> (Needle m +> s) -> Norm s -> Norm (Needle m)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap s (Needle m) s
Needle m +> s
δj
                                      ([DualVector s] -> Norm s
forall v. LSpace v => [DualVector v] -> Seminorm v
spanNorm [s -> s
forall a. Fractional a => a -> a
recip (s -> s) -> s -> s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s -> s
forall a. Fractional a => a -> a
recip(Norm s
Metric s
dNorm s -> s -> Scalar s
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$|s
1) s -> s -> s
forall a. Num a => a -> a -> a
+ s
fx s -> s -> s
forall a. Num a => a -> a -> a
- s
gx]) )
         | Bool
otherwise = ( s
fx, (LinearMap s (Needle m) s
jfLinearMap s (Needle m) s
-> LinearMap s (Needle m) s -> LinearMap s (Needle m) s
forall v. AdditiveGroup v => v -> v -> v
^+^LinearMap s (Needle m) s
jg)LinearMap s (Needle m) s -> s -> LinearMap s (Needle m) s
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/s
2
                       , \Metric s
d -> Norm s -> Norm (Needle m)
devf Norm s
Metric s
d Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> Norm s -> Norm (Needle m)
devg Norm s
Metric s
d
                               Norm (Needle m) -> Norm (Needle m) -> Norm (Needle m)
forall a. Semigroup a => a -> a -> a
<> (Needle m +> s) -> Norm s -> Norm (Needle m)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap s (Needle m) s
Needle m +> s
δj Norm s
Metric s
d )
        where (s
fx, LinearMap s (Needle m) s
jf, Norm s -> Norm (Needle m)
devf) = m -> (s, Needle m +> Needle s, LinDevPropag m s)
f m
x
              (s
gx, LinearMap s (Needle m) s
jg, Norm s -> Norm (Needle m)
devg) = m -> (s, Needle m +> Needle s, LinDevPropag m s)
g m
x
              δj :: LinearMap s (Needle m) s
δj = LinearMap s (Needle m) s
jf LinearMap s (Needle m) s
-> LinearMap s (Needle m) s -> LinearMap s (Needle m) s
forall v. AdditiveGroup v => v -> v -> v
^-^ LinearMap s (Needle m) s
jg


postEndo ::  c a b . (HasAgent c, Object c a, Object c b)
                        => c a a -> GenericAgent c b a -> GenericAgent c b a
postEndo :: c a a -> GenericAgent c b a -> GenericAgent c b a
postEndo = c a a -> GenericAgent c b a -> GenericAgent c b a
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> GenericAgent k a b -> GenericAgent k a c
genericAgentMap



genericisePreRegion ::  m s
    . ( RealFloat'' s, LocallyScalable s m, Manifold m
      , Atlas' m, Atlas' s, SimpleSpace (Needle m)
      )
                          => PreRegion s m -> PreRegion s m
genericisePreRegion :: PreRegion s m -> PreRegion s m
genericisePreRegion
 = (OpenManifold (Scalar (Needle (Interior m))) =>
 PreRegion s m -> PreRegion s m)
-> PreRegion s m -> PreRegion s m
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Scalar (Needle (Interior m))) => r) -> r
scalarIsOpenMfd @m ((OpenManifold (Needle (Interior m)) =>
 PreRegion s m -> PreRegion s m)
-> PreRegion s m -> PreRegion s m
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @m ((ProjectableBoundary (Needle (Interior m)) =>
 PreRegion s m -> PreRegion s m)
-> PreRegion s m -> PreRegion s m
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @m 
    ((ProjectableBoundary (Scalar (Needle (Interior m))) =>
 PreRegion s m -> PreRegion s m)
-> PreRegion s m -> PreRegion s m
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Scalar (Needle (Interior m))) => r) -> r
scalarBoundaryIsTriviallyProjectible @m (
      case ( TensorSpace s => LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @s, Num' s => ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness @s, Semimanifold m => SemimanifoldWitness m
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @m ) of
    (LinearManifoldWitness s
LinearManifoldWitness, ClosedScalarWitness s
ClosedScalarWitness, SemimanifoldWitness m
SemimanifoldWitness)
          -> \case
          PreRegion s m
GlobalRegion -> Differentiable s m s -> PreRegion s m
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s m s -> PreRegion s m)
-> Differentiable s m s -> PreRegion s m
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s -> Differentiable s m s
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const s
1
          RealSubray S⁰_ ℝ
PositiveHalfSphere s
xl -> s -> PreRegion s s
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom' s
xl
          RealSubray S⁰_ ℝ
NegativeHalfSphere s
xr -> s -> PreRegion s s
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo' s
xr
          PreRegion s m
r -> PreRegion s m
r
  ))))

-- | Set-intersection of regions would not be guaranteed to yield a connected result
--   or even have the reference point of one region contained in the other. This
--   combinator assumes (unchecked) that the references are in a connected
--   sub-intersection, which is used as the result.
unsafePreRegionIntersect ::  a s
    . ( RealFloat'' s, LocallyScalable s a
      , Manifold a, Atlas' a, Atlas' s
      , SimpleSpace (Needle a) )
                  => PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect :: PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s a
GlobalRegion PreRegion s a
r = PreRegion s a
r
unsafePreRegionIntersect PreRegion s a
r PreRegion s a
GlobalRegion = PreRegion s a
r
unsafePreRegionIntersect (RealSubray S⁰_ ℝ
PositiveHalfSphere s
xl) (RealSubray S⁰_ ℝ
PositiveHalfSphere s
xl')
                 = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
PositiveHalfSphere (s -> PreRegion s a) -> s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s -> s -> s
forall a. Ord a => a -> a -> a
max s
xl s
xl'
unsafePreRegionIntersect (RealSubray S⁰_ ℝ
NegativeHalfSphere s
xr) (RealSubray S⁰_ ℝ
NegativeHalfSphere s
xr')
                 = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
NegativeHalfSphere (s -> PreRegion s a) -> s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s -> s -> s
forall a. Ord a => a -> a -> a
min s
xr s
xr'
unsafePreRegionIntersect (PreRegion Differentiable s a s
ra) (PreRegion Differentiable s a s
rb) = case TensorSpace s => ScalarSpaceWitness s
forall v. TensorSpace v => ScalarSpaceWitness v
scalarSpaceWitness @s of
      ScalarSpaceWitness s
ScalarSpaceWitness -> Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
-> Differentiable s a s -> Differentiable s a s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs Differentiable s a s
ra Differentiable s a s
rb
unsafePreRegionIntersect PreRegion s a
ra PreRegion s a
rb
   = PreRegion s a -> PreRegion s a -> PreRegion s a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect (PreRegion s a -> PreRegion s a
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s a
ra) (PreRegion s a -> PreRegion s a
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s a
rb)

-- | Cartesian product of two regions.
regionProd ::  a b s . ( RealDimension s, ObjectPair (Differentiable s) a b )
                  => Region s a -> Region s b -> Region s (a,b)
regionProd :: Region s a -> Region s b -> Region s (a, b)
regionProd (Region a
a₀ PreRegion s a
ra) (Region b
b₀ PreRegion s b
rb) = (a, b) -> PreRegion s (a, b) -> Region s (a, b)
forall s m. m -> PreRegion s m -> Region s m
Region (a
a₀,b
b₀) (PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
forall a b s.
(RealDimension s, ObjectPair (Differentiable s) a b) =>
PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
preRegionProd PreRegion s a
ra PreRegion s b
rb)

-- | Cartesian product of two pre-regions.
preRegionProd ::  a b s . ( RealDimension s, ObjectPair (Differentiable s) a b )
                  => PreRegion s a -> PreRegion s b -> PreRegion s (a,b)
preRegionProd :: PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
preRegionProd = ((LinearSpace (Needle (Boundary b)),
  Scalar (Needle (Boundary b)) ~ Scalar (Needle (Interior b))) =>
 PreRegion s a -> PreRegion s b -> PreRegion s (a, b))
-> PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
forall m r.
SemimanifoldWithBoundary m =>
((LinearSpace (Needle (Boundary m)),
  Scalar (Needle (Boundary m)) ~ Scalar (Needle (Interior m))) =>
 r)
-> r
boundaryHasSameScalar @b
              ( case ( Semimanifold a => SemimanifoldWitness a
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @a, Semimanifold b => SemimanifoldWitness b
forall x. Semimanifold x => SemimanifoldWitness x
semimanifoldWitness @b
                     , TensorSpace s => LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @s, Num' s => ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness @s
                     , SemimanifoldWithBoundary b => SmfdWBoundWitness b
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @b ) of
     ( SemimanifoldWitness a
SemimanifoldWitness, SemimanifoldWitness b
SemimanifoldWitness
      ,LinearManifoldWitness s
LinearManifoldWitness, ClosedScalarWitness s
ClosedScalarWitness
      ,SmfdWBoundWitness b
OpenManifoldWitness ) -> \case
                      PreRegion s a
GlobalRegion -> \case
                          PreRegion s b
GlobalRegion -> PreRegion s (a, b)
forall s m. PreRegion s m
GlobalRegion
                          (PreRegion Differentiable s b s
rb) -> Differentiable s (a, b) s -> PreRegion s (a, b)
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s (a, b) s -> PreRegion s (a, b))
-> Differentiable s (a, b) s -> PreRegion s (a, b)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s b s
rb Differentiable s b s
-> Differentiable s (a, b) b -> Differentiable s (a, b) s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s (a, b) b
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd
                      (PreRegion Differentiable s a s
ra) -> \case
                          PreRegion s b
GlobalRegion -> Differentiable s (a, b) s -> PreRegion s (a, b)
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s (a, b) s -> PreRegion s (a, b))
-> Differentiable s (a, b) s -> PreRegion s (a, b)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
ra Differentiable s a s
-> Differentiable s (a, b) a -> Differentiable s (a, b) s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s (a, b) a
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst
                          (PreRegion Differentiable s b s
rb) -> Differentiable s (a, b) s -> PreRegion s (a, b)
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s (a, b) s -> PreRegion s (a, b))
-> Differentiable s (a, b) s -> PreRegion s (a, b)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s (a, b) s
-> Differentiable s (a, b) s -> Differentiable s (a, b) s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable s a s
raDifferentiable s a s
-> Differentiable s (a, b) a -> Differentiable s (a, b) s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.Differentiable s (a, b) a
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst) (Differentiable s b s
rbDifferentiable s b s
-> Differentiable s (a, b) b -> Differentiable s (a, b) s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.Differentiable s (a, b) b
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd)
                      PreRegion s a
ra -> \PreRegion s b
rb -> PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
forall a b s.
(RealDimension s, ObjectPair (Differentiable s) a b) =>
PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
preRegionProd (PreRegion s a -> PreRegion s a
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s a
ra)
                                                 (PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
rb)
   )


positivePreRegion, negativePreRegion :: (RealDimension s) => PreRegion s s
positivePreRegion :: PreRegion s s
positivePreRegion = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
PositiveHalfSphere s
0
negativePreRegion :: PreRegion s s
negativePreRegion = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
NegativeHalfSphere s
0


positivePreRegion', negativePreRegion' ::  s . (RealDimension s) => PreRegion s s
positivePreRegion' :: PreRegion s s
positivePreRegion' = Differentiable s s s -> PreRegion s s
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s s s -> PreRegion s s)
-> ((s
     -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
         Norm (Needle s) -> Norm (Needle s)))
    -> Differentiable s s s)
-> (s
    -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
        Norm (Needle s) -> Norm (Needle s)))
-> PreRegion s s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (s
 -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
     Norm (Needle s) -> Norm (Needle s)))
-> Differentiable s s s
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable
                       ((s
  -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
      Norm (Needle s) -> Norm (Needle s)))
 -> PreRegion s s)
-> (s
    -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
        Norm (Needle s) -> Norm (Needle s)))
-> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearManifoldWitness s
-> ClosedScalarWitness s
-> s
-> (s, Needle s +> Needle s, Norm (Needle s) -> Norm (Needle s))
prr LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness
 where prr :: LinearManifoldWitness s -> ClosedScalarWitness s
           -> s -> (s, Needle s+>Needle s, LinDevPropag s s)
       prr :: LinearManifoldWitness s
-> ClosedScalarWitness s
-> s
-> (s, Needle s +> Needle s, Norm (Needle s) -> Norm (Needle s))
prr (LinearManifoldWitness s
LinearManifoldWitness) ClosedScalarWitness s
ClosedScalarWitness
           s
x = ( s
1 s -> s -> s
forall a. Num a => a -> a -> a
- s
1s -> s -> s
forall a. Fractional a => a -> a -> a
/s
xp1
               , (s
1s -> s -> s
forall a. Fractional a => a -> a -> a
/s
xp1²) Scalar (LinearMap s s s) -> LinearMap s s s -> LinearMap s s s
forall v. VectorSpace v => Scalar v -> v -> v
*^ LinearMap s s s
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
               , String -> (s -> s) -> Norm (Needle s) -> Norm (Needle s)
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"positivePreRegion@"String -> String -> String
forall a. [a] -> [a] -> [a]
++s -> String
forall r. RealFloat r => r -> String
showℝ s
x) s -> s
δ )
                 -- ε = (1 − 1/(1+x)) + (-δ · 1/(x+1)²) − (1 − 1/(1+x−δ))
                 --   = 1/(1+x−δ) − 1/(1+x) − δ · 1/(x+1)²
                 --
                 -- ε·(1+x−δ) = 1 − (1+x−δ)/(1+x) − δ·(1+x-δ)/(x+1)²
                 -- ε·(1+x) − ε·δ = 1 − 1/(1+x) − x/(1+x) + δ/(1+x)
                 --                               − δ/(x+1)² − δ⋅x/(x+1)² + δ²/(x+1)²
                 --               = 1 − (1+x)/(1+x) + ((x+1) − 1)⋅δ/(x+1)²
                 --                               − δ⋅x/(x+1)² + δ²/(x+1)²
                 --               = 1 − 1 + x⋅δ/(x+1)² − δ⋅x/(x+1)² + δ²/(x+1)²
                 --               = δ²/(x+1)²
                 --
                 -- ε·(x+1)⋅(x+1)² − ε·δ⋅(x+1)² = δ²
                 -- 0 = δ² + ε·(x+1)²·δ − ε·(x+1)³
                 --
                 -- δ = let μ = ε·(x+1)²/2          -- Exact form
                 --     in -μ + √(μ² + ε·(x+1)³)    -- (not overflow save)
                 --
                 -- Safe approximation for large x:
                 -- ε = 1/(1+x−δ) − 1/(1+x) − δ · 1/(x+1)²
                 --   ≤ 1/(1+x−δ) − 1/(1+x)
                 -- 
                 -- ε⋅(1+x−δ)⋅(1+x) ≤ 1+x − (1+x−δ) = δ
                 -- 
                 -- δ ≥ ε + ε⋅x − ε⋅δ + ε⋅x + ε⋅x² − ε⋅δ⋅x
                 --
                 -- δ⋅(1 + ε + ε⋅x) ≥ ε + ε⋅x + ε⋅x + ε⋅x² ≥ ε⋅x²
                 --
                 -- δ ≥ ε⋅x²/(1 + ε + ε⋅x)
                 --   = ε⋅x/(1/x + ε/x + ε)
        where δ :: s -> s
δ s
ε | s
xs -> s -> Bool
forall a. Ord a => a -> a -> Bool
<s
100      = let μ :: s
μ = s
εs -> s -> s
forall a. Num a => a -> a -> a
*s
xp1²s -> s -> s
forall a. Fractional a => a -> a -> a
/s
2
                                 in s -> s
forall a. Floating a => a -> a
sqrt(s
μs -> Int -> s
forall a. Num a => a -> Int -> a
^Int
2 s -> s -> s
forall a. Num a => a -> a -> a
+ s
ε s -> s -> s
forall a. Num a => a -> a -> a
* s
xp1² s -> s -> s
forall a. Num a => a -> a -> a
* s
xp1) s -> s -> s
forall a. Num a => a -> a -> a
- s
μ
                  | Bool
otherwise  = s
ε s -> s -> s
forall a. Num a => a -> a -> a
* s
x s -> s -> s
forall a. Fractional a => a -> a -> a
/ ((s
1s -> s -> s
forall a. Num a => a -> a -> a
+s
ε)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
x s -> s -> s
forall a. Num a => a -> a -> a
+ s
ε)
              xp1 :: s
xp1 = (s
xs -> s -> s
forall a. Num a => a -> a -> a
+s
1)
              xp1² :: s
xp1² = s
xp1 s -> Int -> s
forall a. Num a => a -> Int -> a
^ Int
2
negativePreRegion' :: PreRegion s s
negativePreRegion' = LinearManifoldWitness s -> ClosedScalarWitness s -> PreRegion s s
npr (LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness s)
                         (ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s)
 where npr :: LinearManifoldWitness s -> ClosedScalarWitness s -> PreRegion s s
npr (LinearManifoldWitness s
LinearManifoldWitness)
           (ClosedScalarWitness :: ClosedScalarWitness s)
                  = Differentiable s s s -> PreRegion s s
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s s s -> PreRegion s s)
-> Differentiable s s s -> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s s s
ppr Differentiable s s s
-> Differentiable s s s -> Differentiable s s s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s s s
Differentiable (Scalar s) s s
ngt
        where PreRegion Differentiable s s s
ppr = PreRegion s s
forall s. RealDimension s => PreRegion s s
positivePreRegion' :: PreRegion s s
              ngt :: Differentiable (Scalar s) s s
ngt = (s +> s) -> Differentiable (Scalar s) s s
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo ((s +> s) -> Differentiable (Scalar s) s s)
-> (s +> s) -> Differentiable (Scalar s) s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (s +> s) -> s +> s
forall v. AdditiveGroup v => v -> v
negateV s +> s
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id

preRegionToInfFrom, preRegionFromMinInfTo :: RealDimension s => s -> PreRegion s s
preRegionToInfFrom :: s -> PreRegion s s
preRegionToInfFrom = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
PositiveHalfSphere
preRegionFromMinInfTo :: s -> PreRegion s s
preRegionFromMinInfTo = S⁰_ ℝ -> s -> PreRegion s s
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
forall r. S⁰_ r
NegativeHalfSphere

preRegionToInfFrom', preRegionFromMinInfTo' ::  s . RealDimension s => s -> PreRegion s s
preRegionToInfFrom' :: s -> PreRegion s s
preRegionToInfFrom' = LinearManifoldWitness s
-> ClosedScalarWitness s -> s -> PreRegion s s
prif (LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness s)
                           (ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s)
 where prif :: LinearManifoldWitness s
-> ClosedScalarWitness s -> s -> PreRegion s s
prif (LinearManifoldWitness s
LinearManifoldWitness)
            (ClosedScalarWitness :: ClosedScalarWitness s)
            s
xs = Differentiable s s s -> PreRegion s s
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s s s -> PreRegion s s)
-> Differentiable s s s -> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s s s
ppr Differentiable s s s
-> Differentiable s s s -> Differentiable s s s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s s s
trl
        where PreRegion Differentiable s s s
ppr = PreRegion s s
forall s. RealDimension s => PreRegion s s
positivePreRegion' :: PreRegion s s
              trl :: Differentiable s s s
trl = s -> (s +> Needle s) -> Differentiable s s s
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo (-s
xs) s +> Needle s
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
preRegionFromMinInfTo' :: s -> PreRegion s s
preRegionFromMinInfTo' = LinearManifoldWitness s
-> ClosedScalarWitness s -> s -> PreRegion s s
prif (LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness s)
                           (ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness :: ClosedScalarWitness s)
 where prif :: LinearManifoldWitness s
-> ClosedScalarWitness s -> s -> PreRegion s s
prif (LinearManifoldWitness s
LinearManifoldWitness)
            (ClosedScalarWitness :: ClosedScalarWitness s)
            s
xe = Differentiable s s s -> PreRegion s s
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s s s -> PreRegion s s)
-> Differentiable s s s -> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s s s
ppr Differentiable s s s
-> Differentiable s s s -> Differentiable s s s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s s s
flp
        where PreRegion Differentiable s s s
ppr = PreRegion s s
forall s. RealDimension s => PreRegion s s
positivePreRegion' :: PreRegion s s
              flp :: Differentiable s s s
flp = s -> (s +> Needle s) -> Differentiable s s s
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo s
xe (LinearMap s s s -> LinearMap s s s
forall v. AdditiveGroup v => v -> v
negateV LinearMap s s s
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)

intervalPreRegion ::  s . RealDimension s => (s,s) -> PreRegion s s
intervalPreRegion :: (s, s) -> PreRegion s s
intervalPreRegion (s
lb,s
rb) = Differentiable s s s -> PreRegion s s
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s s s -> PreRegion s s)
-> ((s
     -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
         Norm (Needle s) -> Norm (Needle s)))
    -> Differentiable s s s)
-> (s
    -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
        Norm (Needle s) -> Norm (Needle s)))
-> PreRegion s s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (s
 -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
     Norm (Needle s) -> Norm (Needle s)))
-> Differentiable s s s
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable
                             ((s
  -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
      Norm (Needle s) -> Norm (Needle s)))
 -> PreRegion s s)
-> (s
    -> (s, LinearMap (Scalar s) (Needle s) (Needle s),
        Norm (Needle s) -> Norm (Needle s)))
-> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearManifoldWitness s
-> ClosedScalarWitness s
-> s
-> (s, Needle s +> Needle s, Norm (Needle s) -> Norm (Needle s))
prr LinearManifoldWitness s
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness ClosedScalarWitness s
forall s. Num' s => ClosedScalarWitness s
closedScalarWitness
 where m :: s
m = s
lb s -> s -> s
forall a. Num a => a -> a -> a
+ s
radius; radius :: s
radius = (s
rb s -> s -> s
forall a. Num a => a -> a -> a
- s
lb)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
2
       prr :: LinearManifoldWitness s -> ClosedScalarWitness s
                -> s -> (s, Needle s+>Needle s, LinDevPropag s s)
       prr :: LinearManifoldWitness s
-> ClosedScalarWitness s
-> s
-> (s, Needle s +> Needle s, Norm (Needle s) -> Norm (Needle s))
prr (LinearManifoldWitness s
LinearManifoldWitness) ClosedScalarWitness s
ClosedScalarWitness
           s
x = ( s
1 s -> s -> s
forall a. Num a => a -> a -> a
- ((s
xs -> s -> s
forall a. Num a => a -> a -> a
-s
m)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
radius)s -> Int -> s
forall a. Num a => a -> Int -> a
^Int
2
               , (s
2s -> s -> s
forall a. Num a => a -> a -> a
*(s
ms -> s -> s
forall a. Num a => a -> a -> a
-s
x)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
radiuss -> Int -> s
forall a. Num a => a -> Int -> a
^Int
2) Scalar (LinearMap s s s) -> LinearMap s s s -> LinearMap s s s
forall v. VectorSpace v => Scalar v -> v -> v
*^ LinearMap s s s
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
               , String -> (s -> s) -> Norm (Needle s) -> Norm (Needle s)
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"intervalPreRegion@"String -> String -> String
forall a. [a] -> [a] -> [a]
++s -> String
forall r. RealFloat r => r -> String
showℝ s
x) ((s -> s) -> Norm (Needle s) -> Norm (Needle s))
-> (s -> s) -> Norm (Needle s) -> Norm (Needle s)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (s -> s -> s
forall a. Num a => a -> a -> a
*s
radius) (s -> s) -> (s -> s) -> s -> s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. s -> s
forall a. Floating a => a -> a
sqrt )











instance (RealDimension s) => Category (RWDiffable s) where
  type Object (RWDiffable s) o = Object (Differentiable s) o
  id :: RWDiffable s a a
id = RWDiffable s a a
forall a. Object (RWDiffable s) a => RWDiffable s a a
rwdid
   where rwdid ::  a . Object (RWDiffable s) a => RWDiffable s a a
         rwdid :: RWDiffable s a a
rwdid = (a -> (PreRegion s a, Maybe (Differentiable s a a)))
-> RWDiffable s a a
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((a -> (PreRegion s a, Maybe (Differentiable s a a)))
 -> RWDiffable s a a)
-> (a -> (PreRegion s a, Maybe (Differentiable s a a)))
-> RWDiffable s a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \a
x -> (PreRegion s a
forall s m. PreRegion s m
GlobalRegion, Differentiable s a a -> Maybe (Differentiable s a a)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Differentiable s a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
  RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b c))
f . :: RWDiffable s b c -> RWDiffable s a b -> RWDiffable s a c
. RWDiffable a -> (PreRegion s a, Maybe (Differentiable s a b))
g = (a -> (PreRegion s a, Maybe (Differentiable s a c)))
-> RWDiffable s a c
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable a -> (PreRegion s a, Maybe (Differentiable s a c))
h where
   h :: a -> (PreRegion s a, Maybe (Differentiable s a c))
h a
x₀ = case a -> (PreRegion s a, Maybe (Differentiable s a b))
g a
x₀ of
           ( PreRegion s a
rg, Just gr' :: Differentiable s a b
gr'@(AffinDiffable DiffableEndoProof a b
IsDiffableEndo Affine s a b
gr) )
            -> let (b
y₀, LinearMap s (Needle a) (Needle a)
ϕg) = Affine s a b -> a -> (b, LinearMap s (Needle a) (Needle b))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine s a b
gr a
x₀
               in case b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
y₀ of
                   (PreRegion s b
GlobalRegion, Just (AffinDiffable DiffableEndoProof b c
fe Affine s b c
fr))
                         -> (PreRegion s a
rg, Differentiable s b c -> Maybe (Differentiable s b c)
forall a. a -> Maybe a
Just (DiffableEndoProof b c -> Affine s b c -> Differentiable s b c
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof b c
fe (Affine s b c
frAffine s b c -> Affine s a b -> Affine s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
.Affine s a b
gr)))
                   (PreRegion s b
GlobalRegion, Maybe (Differentiable s b c)
fhr)
                         -> (PreRegion s a
rg, (Differentiable s a c -> Differentiable s a c)
-> Maybe (Differentiable s b c) -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr') Maybe (Differentiable s b c)
fhr)
                   (RealSubray S⁰_ ℝ
diry s
yl, Maybe (Differentiable s b c)
fhr)
                      -> let hhr :: Maybe (Differentiable s s c)
hhr = (Differentiable s s c -> Differentiable s s c)
-> Maybe (Differentiable s b c) -> Maybe (Differentiable s s c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr') Maybe (Differentiable s b c)
fhr
                         in case LinearMap s s s
LinearMap s (Needle a) (Needle a)
ϕg LinearMap s s s -> s -> s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ s
1 of
                              s
y' | s
y's -> s -> Bool
forall a. Ord a => a -> a -> Bool
>s
0 -> ( PreRegion s a -> PreRegion s a -> PreRegion s a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s a
rg
                                                  (PreRegion a a -> PreRegion s s) -> PreRegion a a -> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ S⁰_ ℝ -> a -> PreRegion a a
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray S⁰_ ℝ
diry (a
x₀ a -> a -> a
forall a. Num a => a -> a -> a
+ (s
yls -> s -> s
forall a. Num a => a -> a -> a
-s
b
y₀)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
y')
                                   -- y'⋅(xl−x₀) + y₀ ≝ yl
                                           , Maybe (Differentiable s s c)
hhr )
                                 | s
y's -> s -> Bool
forall a. Ord a => a -> a -> Bool
<s
0 -> ( PreRegion s a -> PreRegion s a -> PreRegion s a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s a
rg
                                                  (PreRegion a a -> PreRegion s s) -> PreRegion a a -> PreRegion s s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ S⁰_ ℝ -> a -> PreRegion a a
forall s. Num' s => S⁰_ ℝ -> s -> PreRegion s s
RealSubray (S⁰_ ℝ -> S⁰_ ℝ
otherHalfSphere S⁰_ ℝ
diry)
                                                               (a
x₀ a -> a -> a
forall a. Num a => a -> a -> a
+ (s
yls -> s -> s
forall a. Num a => a -> a -> a
-s
b
y₀)s -> s -> s
forall a. Fractional a => a -> a -> a
/s
y')
                                           , Maybe (Differentiable s s c)
hhr )
                                 | Bool
otherwise -> (PreRegion s a
rg, Maybe (Differentiable s s c)
hhr)
                   (PreRegion Differentiable s b s
ry, Maybe (Differentiable s b c)
fhr)
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr', (Differentiable s a c -> Differentiable s a c)
-> Maybe (Differentiable s b c) -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap (Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr') Maybe (Differentiable s b c)
fhr )
           ( PreRegion s a
rg, Just gr' :: Differentiable s a b
gr'@(AffinDiffable DiffableEndoProof a b
_ Affine s a b
gr) )
            -> String -> (PreRegion s a, Maybe (Differentiable s a c))
forall a. HasCallStack => String -> a
error String
"( rg, Just gr'@(AffinDiffable gr) )"
           (PreRegion s a
GlobalRegion, Just gr :: Differentiable s a b
gr@(Differentiable a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd))
            -> let (b
y₀,LinearMap s (Needle a) (Needle b)
_,LinDevPropag a b
_) = a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd a
x₀
               in case b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
y₀ of
                   (PreRegion s b
GlobalRegion, Maybe (Differentiable s b c)
Nothing)
                         -> (PreRegion s a
forall s m. PreRegion s m
GlobalRegion, Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                   (PreRegion s b
GlobalRegion, Just Differentiable s b c
fr)
                         -> (PreRegion s a
forall s m. PreRegion s m
GlobalRegion, Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr))
                   (PreRegion s b
r, Maybe (Differentiable s b c)
Nothing) | PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
r
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr, Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere )
                   (PreRegion s b
r, (Just Differentiable s b c
fr)) | PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
r
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr, Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) )
           (rg :: PreRegion s a
rg@(RealSubray S⁰_ ℝ
_ s
_), Just gr :: Differentiable s a b
gr@(Differentiable a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd))
            -> let (b
y₀,LinearMap s s (Needle b)
_,Norm (Needle b) -> Norm s
_) = a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd a
x₀
               in case b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
y₀ of
                   (PreRegion s b
GlobalRegion, Maybe (Differentiable s b c)
Nothing)
                         -> (PreRegion s a
rg, Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                   (PreRegion s b
GlobalRegion, Just Differentiable s b c
fr)
                         -> (PreRegion s a
rg, Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr))
                   (PreRegion s b
rf, Maybe (Differentiable s b c)
Nothing)
                     | PreRegion Differentiable s a s
rx <- PreRegion s a -> PreRegion s a
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s a
rg
                     , PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
rf
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
-> Differentiable s a s -> Differentiable s a s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) Differentiable s a s
rx
                            , Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere )
                   (PreRegion s b
rf, Just Differentiable s b c
fr)
                     | PreRegion Differentiable s a s
rx <- PreRegion s a -> PreRegion s a
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s a
rg
                     , PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
rf
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
-> Differentiable s a s -> Differentiable s a s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) Differentiable s a s
rx
                            , Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) )
           (PreRegion Differentiable s a s
rx, Just gr :: Differentiable s a b
gr@(Differentiable a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd))
            -> let (b
y₀,LinearMap s (Needle a) (Needle b)
_,LinDevPropag a b
_) = a -> (b, Needle a +> Needle b, LinDevPropag a b)
grd a
x₀
               in case b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
y₀ of
                   (PreRegion s b
GlobalRegion, Maybe (Differentiable s b c)
Nothing)
                         -> (Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion Differentiable s a s
rx, Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                   (PreRegion s b
GlobalRegion, Just Differentiable s b c
fr)
                         -> (Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion Differentiable s a s
rx, Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr))
                   (PreRegion s b
r, Maybe (Differentiable s b c)
Nothing) | PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
r
                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
-> Differentiable s a s -> Differentiable s a s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) Differentiable s a s
rx
                            , Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere )
                   (PreRegion s b
r, Just Differentiable s b c
fr) | PreRegion Differentiable s b s
ry <- PreRegion s b -> PreRegion s b
forall m s.
(RealFloat'' s, LocallyScalable s m, Manifold m, Atlas' m,
 Atlas' s, SimpleSpace (Needle m)) =>
PreRegion s m -> PreRegion s m
genericisePreRegion PreRegion s b
r

                         -> ( Differentiable s a s -> PreRegion s a
forall s m. Differentiable s m s -> PreRegion s m
PreRegion (Differentiable s a s -> PreRegion s a)
-> Differentiable s a s -> PreRegion s a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a s
-> Differentiable s a s -> Differentiable s a s
forall m s.
(LocallyScalable s m, RealFloat'' s) =>
Differentiable s m s
-> Differentiable s m s -> Differentiable s m s
minDblfuncs (Differentiable s b s
ry Differentiable s b s
-> Differentiable s a b -> Differentiable s a s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) Differentiable s a s
rx
                            , Differentiable s a c -> Maybe (Differentiable s a c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s b c
fr Differentiable s b c
-> Differentiable s a b -> Differentiable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. Differentiable s a b
gr) )
           (PreRegion s a
r, Maybe (Differentiable s a b)
Nothing)
            -> (PreRegion s a
r, Maybe (Differentiable s a c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
          


globalDiffable' :: Differentiable s a b -> RWDiffable s a b
globalDiffable' :: Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s a b
f = (a -> (PreRegion s a, Maybe (Differentiable s a b)))
-> RWDiffable s a b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((a -> (PreRegion s a, Maybe (Differentiable s a b)))
 -> RWDiffable s a b)
-> (a -> (PreRegion s a, Maybe (Differentiable s a b)))
-> RWDiffable s a b
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (PreRegion s a, Maybe (Differentiable s a b))
-> a -> (PreRegion s a, Maybe (Differentiable s a b))
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const (PreRegion s a
forall s m. PreRegion s m
GlobalRegion, Differentiable s a b -> Maybe (Differentiable s a b)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Differentiable s a b
f)



instance (RealDimension s) => EnhancedCat (RWDiffable s) (Differentiable s) where
  arr :: Differentiable s b c -> RWDiffable s b c
arr = Differentiable s b c -> RWDiffable s b c
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable'
                
instance (RealDimension s) => Cartesian (RWDiffable s) where
  type UnitObject (RWDiffable s) = ZeroDim s
  swap :: RWDiffable s (a, b) (b, a)
swap = Differentiable s (a, b) (b, a) -> RWDiffable s (a, b) (b, a)
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s (a, b) (b, a)
forall (k :: * -> * -> *) a b.
(Cartesian k, ObjectPair k a b, ObjectPair k b a) =>
k (a, b) (b, a)
swap
  attachUnit :: RWDiffable s a (a, unit)
attachUnit = Differentiable s a (a, unit) -> RWDiffable s a (a, unit)
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s a (a, unit)
forall (k :: * -> * -> *) unit a.
(Cartesian k, unit ~ UnitObject k, ObjectPair k a unit) =>
k a (a, unit)
attachUnit
  detachUnit :: RWDiffable s (a, unit) a
detachUnit = Differentiable s (a, unit) a -> RWDiffable s (a, unit) a
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s (a, unit) a
forall (k :: * -> * -> *) unit a.
(Cartesian k, unit ~ UnitObject k, ObjectPair k a unit) =>
k (a, unit) a
detachUnit
  regroup :: RWDiffable s (a, (b, c)) ((a, b), c)
regroup = Differentiable s (a, (b, c)) ((a, b), c)
-> RWDiffable s (a, (b, c)) ((a, b), c)
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s (a, (b, c)) ((a, b), c)
forall (k :: * -> * -> *) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k (a, (b, c)) ((a, b), c)
regroup
  regroup' :: RWDiffable s ((a, b), c) (a, (b, c))
regroup' = Differentiable s ((a, b), c) (a, (b, c))
-> RWDiffable s ((a, b), c) (a, (b, c))
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s ((a, b), c) (a, (b, c))
forall (k :: * -> * -> *) a b c.
(Cartesian k, ObjectPair k a b, ObjectPair k b c,
 ObjectPair k a (b, c), ObjectPair k (a, b) c) =>
k ((a, b), c) (a, (b, c))
regroup'
  
instance (RealDimension s) => Morphism (RWDiffable s) where
  RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b c))
f *** :: RWDiffable s b c
-> RWDiffable s b' c' -> RWDiffable s (b, b') (c, c')
*** RWDiffable b' -> (PreRegion s b', Maybe (Differentiable s b' c'))
g = ((b, b')
 -> (PreRegion s (b, b'), Maybe (Differentiable s (b, b') (c, c'))))
-> RWDiffable s (b, b') (c, c')
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable (b, b')
-> (PreRegion s (b, b'), Maybe (Differentiable s (b, b') (c, c')))
h
   where h :: (b, b')
-> (PreRegion s (b, b'), Maybe (Differentiable s (b, b') (c, c')))
h (b
x,b'
y) = (PreRegion s b -> PreRegion s b' -> PreRegion s (b, b')
forall a b s.
(RealDimension s, ObjectPair (Differentiable s) a b) =>
PreRegion s a -> PreRegion s b -> PreRegion s (a, b)
preRegionProd PreRegion s b
rfx PreRegion s b'
rgy, (Differentiable s b c
 -> Differentiable s b' c' -> Differentiable s (b, b') (c, c'))
-> Maybe (Differentiable s b c)
-> Maybe (Differentiable s b' c')
-> Maybe (Differentiable s (b, b') (c, c'))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 Differentiable s b c
-> Differentiable s b' c' -> Differentiable s (b, b') (c, c')
forall (a :: * -> * -> *) b b' c c'.
(Morphism a, ObjectPair a b b', ObjectPair a c c') =>
a b c -> a b' c' -> a (b, b') (c, c')
(***) Maybe (Differentiable s b c)
dff Maybe (Differentiable s b' c')
dfg)
          where (PreRegion s b
rfx, Maybe (Differentiable s b c)
dff) = b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
x
                (PreRegion s b'
rgy, Maybe (Differentiable s b' c')
dfg) = b' -> (PreRegion s b', Maybe (Differentiable s b' c'))
g b'
y

instance (RealDimension s) => PreArrow (RWDiffable s) where
  RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b c))
f &&& :: RWDiffable s b c -> RWDiffable s b c' -> RWDiffable s b (c, c')
&&& RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b c'))
g = (b -> (PreRegion s b, Maybe (Differentiable s b (c, c'))))
-> RWDiffable s b (c, c')
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b (c, c')))
h
   where h :: b -> (PreRegion s b, Maybe (Differentiable s b (c, c')))
h b
x = (PreRegion s b -> PreRegion s b -> PreRegion s b
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s b
rfx PreRegion s b
rgx, (Differentiable s b c
 -> Differentiable s b c' -> Differentiable s b (c, c'))
-> Maybe (Differentiable s b c)
-> Maybe (Differentiable s b c')
-> Maybe (Differentiable s b (c, c'))
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 Differentiable s b c
-> Differentiable s b c' -> Differentiable s b (c, c')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
(&&&) Maybe (Differentiable s b c)
dff Maybe (Differentiable s b c')
dfg)
          where (PreRegion s b
rfx, Maybe (Differentiable s b c)
dff) = b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
x
                (PreRegion s b
rgx, Maybe (Differentiable s b c')
dfg) = b -> (PreRegion s b, Maybe (Differentiable s b c'))
g b
x
  terminal :: RWDiffable s b (UnitObject (RWDiffable s))
terminal = Differentiable s b (ZeroDim s) -> RWDiffable s b (ZeroDim s)
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s b (ZeroDim s)
forall (a :: * -> * -> *) b.
(PreArrow a, Object a b) =>
a b (UnitObject a)
terminal
  fst :: RWDiffable s (x, y) x
fst = Differentiable s (x, y) x -> RWDiffable s (x, y) x
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s (x, y) x
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst
  snd :: RWDiffable s (x, y) y
snd = Differentiable s (x, y) y -> RWDiffable s (x, y) y
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' Differentiable s (x, y) y
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd


instance (RealDimension s) => WellPointed (RWDiffable s) where
  unit :: CatTagged (RWDiffable s) (UnitObject (RWDiffable s))
unit = ZeroDim s
-> Tagged (RWDiffable s (ZeroDim s) (ZeroDim s)) (ZeroDim s)
forall k (s :: k) b. b -> Tagged s b
Tagged ZeroDim s
forall s. ZeroDim s
Origin
  globalElement :: x -> RWDiffable s (UnitObject (RWDiffable s)) x
globalElement x
x = (ZeroDim s
 -> (PreRegion s (ZeroDim s),
     Maybe (Differentiable s (ZeroDim s) x)))
-> RWDiffable s (ZeroDim s) x
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((ZeroDim s
  -> (PreRegion s (ZeroDim s),
      Maybe (Differentiable s (ZeroDim s) x)))
 -> RWDiffable s (ZeroDim s) x)
-> (ZeroDim s
    -> (PreRegion s (ZeroDim s),
        Maybe (Differentiable s (ZeroDim s) x)))
-> RWDiffable s (ZeroDim s) x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \ZeroDim s
Origin -> (PreRegion s (ZeroDim s)
forall s m. PreRegion s m
GlobalRegion, Differentiable s (ZeroDim s) x
-> Maybe (Differentiable s (ZeroDim s) x)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (x -> Differentiable s (UnitObject (Differentiable s)) x
forall (a :: * -> * -> *) x.
(WellPointed a, ObjectPoint a x) =>
x -> a (UnitObject a) x
globalElement x
x))
  const :: x -> RWDiffable s b x
const x
x = (b -> (PreRegion s b, Maybe (Differentiable s b x)))
-> RWDiffable s b x
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((b -> (PreRegion s b, Maybe (Differentiable s b x)))
 -> RWDiffable s b x)
-> (b -> (PreRegion s b, Maybe (Differentiable s b x)))
-> RWDiffable s b x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \b
_ -> (PreRegion s b
forall s m. PreRegion s m
GlobalRegion, Differentiable s b x -> Maybe (Differentiable s b x)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (x -> Differentiable s b x
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const x
x))


data RWDfblFuncValue s d c where
  ConstRWDFV :: c -> RWDfblFuncValue s d c
  RWDFV_IdVar :: RWDfblFuncValue s c c
  GenericRWDFV :: RWDiffable s d c -> RWDfblFuncValue s d c

genericiseRWDFV ::
   ( RealDimension s, Object (Differentiable s) d, Object (Differentiable s) c )
                    => RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV :: RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV (ConstRWDFV c
c) = RWDiffable s d c -> RWDfblFuncValue s d c
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s d c -> RWDfblFuncValue s d c)
-> RWDiffable s d c -> RWDfblFuncValue s d c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ c -> RWDiffable s d c
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const c
c
genericiseRWDFV RWDfblFuncValue s d c
RWDFV_IdVar = RWDiffable s d d -> RWDfblFuncValue s d d
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s d d
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
genericiseRWDFV RWDfblFuncValue s d c
v = RWDfblFuncValue s d c
v

instance RealDimension s => HasAgent (RWDiffable s) where
  type AgentVal (RWDiffable s) d c = RWDfblFuncValue s d c
  alg :: (forall q.
 Object (RWDiffable s) q =>
 AgentVal (RWDiffable s) q a -> AgentVal (RWDiffable s) q b)
-> RWDiffable s a b
alg forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a -> AgentVal (RWDiffable s) q b
fq = case AgentVal (RWDiffable s) a a -> AgentVal (RWDiffable s) a b
forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a -> AgentVal (RWDiffable s) q b
fq AgentVal (RWDiffable s) a a
forall s c. RWDfblFuncValue s c c
RWDFV_IdVar of
    GenericRWDFV f -> RWDiffable s a b
f
    ConstRWDFV c -> b -> RWDiffable s a b
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const b
c
    AgentVal (RWDiffable s) a b
RWDFV_IdVar -> RWDiffable s a b
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
  $~ :: RWDiffable s b c
-> AgentVal (RWDiffable s) a b -> AgentVal (RWDiffable s) a c
($~) = RWDiffable s b c
-> AgentVal (RWDiffable s) a b -> AgentVal (RWDiffable s) a c
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW
instance RealDimension s => CartesianAgent (RWDiffable s) where
  alg1to2 :: (forall q.
 Object (RWDiffable s) q =>
 AgentVal (RWDiffable s) q a
 -> (AgentVal (RWDiffable s) q b, AgentVal (RWDiffable s) q c))
-> RWDiffable s a (b, c)
alg1to2 forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> (AgentVal (RWDiffable s) q b, AgentVal (RWDiffable s) q c)
fgq = case AgentVal (RWDiffable s) a a
-> (AgentVal (RWDiffable s) a b, AgentVal (RWDiffable s) a c)
forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> (AgentVal (RWDiffable s) q b, AgentVal (RWDiffable s) q c)
fgq AgentVal (RWDiffable s) a a
forall s c. RWDfblFuncValue s c c
RWDFV_IdVar of
    (GenericRWDFV f, GenericRWDFV g) -> RWDiffable s a b
f RWDiffable s a b -> RWDiffable s a c -> RWDiffable s a (b, c)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&& RWDiffable s a c
g
  alg2to1 :: (forall q.
 Object (RWDiffable s) q =>
 AgentVal (RWDiffable s) q a
 -> AgentVal (RWDiffable s) q b -> AgentVal (RWDiffable s) q c)
-> RWDiffable s (a, b) c
alg2to1 forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> AgentVal (RWDiffable s) q b -> AgentVal (RWDiffable s) q c
fq = case AgentVal (RWDiffable s) (a, b) a
-> AgentVal (RWDiffable s) (a, b) b
-> AgentVal (RWDiffable s) (a, b) c
forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> AgentVal (RWDiffable s) q b -> AgentVal (RWDiffable s) q c
fq (RWDiffable s (a, b) a -> RWDfblFuncValue s (a, b) a
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s (a, b) a
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst) (RWDiffable s (a, b) b -> RWDfblFuncValue s (a, b) b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s (a, b) b
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd) of
    GenericRWDFV f -> RWDiffable s (a, b) c
f
  alg2to2 :: (forall q.
 Object (RWDiffable s) q =>
 AgentVal (RWDiffable s) q a
 -> AgentVal (RWDiffable s) q b
 -> (AgentVal (RWDiffable s) q c, AgentVal (RWDiffable s) q d))
-> RWDiffable s (a, b) (c, d)
alg2to2 forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> AgentVal (RWDiffable s) q b
-> (AgentVal (RWDiffable s) q c, AgentVal (RWDiffable s) q d)
fgq = case AgentVal (RWDiffable s) (a, b) a
-> AgentVal (RWDiffable s) (a, b) b
-> (AgentVal (RWDiffable s) (a, b) c,
    AgentVal (RWDiffable s) (a, b) d)
forall q.
Object (RWDiffable s) q =>
AgentVal (RWDiffable s) q a
-> AgentVal (RWDiffable s) q b
-> (AgentVal (RWDiffable s) q c, AgentVal (RWDiffable s) q d)
fgq (RWDiffable s (a, b) a -> RWDfblFuncValue s (a, b) a
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s (a, b) a
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) x
fst) (RWDiffable s (a, b) b -> RWDfblFuncValue s (a, b) b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s (a, b) b
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd) of
    (GenericRWDFV f, GenericRWDFV g) -> RWDiffable s (a, b) c
f RWDiffable s (a, b) c
-> RWDiffable s (a, b) d -> RWDiffable s (a, b) (c, d)
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&& RWDiffable s (a, b) d
g
instance (RealDimension s)
      => PointAgent (RWDfblFuncValue s) (RWDiffable s) a x where
  point :: x -> RWDfblFuncValue s a x
point = x -> RWDfblFuncValue s a x
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV

grwDfblFnValsFunc
     :: ( RealDimension s
        , Object (Differentiable s) d, Object (Differentiable s) c, Object (Differentiable s) c'
        , v ~ Needle c, v' ~ Needle c'
        , SimpleSpace v
        , ε ~ Norm v, ε ~ Norm v' )
             => (c' -> (c, v'+>v, ε->ε)) -> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc :: (c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc c' -> (c, v' +> v, ε -> ε)
f = ((c' -> (PreRegion s c', Maybe (Differentiable s c' c)))
-> RWDiffable s c' c
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable (\c'
_ -> (PreRegion s c'
forall s m. PreRegion s m
GlobalRegion, Differentiable s c' c -> Maybe (Differentiable s c' c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((c' -> (c, Needle c' +> Needle c, LinDevPropag c' c))
-> Differentiable s c' c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable c' -> (c, v' +> v, ε -> ε)
c' -> (c, Needle c' +> Needle c, LinDevPropag c' c)
f))) RWDiffable s c' c
-> AgentVal (RWDiffable s) d c' -> AgentVal (RWDiffable s) d c
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~)

grwDfblFnValsCombine :: forall d c c' c'' v v' v'' ε ε' ε'' s. 
         ( RealDimension s
         , Object (Differentiable s) d, Object (Differentiable s) c'
         , Object (Differentiable s) c', Object (Differentiable s) c''
         , v ~ Needle c, v' ~ Needle c', v'' ~ Needle c''
         , SimpleSpace v
         , ε ~ Norm v  , ε' ~ Norm v'  , ε'' ~ Norm v'', ε~ε', ε~ε''  )
       => (  c' -> c'' -> (c, (v',v'')+>v, ε -> (ε',ε''))  )
         -> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c'' -> RWDfblFuncValue s d c
grwDfblFnValsCombine :: (c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> RWDfblFuncValue s d c'
-> RWDfblFuncValue s d c''
-> RWDfblFuncValue s d c
grwDfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb (GenericRWDFV (RWDiffable d -> (PreRegion s d, Maybe (Differentiable s d c'))
fpcs))
                         (GenericRWDFV (RWDiffable d -> (PreRegion s d, Maybe (Differentiable s d c''))
gpcs)) 
    = RWDiffable s d c -> RWDfblFuncValue s d c
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s d c -> RWDfblFuncValue s d c)
-> ((d -> (PreRegion s d, Maybe (Differentiable s d c)))
    -> RWDiffable s d c)
-> (d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDfblFuncValue s d c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((d -> (PreRegion s d, Maybe (Differentiable s d c)))
 -> RWDfblFuncValue s d c)
-> (d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDfblFuncValue s d c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
        \d
d₀ -> let (PreRegion s d
rc', Maybe (Differentiable s d c')
fmay) = d -> (PreRegion s d, Maybe (Differentiable s d c'))
fpcs d
d₀
                   (PreRegion s d
rc'',Maybe (Differentiable s d c'')
gmay) = d -> (PreRegion s d, Maybe (Differentiable s d c''))
gpcs d
d₀
               in (PreRegion s d -> PreRegion s d -> PreRegion s d
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s d
rc' PreRegion s d
rc'',) (Maybe (Differentiable s d c)
 -> (PreRegion s d, Maybe (Differentiable s d c)))
-> Maybe (Differentiable s d c)
-> (PreRegion s d, Maybe (Differentiable s d c))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                    case (Differentiable s d c' -> Differentiable s d c'
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable(Differentiable s d c' -> Differentiable s d c')
-> Maybe (Differentiable s d c') -> Maybe (Differentiable s d c')
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>Maybe (Differentiable s d c')
fmay, Differentiable s d c'' -> Differentiable s d c''
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable(Differentiable s d c'' -> Differentiable s d c'')
-> Maybe (Differentiable s d c'') -> Maybe (Differentiable s d c'')
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$>Maybe (Differentiable s d c'')
gmay) of
                      (Just(Differentiable d -> (c', Needle d +> Needle c', LinDevPropag d c')
f), Just(Differentiable d -> (c'', Needle d +> Needle c'', LinDevPropag d c'')
g)) ->
                        Differentiable s d c -> Maybe (Differentiable s d c)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable s d c -> Maybe (Differentiable s d c))
-> ((d
     -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
         ε -> Norm (Needle d)))
    -> Differentiable s d c)
-> (d
    -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
        ε -> Norm (Needle d)))
-> Maybe (Differentiable s d c)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (d
 -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
     ε -> Norm (Needle d)))
-> Differentiable s d c
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((d
  -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
      ε -> Norm (Needle d)))
 -> Maybe (Differentiable s d c))
-> (d
    -> (c, LinearMap (Scalar (Needle d)) (Needle d) v'',
        ε -> Norm (Needle d)))
-> Maybe (Differentiable s d c)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \d
d
                         -> let (c'
c', LinearMap (Scalar (Needle d)) (Needle d) v''
jf, Norm v'' -> Norm (Needle d)
devf) = d -> (c', Needle d +> Needle c', LinDevPropag d c')
f d
d
                                (c''
c'',LinearMap (Scalar (Needle d)) (Needle d) v''
jg, Norm v'' -> Norm (Needle d)
devg) = d -> (c'', Needle d +> Needle c'', LinDevPropag d c'')
g d
d
                                (c
c, LinearMap (Scalar (Needle d)) (v'', v'') v''
jh, ε -> (ε', ε'')
devh) = c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb c'
c' c''
c''
                                jhl :: LinearMap (Scalar (Needle d)) v'' v''
jhl = LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
-> LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
idLinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) v'' v''
forall v. AdditiveGroup v => v
zeroV); jhr :: LinearMap (Scalar (Needle d)) v'' v''
jhr = LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
-> LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (LinearMap (Scalar (Needle d)) v'' v''
forall v. AdditiveGroup v => v
zeroVLinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' v''
-> LinearMap (Scalar (Needle d)) v'' (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) v'' v''
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
                            in ( c
c
                               , LinearMap (Scalar (Needle d)) (v'', v'') v''
jh LinearMap (Scalar (Needle d)) (v'', v'') v''
-> LinearMap (Scalar (Needle d)) (Needle d) (v'', v'')
-> LinearMap (Scalar (Needle d)) (Needle d) v''
forall (k :: * -> * -> *) a b c.
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
<<< LinearMap (Scalar (Needle d)) (Needle d) v''
jfLinearMap (Scalar (Needle d)) (Needle d) v''
-> LinearMap (Scalar (Needle d)) (Needle d) v''
-> LinearMap (Scalar (Needle d)) (Needle d) (v'', v'')
forall (a :: * -> * -> *) b c c'.
(PreArrow a, Object a b, ObjectPair a c c') =>
a b c -> a b c' -> a b (c, c')
&&&LinearMap (Scalar (Needle d)) (Needle d) v''
jg
                               , \ε
εc -> let εc' :: Norm v''
εc' = (v'' +> v'') -> Norm v'' -> Norm v''
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm v'' +> v''
LinearMap (Scalar (Needle d)) v'' v''
jhl ε
Norm v''
εc
                                            εc'' :: Norm v''
εc'' = (v'' +> v'') -> Norm v'' -> Norm v''
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm v'' +> v''
LinearMap (Scalar (Needle d)) v'' v''
jhr ε
Norm v''
εc
                                            (ε'
δc',ε''
δc'') = ε -> (ε', ε'')
devh ε
εc 
                                        in Norm v'' -> Norm (Needle d)
devf Norm v''
εc' Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> Norm v'' -> Norm (Needle d)
devg Norm v''
εc''
                                             Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> LinearMap (Scalar (Needle d)) (Needle d) v''
-> Norm v'' -> Norm (Needle d)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap (Scalar (Needle d)) (Needle d) v''
jf ε'
Norm v''
δc'
                                             Norm (Needle d) -> Norm (Needle d) -> Norm (Needle d)
forall a. Semigroup a => a -> a -> a
<> LinearMap (Scalar (Needle d)) (Needle d) v''
-> Norm v'' -> Norm (Needle d)
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap (Scalar (Needle d)) (Needle d) v''
jg ε''
Norm v''
δc''
                               )
                      (Maybe (Differentiable s d c'), Maybe (Differentiable s d c''))
_ -> Maybe (Differentiable s d c)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere
grwDfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb RWDfblFuncValue s d c'
fv RWDfblFuncValue s d c''
gv
        = (c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> RWDfblFuncValue s d c'
-> RWDfblFuncValue s d c''
-> RWDfblFuncValue s d c
forall d c c' c'' v v' v'' ε ε' ε'' s.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c', Object (Differentiable s) c',
 Object (Differentiable s) c'', v ~ Needle c, v' ~ Needle c',
 v'' ~ Needle c'', SimpleSpace v, ε ~ Norm v, ε' ~ Norm v',
 ε'' ~ Norm v'', ε ~ ε', ε ~ ε'') =>
(c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε'')))
-> RWDfblFuncValue s d c'
-> RWDfblFuncValue s d c''
-> RWDfblFuncValue s d c
grwDfblFnValsCombine c' -> c'' -> (c, (v', v'') +> v, ε -> (ε', ε''))
cmb (RWDfblFuncValue s d c' -> RWDfblFuncValue s d c'
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue s d c'
fv) (RWDfblFuncValue s d c'' -> RWDfblFuncValue s d c''
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue s d c''
gv)

          
rwDfbl_plus ::  a v s .
        ( RealDimension s
        , Object (Differentiable s) a, Object (Differentiable s) v
        , LinearSpace v )
      => RWDiffable s a v -> RWDiffable s a v -> RWDiffable s a v
rwDfbl_plus :: RWDiffable s a v -> RWDiffable s a v -> RWDiffable s a v
rwDfbl_plus (RWDiffable a -> (PreRegion s a, Maybe (Differentiable s a v))
f) (RWDiffable a -> (PreRegion s a, Maybe (Differentiable s a v))
g) = (a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> RWDiffable s a v
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable
              ((a -> (PreRegion s a, Maybe (Differentiable s a v)))
 -> RWDiffable s a v)
-> (a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> RWDiffable s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (OpenManifold (Needle (Interior a)) =>
 a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> a -> (PreRegion s a, Maybe (Differentiable s a v))
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a ((ProjectableBoundary (Needle (Interior a)) =>
 a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> a -> (PreRegion s a, Maybe (Differentiable s a v))
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (
                   (OpenManifold (Needle a), ProjectableBoundary (Needle a)) =>
LinearManifoldWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness v
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
LinearManifoldWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness v
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
h LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness LinearManifoldWitness (Needle a)
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness
                        DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness DualSpaceWitness (Needle a)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness))
   where h :: (OpenManifold (Needle a), ProjectableBoundary (Needle a))
               => LinearManifoldWitness v -> LinearManifoldWitness (Needle a)
               -> DualSpaceWitness v -> DualSpaceWitness (Needle a)
                -> a -> (PreRegion s a, Maybe (Differentiable s a v))
         h :: LinearManifoldWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness v
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
h LinearManifoldWitness v
LinearManifoldWitness LinearManifoldWitness (Needle a)
LinearManifoldWitness DualSpaceWitness v
DualSpaceWitness DualSpaceWitness (Needle a)
DualSpaceWitness
           a
x₀ = (PreRegion s a
rh, (Differentiable s a v
 -> Differentiable s a v -> Differentiable s a v)
-> Maybe (Differentiable s a v)
-> Maybe (Differentiable s a v)
-> Maybe (Differentiable s a v)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) c b a.
(Applicative f r t, Object r c, ObjectMorphism r b c,
 Object t (f c), ObjectMorphism t (f b) (f c), ObjectPair r a b,
 ObjectPair t (f a) (f b)) =>
r a (r b c) -> t (f a) (t (f b) (f c))
liftA2 Differentiable s a v
-> Differentiable s a v -> Differentiable s a v
fgplus Maybe (Differentiable s a v)
ff Maybe (Differentiable s a v)
gf)
          where (PreRegion s a
rf, Maybe (Differentiable s a v)
ff) = a -> (PreRegion s a, Maybe (Differentiable s a v))
f a
x₀
                (PreRegion s a
rg, Maybe (Differentiable s a v)
gf) = a -> (PreRegion s a, Maybe (Differentiable s a v))
g a
x₀
                rh :: PreRegion s a
rh = PreRegion s a -> PreRegion s a -> PreRegion s a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion s a
rf PreRegion s a
rg
                fgplus :: Differentiable s a v -> Differentiable s a v -> Differentiable s a v
                fgplus :: Differentiable s a v
-> Differentiable s a v -> Differentiable s a v
fgplus (Differentiable a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd) (Differentiable a -> (v, Needle a +> Needle v, LinDevPropag a v)
gd) = (a -> (v, Needle a +> Needle v, LinDevPropag a v))
-> Differentiable s a v
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
a -> (v, Needle a +> Needle v, LinDevPropag a v)
hd
                 where hd :: a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
hd a
x = (v
fxv -> v -> v
forall v. AdditiveGroup v => v -> v -> v
^+^v
gx, LinearMap s (Needle a) v
jfLinearMap s (Needle a) v
-> LinearMap s (Needle a) v -> LinearMap s (Needle a) v
forall v. AdditiveGroup v => v -> v -> v
^+^LinearMap s (Needle a) v
jg, \Norm v
ε -> Norm v -> Norm (Needle a)
δf(Scalar v -> Norm v -> Norm v
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm Scalar v
2 Norm v
ε)
                                                     Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall a. Semigroup a => a -> a -> a
<> Norm v -> Norm (Needle a)
δg(Scalar v -> Norm v -> Norm v
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm Scalar v
2 Norm v
ε))
                        where (v
fx, LinearMap s (Needle a) v
jf, Norm v -> Norm (Needle a)
δf) = a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd a
x
                              (v
gx, LinearMap s (Needle a) v
jg, Norm v -> Norm (Needle a)
δg) = a -> (v, Needle a +> Needle v, LinDevPropag a v)
gd a
x
                fgplus (Differentiable a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd) (AffinDiffable DiffableEndoProof a v
_ Affine s a v
ga)
                                 = (a -> (v, Needle a +> Needle v, LinDevPropag a v))
-> Differentiable s a v
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
a -> (v, Needle a +> Needle v, LinDevPropag a v)
hd
                 where hd :: a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
hd a
x = (v
fxv -> v -> v
forall v. AdditiveGroup v => v -> v -> v
^+^v
gx, LinearMap s (Needle a) v
jfLinearMap s (Needle a) v
-> LinearMap s (Needle a) v -> LinearMap s (Needle a) v
forall v. AdditiveGroup v => v -> v -> v
^+^LinearMap s (Needle a) v
ϕg, Norm v -> Norm (Needle a)
δf)
                        where (v
fx, LinearMap s (Needle a) v
jf, Norm v -> Norm (Needle a)
δf) = a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd a
x
                              (v
gx, LinearMap s (Needle a) v
ϕg) = Affine s a v -> a -> (v, LinearMap s (Needle a) (Needle v))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine s a v
ga a
x
                fgplus (AffinDiffable DiffableEndoProof a v
_ Affine s a v
fa) (Differentiable a -> (v, Needle a +> Needle v, LinDevPropag a v)
gd)
                                 = (a -> (v, Needle a +> Needle v, LinDevPropag a v))
-> Differentiable s a v
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
a -> (v, Needle a +> Needle v, LinDevPropag a v)
hd
                 where hd :: a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
hd a
x = (v
fxv -> v -> v
forall v. AdditiveGroup v => v -> v -> v
^+^v
gx, LinearMap s (Needle a) v
ϕfLinearMap s (Needle a) v
-> LinearMap s (Needle a) v -> LinearMap s (Needle a) v
forall v. AdditiveGroup v => v -> v -> v
^+^LinearMap s (Needle a) v
jg, Norm v -> Norm (Needle a)
δg)
                        where (v
gx, LinearMap s (Needle a) v
jg, Norm v -> Norm (Needle a)
δg) = a -> (v, Needle a +> Needle v, LinDevPropag a v)
gd a
x
                              (v
fx, LinearMap s (Needle a) v
ϕf) = Affine s a v -> a -> (v, LinearMap s (Needle a) (Needle v))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine s a v
fa a
x
                fgplus (AffinDiffable DiffableEndoProof a v
fe Affine s a v
fa) (AffinDiffable DiffableEndoProof a v
ge Affine s a v
ga)
                           = DiffableEndoProof a v -> Affine s a v -> Differentiable s a v
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable (DiffableEndoProof a v
feDiffableEndoProof a v
-> DiffableEndoProof a v -> DiffableEndoProof a v
forall a. Semigroup a => a -> a -> a
<>DiffableEndoProof a v
ge) (Affine s a v
faAffine s a v -> Affine s a v -> Affine s a v
forall v. AdditiveGroup v => v -> v -> v
^+^Affine s a v
ga)

rwDfbl_negateV ::  a v s .
        ( WithField s Manifold a
        , LinearSpace v, Scalar v ~ s
        , RealDimension s )
      => RWDiffable s a v -> RWDiffable s a v
rwDfbl_negateV :: RWDiffable s a v -> RWDiffable s a v
rwDfbl_negateV (RWDiffable a -> (PreRegion s a, Maybe (Differentiable s a v))
f) = (a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> RWDiffable s a v
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable
           ((a -> (PreRegion s a, Maybe (Differentiable s a v)))
 -> RWDiffable s a v)
-> (a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> RWDiffable s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (OpenManifold (Needle (Interior a)) =>
 a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> a -> (PreRegion s a, Maybe (Differentiable s a v))
forall m r.
SemimanifoldWithBoundary m =>
(OpenManifold (Needle (Interior m)) => r) -> r
needleIsOpenMfd @a ((ProjectableBoundary (Needle (Interior a)) =>
 a -> (PreRegion s a, Maybe (Differentiable s a v)))
-> a -> (PreRegion s a, Maybe (Differentiable s a v))
forall m r.
ProjectableBoundary m =>
(ProjectableBoundary (Needle (Interior m)) => r) -> r
needleBoundaryIsTriviallyProjectible @a (
                  (OpenManifold (Needle a), ProjectableBoundary (Needle a)) =>
LinearManifoldWitness v
-> DualSpaceWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
LinearManifoldWitness v
-> DualSpaceWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
h LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness
                    LinearManifoldWitness (Needle a)
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness DualSpaceWitness (Needle a)
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness))
   where h :: (OpenManifold (Needle a), ProjectableBoundary (Needle a))
             => LinearManifoldWitness v -> DualSpaceWitness v
              -> LinearManifoldWitness (Needle a) -> DualSpaceWitness (Needle a)
                -> a -> (PreRegion s a, Maybe (Differentiable s a v))
         h :: LinearManifoldWitness v
-> DualSpaceWitness v
-> LinearManifoldWitness (Needle a)
-> DualSpaceWitness (Needle a)
-> a
-> (PreRegion s a, Maybe (Differentiable s a v))
h LinearManifoldWitness v
LinearManifoldWitness DualSpaceWitness v
DualSpaceWitness LinearManifoldWitness (Needle a)
LinearManifoldWitness DualSpaceWitness (Needle a)
DualSpaceWitness
           a
x₀ = (PreRegion s a
rf, (Differentiable s a v -> Differentiable s a v)
-> Maybe (Differentiable s a v) -> Maybe (Differentiable s a v)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Functor f r t, Object r a, Object t (f a), Object r b,
 Object t (f b)) =>
r a b -> t (f a) (f b)
fmap Differentiable s a v -> Differentiable s a v
fneg Maybe (Differentiable s a v)
ff)
          where (PreRegion s a
rf, Maybe (Differentiable s a v)
ff) = a -> (PreRegion s a, Maybe (Differentiable s a v))
f a
x₀
                fneg :: Differentiable s a v -> Differentiable s a v
                fneg :: Differentiable s a v -> Differentiable s a v
fneg (Differentiable a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd) = (a -> (v, Needle a +> Needle v, LinDevPropag a v))
-> Differentiable s a v
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
a -> (v, Needle a +> Needle v, LinDevPropag a v)
hd
                 where hd :: a -> (v, LinearMap s (Needle a) v, Norm v -> Norm (Needle a))
hd a
x = (v -> v
forall v. AdditiveGroup v => v -> v
negateV v
fx, LinearMap s (Needle a) v -> LinearMap s (Needle a) v
forall v. AdditiveGroup v => v -> v
negateV LinearMap s (Needle a) v
jf, Norm v -> Norm (Needle a)
δf)
                        where (v
fx, LinearMap s (Needle a) v
jf, Norm v -> Norm (Needle a)
δf) = a -> (v, Needle a +> Needle v, LinDevPropag a v)
fd a
x
                fneg (AffinDiffable DiffableEndoProof a v
ef Affine s a v
af) = DiffableEndoProof a v -> Affine s a v -> Differentiable s a v
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof a v
ef (Affine s a v -> Differentiable s a v)
-> Affine s a v -> Differentiable s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Affine s a v -> Affine s a v
forall v. AdditiveGroup v => v -> v
negateV Affine s a v
af

postCompRW ::  a b c s . ( RealDimension s
                          , Object (Differentiable s) a
                          , Object (Differentiable s) b
                          , Object (Differentiable s) c )
              => RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW :: RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable b -> (PreRegion s b, Maybe (Differentiable s b c))
f) (ConstRWDFV b
x) = case b -> (PreRegion s b, Maybe (Differentiable s b c))
f b
x of
     (PreRegion s b
_, Just Differentiable s b c
fd) -> c -> RWDfblFuncValue s a c
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV (c -> RWDfblFuncValue s a c) -> c -> RWDfblFuncValue s a c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s b c
fd Differentiable s b c -> b -> c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b
x
postCompRW RWDiffable s b c
f RWDfblFuncValue s a b
RWDFV_IdVar = RWDiffable s b c -> RWDfblFuncValue s b c
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV RWDiffable s b c
f
postCompRW RWDiffable s b c
f (GenericRWDFV RWDiffable s a b
g) = RWDiffable s a c -> RWDfblFuncValue s a c
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a c -> RWDfblFuncValue s a c)
-> RWDiffable s a c -> RWDfblFuncValue s a c
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ RWDiffable s b c
f RWDiffable s b c -> RWDiffable s a b -> RWDiffable s a c
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. RWDiffable s a b
g


instance  s a v . ( RealDimension s
                   , Object (Differentiable s) a, Object (Differentiable s) v
                   , LinearSpace v )
    => AdditiveGroup (RWDfblFuncValue s a v) where
  zeroV :: RWDfblFuncValue s a v
zeroV = case ( LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v
               , DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (LinearManifoldWitness v
LinearManifoldWitness, DualSpaceWitness v
DualSpaceWitness) -> v -> RWDfblFuncValue s a v
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point v
forall v. AdditiveGroup v => v
zeroV
  ^+^ :: RWDfblFuncValue s a v
-> RWDfblFuncValue s a v -> RWDfblFuncValue s a v
(^+^) = case ( LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v
               , DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (LinearManifoldWitness v
LinearManifoldWitness, DualSpaceWitness v
DualSpaceWitness)
         -> ((RWDfblFuncValue s a v, RWDfblFuncValue s a v)
 -> RWDfblFuncValue s a v)
-> RWDfblFuncValue s a v
-> RWDfblFuncValue s a v
-> RWDfblFuncValue s a v
forall (k :: * -> * -> *) a b c.
(Curry k, ObjectPair k a b, ObjectMorphism k b c) =>
k (a, b) c -> k a (k b c)
curry (((RWDfblFuncValue s a v, RWDfblFuncValue s a v)
  -> RWDfblFuncValue s a v)
 -> RWDfblFuncValue s a v
 -> RWDfblFuncValue s a v
 -> RWDfblFuncValue s a v)
-> ((RWDfblFuncValue s a v, RWDfblFuncValue s a v)
    -> RWDfblFuncValue s a v)
-> RWDfblFuncValue s a v
-> RWDfblFuncValue s a v
-> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \case
              (ConstRWDFV v
c₁, ConstRWDFV v
c₂) -> v -> RWDfblFuncValue s a v
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV (v
c₁v -> v -> v
forall v. AdditiveGroup v => v -> v -> v
^+^v
c₂)
              (ConstRWDFV v
c₁, RWDfblFuncValue s a v
RWDFV_IdVar) -> RWDiffable s v v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s v v -> RWDfblFuncValue s a v)
-> RWDiffable s v v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable s v v -> RWDiffable s v v
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (v -> (v +> Needle v) -> Differentiable s v v
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo v
c₁ v +> Needle v
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
              (RWDfblFuncValue s a v
RWDFV_IdVar, ConstRWDFV v
c₂) -> RWDiffable s v v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s v v -> RWDfblFuncValue s a v)
-> RWDiffable s v v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable s v v -> RWDiffable s v v
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (v -> (v +> Needle v) -> Differentiable s v v
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo v
c₂ v +> Needle v
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
              (ConstRWDFV v
c₁, GenericRWDFV RWDiffable s a v
g) -> RWDiffable s a v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a v -> RWDfblFuncValue s a v)
-> RWDiffable s a v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable s v v -> RWDiffable s v v
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (v -> (v +> Needle v) -> Differentiable s v v
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo v
c₁ v +> Needle v
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) RWDiffable s v v -> RWDiffable s a v -> RWDiffable s a v
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. RWDiffable s a v
g
              (GenericRWDFV RWDiffable s a v
f, ConstRWDFV v
c₂) -> RWDiffable s a v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a v -> RWDfblFuncValue s a v)
-> RWDiffable s a v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                                  Differentiable s v v -> RWDiffable s v v
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (v -> (v +> Needle v) -> Differentiable s v v
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo v
c₂ v +> Needle v
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) RWDiffable s v v -> RWDiffable s a v -> RWDiffable s a v
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. RWDiffable s a v
f
              (RWDfblFuncValue s a v
fa, RWDfblFuncValue s a v
ga) | GenericRWDFV RWDiffable s a v
f <- RWDfblFuncValue s a v -> RWDfblFuncValue s a v
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue s a v
fa
                       , GenericRWDFV RWDiffable s a v
g <- RWDfblFuncValue s a v -> RWDfblFuncValue s a v
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue s a v
ga
                                -> RWDiffable s a v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a v -> RWDfblFuncValue s a v)
-> RWDiffable s a v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ RWDiffable s a v -> RWDiffable s a v -> RWDiffable s a v
forall a v s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) v, LinearSpace v) =>
RWDiffable s a v -> RWDiffable s a v -> RWDiffable s a v
rwDfbl_plus RWDiffable s a v
f RWDiffable s a v
g
  negateV :: RWDfblFuncValue s a v -> RWDfblFuncValue s a v
negateV = case ( LinearManifoldWitness v
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness :: LinearManifoldWitness v
                 , DualSpaceWitness v
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness :: DualSpaceWitness v ) of
      (LinearManifoldWitness v
LinearManifoldWitness, DualSpaceWitness v
DualSpaceWitness) -> \case
        (ConstRWDFV v
c) -> v -> RWDfblFuncValue s a v
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV (v -> v
forall v. AdditiveGroup v => v -> v
negateV v
c)
        RWDfblFuncValue s a v
RWDFV_IdVar -> RWDiffable s a a -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a a -> RWDfblFuncValue s a v)
-> RWDiffable s a a -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Differentiable s a a -> RWDiffable s a a
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (LinearMap (Scalar (Needle a)) a a -> Differentiable s a a
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar (Needle a)) a a -> Differentiable s a a)
-> LinearMap (Scalar (Needle a)) a a -> Differentiable s a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar (Needle a)) a a
-> LinearMap (Scalar (Needle a)) a a
forall v. AdditiveGroup v => v -> v
negateV LinearMap (Scalar (Needle a)) a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
        (GenericRWDFV RWDiffable s a v
f) -> RWDiffable s a v -> RWDfblFuncValue s a v
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable s a v -> RWDfblFuncValue s a v)
-> RWDiffable s a v -> RWDfblFuncValue s a v
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ RWDiffable s a v -> RWDiffable s a v
forall a v s.
(WithField s Manifold a, LinearSpace v, Scalar v ~ s,
 RealDimension s) =>
RWDiffable s a v -> RWDiffable s a v
rwDfbl_negateV RWDiffable s a v
f

dualCoCoProduct ::  v w s .
                   ( SimpleSpace v, HilbertSpace v
                   , SimpleSpace w, Scalar v ~ s, Scalar w ~ s )
           => LinearMap s w v -> LinearMap s w v -> Norm w
dualCoCoProduct :: LinearMap s w v -> LinearMap s w v -> Norm w
dualCoCoProduct = DualSpaceWitness w -> LinearMap s w v -> LinearMap s w v -> Norm w
dccp (DualSpaceWitness w
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness::DualSpaceWitness w)
 where dccp :: DualSpaceWitness w -> LinearMap s w v -> LinearMap s w v -> Norm w
dccp DualSpaceWitness w
DualSpaceWitness LinearMap s w v
s LinearMap s w v
t = LinearFunction (Scalar (DualVector w)) w (DualVector w) -> Norm w
forall v. (v -+> DualVector v) -> Norm v
Norm (LinearFunction (Scalar (DualVector w)) w (DualVector w) -> Norm w)
-> LinearFunction (Scalar (DualVector w)) w (DualVector w)
-> Norm w
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (s
tSpreads -> s -> s
forall a. Num a => a -> a -> a
*s
sSpread) Scalar (LinearFunction (Scalar (DualVector w)) w (DualVector w))
-> LinearFunction (Scalar (DualVector w)) w (DualVector w)
-> LinearFunction (Scalar (DualVector w)) w (DualVector w)
forall v. VectorSpace v => Scalar v -> v -> v
*^ LinearFunction (Scalar (DualVector w)) w (DualVector w)
t²Ps²M
        where t' :: LinearMap s v (DualVector w)
t' = LinearFunction
  (Scalar v)
  (LinearMap (Scalar w) w (DualVector v))
  (LinearMap (Scalar v) v (DualVector w))
forall v w.
(LinearSpace v, LinearSpace w, Scalar v ~ Scalar w) =>
(v +> DualVector w) -+> (w +> DualVector v)
adjoint LinearFunction
  (Scalar v)
  (LinearMap (Scalar w) w (DualVector v))
  (LinearMap (Scalar v) v (DualVector w))
-> LinearMap (Scalar w) w (DualVector v)
-> LinearMap (Scalar v) v (DualVector w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s w v
LinearMap (Scalar w) w (DualVector v)
t :: LinearMap s v (DualVector w)
              s' :: LinearMap s v (DualVector w)
s' = LinearFunction
  (Scalar v)
  (LinearMap (Scalar w) w (DualVector v))
  (LinearMap (Scalar v) v (DualVector w))
forall v w.
(LinearSpace v, LinearSpace w, Scalar v ~ Scalar w) =>
(v +> DualVector w) -+> (w +> DualVector v)
adjoint LinearFunction
  (Scalar v)
  (LinearMap (Scalar w) w (DualVector v))
  (LinearMap (Scalar v) v (DualVector w))
-> LinearMap (Scalar w) w (DualVector v)
-> LinearMap (Scalar v) v (DualVector w)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap s w v
LinearMap (Scalar w) w (DualVector v)
s :: LinearMap s v (DualVector w)
              tSpread :: s
tSpread = [s] -> s
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([s] -> s) -> ([DualVector w] -> [s]) -> [DualVector w] -> s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (DualVector w -> s) -> [DualVector w] -> [s]
forall a b. (a -> b) -> [a] -> [b]
map DualVector w -> s
recip_t²PLUSs² ([DualVector w] -> s) -> [DualVector w] -> s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (SubBasis v, [DualVector w] -> [DualVector w])
-> [DualVector w] -> [DualVector w]
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd (LinearMap (Scalar v) v (DualVector w)
-> (SubBasis v, [DualVector w] -> [DualVector w])
forall v w.
(FiniteDimensional v, LSpace w, Scalar w ~ Scalar v) =>
(v +> w) -> (SubBasis v, DList w)
decomposeLinMap LinearMap s v (DualVector w)
LinearMap (Scalar v) v (DualVector w)
t') []
              sSpread :: s
sSpread = [s] -> s
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([s] -> s) -> ([DualVector w] -> [s]) -> [DualVector w] -> s
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (DualVector w -> s) -> [DualVector w] -> [s]
forall a b. (a -> b) -> [a] -> [b]
map DualVector w -> s
recip_t²PLUSs² ([DualVector w] -> s) -> [DualVector w] -> s
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ (SubBasis v, [DualVector w] -> [DualVector w])
-> [DualVector w] -> [DualVector w]
forall (a :: * -> * -> *) x y.
(PreArrow a, ObjectPair a x y) =>
a (x, y) y
snd (LinearMap (Scalar v) v (DualVector w)
-> (SubBasis v, [DualVector w] -> [DualVector w])
forall v w.
(FiniteDimensional v, LSpace w, Scalar w ~ Scalar v) =>
(v +> w) -> (SubBasis v, DList w)
decomposeLinMap LinearMap s v (DualVector w)
LinearMap (Scalar v) v (DualVector w)
s') []
              t²PLUSs²' :: Norm w
t²PLUSs²'@(Norm LinearFunction (Scalar (DualVector w)) w (DualVector w)
t²Ps²M)
                = (w +> v) -> Norm v -> Norm w
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap s w v
w +> v
t Norm v
forall v. HilbertSpace v => Norm v
euclideanNorm Norm w -> Norm w -> Norm w
forall a. Semigroup a => a -> a -> a
<> (w +> v) -> Norm v -> Norm w
forall v w.
(LSpace v, LSpace w, Scalar v ~ Scalar w) =>
(v +> w) -> Norm w -> Norm v
transformNorm LinearMap s w v
w +> v
s Norm v
forall v. HilbertSpace v => Norm v
euclideanNorm :: Norm w
              recip_t²PLUSs² :: DualVector w -> s
recip_t²PLUSs² = Seminorm (DualVector w) -> DualVector w -> Scalar (DualVector w)
forall v. LSpace v => Seminorm v -> v -> Scalar v
normSq (Norm w -> Seminorm (DualVector w)
forall v. SimpleSpace v => Norm v -> Variance v
dualNorm Norm w
t²PLUSs²') :: DualVector w -> s

instance  n a . ( RealDimension n, Object (Differentiable n) a, SimpleSpace (Needle a) )
            => Num (RWDfblFuncValue n a n) where
  fromInteger :: Integer -> RWDfblFuncValue n a n
fromInteger Integer
i = n -> RWDfblFuncValue n a n
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point (n -> RWDfblFuncValue n a n) -> n -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Integer -> n
forall a. Num a => Integer -> a
fromInteger Integer
i
  + :: RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
(+) = RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall v. AdditiveGroup v => v -> v -> v
(^+^)
  ConstRWDFV n
c₁ * :: RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
* ConstRWDFV n
c₂ = n -> RWDfblFuncValue n a n
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV (n
c₁n -> n -> n
forall a. Num a => a -> a -> a
*n
c₂)
  ConstRWDFV n
c₁ * RWDfblFuncValue n a n
RWDFV_IdVar = RWDiffable a a a -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable a a a -> RWDfblFuncValue n a n)
-> RWDiffable a a a -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable a a a -> RWDiffable a a a
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (LinearMap (Scalar (Needle a)) a a -> Differentiable a a a
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar (Needle a)) a a -> Differentiable a a a)
-> (LinearFunction (Scalar (Needle a)) a a
    -> LinearMap (Scalar (Needle a)) a a)
-> LinearFunction (Scalar (Needle a)) a a
-> Differentiable a a a
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction (Scalar (Needle a)) a a
-> LinearMap (Scalar (Needle a)) a a
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar (Needle a)) a a -> Differentiable a a a)
-> LinearFunction (Scalar (Needle a)) a a -> Differentiable a a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
-> n -> LinearFunction (Scalar (Needle a)) a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₁)
  RWDfblFuncValue n a n
RWDFV_IdVar * ConstRWDFV n
c₂ = RWDiffable a a a -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable a a a -> RWDfblFuncValue n a n)
-> RWDiffable a a a -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable a a a -> RWDiffable a a a
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (LinearMap (Scalar (Needle a)) a a -> Differentiable a a a
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar (Needle a)) a a -> Differentiable a a a)
-> (LinearFunction (Scalar (Needle a)) a a
    -> LinearMap (Scalar (Needle a)) a a)
-> LinearFunction (Scalar (Needle a)) a a
-> Differentiable a a a
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction (Scalar (Needle a)) a a
-> LinearMap (Scalar (Needle a)) a a
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar (Needle a)) a a -> Differentiable a a a)
-> LinearFunction (Scalar (Needle a)) a a -> Differentiable a a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
-> n -> LinearFunction (Scalar (Needle a)) a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₂)
  ConstRWDFV n
c₁ * GenericRWDFV RWDiffable n a n
g = RWDiffable n a n -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable n a n -> RWDfblFuncValue n a n)
-> RWDiffable n a n -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable n n n -> RWDiffable n n n
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (LinearMap (Scalar n) n n -> Differentiable n n n
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar n) n n -> Differentiable n n n)
-> (LinearFunction (Scalar n) n n -> LinearMap (Scalar n) n n)
-> LinearFunction (Scalar n) n n
-> Differentiable n n n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction (Scalar n) n n -> LinearMap (Scalar n) n n
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar n) n n -> Differentiable n n n)
-> LinearFunction (Scalar n) n n -> Differentiable n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar n) n (LinearFunction (Scalar n) n n)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction (Scalar n) n (LinearFunction (Scalar n) n n)
-> n -> LinearFunction (Scalar n) n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₁) RWDiffable n n n -> RWDiffable n a n -> RWDiffable n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. RWDiffable n a n
g
  GenericRWDFV RWDiffable n a n
f * ConstRWDFV n
c₂ = RWDiffable n a n -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable n a n -> RWDfblFuncValue n a n)
-> RWDiffable n a n -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                               Differentiable n n n -> RWDiffable n n n
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (LinearMap (Scalar n) n n -> Differentiable n n n
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar n) n n -> Differentiable n n n)
-> (LinearFunction (Scalar n) n n -> LinearMap (Scalar n) n n)
-> LinearFunction (Scalar n) n n
-> Differentiable n n n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction (Scalar n) n n -> LinearMap (Scalar n) n n
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar n) n n -> Differentiable n n n)
-> LinearFunction (Scalar n) n n -> Differentiable n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction (Scalar n) n (LinearFunction (Scalar n) n n)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction (Scalar n) n (LinearFunction (Scalar n) n n)
-> n -> LinearFunction (Scalar n) n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₂) RWDiffable n n n -> RWDiffable n a n -> RWDiffable n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. RWDiffable n a n
f
  RWDfblFuncValue n a n
f*RWDfblFuncValue n a n
g = RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue n a n
f RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
 RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue n a n
g
   where (⋅) :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n 
         GenericRWDFV (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a n))
fpcs) ⋅ :: RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
 GenericRWDFV (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a n))
gpcs)
           = RWDiffable n a n -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable n a n -> RWDfblFuncValue n a n)
-> ((a -> (PreRegion n a, Maybe (Differentiable n a n)))
    -> RWDiffable n a n)
-> (a -> (PreRegion n a, Maybe (Differentiable n a n)))
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (a -> (PreRegion n a, Maybe (Differentiable n a n)))
-> RWDiffable n a n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((a -> (PreRegion n a, Maybe (Differentiable n a n)))
 -> RWDfblFuncValue n a n)
-> (a -> (PreRegion n a, Maybe (Differentiable n a n)))
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
               \a
d₀ -> let (PreRegion n a
rc₁, Maybe (Differentiable n a n)
fmay) = a -> (PreRegion n a, Maybe (Differentiable n a n))
fpcs a
d₀
                          (PreRegion n a
rc₂,Maybe (Differentiable n a n)
gmay) = a -> (PreRegion n a, Maybe (Differentiable n a n))
gpcs a
d₀
                      in (PreRegion n a -> PreRegion n a -> PreRegion n a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion n a
rc₁ PreRegion n a
rc₂, Differentiable n a n
-> Differentiable n a n -> Differentiable n a n
mulDi (Differentiable n a n
 -> Differentiable n a n -> Differentiable n a n)
-> Maybe (Differentiable n a n)
-> Maybe (Differentiable n a n -> Differentiable n a n)
forall (f :: * -> *) (r :: * -> * -> *) a b.
(Functor f r (->), Object r a, Object r b) =>
r a b -> f a -> f b
<$> Maybe (Differentiable n a n)
fmay Maybe (Differentiable n a n -> Differentiable n a n)
-> Maybe (Differentiable n a n) -> Maybe (Differentiable n a n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a b.
(Applicative f r t, ObjectMorphism r a b,
 ObjectMorphism t (f a) (f b), Object t (t (f a) (f b)),
 ObjectPair r (r a b) a, ObjectPair t (f (r a b)) (f a), Object r a,
 Object r b) =>
t (f (r a b)) (t (f a) (f b))
<*> Maybe (Differentiable n a n)
gmay)
          where mulDi :: Differentiable n a n -> Differentiable n a n -> Differentiable n a n
                mulDi :: Differentiable n a n
-> Differentiable n a n -> Differentiable n a n
mulDi f :: Differentiable n a n
f@(AffinDiffable DiffableEndoProof a n
ef Affine n a n
af) g :: Differentiable n a n
g@(AffinDiffable DiffableEndoProof a n
eg Affine n a n
ag) = case DiffableEndoProof a n
efDiffableEndoProof a n
-> DiffableEndoProof a n -> DiffableEndoProof a n
forall a. Semigroup a => a -> a -> a
<>DiffableEndoProof a n
eg of
                   DiffableEndoProof a n
IsDiffableEndo ->
                  {- let f' = lapply slf 1; g' = lapply slg 1
                     in case f'*g' of
                          0 -> AffinDiffableEndo $ const (aof*aog)
                          f'g' -> -} (a
 -> (n, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
     Norm (Needle a) -> Norm (Needle a)))
-> Differentiable n a n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((a
  -> (n, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
      Norm (Needle a) -> Norm (Needle a)))
 -> Differentiable n a n)
-> (a
    -> (n, LinearMap (Scalar (Needle a)) (Needle a) (Needle a),
        Norm (Needle a) -> Norm (Needle a)))
-> Differentiable n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                           \a
d -> let (n
fd,LinearMap a a n
ϕf) = Affine n a n -> a -> (n, LinearMap n (Needle a) (Needle n))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine n a n
af a
d
                                     (n
gd,LinearMap a a n
ϕg) = Affine n a n -> a -> (n, LinearMap n (Needle a) (Needle n))
forall x y s.
(Manifold x, Atlas x, HasTrie (ChartIndex x), Manifold y,
 s ~ Scalar (Needle x), s ~ Scalar (Needle y)) =>
Affine s x y -> x -> (y, LinearMap s (Needle x) (Needle y))
evalAffine Affine n a n
ag a
d
                                     jf :: n
jf = LinearMap a a n
ϕf LinearMap a a n -> a -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a
1; jg :: n
jg = LinearMap a a n
ϕg LinearMap a a n -> a -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a
1
                                     invf'g' :: a
invf'g' = n -> a
forall a. Fractional a => a -> a
recip (n -> a) -> n -> a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
jfn -> n -> n
forall a. Num a => a -> a -> a
*n
jg
                                 in ( n
fdn -> n -> n
forall a. Num a => a -> a -> a
*n
gd
                                    , LinearFunction (Scalar (Needle a)) a a
-> LinearMap (Scalar (Needle a)) (Needle a) (Needle a)
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar (Needle a)) a a
 -> LinearMap (Scalar (Needle a)) (Needle a) (Needle a))
-> LinearFunction (Scalar (Needle a)) a a
-> LinearMap (Scalar (Needle a)) (Needle a) (Needle a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction
  (Scalar (Needle a)) n (LinearFunction (Scalar (Needle a)) a a)
-> n -> LinearFunction (Scalar (Needle a)) a a
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
fdn -> n -> n
forall a. Num a => a -> a -> a
*n
jg n -> n -> n
forall a. Num a => a -> a -> a
+ n
gdn -> n -> n
forall a. Num a => a -> a -> a
*n
jf
                                    , String -> (a -> a) -> Norm (Needle a) -> Norm (Needle a)
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ String
"*" ((a -> a) -> Norm (Needle a) -> Norm (Needle a))
-> (a -> a) -> Norm (Needle a) -> Norm (Needle a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ a -> a
forall a. Floating a => a -> a
sqrt (a -> a) -> (a -> a) -> a -> a
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (a -> a -> a
forall a. Num a => a -> a -> a
*a
invf'g') )
                   DiffableEndoProof a n
_ -> Differentiable n a n
-> Differentiable n a n -> Differentiable n a n
mulDi (Differentiable n a n -> Differentiable n a n
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable n a n
f) (Differentiable n a n -> Differentiable n a n
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable n a n
g)
                mulDi (Differentiable a -> (n, Needle a +> Needle n, LinDevPropag a n)
f) (Differentiable a -> (n, Needle a +> Needle n, LinDevPropag a n)
g)
                   = (a -> (n, LinearMap n (Needle a) n, Norm n -> Norm (Needle a)))
-> Differentiable n a n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable ((a -> (n, LinearMap n (Needle a) n, Norm n -> Norm (Needle a)))
 -> Differentiable n a n)
-> (a -> (n, LinearMap n (Needle a) n, Norm n -> Norm (Needle a)))
-> Differentiable n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                       \a
d -> let (n
c₁, LinearMap n (Needle a) n
jf, Norm n -> Norm (Needle a)
devf) = a -> (n, Needle a +> Needle n, LinDevPropag a n)
f a
d
                                 (n
c₂, LinearMap n (Needle a) n
jg, Norm n -> Norm (Needle a)
devg) = a -> (n, Needle a +> Needle n, LinDevPropag a n)
g a
d
                                 c :: n
c = n
c₁n -> n -> n
forall a. Num a => a -> a -> a
*n
c₂; c₁² :: n
c₁² = n
c₁n -> Int -> n
forall a. Num a => a -> Int -> a
^Int
2; c₂² :: n
c₂² = n
c₂n -> Int -> n
forall a. Num a => a -> Int -> a
^Int
2
                                 h' :: LinearMap n (Needle a) n
h' = n
Scalar (LinearMap n (Needle a) n)
c₁Scalar (LinearMap n (Needle a) n)
-> LinearMap n (Needle a) n -> LinearMap n (Needle a) n
forall v. VectorSpace v => Scalar v -> v -> v
*^LinearMap n (Needle a) n
jg LinearMap n (Needle a) n
-> LinearMap n (Needle a) n -> LinearMap n (Needle a) n
forall v. AdditiveGroup v => v -> v -> v
^+^ n
Scalar (LinearMap n (Needle a) n)
c₂Scalar (LinearMap n (Needle a) n)
-> LinearMap n (Needle a) n -> LinearMap n (Needle a) n
forall v. VectorSpace v => Scalar v -> v -> v
*^LinearMap n (Needle a) n
jf
                                 in ( n
c
                                    , LinearMap n (Needle a) n
h'
                                    , \Norm n
εc -> let rε :: Scalar n
 = Norm n
εcNorm n -> n -> Scalar n
forall v.
(LSpace v, Floating (Scalar v)) =>
Seminorm v -> v -> Scalar v
|$|n
1
                                                 c₁worst :: n
c₁worst = n -> n
forall a. Floating a => a -> a
sqrt (n -> n) -> n -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₁² n -> n -> n
forall a. Num a => a -> a -> a
+ n -> n
forall a. Fractional a => a -> a
recip(n
1 n -> n -> n
forall a. Num a => a -> a -> a
+ n
c₂²n -> n -> n
forall a. Num a => a -> a -> a
*n
Scalar n
n -> Int -> n
forall a. Num a => a -> Int -> a
^Int
2)
                                                 c₂worst :: n
c₂worst = n -> n
forall a. Floating a => a -> a
sqrt (n -> n) -> n -> n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n
c₂² n -> n -> n
forall a. Num a => a -> a -> a
+ n -> n
forall a. Fractional a => a -> a
recip(n
1 n -> n -> n
forall a. Num a => a -> a -> a
+ n
c₁²n -> n -> n
forall a. Num a => a -> a -> a
*n
Scalar n
n -> Int -> n
forall a. Num a => a -> Int -> a
^Int
2)
                                             in Scalar (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm (n
2n -> n -> n
forall a. Num a => a -> a -> a
*n
Scalar n
) (LinearMap n (Needle a) n
-> LinearMap n (Needle a) n -> Norm (Needle a)
forall v w s.
(SimpleSpace v, HilbertSpace v, SimpleSpace w, Scalar v ~ s,
 Scalar w ~ s) =>
LinearMap s w v -> LinearMap s w v -> Norm w
dualCoCoProduct LinearMap n (Needle a) n
jf LinearMap n (Needle a) n
jg)
                                                Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall a. Semigroup a => a -> a -> a
<> Norm n -> Norm (Needle a)
devf (Scalar n -> Norm n -> Norm n
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm (n
2n -> n -> n
forall a. Num a => a -> a -> a
*n
c₂worst) Norm n
εc)
                                                Norm (Needle a) -> Norm (Needle a) -> Norm (Needle a)
forall a. Semigroup a => a -> a -> a
<> Norm n -> Norm (Needle a)
devg (Scalar n -> Norm n -> Norm n
forall v. LSpace v => Scalar v -> Norm v -> Norm v
scaleNorm (n
2n -> n -> n
forall a. Num a => a -> a -> a
*n
c₁worst) Norm n
εc)
                    -- TODO: add formal proof for this (or, if necessary, the correct form)
                                        )
                mulDi Differentiable n a n
f Differentiable n a n
g = Differentiable n a n
-> Differentiable n a n -> Differentiable n a n
mulDi (Differentiable n a n -> Differentiable n a n
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable n a n
f) (Differentiable n a n -> Differentiable n a n
forall s d c.
(LocallyScalable s d, LocallyScalable s c) =>
Differentiable s d c -> Differentiable s d c
genericiseDifferentiable Differentiable n a n
g)
                
  negate :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
negate = RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall v. AdditiveGroup v => v -> v
negateV
  abs :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
abs = ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable n -> (PreRegion n n, Maybe (Differentiable n n n))
absPW RWDiffable n n n
-> AgentVal (RWDiffable n) a n -> AgentVal (RWDiffable n) a n
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~)
   where absPW :: n -> (PreRegion n n, Maybe (Differentiable n n n))
absPW n
a₀
          | n
a₀n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<n
0       = (PreRegion n n
forall s. RealDimension s => PreRegion s s
negativePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Differentiable n n n
Differentiable (Scalar n) n n
desc)
          | Bool
otherwise  = (PreRegion n n
forall s. RealDimension s => PreRegion s s
positivePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Differentiable n n n
Differentiable (Scalar n) n n
asc)
         desc :: Differentiable (Scalar n) n n
desc = LinearMap (Scalar n) n n -> Differentiable (Scalar n) n n
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo (LinearMap (Scalar n) n n -> Differentiable (Scalar n) n n)
-> LinearMap (Scalar n) n n -> Differentiable (Scalar n) n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ LinearMap (Scalar n) n n -> LinearMap (Scalar n) n n
forall v. AdditiveGroup v => v -> v
negateV LinearMap (Scalar n) n n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
         asc :: Differentiable (Scalar n) n n
asc = LinearMap (Scalar n) n n -> Differentiable (Scalar n) n n
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
(x +> x) -> Differentiable s x x
actuallyLinearEndo LinearMap (Scalar n) n n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
  signum :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
signum = ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable n -> (PreRegion n n, Maybe (Differentiable n n n))
forall (a :: * -> * -> *) b x s (f :: * -> *) a.
(Object a b, Object a x, PointObject a x,
 LinearSpace (DualVector (Needle s)), LinearSpace (Needle s),
 ProjectableBoundary s, Empty (Boundary s),
 SemimanifoldWithBoundary (Needle s),
 SemimanifoldWithBoundary (Scalar (Needle s)), FiniteDimensional s,
 FiniteDimensional (DualVector s), SemiInner s,
 SemiInner (DualVector s), Num' s, Num' (Scalar (Needle s)), IEEE s,
 IEEE (Scalar s), InnerSpace s, InnerSpace (Scalar s), Atlas s,
 HasTrie (ChartIndex s), WellPointed a, Applicative f, Num a, Num x,
 Ord a, Interior s ~ s, DualVector s ~ s, Scalar s ~ s,
 Needle s ~ s) =>
a -> (PreRegion s s, f (a b x))
sgnPW RWDiffable n n n
-> AgentVal (RWDiffable n) a n -> AgentVal (RWDiffable n) a n
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~)
   where sgnPW :: a -> (PreRegion s s, f (a b x))
sgnPW a
a₀
          | a
a₀a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<a
0       = (PreRegion s s
forall s. RealDimension s => PreRegion s s
negativePreRegion, a b x -> f (a b x)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (x -> a b x
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const (x -> a b x) -> x -> a b x
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ -x
1))
          | Bool
otherwise  = (PreRegion s s
forall s. RealDimension s => PreRegion s s
positivePreRegion, a b x -> f (a b x)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (x -> a b x
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const x
1))

instance  n a . ( RealDimension n, Object (Differentiable n) a, SimpleSpace (Needle a) )
            => Fractional (RWDfblFuncValue n a n) where
  fromRational :: Rational -> RWDfblFuncValue n a n
fromRational Rational
i = n -> RWDfblFuncValue n a n
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point (n -> RWDfblFuncValue n a n) -> n -> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Rational -> n
forall a. Fractional a => Rational -> a
fromRational Rational
i
  recip :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
recip = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
a₀ -> if n
a₀n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<n
0
                                    then (PreRegion n n
forall s. RealDimension s => PreRegion s s
negativePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
negp))
                                    else (PreRegion n n
forall s. RealDimension s => PreRegion s s
positivePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
posp))
   where negp :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
negp Scalar (k a a)
x = (Scalar (k a a)
x'¹, (- Scalar (k a a)
x'¹Scalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2) Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"1/"String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ)
                 -- ε = 1/x − δ/x² − 1/(x+δ)
                 -- ε·x + ε·δ = 1 + δ/x − δ/x − δ²/x² − 1
                 --           = -δ²/x²
                 -- 0 = δ² + ε·x²·δ + ε·x³
                 -- δ = let mph = -ε·x²/2 in mph + sqrt (mph² − ε·x³)
          where δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = let mph :: Scalar (k a a)
mph = -Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
2
                          δ₀ :: Scalar (k a a)
δ₀ = Scalar (k a a)
mph Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt (Scalar (k a a)
mphScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
3)
                      in if Scalar (k a a)
δ₀ Scalar (k a a) -> Scalar (k a a) -> Bool
forall a. Ord a => a -> a -> Bool
> Scalar (k a a)
0
                           then Scalar (k a a)
δ₀
                           else - Scalar (k a a)
x -- numerical underflow of εx³ vs mph
                                    --  ≡ ε*x^3 / (2*mph) (Taylor-expansion of the root)
                x'¹ :: Scalar (k a a)
x'¹ = Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip Scalar (k a a)
x
         posp :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
posp Scalar (k a a)
x = (Scalar (k a a)
x'¹, (- Scalar (k a a)
x'¹Scalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2) Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"1/"String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ)
          where δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = let mph :: Scalar (k a a)
mph = Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
2
                          δ₀ :: Scalar (k a a)
δ₀ = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt (Scalar (k a a)
mphScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
3) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
mph
                      in if Scalar (k a a)
δ₀Scalar (k a a) -> Scalar (k a a) -> Bool
forall a. Ord a => a -> a -> Bool
>Scalar (k a a)
0 then Scalar (k a a)
δ₀ else Scalar (k a a)
x
                x'¹ :: Scalar (k a a)
x'¹ = Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip Scalar (k a a)
x




instance  n a . ( RealDimension n, Object (Differentiable n) a, SimpleSpace (Needle a) )
            => Floating (RWDfblFuncValue n a n) where
  pi :: RWDfblFuncValue n a n
pi = n -> RWDfblFuncValue n a n
forall (p :: * -> * -> *) (k :: * -> * -> *) a x.
(PointAgent p k a x, Object k a, Object k x) =>
x -> p a x
point n
forall a. Floating a => a
pi
  
  exp :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
exp = (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c c' v v' ε.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c, Object (Differentiable s) c',
 v ~ Needle c, v' ~ Needle c', SimpleSpace v, ε ~ Norm v,
 ε ~ Norm v') =>
(c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc
    ((n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> let ex :: n
ex = n -> n
forall a. Floating a => a -> a
exp n
x
            in if n
exn -> n -> n
forall a. Num a => a -> a -> a
*n
2 n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
ex  -- numerical trouble...
                then if n
xn -> n -> Bool
forall a. Ord a => a -> a -> Bool
<n
0 then ( n
0, LinearMap (Scalar n) n n
forall v. AdditiveGroup v => v
zeroV, String -> (n -> n) -> LinDevPropag n n
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"exp "String -> String -> String
forall a. [a] -> [a] -> [a]
++n -> String
forall r. RealFloat r => r -> String
showℝ n
x) ((n -> n) -> Norm n -> Norm n) -> (n -> n) -> Norm n -> Norm n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
ε -> n -> n
forall a. Floating a => a -> a
log n
ε n -> n -> n
forall a. Num a => a -> a -> a
- n
x )
                            else ( n
ex, n
Scalar (LinearMap (Scalar n) n n)
exScalar (LinearMap (Scalar n) n n)
-> LinearMap (Scalar n) n n -> LinearMap (Scalar n) n n
forall v. VectorSpace v => Scalar v -> v -> v
*^LinearMap (Scalar n) n n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id
                                 , String -> (n -> n) -> LinDevPropag n n
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"exp "String -> String -> String
forall a. [a] -> [a] -> [a]
++n -> String
forall r. RealFloat r => r -> String
showℝ n
x) ((n -> n) -> Norm n -> Norm n) -> (n -> n) -> Norm n -> Norm n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
_ -> n
1e-300 :: n )
                else ( n
ex, n
Scalar (LinearMap (Scalar n) n n)
ex Scalar (LinearMap (Scalar n) n n)
-> LinearMap (Scalar n) n n -> LinearMap (Scalar n) n n
forall v. VectorSpace v => Scalar v -> v -> v
*^ LinearMap (Scalar n) n n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String -> (n -> n) -> LinDevPropag n n
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"exp "String -> String -> String
forall a. [a] -> [a] -> [a]
++n -> String
forall r. RealFloat r => r -> String
showℝ n
x)
                          ((n -> n) -> Norm n -> Norm n) -> (n -> n) -> Norm n -> Norm n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
ε -> case n -> n
forall a. Floating a => a -> a
acosh(n
εn -> n -> n
forall a. Fractional a => a -> a -> a
/(n
2n -> n -> n
forall a. Num a => a -> a -> a
*n
ex) n -> n -> n
forall a. Num a => a -> a -> a
+ n
1) of
                                    n
δ | n
δn -> n -> Bool
forall a. Eq a => a -> a -> Bool
==n
δ      -> n
δ
                                      | Bool
otherwise -> n -> n
forall a. Floating a => a -> a
log n
ε n -> n -> n
forall a. Num a => a -> a -> a
- n
x )
                 -- ε = e^(x+δ) − eˣ − eˣ·δ 
                 --   = eˣ·(e^δ − 1 − δ) 
                 --   ≤ eˣ · (e^δ − 1 + e^(-δ) − 1)
                 --   = eˣ · 2·(cosh(δ) − 1)
                 -- cosh(δ) ≥ ε/(2·eˣ) + 1
                 -- δ ≥ acosh(ε/(2·eˣ) + 1)
  log :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
log = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if n
xn -> n -> Bool
forall a. Ord a => a -> a -> Bool
>n
0
                                  then (PreRegion n n
forall s. RealDimension s => PreRegion s s
positivePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
lnPosR))
                                  else (PreRegion n n
forall s. RealDimension s => PreRegion s s
negativePreRegion, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
   where lnPosR :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
lnPosR Scalar (k a a)
x = ( Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
log Scalar (k a a)
x, Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip Scalar (k a a)
x Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"log "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) ((Scalar (k a a) -> Scalar (k a a))
 -> Norm (Needle (Scalar (k a a)))
 -> Norm (Needle (Scalar (k a a))))
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (k a a)
ε -> Scalar (k a a)
x Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
exp(-Scalar (k a a)
ε)) )
                 -- ε = ln x + (-δ)/x − ln(x−δ)
                 --   = ln (x / ((x−δ) · exp(δ/x)))
                 -- x/e^ε = (x−δ) · exp(δ/x)
                 -- let γ = δ/x ∈ [0,1[
                 -- exp(-ε) = (1−γ) · e^γ
                 --         ≥ (1−γ) · (1+γ)
                 --         = 1 − γ²
                 -- γ ≥ sqrt(1 − exp(-ε)) 
                 -- δ ≥ x · sqrt(1 − exp(-ε)) 
                    
  sqrt :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
sqrt = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if n
xn -> n -> Bool
forall a. Ord a => a -> a -> Bool
>n
0
                                   then (PreRegion n n
forall s. RealDimension s => PreRegion s s
positivePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
sqrtPosR))
                                   else (PreRegion n n
forall s. RealDimension s => PreRegion s s
negativePreRegion, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
   where sqrtPosR :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
sqrtPosR Scalar (k a a)
x = ( Scalar (k a a)
sx, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id k a a -> Scalar (k a a) -> k a a
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ (Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
sx), String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"sqrt "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) ((Scalar (k a a) -> Scalar (k a a))
 -> Norm (Needle (Scalar (k a a)))
 -> Norm (Needle (Scalar (k a a))))
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
                          \Scalar (k a a)
ε -> Scalar (k a a)
2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* (Scalar (k a a)
s2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
sxScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
3 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
signum (Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
-Scalar (k a a)
sx) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
sx Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
ε) )
          where sx :: Scalar (k a a)
sx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
x; s2 :: Scalar (k a a)
s2 = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
2
                 -- Exact inverse of O(δ²) remainder.
  
  sin :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
sin = (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c c' v v' ε.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c, Object (Differentiable s) c',
 v ~ Needle c, v' ~ Needle c', SimpleSpace v, ε ~ Norm v,
 ε ~ Norm v') =>
(c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
sinDfb
   where sinDfb :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
sinDfb Scalar (k a a)
x = ( Scalar (k a a)
sx, Scalar (k a a)
cx Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"sin "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where sx :: Scalar (k a a)
sx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sin Scalar (k a a)
x; cx :: Scalar (k a a)
cx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
cos Scalar (k a a)
x
                sx² :: Scalar (k a a)
sx² = Scalar (k a a)
sxScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2; cx² :: Scalar (k a a)
cx² = Scalar (k a a)
cxScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2
                sx' :: Scalar (k a a)
sx' = Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
sx; cx' :: Scalar (k a a)
cx' = Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
cx
                sx'³ :: Scalar (k a a)
sx'³ = Scalar (k a a)
sx'Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
sx²; cx⁴ :: Scalar (k a a)
cx⁴ = Scalar (k a a)
cx²Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
cx²
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = (Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*(Scalar (k a a)
1.8 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
εScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a)
cx' Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ (Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+Scalar (k a a)
40Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
cx⁴)Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
ε)) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
σ₃³Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
sx'³)Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a -> a
**(Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
3) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
σ₃Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
sx'
                        Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
σ₂Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a)
σ₂Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+Scalar (k a a)
cx²)
                    -- Carefully fine-tuned to give everywhere a good and safe bound.
                    -- The third root makes it pretty slow too, but since tight
                    -- deviation bounds can dramatically reduce the number of evaluations
                    -- needed in the first place, this is probably worthwhile.
                σ₂ :: Scalar (k a a)
σ₂ = Scalar (k a a)
1.4; σ₃ :: Scalar (k a a)
σ₃ = Scalar (k a a)
1.75; σ₃³ :: Scalar (k a a)
σ₃³ = Scalar (k a a)
σ₃Scalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
3
                    -- Safety margins for overlap between quadratic and cubic model
                    -- (these aren't naturally compatible to be used both together)
                      
  cos :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
cos = RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Floating a => a -> a
sin (RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (Differentiable n n n -> RWDiffable n n n
forall s a b. Differentiable s a b -> RWDiffable s a b
globalDiffable' (n -> (n +> Needle n) -> Differentiable n n n
forall s x.
(Object (Affine s) x, Object (LinearMap s) x) =>
x -> (x +> Needle x) -> Differentiable s x x
actuallyAffineEndo (n
forall a. Floating a => a
pin -> n -> n
forall a. Fractional a => a -> a -> a
/n
2) n +> Needle n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id) RWDiffable n n n
-> AgentVal (RWDiffable n) a n -> AgentVal (RWDiffable n) a n
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~)
  
  sinh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
sinh RWDfblFuncValue n a n
x = (RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Floating a => a -> a
exp RWDfblFuncValue n a n
x RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Num a => a -> a -> a
- RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Floating a => a -> a
exp (-RWDfblFuncValue n a n
x))RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Fractional a => a -> a -> a
/RWDfblFuncValue n a n
2
    {- = grwDfblFnValsFunc sinhDfb
   where sinhDfb x = ( sx, cx *^ idL, unsafe_dev_ε_δ δ )
          where sx = sinh x; cx = cosh x
                δ ε = undefined -}
                 -- ε = sinh x + δ · cosh x − sinh(x+δ)
                 --   = ½ · ( eˣ − e⁻ˣ + δ · (eˣ + e⁻ˣ) − exp(x+δ) + exp(-x−δ) )
                 --                  = ½·e⁻ˣ · ( e²ˣ − 1 + δ · (e²ˣ + 1) − e²ˣ·e^δ + e^-δ )
                 --   = ½ · ( eˣ − e⁻ˣ + δ · (eˣ + e⁻ˣ) − exp(x+δ) + exp(-x−δ) )
  cosh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
cosh RWDfblFuncValue n a n
x = (RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Floating a => a -> a
exp RWDfblFuncValue n a n
x RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Num a => a -> a -> a
+ RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Floating a => a -> a
exp (-RWDfblFuncValue n a n
x))RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Fractional a => a -> a -> a
/RWDfblFuncValue n a n
2
  
  tanh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
tanh = (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c c' v v' ε.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c, Object (Differentiable s) c',
 v ~ Needle c, v' ~ Needle c', SimpleSpace v, ε ~ Norm v,
 ε ~ Norm v') =>
(c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
tanhDfb
   where tanhDfb :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
tanhDfb Scalar (k a a)
x = ( Scalar (k a a)
tnhx, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id k a a -> Scalar (k a a) -> k a a
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ (Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
cosh Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2), String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"tan "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where tnhx :: Scalar (k a a)
tnhx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
tanh Scalar (k a a)
x
                c :: Scalar (k a a)
c = (Scalar (k a a)
tnhxScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
forall a. Floating a => a
pi)Scalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2
                p :: Scalar (k a a)
p = Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
xScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
forall a. Floating a => a
pi)
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = Scalar (k a a)
p Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* (Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
c)
                  -- copied from 'atan' definition. Empirically works safely, in fact
                  -- with quite a big margin. TODO: find a tighter definition.

  atan :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
atan = (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c c' v v' ε.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c, Object (Differentiable s) c',
 v ~ Needle c, v' ~ Needle c', SimpleSpace v, ε ~ Norm v,
 ε ~ Norm v') =>
(c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
atanDfb
   where atanDfb :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
atanDfb Scalar (k a a)
x = ( Scalar (k a a)
atnx, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id k a a -> Scalar (k a a) -> k a a
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ (Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2), String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"atan "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where atnx :: Scalar (k a a)
atnx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
atan Scalar (k a a)
x
                c :: Scalar (k a a)
c = (Scalar (k a a)
atnxScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
forall a. Floating a => a
pi)Scalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2
                p :: Scalar (k a a)
p = Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
xScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a)
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
forall a. Floating a => a
pi)
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = Scalar (k a a)
p Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* (Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
c)
                 -- Semi-empirically obtained: with the epsEst helper,
                 -- it is observed that this function is (for xc≥0) a lower bound
                 -- to the arctangent. The growth of the p coefficient makes sense
                 -- and holds for arbitrarily large xc, because those move us linearly
                 -- away from the only place where the function is not virtually constant
                 -- (around 0).
   
  asin :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
asin = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< (-n
1)   -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo (-n
1), Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)  
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
1      -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
1, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                  | Bool
otherwise  -> ((n, n) -> PreRegion n n
forall s. RealDimension s => (s, s) -> PreRegion s s
intervalPreRegion (-n
1,n
1), Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
asinDefdR))
   where asinDefdR :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
asinDefdR Scalar (k a a)
x = ( Scalar (k a a)
asinx, Scalar (k a a)
asin'x Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"asin "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where asinx :: Scalar (k a a)
asinx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
asin Scalar (k a a)
x; asin'x :: Scalar (k a a)
asin'x = Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip (Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt (Scalar (k a a) -> Scalar (k a a))
-> Scalar (k a a) -> Scalar (k a a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2)
                c :: Scalar (k a a)
c = Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2 
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
c
                 -- Empirical, with epsEst upper bound.

  acos :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
acos = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< (-n
1)   -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo (-n
1), Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)  
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
1      -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
1, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                  | Bool
otherwise  -> ((n, n) -> PreRegion n n
forall s. RealDimension s => (s, s) -> PreRegion s s
intervalPreRegion (-n
1,n
1), Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
acosDefdR))
   where acosDefdR :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
acosDefdR Scalar (k a a)
x = ( Scalar (k a a)
acosx, Scalar (k a a)
acos'x Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"acos "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where acosx :: Scalar (k a a)
acosx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
acos Scalar (k a a)
x; acos'x :: Scalar (k a a)
acos'x = - Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip (Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt (Scalar (k a a) -> Scalar (k a a))
-> Scalar (k a a) -> Scalar (k a a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2)
                c :: Scalar (k a a)
c = Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
ε Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
c -- Like for asin – it's just a translation/reflection.

  asinh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
asinh = (n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n))
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall s d c c' v v' ε.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c, Object (Differentiable s) c',
 v ~ Needle c, v' ~ Needle c', SimpleSpace v, ε ~ Norm v,
 ε ~ Norm v') =>
(c' -> (c, v' +> v, ε -> ε))
-> RWDfblFuncValue s d c' -> RWDfblFuncValue s d c
grwDfblFnValsFunc n -> (n, LinearMap (Scalar n) n n, Norm n -> Norm n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
asinhDfb
   where asinhDfb :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
asinhDfb Scalar (k a a)
x = ( Scalar (k a a)
asinhx, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id k a a -> Scalar (k a a) -> k a a
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2), String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"asinh "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where asinhx :: Scalar (k a a)
asinhx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
asinh Scalar (k a a)
x
                δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
x Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt((Scalar (k a a)
1 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
exp(-Scalar (k a a)
ε))Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
0.8 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
εScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a)
3Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
x Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a)
1)) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/(Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
xScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+Scalar (k a a)
0.5))
                 -- Empirical, modified from log function (the area hyperbolic sine
                 -- resembles two logarithmic lobes), with epsEst-checked lower bound.
  
  acosh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
acosh = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if n
xn -> n -> Bool
forall a. Ord a => a -> a -> Bool
>n
1
                                   then (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
1, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
acoshDfb))
                                   else (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo n
1, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
   where acoshDfb :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
acoshDfb Scalar (k a a)
x = ( Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
acosh Scalar (k a a)
x, k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id k a a -> Scalar (k a a) -> k a a
forall v s.
(VectorSpace v, s ~ Scalar v, Fractional s) =>
v -> s -> v
^/ Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
1), String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"acosh "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a)
δ )
          where δ :: Scalar (k a a) -> Scalar (k a a)
δ Scalar (k a a)
ε = (Scalar (k a a)
2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
- Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
x) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* (Scalar (k a a)
s2 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
sxScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
3 Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
s2) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
+ Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
signum (Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*Scalar (k a a)
s2Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
-Scalar (k a a)
sx) Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
sx Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
* Scalar (k a a)
εScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a -> a
/Scalar (k a a)
s2) 
                sx :: Scalar (k a a)
sx = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a)
xScalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
-Scalar (k a a)
1)
                s2 :: Scalar (k a a)
s2 = Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt Scalar (k a a)
2
                 -- Empirical, modified from sqrt function – the area hyperbolic cosine
                 -- strongly resembles \x -> sqrt(2 · (x-1)).
                    
  atanh :: RWDfblFuncValue n a n -> RWDfblFuncValue n a n
atanh = RWDiffable n n n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a b c s.
(RealDimension s, Object (Differentiable s) a,
 Object (Differentiable s) b, Object (Differentiable s) c) =>
RWDiffable s b c -> RWDfblFuncValue s a b -> RWDfblFuncValue s a c
postCompRW (RWDiffable n n n
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
    -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDfblFuncValue n a n
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x -> if
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< (-n
1)   -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo (-n
1), Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)  
                  | n
x n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
1      -> (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
1, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
                  | Bool
otherwise  -> ((n, n) -> PreRegion n n
forall s. RealDimension s => (s, s) -> PreRegion s s
intervalPreRegion (-n
1,n
1), Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure ((n -> (n, Needle n +> Needle n, LinDevPropag n n))
-> Differentiable n n n
forall d c s.
(d -> (c, Needle d +> Needle c, LinDevPropag d c))
-> Differentiable s d c
Differentiable n -> (n, Needle n +> Needle n, LinDevPropag n n)
forall (k :: * -> * -> *) a.
(Object k a, HasTrie (ChartIndex (Scalar (k a a))), Category k,
 Empty (Boundary (Scalar (k a a))),
 Num' (Scalar (Needle (Scalar (k a a)))), Num' (Scalar (k a a)),
 Atlas (Scalar (k a a)), VectorSpace (k a a),
 IEEE (Scalar (Scalar (k a a))), IEEE (Scalar (k a a)),
 InnerSpace (Scalar (Scalar (k a a))), InnerSpace (Scalar (k a a)),
 FiniteDimensional (DualVector (Scalar (k a a))),
 FiniteDimensional (Scalar (k a a)),
 SemiInner (DualVector (Scalar (k a a))),
 SemiInner (Scalar (k a a)), ProjectableBoundary (Scalar (k a a)),
 LinearSpace (DualVector (Needle (Scalar (k a a)))),
 LinearSpace (Needle (Scalar (k a a))),
 SemimanifoldWithBoundary (Scalar (Needle (Scalar (k a a)))),
 SemimanifoldWithBoundary (Needle (Scalar (k a a))),
 Needle (Scalar (k a a)) ~ Scalar (k a a),
 Scalar (Scalar (k a a)) ~ Scalar (k a a),
 Interior (Scalar (k a a)) ~ Scalar (k a a),
 DualVector (Scalar (k a a)) ~ Scalar (k a a)) =>
Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
atnhDefdR))
   where atnhDefdR :: Scalar (k a a)
-> (Scalar (k a a), k a a,
    Norm (Needle (Scalar (k a a))) -> Norm (Needle (Scalar (k a a))))
atnhDefdR Scalar (k a a)
x = ( Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
atanh Scalar (k a a)
x, Scalar (k a a) -> Scalar (k a a)
forall a. Fractional a => a -> a
recip(Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
-Scalar (k a a)
xScalar (k a a) -> Int -> Scalar (k a a)
forall a. Num a => a -> Int -> a
^Int
2) Scalar (k a a) -> k a a -> k a a
forall v. VectorSpace v => Scalar v -> v -> v
*^ k a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id, String
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall a. RealDimension a => String -> (a -> a) -> LinDevPropag a a
unsafe_dev_ε_δ(String
"atanh "String -> String -> String
forall a. [a] -> [a] -> [a]
++Scalar (k a a) -> String
forall r. RealFloat r => r -> String
showℝ Scalar (k a a)
x) ((Scalar (k a a) -> Scalar (k a a))
 -> Norm (Needle (Scalar (k a a)))
 -> Norm (Needle (Scalar (k a a))))
-> (Scalar (k a a) -> Scalar (k a a))
-> Norm (Needle (Scalar (k a a)))
-> Norm (Needle (Scalar (k a a)))
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \Scalar (k a a)
ε -> Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
sqrt(Scalar (k a a) -> Scalar (k a a)
forall a. Floating a => a -> a
tanh Scalar (k a a)
ε)Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
*(Scalar (k a a)
1Scalar (k a a) -> Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a -> a
-Scalar (k a a) -> Scalar (k a a)
forall a. Num a => a -> a
abs Scalar (k a a)
x) )
                 -- Empirical, with epsEst upper bound.
  



-- $definitionRegionOps
-- Because the agents of 'RWDiffable' aren't really values in /Hask/, you can't use
-- the standard comparison operators on them, nor the built-in syntax of guards
-- or if-statements.
-- 
-- However, because this category allows functions to be undefined in some region,
-- such decisions can be faked quite well: '?->' restricts a function to
-- some region, by simply marking it undefined outside, and '?|:' replaces these
-- regions with values from another function.
-- 
-- Example: define a function that is compactly supported on the interval ]-1,1[,
-- i.e. exactly zero everywhere outside.
--
-- @
-- Graphics.Dynamic.Plot.R2> plotWindow [fnPlot (\\x -> -1 '?<' x '?<' 1 '?->' cos (x*pi/2)^2 '?|:' 0)]
-- @
-- 
-- <<images/examples/DiffableFunction-plots/Hann-window.png>>
-- 
-- Note that it may not be necessary to restrict explicitly: for instance if a
-- square root appears somewhere in an expression, then the expression is automatically
-- restricted so that the root has a positive argument!
-- 
-- @
-- Graphics.Dynamic.Plot.R2> plotWindow [fnPlot (\\x -> sqrt x '?|:' -sqrt (-x))]
-- @
-- 
-- <<images/examples/DiffableFunction-plots/safe-sqrt.png>>
  
infixr 4 ?->
-- | Require the LHS to be defined before considering the RHS as result.
--   This works analogously to the standard `Control.Applicative.Applicative` method
-- 
--   @
--   ('Control.Applicative.*>') :: Maybe a -> Maybe b -> Maybe b
--   Just _ 'Control.Applicative.*>' a = a
--   _      'Control.Applicative.*>' a = Nothing
--   @
(?->) :: ( RealDimension n, Object (Differentiable n) a, Object (Differentiable n) b
         , Object (Differentiable n) c )
      => RWDfblFuncValue n c a -> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
ConstRWDFV a
_ ?-> :: RWDfblFuncValue n c a
-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
?-> RWDfblFuncValue n c b
f = RWDfblFuncValue n c b
f
RWDfblFuncValue n c a
RWDFV_IdVar ?-> RWDfblFuncValue n c b
f = RWDfblFuncValue n c b
f
GenericRWDFV (RWDiffable c -> (PreRegion n c, Maybe (Differentiable n c a))
r) ?-> ConstRWDFV b
c = RWDiffable n c b -> RWDfblFuncValue n c b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV ((c -> (PreRegion n c, Maybe (Differentiable n c b)))
-> RWDiffable n c b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable c -> (PreRegion n c, Maybe (Differentiable n c b))
s)
 where s :: c -> (PreRegion n c, Maybe (Differentiable n c b))
s c
x₀ = case c -> (PreRegion n c, Maybe (Differentiable n c a))
r c
x₀ of
                (PreRegion n c
rd, Just Differentiable n c a
q)  -> (PreRegion n c
rd, Differentiable n c b -> Maybe (Differentiable n c b)
forall (m :: * -> *) a. Monad m (->) => a -> m a
return (Differentiable n c b -> Maybe (Differentiable n c b))
-> Differentiable n c b -> Maybe (Differentiable n c b)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b -> Differentiable n c b
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const b
c)
                (PreRegion n c
rd, Maybe (Differentiable n c a)
Nothing) -> (PreRegion n c
rd, Maybe (Differentiable n c b)
forall (f :: * -> *) a. Alternative f => f a
empty)
GenericRWDFV (RWDiffable c -> (PreRegion n c, Maybe (Differentiable n c a))
f) ?-> GenericRWDFV (RWDiffable c -> (PreRegion n c, Maybe (Differentiable n c b))
g) = RWDiffable n c b -> RWDfblFuncValue n c b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV ((c -> (PreRegion n c, Maybe (Differentiable n c b)))
-> RWDiffable n c b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable c -> (PreRegion n c, Maybe (Differentiable n c b))
h)
 where h :: c -> (PreRegion n c, Maybe (Differentiable n c b))
h c
x₀ = case c -> (PreRegion n c, Maybe (Differentiable n c a))
f c
x₀ of
                (PreRegion n c
rf, Just Differentiable n c a
_) | (PreRegion n c
rg, Maybe (Differentiable n c b)
q) <- c -> (PreRegion n c, Maybe (Differentiable n c b))
g c
x₀
                        -> (PreRegion n c -> PreRegion n c -> PreRegion n c
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion n c
rf PreRegion n c
rg, Maybe (Differentiable n c b)
q)
                (PreRegion n c
rf, Maybe (Differentiable n c a)
Nothing) -> (PreRegion n c
rf, Maybe (Differentiable n c b)
forall (f :: * -> *) a. Alternative f => f a
empty)
RWDfblFuncValue n c a
c ?-> RWDfblFuncValue n c b
f = RWDfblFuncValue n c a
c RWDfblFuncValue n c a
-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
forall n a b c.
(RealDimension n, Object (Differentiable n) a,
 Object (Differentiable n) b, Object (Differentiable n) c) =>
RWDfblFuncValue n c a
-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
?-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue n c b
f

positiveRegionalId :: RealDimension n => RWDiffable n n n
positiveRegionalId :: RWDiffable n n n
positiveRegionalId = (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable n n n)))
 -> RWDiffable n n n)
-> (n -> (PreRegion n n, Maybe (Differentiable n n n)))
-> RWDiffable n n n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ \n
x₀ ->
       if n
x₀ n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
0 then (PreRegion n n
forall s. RealDimension s => PreRegion s s
positivePreRegion, Differentiable n n n -> Maybe (Differentiable n n n)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable n n n -> Maybe (Differentiable n n n))
-> (Affine n n n -> Differentiable n n n)
-> Affine n n n
-> Maybe (Differentiable n n n)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. DiffableEndoProof n n -> Affine n n n -> Differentiable n n n
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof n n
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine n n n -> Maybe (Differentiable n n n))
-> Affine n n n -> Maybe (Differentiable n n n)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Affine n n n
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
                 else (PreRegion n n
forall s. RealDimension s => PreRegion s s
negativePreRegion, Maybe (Differentiable n n n)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)

infixl 5 ?> , ?<
-- | Return the RHS, if it is less than the LHS.
--   (Really the purpose is just to compare the values, but returning one of them
--   allows chaining of comparison operators like in Python.)
--   Note that less-than comparison is <http://www.paultaylor.eu/ASD/ equivalent>
--   to less-or-equal comparison, because there is no such thing as equality.
(?>) :: ( RealDimension n, Object (Differentiable n) a, SimpleSpace (Needle a) )
           => RWDfblFuncValue n a n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
RWDfblFuncValue n a n
a ?> :: RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
?> RWDfblFuncValue n a n
b = (RWDiffable n n n
forall n. RealDimension n => RWDiffable n n n
positiveRegionalId RWDiffable n n n
-> AgentVal (RWDiffable n) a n -> AgentVal (RWDiffable n) a n
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~ RWDfblFuncValue n a n
aRWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Num a => a -> a -> a
-RWDfblFuncValue n a n
b) RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall n a b c.
(RealDimension n, Object (Differentiable n) a,
 Object (Differentiable n) b, Object (Differentiable n) c) =>
RWDfblFuncValue n c a
-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
?-> RWDfblFuncValue n a n
b

-- | Return the RHS, if it is greater than the LHS.
(?<) :: ( RealDimension n, Object (Differentiable n) a, SimpleSpace (Needle a) )
           => RWDfblFuncValue n a n -> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
ConstRWDFV n
a ?< :: RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
?< RWDfblFuncValue n a n
RWDFV_IdVar = RWDiffable a a a -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable a a a -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable a a a)))
    -> RWDiffable a a a)
-> (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDiffable a a a
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable a a a)))
 -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
       \n
x₀ -> if n
a n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
x₀ then ( n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
a
                             , Differentiable a a a -> Maybe (Differentiable a a a)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable a a a -> Maybe (Differentiable a a a))
-> (Affine a a a -> Differentiable a a a)
-> Affine a a a
-> Maybe (Differentiable a a a)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. DiffableEndoProof a a -> Affine a a a -> Differentiable a a a
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof a a
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine a a a -> Maybe (Differentiable a a a))
-> Affine a a a -> Maybe (Differentiable a a a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Affine a a a
forall κ (k :: κ -> κ -> *) (a :: κ).
(Category k, Object k a) =>
k a a
id)
                        else (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo n
a, Maybe (Differentiable a a a)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
RWDfblFuncValue n a n
RWDFV_IdVar ?< ConstRWDFV n
a = RWDiffable a a a -> RWDfblFuncValue n a n
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV (RWDiffable a a a -> RWDfblFuncValue n a n)
-> ((n -> (PreRegion n n, Maybe (Differentiable a a a)))
    -> RWDiffable a a a)
-> (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDfblFuncValue n a n
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDiffable a a a
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable ((n -> (PreRegion n n, Maybe (Differentiable a a a)))
 -> RWDfblFuncValue n a n)
-> (n -> (PreRegion n n, Maybe (Differentiable a a a)))
-> RWDfblFuncValue n a n
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$
       \n
x₀ -> if n
x₀ n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
a then ( n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionFromMinInfTo n
a
                             , Differentiable a a a -> Maybe (Differentiable a a a)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure (Differentiable a a a -> Maybe (Differentiable a a a))
-> (Affine a a n -> Differentiable a a a)
-> Affine a a n
-> Maybe (Differentiable a a a)
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. DiffableEndoProof a a -> Affine a a a -> Differentiable a a a
forall s d c.
(Object (Affine s) d, Object (Affine s) c) =>
DiffableEndoProof d c -> Affine s d c -> Differentiable s d c
AffinDiffable DiffableEndoProof a a
forall d. DiffableEndoProof d d
IsDiffableEndo (Affine a a n -> Maybe (Differentiable a a a))
-> Affine a a n -> Maybe (Differentiable a a a)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ n -> Affine a a n
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const n
a)
                        else (n -> PreRegion n n
forall s. RealDimension s => s -> PreRegion s s
preRegionToInfFrom n
a, Maybe (Differentiable a a a)
forall s d c. Maybe (Differentiable s d c)
notDefinedHere)
RWDfblFuncValue n a n
a ?< RWDfblFuncValue n a n
b = (RWDiffable n n n
forall n. RealDimension n => RWDiffable n n n
positiveRegionalId RWDiffable n n n
-> AgentVal (RWDiffable n) a n -> AgentVal (RWDiffable n) a n
forall (k :: * -> * -> *) a b c.
(HasAgent k, Object k a, Object k b, Object k c) =>
k b c -> AgentVal k a b -> AgentVal k a c
$~ RWDfblFuncValue n a n
bRWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall a. Num a => a -> a -> a
-RWDfblFuncValue n a n
a) RWDfblFuncValue n a n
-> RWDfblFuncValue n a n -> RWDfblFuncValue n a n
forall n a b c.
(RealDimension n, Object (Differentiable n) a,
 Object (Differentiable n) b, Object (Differentiable n) c) =>
RWDfblFuncValue n c a
-> RWDfblFuncValue n c b -> RWDfblFuncValue n c b
?-> RWDfblFuncValue n a n
b

infixl 3 ?|:
-- | Try the LHS, if it is undefined use the RHS. This works analogously to
--   the standard `Control.Applicative.Alternative` method
-- 
--   @
--   ('Control.Applicative.<|>') :: Maybe a -> Maybe a -> Maybe a
--   Just x 'Control.Applicative.<|>' _ = Just x
--   _      'Control.Applicative.<|>' a = a
--   @
-- 
--  Basically a weaker and agent-ised version of 'backupRegions'.
(?|:) :: ( RealDimension n, Object (Differentiable n) a, Object (Differentiable n) b )
      => RWDfblFuncValue n a b -> RWDfblFuncValue n a b -> RWDfblFuncValue n a b
ConstRWDFV b
c ?|: :: RWDfblFuncValue n a b
-> RWDfblFuncValue n a b -> RWDfblFuncValue n a b
?|: RWDfblFuncValue n a b
_ = b -> RWDfblFuncValue n a b
forall c s d. c -> RWDfblFuncValue s d c
ConstRWDFV b
c
RWDfblFuncValue n a b
RWDFV_IdVar ?|: RWDfblFuncValue n a b
_ = RWDfblFuncValue n a b
forall s c. RWDfblFuncValue s c c
RWDFV_IdVar
GenericRWDFV (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
f) ?|: ConstRWDFV b
c = RWDiffable n a b -> RWDfblFuncValue n a b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV ((a -> (PreRegion n a, Maybe (Differentiable n a b)))
-> RWDiffable n a b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
h)
 where h :: a -> (PreRegion n a, Maybe (Differentiable n a b))
h a
x₀ = case a -> (PreRegion n a, Maybe (Differentiable n a b))
f a
x₀ of
                (PreRegion n a
rd, Just Differentiable n a b
q) -> (PreRegion n a
rd, Differentiable n a b -> Maybe (Differentiable n a b)
forall a. a -> Maybe a
Just Differentiable n a b
q)
                (PreRegion n a
rd, Maybe (Differentiable n a b)
Nothing) -> (PreRegion n a
rd, Differentiable n a b -> Maybe (Differentiable n a b)
forall a. a -> Maybe a
Just (Differentiable n a b -> Maybe (Differentiable n a b))
-> Differentiable n a b -> Maybe (Differentiable n a b)
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ b -> Differentiable n a b
forall (a :: * -> * -> *) b x.
(WellPointed a, Object a b, ObjectPoint a x) =>
x -> a b x
const b
c)
GenericRWDFV (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
f) ?|: GenericRWDFV (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
g) = RWDiffable n a b -> RWDfblFuncValue n a b
forall s d c. RWDiffable s d c -> RWDfblFuncValue s d c
GenericRWDFV ((a -> (PreRegion n a, Maybe (Differentiable n a b)))
-> RWDiffable n a b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
h)
 where h :: a -> (PreRegion n a, Maybe (Differentiable n a b))
h a
x₀ = case a -> (PreRegion n a, Maybe (Differentiable n a b))
f a
x₀ of
                (PreRegion n a
rf, Just Differentiable n a b
q) -> (PreRegion n a
rf, Differentiable n a b -> Maybe (Differentiable n a b)
forall (f :: * -> *) (r :: * -> * -> *) (t :: * -> * -> *) a.
(Applicative f r t, Object r a, Object t (f a)) =>
t a (f a)
pure Differentiable n a b
q)
                (PreRegion n a
rf, Maybe (Differentiable n a b)
Nothing) | (PreRegion n a
rg, Maybe (Differentiable n a b)
q) <- a -> (PreRegion n a, Maybe (Differentiable n a b))
g a
x₀
                        -> (PreRegion n a -> PreRegion n a -> PreRegion n a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion n a
rf PreRegion n a
rg, Maybe (Differentiable n a b)
q)
RWDfblFuncValue n a b
c ?|: RWDfblFuncValue n a b
f = RWDfblFuncValue n a b
c RWDfblFuncValue n a b
-> RWDfblFuncValue n a b -> RWDfblFuncValue n a b
forall n a b.
(RealDimension n, Object (Differentiable n) a,
 Object (Differentiable n) b) =>
RWDfblFuncValue n a b
-> RWDfblFuncValue n a b -> RWDfblFuncValue n a b
?|: RWDfblFuncValue n a b -> RWDfblFuncValue n a b
forall s d c.
(RealDimension s, Object (Differentiable s) d,
 Object (Differentiable s) c) =>
RWDfblFuncValue s d c -> RWDfblFuncValue s d c
genericiseRWDFV RWDfblFuncValue n a b
f

-- | Replace the regions in which the first function is undefined with values
--   from the second function.
backupRegions :: (RealDimension n, Object (Differentiable n) a, Object (Differentiable n) b)
      => RWDiffable n a b -> RWDiffable n a b -> RWDiffable n a b
backupRegions :: RWDiffable n a b -> RWDiffable n a b -> RWDiffable n a b
backupRegions (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
f) (RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
g) = (a -> (PreRegion n a, Maybe (Differentiable n a b)))
-> RWDiffable n a b
forall s d c.
(d -> (PreRegion s d, Maybe (Differentiable s d c)))
-> RWDiffable s d c
RWDiffable a -> (PreRegion n a, Maybe (Differentiable n a b))
h
 where h :: a -> (PreRegion n a, Maybe (Differentiable n a b))
h a
x₀ = case a -> (PreRegion n a, Maybe (Differentiable n a b))
f a
x₀ of
                (PreRegion n a
rf, q :: Maybe (Differentiable n a b)
q@(Just Differentiable n a b
_)) -> (PreRegion n a
rf, Maybe (Differentiable n a b)
q)
                (PreRegion n a
rf, Maybe (Differentiable n a b)
Nothing) | (PreRegion n a
rg, Maybe (Differentiable n a b)
q) <- a -> (PreRegion n a, Maybe (Differentiable n a b))
g a
x₀
                        -> (PreRegion n a -> PreRegion n a -> PreRegion n a
forall a s.
(RealFloat'' s, LocallyScalable s a, Manifold a, Atlas' a,
 Atlas' s, SimpleSpace (Needle a)) =>
PreRegion s a -> PreRegion s a -> PreRegion s a
unsafePreRegionIntersect PreRegion n a
rf PreRegion n a
rg, Maybe (Differentiable n a b)
q)





-- | Like 'Data.VectorSpace.lerp', but gives a differentiable function
--   instead of a Hask one.
lerp_diffable ::  m s . ( LinearSpace m, RealDimension s, Object (Differentiable s) m )
      => m -> m -> Differentiable s s m
lerp_diffable :: m -> m -> Differentiable s s m
lerp_diffable = case ( TensorSpace m => LinearManifoldWitness m
forall v. TensorSpace v => LinearManifoldWitness v
linearManifoldWitness @m
                     , LinearSpace m => DualSpaceWitness m
forall v. LinearSpace v => DualSpaceWitness v
dualSpaceWitness @m
                     , SemimanifoldWithBoundary m => SmfdWBoundWitness m
forall m. SemimanifoldWithBoundary m => SmfdWBoundWitness m
smfdWBoundWitness @m) of
     (LinearManifoldWitness m
LinearManifoldWitness, DualSpaceWitness m
DualSpaceWitness, SmfdWBoundWitness m
OpenManifoldWitness)
         -> \m
a m
b -> m -> (s +> Needle m) -> Differentiable s s m
forall s x y.
(Object (Affine s) x, Object (Affine s) y, Object (LinearMap s) x,
 Object (LinearMap s) (Needle y)) =>
y -> (x +> Needle y) -> Differentiable s x y
actuallyAffine m
a (LinearMap (Scalar s) s m -> Differentiable s s m)
-> (LinearFunction (Scalar m) s m -> LinearMap (Scalar s) s m)
-> LinearFunction (Scalar m) s m
-> Differentiable s s m
forall κ (k :: κ -> κ -> *) (a :: κ) (b :: κ) (c :: κ).
(Category k, Object k a, Object k b, Object k c) =>
k b c -> k a b -> k a c
. LinearFunction (Scalar m) s m -> LinearMap (Scalar s) s m
forall (a :: * -> * -> *) (k :: * -> * -> *) b c.
(EnhancedCat a k, Object k b, Object k c, Object a b,
 Object a c) =>
k b c -> a b c
arr (LinearFunction (Scalar m) s m -> Differentiable s s m)
-> LinearFunction (Scalar m) s m -> Differentiable s s m
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ Bilinear s m m
-> LinearFunction (Scalar m) m (LinearFunction (Scalar m) s m)
forall v w y. Bilinear v w y -> Bilinear w v y
flipBilin Bilinear s m m
forall v. VectorSpace v => Bilinear (Scalar v) v v
scale LinearFunction (Scalar m) m (LinearFunction (Scalar m) s m)
-> m -> LinearFunction (Scalar m) s m
forall (f :: * -> * -> *) a b.
(Function f, Object f a, Object f b) =>
f a b -> a -> b
$ m
bm -> m -> Diff m
forall p. AffineSpace p => p -> p -> Diff p
.-.m
a