Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines the algebraic type-classes used in subhask. The class hierarchies are significantly more general than those in the standard Prelude.
- type family Logic a :: *
- type ValidLogic a = Complemented (Logic a)
- type ClassicalLogic a = Logic a ~ Bool
- class Eq_ a where
- (==) :: a -> a -> Logic a
- (/=) :: ValidLogic a => a -> a -> Logic a
- type Eq a = (Eq_ a, Logic a ~ Bool)
- type ValidEq a = (Eq_ a, ValidLogic a)
- law_Eq_reflexive :: Eq a => a -> Logic a
- law_Eq_symmetric :: Eq a => a -> a -> Logic a
- law_Eq_transitive :: Eq a => a -> a -> a -> Logic a
- class Eq_ b => POrd_ b where
- type POrd a = (Eq a, POrd_ a)
- law_POrd_commutative :: (Eq b, POrd_ b) => b -> b -> Bool
- law_POrd_associative :: (Eq b, POrd_ b) => b -> b -> b -> Bool
- theorem_POrd_idempotent :: (Eq b, POrd_ b) => b -> Bool
- class POrd_ b => Lattice_ b where
- type Lattice a = (Eq a, Lattice_ a)
- isChain :: Lattice a => [a] -> Logic a
- isAntichain :: Lattice a => [a] -> Logic a
- data POrdering
- law_Lattice_commutative :: (Eq b, Lattice_ b) => b -> b -> Bool
- law_Lattice_associative :: (Eq b, Lattice_ b) => b -> b -> b -> Bool
- theorem_Lattice_idempotent :: (Eq b, Lattice_ b) => b -> Bool
- law_Lattice_infabsorption :: (Eq b, Lattice b) => b -> b -> Bool
- law_Lattice_supabsorption :: (Eq b, Lattice b) => b -> b -> Bool
- law_Lattice_reflexivity :: Lattice a => a -> Logic a
- law_Lattice_antisymmetry :: Lattice a => a -> a -> Logic a
- law_Lattice_transitivity :: Lattice a => a -> a -> a -> Logic a
- defn_Lattice_greaterthan :: Lattice a => a -> a -> Logic a
- class POrd_ b => MinBound_ b where
- minBound :: b
- type MinBound a = (Eq a, MinBound_ a)
- law_MinBound_inf :: (Eq b, MinBound_ b) => b -> Bool
- class (Lattice_ b, MinBound_ b) => Bounded b where
- maxBound :: b
- law_Bounded_sup :: (Eq b, Bounded b) => b -> Bool
- supremum :: (Foldable bs, Elem bs ~ b, Bounded b) => bs -> b
- supremum_ :: (Foldable bs, Elem bs ~ b, Lattice_ b) => b -> bs -> b
- infimum :: (Foldable bs, Elem bs ~ b, Bounded b) => bs -> b
- infimum_ :: (Foldable bs, Elem bs ~ b, POrd_ b) => b -> bs -> b
- class Bounded b => Complemented b where
- not :: b -> b
- law_Complemented_not :: (ValidLogic b, Complemented b) => b -> Logic b
- class Bounded b => Heyting b where
- (==>) :: b -> b -> b
- modusPonens :: Boolean b => b -> b -> b
- law_Heyting_maxbound :: (Eq b, Heyting b) => b -> Bool
- law_Heyting_infleft :: (Eq b, Heyting b) => b -> b -> Bool
- law_Heyting_infright :: (Eq b, Heyting b) => b -> b -> Bool
- law_Heyting_distributive :: (Eq b, Heyting b) => b -> b -> b -> Bool
- class (Complemented b, Heyting b) => Boolean b
- law_Boolean_infcomplement :: (Eq b, Boolean b) => b -> Bool
- law_Boolean_supcomplement :: (Eq b, Boolean b) => b -> Bool
- law_Boolean_infdistributivity :: (Eq b, Boolean b) => b -> b -> b -> Bool
- law_Boolean_supdistributivity :: (Eq b, Boolean b) => b -> b -> b -> Bool
- class Lattice b => Graded b where
- law_Graded_pred :: Graded b => b -> b -> Bool
- law_Graded_fromEnum :: (Lattice b, Graded b) => b -> b -> Bool
- class Lattice_ a => Ord_ a where
- law_Ord_totality :: Ord a => a -> a -> Bool
- law_Ord_min :: Ord a => a -> a -> Bool
- law_Ord_max :: Ord a => a -> a -> Bool
- type Ord a = (Eq a, Ord_ a)
- data Ordering :: *
- min :: Ord_ a => a -> a -> a
- max :: Ord_ a => a -> a -> a
- maximum :: (ValidLogic b, Bounded b) => [b] -> b
- maximum_ :: (ValidLogic b, Ord_ b) => b -> [b] -> b
- minimum :: (ValidLogic b, Bounded b) => [b] -> b
- minimum_ :: (ValidLogic b, Ord_ b) => b -> [b] -> b
- argmin :: Ord b => a -> a -> (a -> b) -> a
- argmax :: Ord b => a -> a -> (a -> b) -> a
- class (Graded b, Ord_ b) => Enum b where
- law_Enum_succ :: Enum b => b -> b -> Bool
- law_Enum_toEnum :: (Lattice b, Enum b) => b -> Bool
- (||) :: Lattice_ b => b -> b -> b
- (&&) :: Lattice_ b => b -> b -> b
- true :: Bounded b => b
- false :: MinBound_ b => b
- and :: (Foldable bs, Elem bs ~ b, Boolean b) => bs -> b
- or :: (Foldable bs, Elem bs ~ b, Boolean b) => bs -> b
- type family Elem s
- type family SetElem s t
- class (ValidLogic s, Constructible s, ValidSetElem s) => Container s where
- law_Container_preservation :: (Heyting (Logic s), Container s) => s -> s -> Elem s -> Logic s
- class Semigroup s => Constructible s where
- type Constructible0 x = (Monoid x, Constructible x)
- law_Constructible_singleton :: Container s => s -> Elem s -> Logic s
- defn_Constructible_cons :: (Eq_ s, Constructible s) => s -> Elem s -> Logic s
- defn_Constructible_snoc :: (Eq_ s, Constructible s) => s -> Elem s -> Logic s
- defn_Constructible_fromList :: (Eq_ s, Constructible s) => s -> Elem s -> [Elem s] -> Logic s
- defn_Constructible_fromListN :: (Eq_ s, Constructible s) => s -> Elem s -> [Elem s] -> Logic s
- theorem_Constructible_cons :: Container s => s -> Elem s -> Logic s
- fromString :: (Monoid s, Constructible s, Elem s ~ Char) => String -> s
- fromList :: (Monoid s, Constructible s) => [Elem s] -> s
- fromListN :: (Monoid s, Constructible s) => Int -> [Elem s] -> s
- generate :: (Monoid v, Constructible v) => Int -> (Int -> Elem v) -> v
- insert :: Constructible s => Elem s -> s -> s
- empty :: (Monoid s, Constructible s) => s
- isEmpty :: (ValidEq s, Monoid s, Constructible s) => s -> Logic s
- class (Constructible s, Monoid s, Normed s, Scalar s ~ Int) => Foldable s where
- toList :: Foldable s => s -> [Elem s]
- uncons :: s -> Maybe (Elem s, s)
- unsnoc :: s -> Maybe (s, Elem s)
- sum :: Monoid (Elem s) => s -> Elem s
- foldMap :: Monoid a => (Elem s -> a) -> s -> a
- foldr :: (Elem s -> a -> a) -> a -> s -> a
- foldr' :: (Elem s -> a -> a) -> a -> s -> a
- foldl :: (a -> Elem s -> a) -> a -> s -> a
- foldl' :: (a -> Elem s -> a) -> a -> s -> a
- foldr1 :: (Elem s -> Elem s -> Elem s) -> s -> Elem s
- foldr1' :: (Elem s -> Elem s -> Elem s) -> s -> Elem s
- foldl1 :: (Elem s -> Elem s -> Elem s) -> s -> Elem s
- foldl1' :: (Elem s -> Elem s -> Elem s) -> s -> Elem s
- law_Foldable_sum :: (Logic (Scalar s) ~ Logic s, Logic (Elem s) ~ Logic s, Heyting (Logic s), Monoid (Elem s), Eq_ (Elem s), Foldable s) => s -> s -> Logic s
- theorem_Foldable_tofrom :: (Eq_ s, Foldable s) => s -> Logic s
- defn_Foldable_foldr :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s)
- defn_Foldable_foldr' :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s)
- defn_Foldable_foldl :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s)
- defn_Foldable_foldl' :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s)
- defn_Foldable_foldr1 :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s)
- defn_Foldable_foldr1' :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s)
- defn_Foldable_foldl1 :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s)
- defn_Foldable_foldl1' :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s)
- foldtree1 :: Monoid a => [a] -> a
- length :: Normed s => s -> Scalar s
- reduce :: (Monoid (Elem s), Foldable s) => s -> Elem s
- concat :: (Monoid (Elem s), Foldable s) => s -> Elem s
- headMaybe :: Foldable s => s -> Maybe (Elem s)
- tailMaybe :: Foldable s => s -> Maybe s
- lastMaybe :: Foldable s => s -> Maybe (Elem s)
- initMaybe :: Foldable s => s -> Maybe s
- type family Index s
- type family SetIndex s a
- class (ValidLogic s, Monoid s, ValidSetElem s) => IxContainer s where
- type ValidElem s e :: Constraint
- lookup :: Index s -> s -> Maybe (Elem s)
- (!) :: s -> Index s -> Elem s
- findWithDefault :: Elem s -> Index s -> s -> Elem s
- hasIndex :: s -> Index s -> Logic s
- imap :: (ValidElem s (Elem s), ValidElem s b) => (Index s -> Elem s -> b) -> s -> SetElem s b
- toIxList :: s -> [(Index s, Elem s)]
- indices :: s -> [Index s]
- values :: s -> [Elem s]
- law_IxContainer_preservation :: (Logic (Elem s) ~ Logic s, ValidLogic s, Eq_ (Elem s), IxContainer s) => s -> s -> Index s -> Logic s
- defn_IxContainer_bang :: (Eq_ (Elem s), ValidLogic (Elem s), IxContainer s) => s -> Index s -> Logic (Elem s)
- defn_IxContainer_findWithDefault :: (Eq_ (Elem s), IxContainer s) => s -> Index s -> Elem s -> Logic (Elem s)
- defn_IxContainer_hasIndex :: (Eq_ (Elem s), IxContainer s) => s -> Index s -> Logic s
- (!?) :: IxContainer s => s -> Index s -> Maybe (Elem s)
- class (IxContainer s, Enum (Index s)) => Sliceable s where
- class IxContainer s => IxConstructible s where
- law_IxConstructible_lookup :: (ValidLogic (Elem s), Eq_ (Elem s), IxConstructible s) => s -> Index s -> Elem s -> Logic (Elem s)
- defn_IxConstructible_consAt :: (Eq_ s, IxConstructible s) => s -> Index s -> Elem s -> Logic s
- defn_IxConstructible_snocAt :: (Eq_ s, IxConstructible s) => s -> Index s -> Elem s -> Logic s
- defn_IxConstructible_fromIxList :: (Eq_ s, IxConstructible s) => s -> [(Index s, Elem s)] -> Logic s
- insertAt :: IxConstructible s => Index s -> Elem s -> s -> s
- class CanError a where
- data Maybe' a
- justs' :: [Maybe' a] -> [a]
- data Labeled' x y = Labeled' {}
- class IsMutable g => Semigroup g where
- law_Semigroup_associativity :: (Eq g, Semigroup g) => g -> g -> g -> Logic g
- defn_Semigroup_plusequal :: (Eq_ g, Semigroup g, IsMutable g) => g -> g -> Logic g
- type family Actor s
- class (IsMutable s, Semigroup (Actor s)) => Action s where
- law_Action_compatibility :: (Eq_ s, Action s) => Actor s -> Actor s -> s -> Logic s
- defn_Action_dotplusequal :: (Eq_ s, Action s, Logic (Actor s) ~ Logic s) => s -> Actor s -> Logic s
- (+.) :: Action s => Actor s -> s -> s
- class Semigroup g => Cancellative g where
- law_Cancellative_rightminus1 :: (Eq g, Cancellative g) => g -> g -> Bool
- law_Cancellative_rightminus2 :: (Eq g, Cancellative g) => g -> g -> Bool
- defn_Cancellative_plusequal :: (Eq_ g, Cancellative g) => g -> g -> Logic g
- class Semigroup g => Monoid g where
- zero :: g
- isZero :: (Monoid g, ValidEq g) => g -> Logic g
- notZero :: (Monoid g, ValidEq g) => g -> Logic g
- law_Monoid_leftid :: (Monoid g, Eq g) => g -> Bool
- law_Monoid_rightid :: (Monoid g, Eq g) => g -> Bool
- defn_Monoid_isZero :: (Monoid g, Eq g) => g -> Bool
- class Semigroup m => Abelian m
- law_Abelian_commutative :: (Abelian g, Eq g) => g -> g -> Bool
- class (Cancellative g, Monoid g) => Group g where
- negate :: g -> g
- law_Group_leftinverse :: (Eq g, Group g) => g -> Bool
- law_Group_rightinverse :: (Eq g, Group g) => g -> Bool
- defn_Group_negateminus :: (Eq g, Group g) => g -> g -> Bool
- class (Abelian r, Monoid r) => Rg r where
- law_Rg_multiplicativeAssociativity :: (Eq r, Rg r) => r -> r -> r -> Bool
- law_Rg_multiplicativeCommutivity :: (Eq r, Rg r) => r -> r -> Bool
- law_Rg_annihilation :: (Eq r, Rg r) => r -> Bool
- law_Rg_distributivityLeft :: (Eq r, Rg r) => r -> r -> r -> Bool
- theorem_Rg_distributivityRight :: (Eq r, Rg r) => r -> r -> r -> Bool
- defn_Rg_timesequal :: (Eq_ g, Rg g) => g -> g -> Logic g
- class (Monoid r, Rg r) => Rig r where
- one :: r
- isOne :: (Rig g, ValidEq g) => g -> Logic g
- notOne :: (Rig g, ValidEq g) => g -> Logic g
- law_Rig_multiplicativeId :: (Eq r, Rig r) => r -> Bool
- type Rng r = (Rg r, Group r)
- defn_Ring_fromInteger :: (Eq r, Ring r) => r -> Integer -> Bool
- class (Rng r, Rig r) => Ring r where
- fromInteger :: Integer -> r
- indicator :: Ring r => Bool -> r
- class Ring a => Integral a where
- law_Integral_divMod :: (Eq a, Integral a) => a -> a -> Bool
- law_Integral_quotRem :: (Eq a, Integral a) => a -> a -> Bool
- law_Integral_toFromInverse :: (Eq a, Integral a) => a -> Bool
- roundUpToNearest :: Int -> Int -> Int
- fromIntegral :: (Integral a, Ring b) => a -> b
- class Ring r => Field r where
- reciprocal :: r -> r
- (/) :: r -> r -> r
- fromRational :: Rational -> r
- class (Field r, Ord r, Normed r, IsScalar r) => OrdField r
- class Field r => RationalField r where
- toRational :: r -> Rational
- convertRationalField :: (RationalField a, RationalField b) => a -> b
- toFloat :: RationalField a => a -> Float
- toDouble :: RationalField a => a -> Double
- class (OrdField r, Bounded r) => BoundedField r where
- infinity :: BoundedField r => r
- negInfinity :: BoundedField r => r
- class Ring r => ExpRing r where
- (^) :: ExpRing r => r -> r -> r
- class (ExpRing r, Field r) => ExpField r where
- class ExpField r => Real r where
- class (Ring r, Integral s) => QuotientField r s where
- class (Ord_ (Scalar g), Scalar (Scalar g) ~ Scalar g, Ring (Scalar g)) => Normed g where
- size :: g -> Scalar g
- sizeSquared :: g -> Scalar g
- abs :: IsScalar g => g -> g
- class (HasScalar v, Eq_ v, Boolean (Logic v), Logic (Scalar v) ~ Logic v) => Metric v where
- distance :: v -> v -> Scalar v
- distanceUB :: v -> v -> Scalar v -> Scalar v
- isFartherThan :: Metric v => v -> v -> Scalar v -> Logic v
- lb2distanceUB :: (Metric a, ClassicalLogic a) => (a -> a -> Scalar a) -> a -> a -> Scalar a -> Scalar a
- law_Metric_nonnegativity :: Metric v => v -> v -> Logic v
- law_Metric_indiscernables :: (Eq v, Metric v) => v -> v -> Logic v
- law_Metric_symmetry :: Metric v => v -> v -> Logic v
- law_Metric_triangle :: Metric v => v -> v -> v -> Logic v
- type family Scalar m
- type IsScalar r = (Ring r, Ord_ r, Scalar r ~ r, Normed r, ClassicalLogic r, r ~ (r >< r))
- type HasScalar a = IsScalar (Scalar a)
- type family a >< b :: *
- class (Cancellative m, HasScalar m, Rig (Scalar m)) => Cone m where
- class (Abelian v, Group v, HasScalar v, v ~ (v >< Scalar v)) => Module v where
- law_Module_multiplication :: (Eq_ m, Module m) => m -> m -> Scalar m -> Logic m
- law_Module_addition :: (Eq_ m, Module m) => m -> Scalar m -> Scalar m -> Logic m
- law_Module_action :: (Eq_ m, Module m) => m -> Scalar m -> Scalar m -> Logic m
- law_Module_unital :: (Eq_ m, Module m) => m -> Logic m
- defn_Module_dotstarequal :: (Eq_ m, Module m) => m -> Scalar m -> Logic m
- (*.) :: Module v => Scalar v -> v -> v
- class Module v => FreeModule v where
- law_FreeModule_commutative :: (Eq_ m, FreeModule m) => m -> m -> Logic m
- law_FreeModule_associative :: (Eq_ m, FreeModule m) => m -> m -> m -> Logic m
- law_FreeModule_id :: (Eq_ m, FreeModule m) => m -> Logic m
- defn_FreeModule_dotstardotequal :: (Eq_ m, FreeModule m) => m -> m -> Logic m
- class (FreeModule v, IxContainer v, Elem v ~ Scalar v, Index v ~ Int, v ~ SetElem v (Elem v)) => FiniteModule v where
- dim :: v -> Int
- unsafeToModule :: [Scalar v] -> v
- class (FreeModule v, Field (Scalar v)) => VectorSpace v where
- class (VectorSpace v, Normed v, Metric v) => Banach v where
- normalize :: v -> v
- class (Banach v, TensorAlgebra v, Real (Scalar v), OrdField (Scalar v)) => Hilbert v where
- innerProductDistance :: Hilbert v => v -> v -> Scalar v
- innerProductNorm :: Hilbert v => v -> Scalar v
- class (VectorSpace v, VectorSpace (v >< v), Scalar (v >< v) ~ Scalar v, Normed (v >< v), Field (v >< v)) => TensorAlgebra v where
- data Any cxt x where
- type All cxt x = forall xs. (cxt xs, Elem xs ~ x) => xs
- simpleMutableDefn :: (Eq_ a, IsMutable a) => (Mutable (ST s) a -> b -> ST s ()) -> (a -> b -> a) -> a -> b -> Logic a
- module SubHask.Mutable
Comparisons
type family Logic a :: * Source
Every type has an associated logic. Most types use classical logic, which corresponds to the Bool type. But types can use any logical system they want. Functions, for example, use an infinite logic. You probably want your logic to be an instance of Boolean, but this is not required.
See wikipedia's articles on algebraic logic, and infinitary logic for more details.
type ValidLogic a = Complemented (Logic a) Source
type ClassicalLogic a = Logic a ~ Bool Source
Classical logic is implemented using the Prelude's Bool type.
Defines equivalence classes over the type. The values need not have identical representations in the machine to be equal.
(==) :: a -> a -> Logic a infix 4 Source
(/=) :: ValidLogic a => a -> a -> Logic a infix 4 Source
In order to have the "not equals to" relation, your logic must have a notion of "not", and therefore must be Boolean.
type ValidEq a = (Eq_ a, ValidLogic a) Source
law_Eq_reflexive :: Eq a => a -> Logic a Source
law_Eq_symmetric :: Eq a => a -> a -> Logic a Source
law_Eq_transitive :: Eq a => a -> a -> a -> Logic a Source
class Eq_ b => POrd_ b where Source
This is more commonly known as a "meet" semilattice
(<=) :: b -> b -> Logic b infix 4 Source
(<) :: Complemented (Logic b) => b -> b -> Logic b infix 4 Source
law_POrd_commutative :: (Eq b, POrd_ b) => b -> b -> Bool Source
law_POrd_associative :: (Eq b, POrd_ b) => b -> b -> b -> Bool Source
theorem_POrd_idempotent :: (Eq b, POrd_ b) => b -> Bool Source
class POrd_ b => Lattice_ b where Source
See wikipedia for more details.
(>=) :: b -> b -> Logic b infix 4 Source
(>) :: Boolean (Logic b) => b -> b -> Logic b infix 4 Source
pcompare :: (Logic b ~ Bool) => b -> b -> POrdering Source
This function does not make sense on non-classical logics
FIXME: there are probably related functions for all these other logics; is there a nice way to represent them all?
isChain :: Lattice a => [a] -> Logic a Source
A chain is a collection of elements all of which can be compared
isAntichain :: Lattice a => [a] -> Logic a Source
An antichain is a collection of elements none of which can be compared
See wikipedia for more details.
See also the article on Dilward's Theorem.
Represents all the possible ordering relations in a classical logic (i.e. Logic a ~ Bool)
Read POrdering Source | |
Show POrdering Source | |
Arbitrary POrdering Source | |
IsMutable POrdering Source | |
Monoid POrdering Source | |
Semigroup POrdering Source | FIXME: there are many semigroups over POrdering; how should we represent the others? newtypes? |
Eq_ POrdering Source | |
type Logic POrdering = Bool Source | |
data Mutable m POrdering = Mutable_ConT_SubHask_Algebra_POrdering (PrimRef m POrdering) Source |
law_Lattice_commutative :: (Eq b, Lattice_ b) => b -> b -> Bool Source
law_Lattice_associative :: (Eq b, Lattice_ b) => b -> b -> b -> Bool Source
theorem_Lattice_idempotent :: (Eq b, Lattice_ b) => b -> Bool Source
law_Lattice_infabsorption :: (Eq b, Lattice b) => b -> b -> Bool Source
law_Lattice_supabsorption :: (Eq b, Lattice b) => b -> b -> Bool Source
law_Lattice_reflexivity :: Lattice a => a -> Logic a Source
law_Lattice_antisymmetry :: Lattice a => a -> a -> Logic a Source
law_Lattice_transitivity :: Lattice a => a -> a -> a -> Logic a Source
defn_Lattice_greaterthan :: Lattice a => a -> a -> Logic a Source
class POrd_ b => MinBound_ b where Source
Most Lattice literature only considers Bounded
lattices, but here we have both upper and lower bounded lattices.
minBound <= b || not (minBound > b)
law_MinBound_inf :: (Eq b, MinBound_ b) => b -> Bool Source
class (Lattice_ b, MinBound_ b) => Bounded b where Source
A Bounded lattice is a lattice with both a minimum and maximum element
Bounded Bool Source | |
Bounded Char Source | |
Bounded Double Source | |
Bounded Float Source | |
Bounded Int Source | |
Bounded () Source | |
Bounded K3 Source | |
Bounded H3 Source | |
(Bounded a0, Lattice_ a0, MinBound_ a0) => Bounded (WithPreludeOrd a) Source | |
(Bounded t0, Lattice_ t0, MinBound_ t0) => Bounded (NonNegative t) Source | |
(Bounded a0, Lattice_ a0, MinBound_ a0) => Bounded (Jaccard a) Source | |
(Bounded a0, Lattice_ a0, MinBound_ a0) => Bounded (Hamming a) Source | |
(Bounded a0, Lattice_ a0, MinBound_ a0) => Bounded (Levenshtein a) Source | |
(Bounded s0, Lattice_ s0, MinBound_ s0) => Bounded (Uncompensated s) Source | |
OrdRing_ r => Bounded (Goedel_ r) Source | |
(Bounded b0, Lattice_ b0, MinBound_ b0) => Bounded (Boolean2Ring b) Source | |
(Bounded a0, Lattice_ a0, MinBound_ a0) => Bounded (PartitionOnNewline a) Source | |
Bounded b => Bounded (a -> b) Source |
law_Bounded_sup :: (Eq b, Bounded b) => b -> Bool Source
class Bounded b => Complemented b where Source
Complemented Bool Source | |
Complemented () Source | |
(Complemented a0, Bounded a0) => Complemented (WithPreludeOrd a) Source | |
(Complemented t0, Bounded t0) => Complemented (NonNegative t) Source | |
(Complemented a0, Bounded a0) => Complemented (Jaccard a) Source | |
(Complemented a0, Bounded a0) => Complemented (Hamming a) Source | |
(Complemented a0, Bounded a0) => Complemented (Levenshtein a) Source | |
(Complemented s0, Bounded s0) => Complemented (Uncompensated s) Source | |
(Complemented b0, Bounded b0) => Complemented (Boolean2Ring b) Source | |
(Complemented a0, Bounded a0) => Complemented (PartitionOnNewline a) Source | |
Complemented b => Complemented (a -> b) Source |
law_Complemented_not :: (ValidLogic b, Complemented b) => b -> Logic b Source
class Bounded b => Heyting b where Source
Heyting algebras are lattices that support implication, but not necessarily the law of excluded middle.
FIXME: Is every Heyting algebra a cancellative Abelian semigroup? If so, should we make that explicit in the class hierarchy?
Laws
There is a single, simple law that Heyting algebras must satisfy:
a ==> b = c ===> a && c < b
Theorems
From the laws, we automatically get the properties of:
distributivity
See wikipedia for more details.
Heyting Bool Source | |
Heyting () Source | |
Heyting H3 Source | |
(Heyting a0, Bounded a0) => Heyting (WithPreludeOrd a) Source | |
(Heyting t0, Bounded t0) => Heyting (NonNegative t) Source | |
(Heyting a0, Bounded a0) => Heyting (Jaccard a) Source | |
(Heyting a0, Bounded a0) => Heyting (Hamming a) Source | |
(Heyting a0, Bounded a0) => Heyting (Levenshtein a) Source | |
(Heyting s0, Bounded s0) => Heyting (Uncompensated s) Source | |
OrdRing_ r => Heyting (Goedel_ r) Source | |
(Heyting b0, Bounded b0) => Heyting (Boolean2Ring b) Source | |
(Heyting a0, Bounded a0) => Heyting (PartitionOnNewline a) Source | |
Heyting b => Heyting (a -> b) Source |
modusPonens :: Boolean b => b -> b -> b Source
law_Heyting_maxbound :: (Eq b, Heyting b) => b -> Bool Source
law_Heyting_infleft :: (Eq b, Heyting b) => b -> b -> Bool Source
law_Heyting_infright :: (Eq b, Heyting b) => b -> b -> Bool Source
law_Heyting_distributive :: (Eq b, Heyting b) => b -> b -> b -> Bool Source
class (Complemented b, Heyting b) => Boolean b Source
Generalizes Boolean variables.
See wikipedia for more details.
Boolean Bool Source | |
Boolean () Source | |
(Boolean a0, Complemented a0, Heyting a0) => Boolean (WithPreludeOrd a) Source | |
(Boolean t0, Complemented t0, Heyting t0) => Boolean (NonNegative t) Source | |
(Boolean a0, Complemented a0, Heyting a0) => Boolean (Jaccard a) Source | |
(Boolean a0, Complemented a0, Heyting a0) => Boolean (Hamming a) Source | |
(Boolean a0, Complemented a0, Heyting a0) => Boolean (Levenshtein a) Source | |
(Boolean s0, Complemented s0, Heyting s0) => Boolean (Uncompensated s) Source | |
(Boolean b0, Complemented b0, Heyting b0) => Boolean (Boolean2Ring b) Source | |
(Boolean a0, Complemented a0, Heyting a0) => Boolean (PartitionOnNewline a) Source | |
Boolean b => Boolean (a -> b) Source |
law_Boolean_infcomplement :: (Eq b, Boolean b) => b -> Bool Source
law_Boolean_supcomplement :: (Eq b, Boolean b) => b -> Bool Source
law_Boolean_infdistributivity :: (Eq b, Boolean b) => b -> b -> b -> Bool Source
law_Boolean_supdistributivity :: (Eq b, Boolean b) => b -> b -> b -> Bool Source
class Lattice b => Graded b where Source
An element of a graded poset has a unique predecessor.
See wikipedia for more details.
the predecessor in the ordering
Algebrists typically call this function the "rank" of the element in the poset; however we use the name from the standard prelude instead
law_Graded_pred :: Graded b => b -> b -> Bool Source
law_Graded_fromEnum :: (Lattice b, Graded b) => b -> b -> Bool Source
class Lattice_ a => Ord_ a where Source
This is the class of total orderings.
Nothing
Ord_ Bool Source | |
Ord_ Char Source | |
Ord_ Double Source | |
Ord_ Float Source | |
Ord_ Int Source | |
Ord_ Integer Source | |
Ord_ Rational Source | |
Ord_ () Source | |
Ord_ K3 Source | |
Ord_ H3 Source | |
Monad OrdHask LexSet Source | |
Functor * OrdHask LexSet Source | |
(Ord_ a0, Lattice_ a0) => Ord_ (WithPreludeOrd a) Source | |
(Ord_ t0, Lattice_ t0) => Ord_ (NonNegative t) Source | |
(Ord_ a0, Lattice_ a0) => Ord_ (Jaccard a) Source | |
(Ord_ a0, Lattice_ a0) => Ord_ (Hamming a) Source | |
(Ord_ a0, Lattice_ a0) => Ord_ (Levenshtein a) Source | |
(Ord_ s0, Lattice_ s0) => Ord_ (Uncompensated s) Source | |
((~) * (Logic a) Bool, Ord (Elem a), Foldable a, Eq_ a) => Ord_ (Lexical a) Source | |
OrdRing_ r => Ord_ (Goedel_ r) Source | |
Ord_ (LexSet a) Source | |
(ClassicalLogic x, Ord_ x) => Ord_ (Labeled' x y) Source |
law_Ord_totality :: Ord a => a -> a -> Bool Source
law_Ord_min :: Ord a => a -> a -> Bool Source
law_Ord_max :: Ord a => a -> a -> Bool Source
data Ordering :: *
Bounded Ordering | |
Enum Ordering | |
Eq Ordering | |
Ord Ordering | |
Read Ordering | |
Show Ordering | |
Ix Ordering | |
Generic Ordering | |
Arbitrary Ordering | |
CoArbitrary Ordering | |
Monoid Ordering | |
Serial Ordering |
|
Hashable Ordering | |
Semigroup Ordering | |
Monoid Ordering Source | |
Semigroup Ordering Source | |
Eq_ Ordering Source | |
type Rep Ordering = D1 D1Ordering ((:+:) (C1 C1_0Ordering U1) ((:+:) (C1 C1_1Ordering U1) (C1 C1_2Ordering U1))) | |
type Logic Ordering = Bool Source | |
data Mutable m Ordering = Mutable_ConT_GHC_Types_Ordering (PrimRef m Ordering) Source | |
type (==) Ordering a b = EqOrdering a b |
maximum :: (ValidLogic b, Bounded b) => [b] -> b Source
maximum_ :: (ValidLogic b, Ord_ b) => b -> [b] -> b Source
minimum :: (ValidLogic b, Bounded b) => [b] -> b Source
minimum_ :: (ValidLogic b, Ord_ b) => b -> [b] -> b Source
class (Graded b, Ord_ b) => Enum b where Source
In a WellFounded type, every element (except the 'maxBound" if it exists) has a successor element
See http://ncatlab.org/nlab/show/well-founded+relation for more info.
law_Enum_succ :: Enum b => b -> b -> Bool Source
law_Enum_toEnum :: (Lattice b, Enum b) => b -> Bool Source
Boolean helpers
Set-like
type family SetElem s t Source
type SetElem Double a = Double Source | |
type SetElem Float a = Float Source | |
type SetElem Int a = Int Source | |
type SetElem Integer a = Integer Source | |
type SetElem Rational a = Rational Source | |
type SetElem [a] b = [b] Source | |
type SetElem (Ball v) v' = Ball v' Source | |
type SetElem (Componentwise v) v' = Componentwise v' Source | |
type SetElem (BArray e) e' = BArray e' Source | |
type SetElem (UArray e) e' = UArray e' Source | |
type SetElem (Box v) v' = Box v' Source | |
type SetElem (Seq a) b = Seq b Source | |
type SetElem (IntMap e) e' = IntMap e' Source | |
type SetElem (IntMap' e) e' = IntMap' e' Source | |
type SetElem (Set a) b = Set b Source | |
type SetElem (LexSet a) b = LexSet b Source | |
type SetElem (ByteString b) c = ByteString c Source | |
type SetElem (BloomFilter n a) b = BloomFilter n b Source | |
type SetElem (Map i e) e' = Map i e' Source | |
type SetElem (Map' i e) e' = Map' i e' Source | |
type SetElem (SVector k n r) b = SVector k n b Source | |
type SetElem (UVector k n r) b = UVector k n b Source |
class (ValidLogic s, Constructible s, ValidSetElem s) => Container s where Source
This is a generalization of a "set". We do not require a container to be a boolean algebra, just a semigroup.
ValidEq a => Container [a] Source | |
(Metric v, HasScalar v, ClassicalLogic v) => Container (Ball v) Source | |
(ValidLogic e, Eq_ e) => Container (BArray e) Source | |
Unboxable e => Container (UArray e) Source | |
(Lattice v, HasScalar v) => Container (Box v) Source | |
Eq a => Container (Seq a) Source | |
Ord a => Container (Set a) Source | |
Ord a => Container (LexSet a) Source | |
Container (ByteString Char) Source | |
KnownNat n => Container (BloomFilter n a) Source |
law_Container_preservation :: (Heyting (Logic s), Container s) => s -> s -> Elem s -> Logic s Source
class Semigroup s => Constructible s where Source
This is the class for any type that gets "constructed" from smaller types. It is a massive generalization of the notion of a constructable set in topology.
See wikipedia for more details.
singleton :: Elem s -> s Source
creates the smallest value containing the given element
cons :: Elem s -> s -> s Source
inserts an element on the left
snoc :: s -> Elem s -> s Source
inserts an element on the right;
in a non-abelian Constructible
, this may not insert the element;
this occurs, for example, in the Map type.
fromList1 :: Elem s -> [Elem s] -> s Source
Construct the type from a list.
Since lists may be empty (but not all Constructible
s can be empty) we explicitly pass in an Elem s.
fromList1N :: Int -> Elem s -> [Elem s] -> s Source
Like "fromList1" but passes in the size of the list for more efficient construction.
type Constructible0 x = (Monoid x, Constructible x) Source
law_Constructible_singleton :: Container s => s -> Elem s -> Logic s Source
defn_Constructible_cons :: (Eq_ s, Constructible s) => s -> Elem s -> Logic s Source
defn_Constructible_snoc :: (Eq_ s, Constructible s) => s -> Elem s -> Logic s Source
defn_Constructible_fromList :: (Eq_ s, Constructible s) => s -> Elem s -> [Elem s] -> Logic s Source
defn_Constructible_fromListN :: (Eq_ s, Constructible s) => s -> Elem s -> [Elem s] -> Logic s Source
theorem_Constructible_cons :: Container s => s -> Elem s -> Logic s Source
fromString :: (Monoid s, Constructible s, Elem s ~ Char) => String -> s Source
This function needed for the OverloadedStrings language extension
fromList :: (Monoid s, Constructible s) => [Elem s] -> s Source
FIXME: if -XOverloadedLists is enabled, this causes an infinite loop for some reason
insert :: Constructible s => Elem s -> s -> s Source
A more suggestive name for inserting an element into a container that does not remember location
empty :: (Monoid s, Constructible s) => s Source
A slightly more suggestive name for a container's monoid identity
isEmpty :: (ValidEq s, Monoid s, Constructible s) => s -> Logic s Source
A slightly more suggestive name for checking if a container is empty
class (Constructible s, Monoid s, Normed s, Scalar s ~ Int) => Foldable s where Source
Provides inverse operations for Constructible.
FIXME: should this class be broken up into smaller pieces?
toList :: Foldable s => s -> [Elem s] Source
Convert the container into a list.
uncons :: s -> Maybe (Elem s, s) Source
Remove an element from the left of the container.
unsnoc :: s -> Maybe (s, Elem s) Source
Remove an element from the right of the container.
sum :: Monoid (Elem s) => s -> Elem s Source
Add all the elements of the container together.
foldMap :: Monoid a => (Elem s -> a) -> s -> a Source
the default summation uses kahan summation sum :: (Abelian (Elem s), Group (Elem s)) => s -> Elem s sum = snd . foldl' go (zero,zero) where go (c,t) i = ((t'-t)-y,t') where y = i-c t' = t+y
foldr :: (Elem s -> a -> a) -> a -> s -> a Source
foldr' :: (Elem s -> a -> a) -> a -> s -> a Source
foldl :: (a -> Elem s -> a) -> a -> s -> a Source
foldl' :: (a -> Elem s -> a) -> a -> s -> a Source
foldr1 :: (Elem s -> Elem s -> Elem s) -> s -> Elem s Source
foldr1' :: (Elem s -> Elem s -> Elem s) -> s -> Elem s Source
foldl1 :: (Elem s -> Elem s -> Elem s) -> s -> Elem s Source
foldl1' :: (Elem s -> Elem s -> Elem s) -> s -> Elem s Source
law_Foldable_sum :: (Logic (Scalar s) ~ Logic s, Logic (Elem s) ~ Logic s, Heyting (Logic s), Monoid (Elem s), Eq_ (Elem s), Foldable s) => s -> s -> Logic s Source
FIXME:
This law can't be automatically included in the current test system because it breaks parametricity by requiring Monoid (Elem s)
theorem_Foldable_tofrom :: (Eq_ s, Foldable s) => s -> Logic s Source
Note:
The inverse "theorem" of (toList . fromList) xs == xs
is actually not true.
See the Set type for a counter example.
defn_Foldable_foldr :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s) Source
defn_Foldable_foldr' :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s) Source
defn_Foldable_foldl :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s) Source
defn_Foldable_foldl' :: (Eq_ a, a ~ Elem s, Logic a ~ Logic (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> Elem s -> s -> Logic (Elem s) Source
defn_Foldable_foldr1 :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s) Source
defn_Foldable_foldr1' :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s) Source
defn_Foldable_foldl1 :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s) Source
defn_Foldable_foldl1' :: (Eq_ (Elem s), Logic (Scalar s) ~ Logic (Elem s), Boolean (Logic (Elem s)), Foldable s) => (Elem s -> Elem s -> Elem s) -> s -> Logic (Elem s) Source
length :: Normed s => s -> Scalar s Source
For anything foldable, the norm must be compatible with the folding structure.
indexed containers
type Index Double = Int Source | |
type Index Double = Int Source | |
type Index Float = Int Source | |
type Index Float = Int Source | |
type Index Int = Int Source | |
type Index Int = Int Source | |
type Index Integer = Int Source | |
type Index Integer = Int Source | |
type Index Rational = Int Source | |
type Index Rational = Int Source | |
type Index [a] = Int Source | |
type Index (BArray e) = Int Source | |
type Index (UArray e) = Int Source | |
type Index (IntMap e) = Key Source | |
type Index (IntMap' e) = Key Source | |
type Index (Map i e) = i Source | |
type Index (Map' i e) = i Source | |
type Index (SVector k n r) = Int Source | |
type Index (UVector k n r) = Int Source |
class (ValidLogic s, Monoid s, ValidSetElem s) => IxContainer s where Source
An indexed constructible container associates an Index
with each Elem
.
This class generalizes the map abstract data type.
There are two differences in the indexed hierarchy of containers from the standard hierarchy.
1. IxConstructible
requires a Monoid
constraint whereas Constructible
requires a Semigroup
constraint because there are no valid IxConstructible
s (that I know of at least) that are not also Monoid
s.
2. Many regular containers are indexed containers, but not the other way around.
So the class hierarchy is in a different order.
type ValidElem s e :: Constraint Source
FIXME: should the functions below be moved to other classes?
lookup :: Index s -> s -> Maybe (Elem s) Source
(!) :: s -> Index s -> Elem s Source
findWithDefault :: Elem s -> Index s -> s -> Elem s Source
hasIndex :: s -> Index s -> Logic s Source
imap :: (ValidElem s (Elem s), ValidElem s b) => (Index s -> Elem s -> b) -> s -> SetElem s b Source
toIxList :: s -> [(Index s, Elem s)] Source
IxContainer Double Source | |
IxContainer Float Source | |
IxContainer Int Source | |
IxContainer Integer Source | |
IxContainer Rational Source | |
ValidLogic a => IxContainer [a] Source | |
ValidLogic e => IxContainer (BArray e) Source | |
Unboxable e => IxContainer (UArray e) Source | |
Eq e => IxContainer (IntMap e) Source | |
Eq e => IxContainer (IntMap' e) Source | |
(Ord i, Eq e) => IxContainer (Map i e) Source | |
(Ord i, Eq e) => IxContainer (Map' i e) Source | |
(KnownNat n, Monoid r, ValidLogic r, ValidSVector Nat n r, IsScalar r, FreeModule r) => IxContainer (SVector Nat n r) Source | |
(Monoid r, ValidLogic r, ValidSVector Symbol n r, IsScalar r, FreeModule r) => IxContainer (SVector Symbol n r) Source | |
(Monoid r, ValidLogic r, Prim r, IsScalar r) => IxContainer (UVector Symbol n r) Source |
law_IxContainer_preservation :: (Logic (Elem s) ~ Logic s, ValidLogic s, Eq_ (Elem s), IxContainer s) => s -> s -> Index s -> Logic s Source
defn_IxContainer_bang :: (Eq_ (Elem s), ValidLogic (Elem s), IxContainer s) => s -> Index s -> Logic (Elem s) Source
defn_IxContainer_findWithDefault :: (Eq_ (Elem s), IxContainer s) => s -> Index s -> Elem s -> Logic (Elem s) Source
defn_IxContainer_hasIndex :: (Eq_ (Elem s), IxContainer s) => s -> Index s -> Logic s Source
(!?) :: IxContainer s => s -> Index s -> Maybe (Elem s) Source
An infix operator equivalent to lookup
class (IxContainer s, Enum (Index s)) => Sliceable s where Source
Sliceable containers generalize the notion of a substring to any IxContainer.
class IxContainer s => IxConstructible s where Source
Some containers that use indices are not typically constructed with those indices (e.g. Arrays).
singletonAt :: Index s -> Elem s -> s Source
Construct a container with only the single (index,element) pair.
This function is equivalent to singleton
in the Constructible
class.
consAt :: Index s -> Elem s -> s -> s Source
Insert an element, overwriting the previous value if the index already exists.
This function is equivalent to cons
in the Constructible
class.
snocAt :: s -> Index s -> Elem s -> s Source
Insert an element only if the index does not already exist.
If the index already exists, the container is unmodified.
This function is equivalent to snoc
in the Constructible
class.
fromIxList :: [(Index s, Elem s)] -> s Source
This function is the equivalent of fromList
in the Constructible
class.
We do not require all the variants of fromList
because of our Monoid
constraint.
Eq e => IxConstructible (IntMap e) Source | |
Eq e => IxConstructible (IntMap' e) Source | |
(Ord i, Eq e) => IxConstructible (Map i e) Source | |
(Ord i, Eq e) => IxConstructible (Map' i e) Source |
law_IxConstructible_lookup :: (ValidLogic (Elem s), Eq_ (Elem s), IxConstructible s) => s -> Index s -> Elem s -> Logic (Elem s) Source
defn_IxConstructible_consAt :: (Eq_ s, IxConstructible s) => s -> Index s -> Elem s -> Logic s Source
defn_IxConstructible_snocAt :: (Eq_ s, IxConstructible s) => s -> Index s -> Elem s -> Logic s Source
defn_IxConstructible_fromIxList :: (Eq_ s, IxConstructible s) => s -> [(Index s, Elem s)] -> Logic s Source
insertAt :: IxConstructible s => Index s -> Elem s -> s -> s Source
Types
NFData a => NFData (Maybe' a) Source | |
IsMutable (Maybe' a) Source | |
CanError (Maybe' a) Source | |
Semigroup a => Monoid (Maybe' a) Source | |
Semigroup a => Semigroup (Maybe' a) Source | |
ValidEq a => Eq_ (Maybe' a) Source | |
data Mutable m (Maybe' a0) = Mutable_AppT__ConT_SubHask_Algebra_Maybe'___VarT_a_1627508936_ (PrimRef m (Maybe' a)) Source | |
type Scalar (Maybe' a) = Scalar a Source | |
type Logic (Maybe' a) = Logic a Source |
Number-like
Classes with one operator
class IsMutable g => Semigroup g where Source
law_Semigroup_associativity :: (Eq g, Semigroup g) => g -> g -> g -> Logic g Source
This type class is only used by the Action class. It represents the semigroup that acts on our type.
class (IsMutable s, Semigroup (Actor s)) => Action s where Source
Semigroup actions let us apply a semigroup to a set. The theory of Modules is essentially the theory of Ring actions. (See <http://mathoverflow.net/questions/100565/why-are-ring-actions-much-harder-to-find-than-group-actions mathoverflow.) That is why the two classes use similar notation.
See wikipedia for more detail.
FIXME: These types could probably use a more expressive name.
FIXME: We would like every Semigroup to act on itself, but this results in a class cycle.
defn_Action_dotplusequal :: (Eq_ s, Action s, Logic (Actor s) ~ Logic s) => s -> Actor s -> Logic s Source
class Semigroup g => Cancellative g where Source
In a cancellative semigroup,
1)
a + b = a + c ==> b = c
so > (a + b) - b = a + (b - b) = a
2)
b + a = c + a ==> b = c
so > -b + (b + a) = (-b + b) + a = a
This allows us to define "subtraction" in the semigroup. If the semigroup is embeddable in a group, subtraction can be thought of as performing the group subtraction and projecting the result back into the domain of the cancellative semigroup. It is an open problem to fully characterize which cancellative semigroups can be embedded into groups.
See wikipedia for more details.
law_Cancellative_rightminus1 :: (Eq g, Cancellative g) => g -> g -> Bool Source
law_Cancellative_rightminus2 :: (Eq g, Cancellative g) => g -> g -> Bool Source
defn_Cancellative_plusequal :: (Eq_ g, Cancellative g) => g -> g -> Logic g Source
class Semigroup g => Monoid g where Source
isZero :: (Monoid g, ValidEq g) => g -> Logic g Source
FIXME: this should be in the Monoid class, but putting it there requires a lot of changes to Eq
notZero :: (Monoid g, ValidEq g) => g -> Logic g Source
FIXME: this should be in the Monoid class, but putting it there requires a lot of changes to Eq
law_Monoid_leftid :: (Monoid g, Eq g) => g -> Bool Source
law_Monoid_rightid :: (Monoid g, Eq g) => g -> Bool Source
defn_Monoid_isZero :: (Monoid g, Eq g) => g -> Bool Source
class Semigroup m => Abelian m Source
law_Abelian_commutative :: (Abelian g, Eq g) => g -> g -> Bool Source
class (Cancellative g, Monoid g) => Group g where Source
Nothing
law_Group_leftinverse :: (Eq g, Group g) => g -> Bool Source
law_Group_rightinverse :: (Eq g, Group g) => g -> Bool Source
defn_Group_negateminus :: (Eq g, Group g) => g -> g -> Bool Source
Classes with two operators
class (Abelian r, Monoid r) => Rg r where Source
A Rg is a Ring without multiplicative identity or negative numbers. (Hence the removal of the i and n from the name.)
There is no standard terminology for this structure. They might also be called "semirings without identity", "pre-semirings", or "hemirings". See this stackexchange question for a discussion on naming.
Rg Double Source | |
Rg Float Source | |
Rg Int Source | |
Rg Integer Source | |
Rg Rational Source | |
(Rg a0, Abelian a0, Monoid a0) => Rg (WithPreludeOrd a) Source | |
(Rg t0, Abelian t0, Monoid t0) => Rg (NonNegative t) Source | |
FreeModule v => Rg (Componentwise v) Source | |
Rg a => Rg (Forward a) Source | |
(Rg a0, Abelian a0, Monoid a0) => Rg (Jaccard a) Source | |
(Rg a0, Abelian a0, Monoid a0) => Rg (Hamming a) Source | |
(Rg a0, Abelian a0, Monoid a0) => Rg (Levenshtein a) Source | |
(IsMutable b, Boolean b, ValidLogic b) => Rg (Boolean2Ring b) Source | |
Rg b => Rg (a -> b) Source | |
(Rg (Z ((^) p0 k0)), Abelian (Z ((^) p0 k0)), Monoid (Z ((^) p0 k0))) => Rg (Galois p k) Source | |
(ValidLogic r, Ring r) => Rg (Polynomial_ r r) Source | |
VectorSpace a => Rg ((+>) a a) Source | |
(ValidLogic a, Ring a) => Rg (ProofOf * Polynomial_ a) Source | |
(Rg a, Quotient k a b) => Rg ((/) k a b) Source |
law_Rg_multiplicativeAssociativity :: (Eq r, Rg r) => r -> r -> r -> Bool Source
law_Rg_multiplicativeCommutivity :: (Eq r, Rg r) => r -> r -> Bool Source
law_Rg_annihilation :: (Eq r, Rg r) => r -> Bool Source
law_Rg_distributivityLeft :: (Eq r, Rg r) => r -> r -> r -> Bool Source
theorem_Rg_distributivityRight :: (Eq r, Rg r) => r -> r -> r -> Bool Source
defn_Rg_timesequal :: (Eq_ g, Rg g) => g -> g -> Logic g Source
class (Monoid r, Rg r) => Rig r where Source
A Rig is a Rg with multiplicative identity. They are also known as semirings.
Rig Double Source | |
Rig Float Source | |
Rig Int Source | |
Rig Integer Source | |
Rig Rational Source | |
(Rig a0, Monoid a0, Rg a0) => Rig (WithPreludeOrd a) Source | |
(Rig t0, Monoid t0, Rg t0) => Rig (NonNegative t) Source | |
FiniteModule v => Rig (Componentwise v) Source | |
Rig a => Rig (Forward a) Source | |
(Rig a0, Monoid a0, Rg a0) => Rig (Jaccard a) Source | |
(Rig a0, Monoid a0, Rg a0) => Rig (Hamming a) Source | |
(Rig a0, Monoid a0, Rg a0) => Rig (Levenshtein a) Source | |
(IsMutable b, Boolean b, ValidLogic b) => Rig (Boolean2Ring b) Source | |
Rig b => Rig (a -> b) Source | |
(Rig (Z ((^) p0 k0)), Monoid (Z ((^) p0 k0)), Rg (Z ((^) p0 k0))) => Rig (Galois p k) Source | |
(ValidLogic r, Ring r) => Rig (Polynomial_ r r) Source | |
VectorSpace a => Rig ((+>) a a) Source | |
(ValidLogic a, Ring a) => Rig (ProofOf * Polynomial_ a) Source | |
(Rig a, Quotient k a b) => Rig ((/) k a b) Source |
isOne :: (Rig g, ValidEq g) => g -> Logic g Source
FIXME: this should be in the Rig class, but putting it there requires a lot of changes to Eq
notOne :: (Rig g, ValidEq g) => g -> Logic g Source
FIXME: this should be in the Rig class, but putting it there requires a lot of changes to Eq
law_Rig_multiplicativeId :: (Eq r, Rig r) => r -> Bool Source
class (Rng r, Rig r) => Ring r where Source
It is not part of the standard definition of rings that they have a "fromInteger" function. It follows from the definition, however, that we can construct such a function. The "slowFromInteger" function is this standard construction.
See wikipedia and ncatlab for more details.
FIXME: We can construct a Module from any ring by taking (*)=(.*.). Thus, Module should be a superclass of Ring. Currently, however, this creates a class cycle, so we can't do it. A number of type signatures are therefore more complicated than they need to be.
Nothing
fromInteger :: Integer -> r Source
Ring Double Source | |
Ring Float Source | |
Ring Int Source | |
Ring Integer Source | |
Ring Rational Source | |
(Ring a0, Rng a0, Rig a0) => Ring (WithPreludeOrd a) Source | |
FiniteModule v => Ring (Componentwise v) Source | |
Ring a => Ring (Forward a) Source | |
(Ring a0, Rng a0, Rig a0) => Ring (Jaccard a) Source | |
(Ring a0, Rng a0, Rig a0) => Ring (Hamming a) Source | |
(Ring a0, Rng a0, Rig a0) => Ring (Levenshtein a) Source | |
(IsMutable b, Boolean b, ValidLogic b) => Ring (Boolean2Ring b) Source | |
Ring b => Ring (a -> b) Source | |
(Ring (Z ((^) p0 k0)), Rng (Z ((^) p0 k0)), Rig (Z ((^) p0 k0))) => Ring (Galois p k) Source | |
(ValidLogic r, Ring r) => Ring (Polynomial_ r r) Source | |
VectorSpace a => Ring ((+>) a a) Source | |
(ValidLogic a, Ring a) => Ring (ProofOf * Polynomial_ a) Source | |
(Ring a, Quotient k a b) => Ring ((/) k a b) Source |
class Ring a => Integral a where Source
Integral
numbers can be formed from a wide class of things that behave
like integers, but intuitively look nothing like integers.
FIXME: All Fields are integral domains; should we make it a subclass? This wouuld have the (minor?) problem of making the Integral class have to be an approximate embedding. FIXME: Not all integral domains are homomorphic to the integers (e.g. a field)
See wikipedia on integral elements, integral domains, and the ring of integers.
law_Integral_divMod :: (Eq a, Integral a) => a -> a -> Bool Source
law_Integral_quotRem :: (Eq a, Integral a) => a -> a -> Bool Source
law_Integral_toFromInverse :: (Eq a, Integral a) => a -> Bool Source
roundUpToNearest :: Int -> Int -> Int Source
FIXME: This should be moved into the class hierarchy and generalized.
FIXME:
There are more efficient implementations available if you restrict m to powers of 2.
Is GHC smart enough to convert rem
into bit shifts?
See for more possibilities:
http://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number
fromIntegral :: (Integral a, Ring b) => a -> b Source
class (Field r, Ord r, Normed r, IsScalar r) => OrdField r Source
Ordered fields are generalizations of the rational numbers that maintain most of the nice properties. In particular, all finite fields and the complex numbers are NOT ordered fields.
See wikipedia for more details.
class Field r => RationalField r where Source
A Rational field is a field with only a single dimension.
FIXME: this isn't part of standard math; why is it here?
toRational :: r -> Rational Source
convertRationalField :: (RationalField a, RationalField b) => a -> b Source
toFloat :: RationalField a => a -> Float Source
FIXME: These functions don't work for Int's, but they should
toDouble :: RationalField a => a -> Double Source
class (OrdField r, Bounded r) => BoundedField r where Source
The prototypical example of a bounded field is the extended real numbers. Other examples are the extended hyperreal numbers and the extended rationals. Each of these fields has been extensively studied, but I don't know of any studies of this particular abstraction of these fields.
See wikipedia for more details.
infinity :: BoundedField r => r Source
negInfinity :: BoundedField r => r Source
class Ring r => ExpRing r where Source
Rings augmented with the ability to take exponents.
Not all rings have this ability. Consider the ring of rational numbers (represented by Rational in Haskell). Raising any rational to an integral power results in another rational. But raising to a fractional power results in an irrational number. For example, the square root of 2.
See wikipedia for more detail.
FIXME: This class hierarchy doesn't give a nice way exponentiate the integers. We need to add instances for all the quotient groups.
(^) :: ExpRing r => r -> r -> r Source
An alternate form of "(**)" that some people find more convenient.
class (ExpRing r, Field r) => ExpField r where Source
Fields augmented with exponents and logarithms.
Technically, there are fields for which only a subset of the functions below are meaningful. But these fields don't have any practical computational uses that I'm aware of. So I've combined them all into a single class for simplicity.
See wikipedia for more detail.
class ExpField r => Real r where Source
This is a catch-all class for things the real numbers can do but don't exist in other classes.
FIXME: Factor this out into a more appropriate class hierarchy. For example, some (all?) trig functions need to move to a separate class in order to support trig in finite fields (see wikipedia).
FIXME: This class is misleading/incorrect for complex numbers.
FIXME: There's a lot more functions that need adding.
class (Ring r, Integral s) => QuotientField r s where Source
A QuotientField
is a field with an IntegralDomain
as a subring.
There may be many such subrings (for example, every field has itself as an integral domain subring).
This is especially true in Haskell because we have different data types that represent essentially the same ring (e.g. Int and Integer).
Therefore this is a multiparameter type class.
The r
parameter represents the quotient field, and the s
parameter represents the subring.
The main purpose of this class is to provide functions that map elements in r
to elements in s
in various ways.
FIXME: Need examples. Is there a better representation?
See wikipedia for more details.
QuotientField Double Int Source | |
QuotientField Double Integer Source | |
QuotientField Float Int Source | |
QuotientField Float Integer Source | |
QuotientField Rational Int Source | |
QuotientField Rational Integer Source | |
QuotientField b1 b2 => QuotientField (a -> b1) (a -> b2) Source |
Sizes
class (Ord_ (Scalar g), Scalar (Scalar g) ~ Scalar g, Ring (Scalar g)) => Normed g where Source
FIXME: What constraint should be here? Semigroup?
See ncatlab
class (HasScalar v, Eq_ v, Boolean (Logic v), Logic (Scalar v) ~ Logic v) => Metric v where Source
Metric spaces give us the most intuitive notion of distance between objects.
FIXME: There are many other notions of distance and we should make a whole hierarchy.
distance :: v -> v -> Scalar v Source
distanceUB :: v -> v -> Scalar v -> Scalar v Source
If the distance between two datapoints is less than or equal to the upper bound, then this function will return the distance. Otherwise, it will return some number greater than the upper bound.
isFartherThan :: Metric v => v -> v -> Scalar v -> Logic v Source
Calling this function will be faster on some Metric
s than manually checking if distance is greater than the bound.
lb2distanceUB :: (Metric a, ClassicalLogic a) => (a -> a -> Scalar a) -> a -> a -> Scalar a -> Scalar a Source
This function constructs an efficient default implementation for distanceUB
given a function that lower bounds the distance metric.
law_Metric_nonnegativity :: Metric v => v -> v -> Logic v Source
law_Metric_indiscernables :: (Eq v, Metric v) => v -> v -> Logic v Source
law_Metric_symmetry :: Metric v => v -> v -> Logic v Source
law_Metric_triangle :: Metric v => v -> v -> v -> Logic v Source
Linear algebra
type IsScalar r = (Ring r, Ord_ r, Scalar r ~ r, Normed r, ClassicalLogic r, r ~ (r >< r)) Source
A synonym that covers everything we intuitively thing scalar variables should have.
type family a >< b :: * infixr 8 Source
type (><) * * Double Double = Double Source | |
type (><) * * Float Float = Float Source | |
type (><) * * Int Int = Int Source | |
type (><) * * Integer Integer = Integer Source | |
type (><) * * Rational Rational = Rational Source | |
type (><) * * (Galois p k) Integer = Galois p k Source | |
type (><) * * (Polynomial_ r r) r = Polynomial_ r r Source | |
type (><) * k (a -> b) c = a -> (><) * k b c Source | |
type (><) * k ((+>) a b) c Source | |
type (><) * * (SVector k m a) b Source | |
type (><) * k ((/) k1 a b) c = (/) k1 ((><) * k a c) b Source | |
type (><) * k (UVector k1 n r) a = UVector k1 n ((><) * k r a) Source |
class (Cancellative m, HasScalar m, Rig (Scalar m)) => Cone m where Source
A Cone is an "almost linear" subspace of a module. Examples include the cone of positive real numbers and the cone of positive semidefinite matrices.
See <http://en.wikipedia.org/wiki/Cone_%28linear_algebra%29 wikipedia for more details.
FIXME: There are many possible laws for cones (as seen in the wikipedia article). I need to explicitly formulate them here. Intuitively, the laws should apply the module operations and then project back into the "closest point" in the cone.
FIXME: We're using the definition of a cone from linear algebra. This definition is closely related to the definition from topology. What is needed to ensure our definition generalizes to topological cones? See wikipedia and ncatlab for more details.
class (Abelian v, Group v, HasScalar v, v ~ (v >< Scalar v)) => Module v where Source
(.*) :: v -> Scalar v -> v infixl 7 Source
Scalar multiplication.
(.*=) :: PrimBase m => Mutable m v -> Scalar v -> m () infixr 5 Source
Module Double Source | |
Module Float Source | |
Module Int Source | |
Module Integer Source | |
Module Rational Source | |
Module b => Module (a -> b) Source | |
KnownNat ((^) p k) => Module (Galois p k) Source | |
IsScalar r => Module (Polynomial_ r r) Source | |
(VectorSpace a, VectorSpace b) => Module ((+>) a b) Source | |
(Module a, Quotient k a b) => Module ((/) k a b) Source | |
(KnownNat n, Module r, ValidSVector Nat n r, IsScalar r) => Module (SVector Nat n r) Source | |
(Module r, ValidSVector Symbol n r, IsScalar r) => Module (SVector Symbol n r) Source | |
(Module r, Prim r) => Module (UVector Symbol n r) Source |
law_Module_unital :: (Eq_ m, Module m) => m -> Logic m Source
class Module v => FreeModule v where Source
Free modules have a basis. This means it makes sense to perform operations elementwise on the basis coefficients.
See wikipedia for more detail.
(.*.) :: v -> v -> v infixl 7 Source
Multiplication of the components pointwise. For matrices, this is commonly called Hadamard multiplication.
See wikipedia for more detail.
FIXME: This is only valid for modules with a basis.
(.*.=) :: PrimBase m => Mutable m v -> v -> m () infixr 5 Source
The identity for Hadamard multiplication. Intuitively, this object has the value "one" in every column.
FreeModule Double Source | |
FreeModule Float Source | |
FreeModule Int Source | |
FreeModule Integer Source | |
FreeModule Rational Source | |
FreeModule b => FreeModule (a -> b) Source | |
IsScalar r => FreeModule (Polynomial_ r r) Source | |
(VectorSpace a, VectorSpace b) => FreeModule ((+>) a b) Source | |
(KnownNat n, FreeModule r, ValidSVector Nat n r, IsScalar r) => FreeModule (SVector Nat n r) Source | |
(FreeModule r, ValidSVector Symbol n r, IsScalar r) => FreeModule (SVector Symbol n r) Source | |
(FreeModule r, Prim r) => FreeModule (UVector Symbol n r) Source |
law_FreeModule_commutative :: (Eq_ m, FreeModule m) => m -> m -> Logic m Source
law_FreeModule_associative :: (Eq_ m, FreeModule m) => m -> m -> m -> Logic m Source
law_FreeModule_id :: (Eq_ m, FreeModule m) => m -> Logic m Source
defn_FreeModule_dotstardotequal :: (Eq_ m, FreeModule m) => m -> m -> Logic m Source
class (FreeModule v, IxContainer v, Elem v ~ Scalar v, Index v ~ Int, v ~ SetElem v (Elem v)) => FiniteModule v where Source
If our FreeModule has a finite basis, then we can:
- index into the modules basis coefficients
- provide a dense construction method that's a bit more convenient than "fromIxList".
Returns the dimension of the object. For some objects, this may be known statically, and so the parameter will not be "seq"ed. But for others, this may not be known statically, and so the parameter will be "seq"ed.
unsafeToModule :: [Scalar v] -> v Source
FiniteModule Double Source | |
FiniteModule Float Source | |
FiniteModule Int Source | |
FiniteModule Integer Source | |
FiniteModule Rational Source | |
(KnownNat n, FreeModule r, ValidLogic r, ValidSVector Nat n r, IsScalar r) => FiniteModule (SVector Nat n r) Source | |
(FreeModule r, ValidLogic r, ValidSVector Symbol n r, IsScalar r) => FiniteModule (SVector Symbol n r) Source | |
(FreeModule r, ValidLogic r, Prim r, IsScalar r) => FiniteModule (UVector Symbol n r) Source |
class (FreeModule v, Field (Scalar v)) => VectorSpace v where Source
(./) :: v -> Scalar v -> v infixl 7 Source
(./.) :: v -> v -> v infixl 7 Source
(./=) :: PrimBase m => Mutable m v -> Scalar v -> m () infixr 5 Source
(./.=) :: PrimBase m => Mutable m v -> v -> m () infixr 5 Source
VectorSpace Double Source | |
VectorSpace Float Source | |
VectorSpace Rational Source | |
VectorSpace b => VectorSpace (a -> b) Source | |
(VectorSpace a, VectorSpace b) => VectorSpace ((+>) a b) Source | |
(KnownNat n, VectorSpace r, ValidSVector Nat n r, IsScalar r) => VectorSpace (SVector Nat n r) Source | |
(VectorSpace r, ValidSVector Symbol n r, IsScalar r) => VectorSpace (SVector Symbol n r) Source | |
(VectorSpace r, Prim r) => VectorSpace (UVector Symbol n r) Source |
class (VectorSpace v, Normed v, Metric v) => Banach v where Source
A Banach space is a Vector Space equipped with a compatible Norm and Metric.
See wikipedia for more details.
Nothing
Banach Double Source | |
Banach Float Source | |
Banach Rational Source | |
(KnownNat n, VectorSpace r, ValidSVector Nat n r, IsScalar r, ExpField r, Real r, ValidSVector Nat n r, ValidSVector Symbol "dyn" r) => Banach (SVector Nat n r) Source | |
(VectorSpace r, ValidSVector Symbol n r, IsScalar r, ExpField r, Real r) => Banach (SVector Symbol n r) Source |
class (Banach v, TensorAlgebra v, Real (Scalar v), OrdField (Scalar v)) => Hilbert v where Source
Hilbert spaces are a natural generalization of Euclidean space that allows for infinite dimension.
See wikipedia for more details.
FIXME: The result of a dot product must always be an ordered field. This is true even when the Hilbert space is over a non-ordered field like the complex numbers. But the OrdField constraint currently prevents us from doing scalar multiplication on Complex Hilbert spaces. See http://math.stackexchange.com/questions/49348/inner-product-spaces-over-finite-fields and http://math.stackexchange.com/questions/47916/banach-spaces-over-fields-other-than-mathbbc for some technical details.
Hilbert Double Source | |
Hilbert Float Source | |
(KnownNat n, VectorSpace r, ValidSVector Nat n r, IsScalar r, ExpField r, Real r, OrdField r, MatrixField r, ValidSVector Nat n r, ValidSVector Symbol "dyn" r) => Hilbert (SVector Nat n r) Source | |
(VectorSpace r, ValidSVector Symbol n r, IsScalar r, ExpField r, Real r, OrdField r, MatrixField r) => Hilbert (SVector Symbol n r) Source |
innerProductDistance :: Hilbert v => v -> v -> Scalar v Source
innerProductNorm :: Hilbert v => v -> Scalar v Source
class (VectorSpace v, VectorSpace (v >< v), Scalar (v >< v) ~ Scalar v, Normed (v >< v), Field (v >< v)) => TensorAlgebra v where Source
Tensor algebras generalize the outer product of vectors to construct a matrix.
See wikipedia for details.
FIXME: This needs to be replaced by the Tensor product in the Monoidal category Vect
(><) :: v -> v -> v >< v infixr 8 Source
Take the tensor product of two vectors
vXm :: v -> (v >< v) -> v Source
"left multiplication" of a square matrix
mXv :: (v >< v) -> v -> v Source
"right multiplication" of a square matrix
TensorAlgebra Double Source | |
TensorAlgebra Float Source | |
TensorAlgebra Rational Source | |
(FiniteModule (SVector k n r), VectorSpace (SVector k n r), MatrixField r, ToFromVector (SVector k n r)) => TensorAlgebra (SVector k n r) Source |
Spatial programming
Show x => Show (Any Foldable x) Source | |
IsMutable (Any cxt x) Source | |
Foldable (Any Foldable x) Source | |
Constructible (Any Foldable x) Source | |
Normed (Any Foldable x) Source | |
Monoid (Any Foldable x) Source | |
Semigroup (Any Foldable x) Source | |
data Mutable m (Any cxt0 x0) = Mutable_AppT__AppT__ConT_SubHask_Algebra_Any___VarT_cxt_1627508297____VarT_x_1627508298_ (PrimRef m (Any cxt x)) Source | |
type Elem (Any cxt x) = x Source | |
type Scalar (Any cxt x) = Int Source |
type All cxt x = forall xs. (cxt xs, Elem xs ~ x) => xs Source
The type of all containers satisfying the cxt
constraint with elements of type x
.
Helper functions
:: (Eq_ a, IsMutable a) | |
=> (Mutable (ST s) a -> b -> ST s ()) | mutable function |
-> (a -> b -> a) | create a mutable function using "immutable2mutable" |
-> a -> b -> Logic a | the output property |
Creates a quickcheck property for a simple mutable operator defined using "immutable2mutable"
module SubHask.Mutable