Copyright | (c) Justus Sagemüller 2015 |
---|---|
License | GPL v3 |
Maintainer | (@) jsag $ hvl.no |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This is the second prototype of a manifold class. It appears to give considerable
advantages over Manifold
, so that class will probably soon be replaced
with the one we define here (though PseudoAffine
does not follow the standard notion
of a manifold very closely, it should work quite equivalently for pretty much all
Haskell types that qualify as manifolds).
Manifolds are interesting as objects of various categories, from continuous to diffeomorphic. At the moment, we mainly focus on region-wise differentiable functions, which are a promising compromise between flexibility of definition and provability of analytic properties. In particular, they are well-suited for visualisation purposes.
The classes in this module are mostly aimed at manifolds without boundary.
Manifolds with boundary (which we call MWBound
, never manifold!)
are more or less treated as a disjoint sum of the interior and the boundary.
To understand how this module works, best first forget about boundaries – in this case,
, Interior
x ~ xfromInterior
and toInterior
are trivial, and
.+~|
, |-~.
and betweenBounds
are irrelevant.
The manifold structure of the boundary itself is not considered at all here.
Synopsis
- class (PseudoAffine m, LSpace (Needle m)) => Manifold m where
- inInterior :: m -> Interior m
- class AdditiveGroup (Needle x) => Semimanifold x where
- type Needle x :: Type
- type Interior x :: Type
- (.+~^) :: Interior x -> Needle x -> x
- fromInterior :: Interior x -> x
- toInterior :: x -> Maybe (Interior x)
- translateP :: Tagged x (Interior x -> Needle x -> Interior x)
- (.-~^) :: Interior x -> Needle x -> x
- semimanifoldWitness :: SemimanifoldWitness x
- type Needle' x = DualVector (Needle x)
- class Semimanifold x => PseudoAffine x where
- (.-~.) :: x -> x -> Maybe (Needle x)
- (.-~!) :: x -> x -> Needle x
- pseudoAffineWitness :: PseudoAffineWitness x
- newtype Local x = Local {
- getLocalOffset :: Needle x
- (⊙+^) :: forall x proxy. Semimanifold x => Interior x -> Needle x -> proxy x -> Interior x
- (!+~^) :: forall x. (Semimanifold x, HasCallStack) => x -> Needle x -> x
- type Metric x = Norm (Needle x)
- type Metric' x = Variance (Needle x)
- type RieMetric x = x -> Metric x
- type RieMetric' x = x -> Metric' x
- data SemimanifoldWitness x where
- SemimanifoldWitness :: forall x. (Semimanifold (Needle x), Needle (Interior x) ~ Needle x, Needle (Needle x) ~ Needle x, Interior (Needle x) ~ Needle x) => BoundarylessWitness (Interior x) -> SemimanifoldWitness x
- data PseudoAffineWitness x where
- PseudoAffineWitness :: forall x. (PseudoAffine (Interior x), PseudoAffine (Needle x)) => SemimanifoldWitness x -> PseudoAffineWitness x
- data BoundarylessWitness m where
- BoundarylessWitness :: forall m. (Semimanifold m, Interior m ~ m) => BoundarylessWitness m
- boundarylessWitness :: Manifold m => BoundarylessWitness m
- type DualNeedleWitness x = DualSpaceWitness (Needle x)
- type WithField s c x = (c x, s ~ Scalar (Needle x), s ~ Scalar (Needle' x))
- type LocallyScalable s x = (PseudoAffine x, LSpace (Needle x), s ~ Scalar (Needle x), s ~ Scalar (Needle' x), Num' s)
- type LocalLinear x y = LinearMap (Scalar (Needle x)) (Needle x) (Needle y)
- type LocalBilinear x y = LinearMap (Scalar (Needle x)) (SymmetricTensor (Scalar (Needle x)) (Needle x)) (Needle y)
- type LocalAffine x y = (Needle y, LocalLinear x y)
- alerpB :: (AffineSpace x, VectorSpace (Diff x), Scalar (Diff x) ~ ℝ) => x -> x -> D¹ -> x
- palerp :: (PseudoAffine x, VectorSpace (Needle x)) => x -> x -> Maybe (Scalar (Needle x) -> x)
- palerpB :: (PseudoAffine x, VectorSpace (Needle x), Scalar (Needle x) ~ ℝ) => x -> x -> Maybe (D¹ -> x)
- class (Semimanifold x, Semimanifold ξ, LSpace (Needle x), LSpace (Needle ξ), Scalar (Needle x) ~ Scalar (Needle ξ)) => LocallyCoercible x ξ where
- locallyTrivialDiffeomorphism :: x -> ξ
- coerceNeedle :: Functor p => p (x, ξ) -> Needle x -+> Needle ξ
- coerceNeedle' :: Functor p => p (x, ξ) -> Needle' x -+> Needle' ξ
- coerceNorm :: Functor p => p (x, ξ) -> Metric x -> Metric ξ
- coerceVariance :: Functor p => p (x, ξ) -> Metric' x -> Metric' ξ
- oppositeLocalCoercion :: CanonicalDiffeomorphism ξ x
- interiorLocalCoercion :: Functor p (->) (->) => p (x, ξ) -> CanonicalDiffeomorphism (Interior x) (Interior ξ)
- data CanonicalDiffeomorphism a b where
- CanonicalDiffeomorphism :: LocallyCoercible a b => CanonicalDiffeomorphism a b
- class ImpliesMetric s where
- type MetricRequirement s x :: Constraint
- inferMetric :: (MetricRequirement s x, LSpace (Needle x)) => s x -> Metric x
- inferMetric' :: (MetricRequirement s x, LSpace (Needle x)) => s x -> Metric' x
- coerceMetric :: forall x ξ. (LocallyCoercible x ξ, LSpace (Needle ξ)) => RieMetric ξ -> RieMetric x
- coerceMetric' :: forall x ξ. (LocallyCoercible x ξ, LSpace (Needle ξ)) => RieMetric' ξ -> RieMetric' x
- class PseudoAffine m => Connected m where
Manifold class
class (PseudoAffine m, LSpace (Needle m)) => Manifold m where Source #
See Semimanifold
and PseudoAffine
for the methods.
Nothing
inInterior :: m -> Interior m Source #
inInterior :: m ~ Interior m => m -> Interior m Source #
Instances
(PseudoAffine m, LSpace (Needle m), Interior m ~ m) => Manifold m Source # | |
Defined in Data.Manifold.PseudoAffine boundarylessWitness :: BoundarylessWitness m Source # inInterior :: m -> Interior m Source # |
class AdditiveGroup (Needle x) => Semimanifold x where #
The space of “natural” ways starting from some reference point
and going to some particular target point. Hence,
the name: like a compass needle, but also with an actual length.
For affine spaces, Needle
is simply the space of
line segments (aka vectors) between two points, i.e. the same as Diff
.
The AffineManifold
constraint makes that requirement explicit.
This space should be isomorphic to the tangent space (and is in fact used somewhat synonymously).
Manifolds with boundary are a bit tricky. We support such manifolds, but carry out most calculations only in “the fleshy part” – the interior, which is an “infinite space”, so you can arbitrarily scale paths.
The default implementation is
, which corresponds
to a manifold that has no boundary to begin with.Interior
x = x
(.+~^) :: Interior x -> Needle x -> x infixl 6 #
Generalised translation operation. Note that the result will always also be in the interior; scaling up the needle can only get you ever closer to a boundary.
fromInterior :: Interior x -> x #
id
sans boundary.
toInterior :: x -> Maybe (Interior x) #
translateP :: Tagged x (Interior x -> Needle x -> Interior x) #
The signature of .+~^
should really be
,
only, this is not possible because it only consists of non-injective type families.
The solution is this tagged signature, which is of course rather unwieldy. That's
why Interior
x -> Needle
x -> Interior
x.+~^
has the stronger, but easier usable signature. Without boundary, these
functions should be equivalent, i.e. translateP = Tagged (.+~^)
.
(.-~^) :: Interior x -> Needle x -> x infixl 6 #
Shorthand for \p v -> p .+~^
, which should obey the asymptotic lawnegateV
v
p .-~^ v .+~^ v ≅ p
Meaning: if v
is scaled down with sufficiently small factors η, then
the difference (p.-~^v.+~^v) .-~. p
should scale down even faster:
as O (η²). For large vectors, it will however behave differently,
except in flat spaces (where all this should be equivalent to the AffineSpace
instance).
Instances
type Needle' x = DualVector (Needle x) Source #
A co-needle can be understood as a “paper stack”, with which you can measure the length that a needle reaches in a given direction by counting the number of holes punched through them.
class Semimanifold x => PseudoAffine x where #
This is the class underlying manifolds. (Manifold
only precludes boundaries
and adds an extra constraint that would be circular if it was in a single
class. You can always just use Manifold
as a constraint in your signatures,
but you must define only PseudoAffine
for manifold types –
the Manifold
instance follows universally from this, if 'Interior x ~ x
.)
The interface is (boundaries aside) almost identical to the better-known
AffineSpace
class, but we don't require associativity of .+~^
with ^+^
– except in an asymptotic sense for small vectors.
That innocent-looking change makes the class applicable to vastly more general types:
while an affine space is basically nothing but a vector space without particularly
designated origin, a pseudo-affine space can have nontrivial topology on the global
scale, and yet be used in practically the same way as an affine space. At least the
usual spheres and tori make good instances, perhaps the class is in fact equivalent to
manifolds in their usual maths definition (with an atlas of charts: a family of
overlapping regions of the topological space, each homeomorphic to the Needle
vector space or some simply-connected subset thereof).
(.-~.) :: x -> x -> Maybe (Needle x) infix 6 #
The path reaching from one point to another.
Should only yield Nothing
if
- The points are on disjoint segments of a non–path-connected space.
- Either of the points is on the boundary. Use
|-~.
to deal with this.
On manifolds, the identity
p .+~^ (q.-~.p) ≡ q
should hold, at least save for floating-point precision limits etc..
.-~.
and .+~^
only really work in manifolds without boundary. If you consider
the path between two points, one of which lies on the boundary, it can't really
be possible to scale this path any longer – it would have to reach “out of the
manifold”. To adress this problem, these functions basically consider only the
interior of the space.
(.-~!) :: x -> x -> Needle x infix 6 #
Unsafe version of .-~.
. If the two points lie in disjoint regions,
the behaviour is undefined.
Instances
Type definitions
Needles
A point on a manifold, as seen from a nearby reference point.
Local | |
|
(⊙+^) :: forall x proxy. Semimanifold x => Interior x -> Needle x -> proxy x -> Interior x infix 6 Source #
Proxy-version of translateP
.
(!+~^) :: forall x. (Semimanifold x, HasCallStack) => x -> Needle x -> x infixl 6 Source #
Boundary-unsafe version of .+~^
.
Metrics
type Metric x = Norm (Needle x) Source #
The word “metric” is used in the sense as in general relativity.
Actually this is just the type of scalar products on the tangent space.
The actual metric is the function x -> x -> Scalar (Needle x)
defined by
\p q -> m |$|
(p.-~!q)
type RieMetric x = x -> Metric x Source #
A Riemannian metric assigns each point on a manifold a scalar product on the tangent space. Note that this association is not continuous, because the charts/tangent spaces in the bundle are a priori disjoint. However, for a proper Riemannian metric, all arising expressions of scalar products from needles between points on the manifold ought to be differentiable.
type RieMetric' x = x -> Metric' x Source #
Constraints
data SemimanifoldWitness x where #
This is the reified form of the property that the interior of a semimanifold
is a manifold. These constraints would ideally be expressed directly as
superclass constraints, but that would require the UndecidableSuperclasses
extension, which is not reliable yet.
Also, if all those equality constraints are in scope, GHC tends to infer needlessly
complicated types like
, which is
the same as just Interior
(Interior
(Needle
(Interior
x)))
.Needle
x
SemimanifoldWitness :: forall x. (Semimanifold (Needle x), Needle (Interior x) ~ Needle x, Needle (Needle x) ~ Needle x, Interior (Needle x) ~ Needle x) => BoundarylessWitness (Interior x) -> SemimanifoldWitness x |
data PseudoAffineWitness x where #
PseudoAffineWitness :: forall x. (PseudoAffine (Interior x), PseudoAffine (Needle x)) => SemimanifoldWitness x -> PseudoAffineWitness x |
data BoundarylessWitness m where #
BoundarylessWitness :: forall m. (Semimanifold m, Interior m ~ m) => BoundarylessWitness m |
boundarylessWitness :: Manifold m => BoundarylessWitness m Source #
type DualNeedleWitness x = DualSpaceWitness (Needle x) Source #
type WithField s c x = (c x, s ~ Scalar (Needle x), s ~ Scalar (Needle' x)) Source #
Require some constraint on a manifold, and also fix the type of the manifold's
underlying field. For example, WithField ℝ
constrains
HilbertManifold
vv
to be a real (i.e., Double
-) Hilbert space.
Note that for this to compile, you will in
general need the -XLiberalTypeSynonyms
extension (except if the constraint
is an actual type class (like Manifold
): only those can always be partially
applied, for type
constraints this is by default not allowed).
type LocallyScalable s x = (PseudoAffine x, LSpace (Needle x), s ~ Scalar (Needle x), s ~ Scalar (Needle' x), Num' s) Source #
Local functions
type LocalBilinear x y = LinearMap (Scalar (Needle x)) (SymmetricTensor (Scalar (Needle x)) (Needle x)) (Needle y) Source #
type LocalAffine x y = (Needle y, LocalLinear x y) Source #
Misc
alerpB :: (AffineSpace x, VectorSpace (Diff x), Scalar (Diff x) ~ ℝ) => x -> x -> D¹ -> x #
Like alerp
, but actually restricted to the interval between the points.
palerp :: (PseudoAffine x, VectorSpace (Needle x)) => x -> x -> Maybe (Scalar (Needle x) -> x) #
Interpolate between points, approximately linearly. For points that aren't close neighbours (i.e. lie in an almost flat region), the pathway is basically undefined – save for its end points.
A proper, really well-defined (on global scales) interpolation
only makes sense on a Riemannian manifold, as Geodesic
.
palerpB :: (PseudoAffine x, VectorSpace (Needle x), Scalar (Needle x) ~ ℝ) => x -> x -> Maybe (D¹ -> x) #
Like palerp
, but actually restricted to the interval between the points,
with a signature like geodesicBetween
rather than alerp
.
class (Semimanifold x, Semimanifold ξ, LSpace (Needle x), LSpace (Needle ξ), Scalar (Needle x) ~ Scalar (Needle ξ)) => LocallyCoercible x ξ where Source #
Instances of this class must be diffeomorphic manifolds, and even have
canonically isomorphic tangent spaces, so that
defines a meaningful “representational identity“ between these spaces.fromPackedVector
. asPackedVector
:: Needle
x -> Needle
ξ
locallyTrivialDiffeomorphism :: x -> ξ Source #
Must be compatible with the isomorphism on the tangent spaces, i.e.
locallyTrivialDiffeomorphism (p .+~^ v)
≡ locallyTrivialDiffeomorphism p .+~^
coerceNeedle
v
coerceNeedle :: Functor p => p (x, ξ) -> Needle x -+> Needle ξ Source #
coerceNeedle' :: Functor p => p (x, ξ) -> Needle' x -+> Needle' ξ Source #
coerceNorm :: Functor p => p (x, ξ) -> Metric x -> Metric ξ Source #
coerceVariance :: Functor p => p (x, ξ) -> Metric' x -> Metric' ξ Source #
oppositeLocalCoercion :: CanonicalDiffeomorphism ξ x Source #
oppositeLocalCoercion :: LocallyCoercible ξ x => CanonicalDiffeomorphism ξ x Source #
interiorLocalCoercion :: Functor p (->) (->) => p (x, ξ) -> CanonicalDiffeomorphism (Interior x) (Interior ξ) Source #
interiorLocalCoercion :: LocallyCoercible (Interior x) (Interior ξ) => p (x, ξ) -> CanonicalDiffeomorphism (Interior x) (Interior ξ) Source #
Instances
data CanonicalDiffeomorphism a b where Source #
CanonicalDiffeomorphism :: LocallyCoercible a b => CanonicalDiffeomorphism a b |
class ImpliesMetric s where Source #
type MetricRequirement s x :: Constraint Source #
inferMetric :: (MetricRequirement s x, LSpace (Needle x)) => s x -> Metric x Source #
inferMetric' :: (MetricRequirement s x, LSpace (Needle x)) => s x -> Metric' x Source #
Instances
ImpliesMetric Norm Source # | |
Defined in Data.Manifold.PseudoAffine type MetricRequirement Norm x :: Constraint Source # inferMetric :: (MetricRequirement Norm x, LSpace (Needle x)) => Norm x -> Metric x Source # inferMetric' :: (MetricRequirement Norm x, LSpace (Needle x)) => Norm x -> Metric' x Source # | |
ImpliesMetric Shade' Source # | |
Defined in Data.Manifold.Shade type MetricRequirement Shade' x :: Constraint Source # inferMetric :: (MetricRequirement Shade' x, LSpace (Needle x)) => Shade' x -> Metric x Source # inferMetric' :: (MetricRequirement Shade' x, LSpace (Needle x)) => Shade' x -> Metric' x Source # | |
ImpliesMetric Shade Source # | |
Defined in Data.Manifold.Shade type MetricRequirement Shade x :: Constraint Source # inferMetric :: (MetricRequirement Shade x, LSpace (Needle x)) => Shade x -> Metric x Source # inferMetric' :: (MetricRequirement Shade x, LSpace (Needle x)) => Shade x -> Metric' x Source # |
coerceMetric :: forall x ξ. (LocallyCoercible x ξ, LSpace (Needle ξ)) => RieMetric ξ -> RieMetric x Source #
coerceMetric' :: forall x ξ. (LocallyCoercible x ξ, LSpace (Needle ξ)) => RieMetric' ξ -> RieMetric' x Source #
class PseudoAffine m => Connected m where Source #
A connected manifold is one where any point can be reached by translation from any other point.
Nothing
Instances
Connected ℝP⁰ Source # | |
Connected S¹ Source # | |
Connected ℝP¹ Source # | |
Connected S² Source # | |
Connected ℝP² Source # | |
Connected ℝ Source # | |
Connected ℝ⁰ Source # | |
Connected ℝ⁴ Source # | |
Connected ℝ³ Source # | |
Connected ℝ² Source # | |
Connected ℝ¹ Source # | |
(Connected x, Connected y) => Connected (x, y) Source # | |
Defined in Data.Manifold.PseudoAffine | |
(Connected x, Connected y, PseudoAffine (FibreBundle x y)) => Connected (FibreBundle x y) Source # | |
Defined in Data.Manifold.PseudoAffine (.−.) :: FibreBundle x y -> FibreBundle x y -> Needle (FibreBundle x y) Source # |
Orphan instances
Semimanifold S² Source # | |
Semimanifold ℝP² Source # | |
PseudoAffine S² Source # | |
PseudoAffine ℝP² Source # | |
(LinearSpace (a n), Needle (a n) ~ a n, Interior (a n) ~ a n) => Semimanifold (Point a n) Source # | |
(.+~^) :: Interior (Point a n) -> Needle (Point a n) -> Point a n # fromInterior :: Interior (Point a n) -> Point a n # toInterior :: Point a n -> Maybe (Interior (Point a n)) # translateP :: Tagged (Point a n) (Interior (Point a n) -> Needle (Point a n) -> Interior (Point a n)) # (.-~^) :: Interior (Point a n) -> Needle (Point a n) -> Point a n # semimanifoldWitness :: SemimanifoldWitness (Point a n) # | |
(LinearSpace (a n), Needle (a n) ~ a n, Interior (a n) ~ a n) => PseudoAffine (Point a n) Source # | |