{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneKindSignatures, StandaloneDeriving #-}
module OAlg.Structure.Vectorial.Definition
(
Vectorial(..), Vec, TransformableVec
, VectorSheaf(..)
, Euclidean(..)
)
where
import Control.Exception
import OAlg.Prelude
import OAlg.Structure.Exception
import OAlg.Structure.Oriented.Orientation
import OAlg.Structure.Oriented.Opposite
import OAlg.Structure.Multiplicative.Definition
import OAlg.Structure.Fibred.Definition
import OAlg.Structure.FibredOriented
import OAlg.Structure.Additive.Definition
import OAlg.Structure.Ring.Definition
import OAlg.Structure.Number.Definition
infixr 8 !
class (Semiring (Scalar v), Commutative (Scalar v), Additive v) => Vectorial v where
type Scalar v
(!) :: Scalar v -> v -> v
data VectorSheaf v = VectorSheaf (Root v) [(Scalar v,v)]
deriving instance Vectorial v => Show (VectorSheaf v)
deriving instance Vectorial v => Eq (VectorSheaf v)
instance Vectorial v => Validable (VectorSheaf v) where
valid :: VectorSheaf v -> Statement
valid (VectorSheaf Root v
r [(Scalar v, v)]
xs) = String -> Label
Label String
"VectorSheaf" Label -> Statement -> Statement
:<=>: Root v -> Statement
forall a. Validable a => a -> Statement
valid Root v
r Statement -> Statement -> Statement
forall a. Logical a => a -> a -> a
&& Root v -> [(Scalar v, v)] -> Statement
forall {a} {a}.
(Fibred a, Validable a) =>
Root a -> [(a, a)] -> Statement
vld Root v
r [(Scalar v, v)]
xs where
vld :: Root a -> [(a, a)] -> Statement
vld Root a
_ [] = Statement
SValid
vld Root a
r ((a
s,a
v):[(a, a)]
xs) = [Statement] -> Statement
And [ a -> Statement
forall a. Validable a => a -> Statement
valid a
s
, a -> Statement
forall a. Validable a => a -> Statement
valid a
v
, (a -> Root a
forall f. Fibred f => f -> Root f
root a
v Root a -> Root a -> Bool
forall a. Eq a => a -> a -> Bool
== Root a
r) Bool -> Message -> Statement
:?> [Parameter] -> Message
Params [String
"r"String -> String -> Parameter
:=Root a -> String
forall a. Show a => a -> String
show Root a
r,String
"v"String -> String -> Parameter
:=a -> String
forall a. Show a => a -> String
show a
v]
, Root a -> [(a, a)] -> Statement
vld Root a
r [(a, a)]
xs
]
instance Vectorial () where
type Scalar () = Q
! :: Scalar () -> () -> ()
(!) = Q -> () -> ()
Scalar () -> () -> ()
forall a. Acyclic a => Q -> a -> a
qtimes
instance Vectorial Int where
type Scalar Int = Int
! :: Scalar Int -> Int -> Int
(!) = Int -> Int -> Int
Scalar Int -> Int -> Int
forall c. Multiplicative c => c -> c -> c
(*)
instance Vectorial Integer where
type Scalar Integer = Integer
! :: Scalar Integer -> Integer -> Integer
(!) = Integer -> Integer -> Integer
Scalar Integer -> Integer -> Integer
forall c. Multiplicative c => c -> c -> c
(*)
instance Vectorial N where
type Scalar N = N
! :: Scalar N -> N -> N
(!) = N -> N -> N
Scalar N -> N -> N
forall c. Multiplicative c => c -> c -> c
(*)
instance Vectorial Z where
type Scalar Z = Z
! :: Scalar Z -> Z -> Z
(!) = Z -> Z -> Z
Scalar Z -> Z -> Z
forall c. Multiplicative c => c -> c -> c
(*)
instance Vectorial Q where
type Scalar Q = Q
! :: Scalar Q -> Q -> Q
(!) = Q -> Q -> Q
Scalar Q -> Q -> Q
forall c. Multiplicative c => c -> c -> c
(*)
instance Entity p => Vectorial (Orientation p) where
type Scalar (Orientation p) = Q
Scalar (Orientation p)
_ ! :: Scalar (Orientation p) -> Orientation p -> Orientation p
! Orientation p
o = Orientation p
o
instance (Vectorial v, FibredOriented v) => Vectorial (Op v) where
type Scalar (Op v) = Scalar v
Scalar (Op v)
s ! :: Scalar (Op v) -> Op v -> Op v
! (Op v
v) = v -> Op v
forall x. x -> Op x
Op (Scalar v
Scalar (Op v)
sScalar v -> v -> v
forall v. Vectorial v => Scalar v -> v -> v
!v
v)
infix 7 <!>
class Vectorial v => Euclidean v where
(<!>) :: v -> v -> Scalar v
instance Euclidean N where
<!> :: N -> N -> Scalar N
(<!>) = N -> N -> N
N -> N -> Scalar N
forall c. Multiplicative c => c -> c -> c
(*)
instance Euclidean Z where
<!> :: Z -> Z -> Scalar Z
(<!>) = Z -> Z -> Z
Z -> Z -> Scalar Z
forall c. Multiplicative c => c -> c -> c
(*)
instance Euclidean Q where
<!> :: Q -> Q -> Scalar Q
(<!>) = Q -> Q -> Q
Q -> Q -> Scalar Q
forall c. Multiplicative c => c -> c -> c
(*)
instance Entity p => Euclidean (Orientation p) where
Orientation p
a <!> :: Orientation p -> Orientation p -> Scalar (Orientation p)
<!> Orientation p
b | Orientation p -> Root (Orientation p)
forall f. Fibred f => f -> Root f
root Orientation p
a Orientation p -> Orientation p -> Bool
forall a. Eq a => a -> a -> Bool
== Orientation p -> Root (Orientation p)
forall f. Fibred f => f -> Root f
root Orientation p
b = Q
Scalar (Orientation p)
0
| Bool
otherwise = ArithmeticException -> Q
forall a e. Exception e => e -> a
throw ArithmeticException
UndefinedScalarproduct
data Vec k
type instance Structure (Vec k) x = (Vectorial x, k ~ Scalar x)
instance Transformable (Vec k) Typ where tau :: forall x. Struct (Vec k) x -> Struct Typ x
tau Struct (Vec k) x
Struct = Struct Typ x
forall s x. Structure s x => Struct s x
Struct
instance Transformable (Vec k) Ent where tau :: forall x. Struct (Vec k) x -> Struct Ent x
tau Struct (Vec k) x
Struct = Struct Ent x
forall s x. Structure s x => Struct s x
Struct
instance Transformable (Vec k) Fbr where tau :: forall x. Struct (Vec k) x -> Struct Fbr x
tau Struct (Vec k) x
Struct = Struct Fbr x
forall s x. Structure s x => Struct s x
Struct
instance Transformable (Vec k) Add where tau :: forall x. Struct (Vec k) x -> Struct Add x
tau Struct (Vec k) x
Struct = Struct Add x
forall s x. Structure s x => Struct s x
Struct
class ( TransformableAdd (s k)
, Transformable (s k) (Vec k)
) => TransformableVec k s
instance TransformableTyp (Vec k)
instance TransformableFbr (Vec k)
instance TransformableAdd (Vec k)
instance TransformableVec k Vec