Copyright | © 2016-2017 George Steel and Peter Jurgec |
---|---|
License | GPL-2+ |
Maintainer | george.steel@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
This module provides a hierarchy of typeclasses to describe rings and their substructures without all of the additional structure found in Num
(which does not apply to most rings). Num
instances are automatically Ring
instances if no explicit instance is given, making Ring
a drop-in replacenent for Num
to make more generic functions.
A typeclass for algebraic modules (aka. vector spaces if over a field) is also included as well as a data type for the vector space ℝ[x]=ℝ∪ℝ²∪ℝ³∪… (usable for ℝⁿ although dimensions are not checked).
In order to not clash with Num or Arrow, this module uses the unicode circled operators '⊕', '⊖', '⊗', and '⊙'. If you are using XIM (Linux) or WinCompose, add the following lines to your .XCompose file:
<Multi_key> <r> <plus> : "⊕" <Multi_key> <r> <period> : "⊙" <Multi_key> <r> <asterisk> : "⊗" <Multi_key> <r> <minus> : "⊖"
- class Additive g where
- class Additive g => AdditiveGroup g where
- class Additive r => Semiring r where
- class (Semiring r, AdditiveGroup r) => Ring r
- newtype RSum r = RSum r
- newtype RProd r = RProd r
- sumR :: (Foldable f, Additive r) => f r -> r
- productR :: (Foldable f, Semiring r) => f r -> r
- class (Ring r, AdditiveGroup v) => RingModule r v where
- newtype Vec = Vec {}
- coords :: Vec -> [Double]
- fromInts :: [Int] -> Vec
- vec :: [Double] -> Vec
- innerProd :: Vec -> Vec -> Double
- normVec :: Vec -> Double
- normalizeVec :: Vec -> Vec
- consVec :: Double -> Vec -> Vec
- l1Vec :: Vec -> Double
- dl1Vec :: Vec -> Vec
- showFVec :: Maybe Int -> Vec -> String
Rings
class Additive g => AdditiveGroup g where Source #
Additive groups with inverses and suntraction
AdditiveGroup () Source # | |
Num r => AdditiveGroup r Source # | |
AdditiveGroup Vec Source # | |
AdditiveGroup r => AdditiveGroup (RProd r) Source # | |
AdditiveGroup r => AdditiveGroup (RSum r) Source # | |
(AdditiveGroup r, AdditiveGroup s) => AdditiveGroup (r, s) Source # | |
class Additive r => Semiring r where Source #
Semirings with addition and multiplication (but not subtraction).
class (Semiring r, AdditiveGroup r) => Ring r Source #
Rings have both subtraction and multiplication
RSum r |
RProd r |
Eq r => Eq (RProd r) Source # | |
Ord r => Ord (RProd r) Source # | |
Show r => Show (RProd r) Source # | |
Semiring r => Monoid (RProd r) Source # | |
Ring r => Ring (RProd r) Source # | |
Semiring r => Semiring (RProd r) Source # | |
AdditiveGroup r => AdditiveGroup (RProd r) Source # | |
Additive r => Additive (RProd r) Source # | |
Modules and vectors
class (Ring r, AdditiveGroup v) => RingModule r v where Source #
A module over a Ring
r is an AdditiveGroup
which can be multiplied by scalars in r.
RingModule Double Vec Source # | |
RingModule Int Double Source # | Since ℝ is a module over ℤ, using scalar multiplication can save a lot of coersion noise. |
RingModule Int Vec Source # | |
Ring r => RingModule r r Source # | Every Ring is a module over itself. |
(RingModule r v, RingModule r w) => RingModule r (v, w) Source # | |
Implements variable-length vectors. Addition batween vectors of different lengths occurs by letting ℝ⊆ℝ²⊆ℝ³⊆… by embedding each length in the space op polynomials.
normalizeVec :: Vec -> Vec Source #
Return a vector of unit length pointing in the same direction.