Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data HerMetric v
- data HerMetric' v
- metricSq :: HasMetric v => HerMetric v -> v -> Scalar v
- metricSq' :: HasMetric v => HerMetric' v -> DualSpace v -> Scalar v
- metric :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> v -> Scalar v
- metric' :: (HasMetric v, Floating (Scalar v)) => HerMetric' v -> DualSpace v -> Scalar v
- metrics :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> [v] -> Scalar v
- metrics' :: (HasMetric v, Floating (Scalar v)) => HerMetric' v -> [DualSpace v] -> Scalar v
- projector :: HasMetric v => DualSpace v -> HerMetric v
- projector' :: HasMetric v => v -> HerMetric' v
- euclideanMetric' :: forall v. (HasMetric v, InnerSpace v) => HerMetric v
- spanHilbertSubspace :: forall s v w. (HasMetric v, Scalar v ~ s, IsFreeSpace w, Scalar w ~ s) => HerMetric v -> [v] -> Option (Embedding (Linear s) w v)
- spanSubHilbertSpace :: forall s v w. (HasMetric v, InnerSpace v, Scalar v ~ s, IsFreeSpace w, Scalar w ~ s) => [v] -> Option (Embedding (Linear s) w v)
- class (FiniteDimensional v, KnownNat (FreeDimension v)) => IsFreeSpace v
- factoriseMetric :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric (v, w) -> (HerMetric v, HerMetric w)
- factoriseMetric' :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric' (v, w) -> (HerMetric' v, HerMetric' w)
- productMetric :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric v -> HerMetric w -> HerMetric (v, w)
- productMetric' :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric' v -> HerMetric' w -> HerMetric' (v, w)
- metricAsLength :: HerMetric ℝ -> ℝ
- metricFromLength :: ℝ -> HerMetric ℝ
- metric'AsLength :: HerMetric' ℝ -> ℝ
- transformMetric :: (HasMetric v, HasMetric w, Scalar v ~ Scalar w) => (w :-* v) -> HerMetric v -> HerMetric w
- transformMetric' :: (HasMetric v, HasMetric w, Scalar v ~ Scalar w) => (v :-* w) -> HerMetric' v -> HerMetric' w
- dualiseMetric :: HasMetric v => HerMetric (DualSpace v) -> HerMetric' v
- dualiseMetric' :: HasMetric v => HerMetric' v -> HerMetric (DualSpace v)
- recipMetric :: HasMetric v => HerMetric' v -> HerMetric v
- recipMetric' :: HasMetric v => HerMetric v -> HerMetric' v
- eigenSpan :: (HasMetric v, Scalar v ~ ℝ) => HerMetric' v -> [v]
- eigenSpan' :: (HasMetric v, Scalar v ~ ℝ) => HerMetric v -> [DualSpace v]
- eigenCoSpan :: (HasMetric v, Scalar v ~ ℝ) => HerMetric' v -> [DualSpace v]
- eigenCoSpan' :: (HasMetric v, Scalar v ~ ℝ) => HerMetric v -> [v]
- metriScale' :: (HasMetric v, Floating (Scalar v)) => HerMetric' v -> DualSpace v -> DualSpace v
- metriScale :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> v -> v
- adjoint :: (HasMetric v, HasMetric w, Scalar w ~ Scalar v) => (v :-* w) -> DualSpace w :-* DualSpace v
- type HasMetric v = (HasMetric' v, HasMetric' (DualSpace v), DualSpace (DualSpace v) ~ v)
- class (FiniteDimensional v, FiniteDimensional (DualSpace v), VectorSpace (DualSpace v), HasBasis (DualSpace v), MetricScalar (Scalar v), Scalar v ~ Scalar (DualSpace v), Basis v ~ Basis (DualSpace v)) => HasMetric' v where
- type DualSpace v :: *
- (<.>^) :: DualSpace v -> v -> Scalar v
- functional :: (v -> Scalar v) -> DualSpace v
- doubleDual :: HasMetric' (DualSpace v) => v -> DualSpace (DualSpace v)
- doubleDual' :: HasMetric' (DualSpace v) => DualSpace (DualSpace v) -> v
- (^<.>) :: HasMetric v => v -> DualSpace v -> Scalar v
- type MetricScalar s = (SmoothScalar s, Ord s)
- class (HasBasis v, HasTrie (Basis v), SmoothScalar (Scalar v)) => FiniteDimensional v where
- dimension :: Tagged v Int
- basisIndex :: Tagged v (Basis v -> Int)
- indexBasis :: Tagged v (Int -> Basis v)
- completeBasis :: Tagged v [Basis v]
- asPackedVector :: v -> Vector (Scalar v)
- asPackedMatrix :: (FiniteDimensional w, Scalar w ~ Scalar v) => (v :-* w) -> Matrix (Scalar v)
- fromPackedVector :: Vector (Scalar v) -> v
- newtype Stiefel1 v = Stiefel1 {
- getStiefel1N :: DualSpace v
Metric operator types
HerMetric
is a portmanteau of Hermitian and metric (in the sense as
used in e.g. general relativity – though those particular ones aren't positive
definite and thus not really metrics).
Mathematically, there are two directly equivalent ways to describe such a metric: as a bilinear mapping of two vectors to a scalar, or as a linear mapping from a vector space to its dual space. We choose the latter, though you can always as well think of metrics as “quadratic dual vectors”.
Yet other possible interpretations of this type include density matrix (as in quantum mechanics), standard range of statistical fluctuations, and volume element.
(HasMetric v, (~) * v (Scalar v), (~) * v (DualSpace v), Floating v) => Floating (HerMetric v) Source | |
(HasMetric v, (~) * v (Scalar v), (~) * v (DualSpace v), Fractional v) => Fractional (HerMetric v) Source | |
(HasMetric v, (~) * v (DualSpace v), Num (Scalar v)) => Num (HerMetric v) Source | |
HasMetric v => VectorSpace (HerMetric v) Source | |
HasMetric v => AdditiveGroup (HerMetric v) Source | |
type Scalar (HerMetric v) = Scalar v Source |
data HerMetric' v Source
A metric on the dual space; equivalent to a linear mapping from the dual space to the original vector space.
Prime-versions of the functions in this module target those dual-space metrics, so we can avoid some explicit handling of double-dual spaces.
HasMetric v => VectorSpace (HerMetric' v) Source | |
HasMetric v => AdditiveGroup (HerMetric' v) Source | |
type Scalar (HerMetric' v) = Scalar v Source |
Evaluating metrics
metricSq :: HasMetric v => HerMetric v -> v -> Scalar v Source
Evaluate a vector through a metric. For the canonical metric on a Hilbert space,
this will be simply magnitudeSq
.
metricSq' :: HasMetric v => HerMetric' v -> DualSpace v -> Scalar v Source
metric :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> v -> Scalar v Source
Evaluate a vector's “magnitude” through a metric. This assumes an actual mathematical metric, i.e. positive definite – otherwise the internally used square root may get negative arguments (though it can still produce results if the scalars are complex; however, complex spaces aren't supported yet).
metrics :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> [v] -> Scalar v Source
Square-sum over the metrics for each dual-space vector.
metrics m vs ≡ sqrt . sum $ metricSq m <$>
vs
Defining metrics
projector :: HasMetric v => DualSpace v -> HerMetric v Source
A metric on v
that simply yields the squared overlap of a vector with the
given dual-space reference.
It will perhaps be the most common way of defining HerMetric
values to start
with such dual-space vectors and superimpose the projectors using the VectorSpace
instance; e.g.
yields a hermitian operator
describing the ellipsoid span of the vectors e₀ and 2⋅e₁.
Metrics generated this way are positive definite if no negative coefficients have
been introduced with the projector
(1,0) ^+^
projector
(0,2)*^
scaling operator or with ^-^
.
projector' :: HasMetric v => v -> HerMetric' v Source
euclideanMetric' :: forall v. (HasMetric v, InnerSpace v) => HerMetric v Source
Metrics induce inner products
:: (HasMetric v, Scalar v ~ s, IsFreeSpace w, Scalar w ~ s) | |
=> HerMetric v | Metric to induce the inner product on the Hilbert space. |
-> [v] |
|
-> Option (Embedding (Linear s) w v) | An embedding of the |
spanSubHilbertSpace :: forall s v w. (HasMetric v, InnerSpace v, Scalar v ~ s, IsFreeSpace w, Scalar w ~ s) => [v] -> Option (Embedding (Linear s) w v) Source
Same as spanHilbertSubspace
, but with the standard euclideanMetric
(i.e., the
basis vectors will be orthonormal in the usual sense, in both w
and v
).
class (FiniteDimensional v, KnownNat (FreeDimension v)) => IsFreeSpace v Source
Class of spaces that directly represent a free vector space, i.e. that are simply
n
-fold products of the base field.
This class basically contains 'ℝ', 'ℝ²', 'ℝ³' etc., in future also the complex and
probably integral versions.
IsFreeSpace ℝ Source | |
(SmoothScalar s, IsFreeSpace v, (~) * (Scalar v) s, FiniteDimensional s, (~) * s (Scalar s)) => IsFreeSpace (v, s) Source |
One-dimensional axes and product spaces
factoriseMetric :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric (v, w) -> (HerMetric v, HerMetric w) Source
Project a metric on each of the factors of a product space. This works by projecting the eigenvectors into both subspaces.
factoriseMetric' :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric' (v, w) -> (HerMetric' v, HerMetric' w) Source
productMetric :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric v -> HerMetric w -> HerMetric (v, w) Source
productMetric' :: forall v w. (HasMetric v, HasMetric w, Scalar v ~ ℝ, Scalar w ~ ℝ) => HerMetric' v -> HerMetric' w -> HerMetric' (v, w) Source
metricAsLength :: HerMetric ℝ -> ℝ Source
metricFromLength :: ℝ -> HerMetric ℝ Source
metric'AsLength :: HerMetric' ℝ -> ℝ Source
Utility for metrics
transformMetric :: (HasMetric v, HasMetric w, Scalar v ~ Scalar w) => (w :-* v) -> HerMetric v -> HerMetric w Source
transformMetric' :: (HasMetric v, HasMetric w, Scalar v ~ Scalar w) => (v :-* w) -> HerMetric' v -> HerMetric' w Source
dualiseMetric :: HasMetric v => HerMetric (DualSpace v) -> HerMetric' v Source
dualiseMetric' :: HasMetric v => HerMetric' v -> HerMetric (DualSpace v) Source
recipMetric :: HasMetric v => HerMetric' v -> HerMetric v Source
recipMetric' :: HasMetric v => HerMetric v -> HerMetric' v Source
The inverse mapping of a metric tensor. Since a metric maps from a space to its dual, the inverse maps from the dual into the (double-dual) space – i.e., it is a metric on the dual space.
eigenSpan :: (HasMetric v, Scalar v ~ ℝ) => HerMetric' v -> [v] Source
The eigenbasis of a positive definite metric, with each eigenvector scaled to the square root of the eigenvalue.
This constitutes, in a sense,
a decomposition of a metric into a set of projector'
vectors. If those
are sumV
ed again, the original metric is obtained. (This holds even for
non-Hilbert/Banach spaces, even though the concept of eigenbasis and
“scaled length” doesn't really makes sense then in the usual way!)
eigenCoSpan :: (HasMetric v, Scalar v ~ ℝ) => HerMetric' v -> [DualSpace v] Source
eigenCoSpan' :: (HasMetric v, Scalar v ~ ℝ) => HerMetric v -> [v] Source
metriScale' :: (HasMetric v, Floating (Scalar v)) => HerMetric' v -> DualSpace v -> DualSpace v Source
metriScale :: (HasMetric v, Floating (Scalar v)) => HerMetric v -> v -> v Source
“Anti-normalise” a vector: multiply with its own norm, according to metric.
adjoint :: (HasMetric v, HasMetric w, Scalar w ~ Scalar v) => (v :-* w) -> DualSpace w :-* DualSpace v Source
Transpose a linear operator. Contrary to popular belief, this does not just inverse the direction of mapping between the spaces, but also switch to their duals.
The dual-space class
type HasMetric v = (HasMetric' v, HasMetric' (DualSpace v), DualSpace (DualSpace v) ~ v) Source
class (FiniteDimensional v, FiniteDimensional (DualSpace v), VectorSpace (DualSpace v), HasBasis (DualSpace v), MetricScalar (Scalar v), Scalar v ~ Scalar (DualSpace v), Basis v ~ Basis (DualSpace v)) => HasMetric' v where Source
While the main purpose of this class is to express HerMetric
, it's actually
all about dual spaces.
is isomorphic to the space of linear functionals on DualSpace
vv
, i.e.
v
.
Typically (for all Hilbert- / :-*
Scalar
vInnerSpace
s) this is in turn isomorphic to v
itself, which will be rather more efficient (hence the distinction between a
vector space and its dual is often neglected or reduced to “column vs row
vectors”).
Mathematically though, it makes sense to keep the concepts apart, even if ultimately
(which needs not always be the case, though!).DualSpace
v ~ v
(<.>^) :: DualSpace v -> v -> Scalar v infixr 7 Source
Apply a dual space vector (aka linear functional) to a vector.
functional :: (v -> Scalar v) -> DualSpace v Source
Interpret a functional as a dual-space vector. Like linear
, this assumes
(completely unchecked) that the supplied function is linear.
doubleDual :: HasMetric' (DualSpace v) => v -> DualSpace (DualSpace v) Source
While isomorphism between a space and its dual isn't generally canonical,
the double-dual space should be canonically isomorphic in pretty much
all relevant cases. Indeed, it is recommended that they are the very same type;
this condition is enforced by the HasMetric
constraint (which is recommended
over using HasMetric'
itself in signatures).
doubleDual' :: HasMetric' (DualSpace v) => DualSpace (DualSpace v) -> v Source
HasMetric' Double Source | |
MetricScalar k => HasMetric' (ZeroDim k) Source | |
(HasMetric v, HasMetric w, (~) * (Scalar v) (Scalar w)) => HasMetric' (v, w) Source |
(^<.>) :: HasMetric v => v -> DualSpace v -> Scalar v infixr 7 Source
Simple flipped version of <.>^
.
Fundamental requirements
type MetricScalar s = (SmoothScalar s, Ord s) Source
Constraint that a space's scalars need to fulfill so it can be used for HerMetric
.
class (HasBasis v, HasTrie (Basis v), SmoothScalar (Scalar v)) => FiniteDimensional v where Source
Many linear algebra operations are best implemented via packed, dense Matrix
es.
For one thing, that makes common general vector operations quite efficient,
in particular on high-dimensional spaces.
More importantly, hmatrix
offers linear facilities
such as inverse and eigenbasis transformations, which aren't available in the
vector-space
library yet. But the classes from that library are strongly preferrable
to plain matrices and arrays, conceptually.
The FiniteDimensional
class is used to convert between both representations.
It would be nice not to have the requirement of finite dimension on HerMetric
,
but it's probably not feasible to get rid of it in forseeable time.
Instead of the run-time dimension
information, we would rather have a compile-time
type Dimension v :: Nat
, but type-level naturals are not mature enough yet. This
will almost certainly change in the future.
dimension :: Tagged v Int Source
basisIndex :: Tagged v (Basis v -> Int) Source
indexBasis :: Tagged v (Int -> Basis v) Source
Index must be in [0 .. dimension-1]
, otherwise this is undefined.
completeBasis :: Tagged v [Basis v] Source
asPackedVector :: v -> Vector (Scalar v) Source
asPackedMatrix :: (FiniteDimensional w, Scalar w ~ Scalar v) => (v :-* w) -> Matrix (Scalar v) Source
fromPackedVector :: Vector (Scalar v) -> v Source
FiniteDimensional ℝ Source | |
SmoothScalar k => FiniteDimensional (ZeroDim k) Source | |
(FiniteDimensional a, FiniteDimensional b, (~) * (Scalar a) (Scalar b)) => FiniteDimensional (a, b) Source |
Misc
The n-th Stiefel manifold is the space of all possible configurations of
n orthonormal vectors. In the case n = 1, simply the subspace of normalised
vectors, i.e. equivalent to the UnitSphere
. Even so, it strictly speaking
requires the containing space to be at least metric (if not Hilbert); we would
however like to be able to use this concept also in spaces with no inner product,
therefore we define this space not as normalised vectors, but rather as all
vectors modulo scaling by positive factors.