Copyright | (c) Erich Gut |
---|---|
License | BSD3 |
Maintainer | zerich.gut@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
natural numbers promotable to type-level. They serve to parameterize the length of finite lists on type-level (see OAlg.Entity.FinList).
Note We need the language extension UndecidableInstances
for type checking the definition
N0 * m = N0 S n * m = m + n * m
for the type family *
.
Using UndecidableInstances
could cause the type checker to not terminate, but this will
obviously not happen for the given definition (we also use the same definition for the
multiplicative structure of N'
).
Synopsis
- data N'
- toN' :: N -> N'
- type family (n :: N') + (m :: k) :: N'
- type family (n :: k) * (m :: N') :: N'
- class Typeable n => Attestable n where
- data Ats n where
- Ats :: Attestable n => Ats n
- nValue :: Attestable n => p n -> N
- data W n where
- cmpW :: W n -> W m -> Ordering
- (++) :: W n -> W m -> W (n + m)
- (**) :: W n -> W m -> W (n * m)
- data W' = forall n. W' (W n)
- toW' :: N -> W'
- data SomeNatural where
- SomeNatural :: Attestable n => W n -> SomeNatural
- succSomeNatural :: SomeNatural -> SomeNatural
- someNatural :: N -> SomeNatural
- naturals :: [SomeNatural]
- induction :: Any n -> f N0 -> (forall i. f i -> f (i + 1)) -> f n
- type Any = W
- type Some = W'
- refl :: Any x -> x :~: x
- lemma1 :: (x :~: y) -> f x :~: f y
- sbstAdd :: (a :~: a') -> (b :~: b') -> (a + b) :~: (a' + b')
- prpAdd0 :: (a + 0) :~: a
- prpAdd1 :: (a + 1) :~: S a
- prpAdd2 :: (a + 2) :~: S (S a)
- prpEqlAny :: (Any n :~: Any m) -> n :~: m
- prpEqlAny' :: (n :~: m) -> Any n :~: Any m
- prpSuccInjective :: (S n :~: S m) -> n :~: m
- prpAddNtrlL :: p a -> (N0 + a) :~: a
- prpAddNtrlR :: Any a -> (a + N0) :~: a
- prpAddAssoc :: Any a -> Any b -> Any c -> ((a + b) + c) :~: (a + (b + c))
- lemmaAdd1 :: Any a -> Any b -> (S a + b) :~: (a + S b)
- prpAddComm :: Any a -> Any b -> (a + b) :~: (b + a)
- prpMltNtrlL :: Any a -> (N1 * a) :~: a
- prpMltNtrlR :: Any a -> (a * N1) :~: a
- prpDstrL :: Any a -> Any b -> Any c -> ((a + b) * c) :~: ((a * c) + (b * c))
- prpMltAssoc :: Any a -> Any b -> Any c -> ((a * b) * c) :~: (a * (b * c))
- lemmaMlt1 :: Any a -> (a * N0) :~: N0
- lemmaAdd2 :: Any a -> Any b -> Any c -> (a + (b + c)) :~: (b + (a + c))
- prpDstrR :: Any a -> Any b -> Any c -> (a * (b + c)) :~: ((a * b) + (a * c))
- prpMltComm :: Any a -> Any b -> (a * b) :~: (b * a)
- codeW :: N -> N -> String
- itfW :: N -> N -> String
- type N0 = 'N0
- type N1 = S N0
- type N2 = S N1
- type N3 = S N2
- type N4 = S N3
- type N5 = S N4
- type N6 = S N5
- type N7 = S N6
- type N8 = S N7
- type N9 = S N8
- type N10 = S N9
- xSomeNatural :: X N -> X SomeNatural
Natrual Numbers
natural number promotable to type-level.
Instances
Enum N' Source # | |
Show N' Source # | |
Eq N' Source # | |
Ord N' Source # | |
LengthN N' Source # | |
Validable N' Source # | |
Entity N' Source # | |
Defined in OAlg.Entity.Natural | |
Additive N' Source # | |
Distributive N' Source # | |
Defined in OAlg.Entity.Natural | |
Fibred N' Source # | |
FibredOriented N' Source # | |
Defined in OAlg.Entity.Natural | |
Commutative N' Source # | |
Defined in OAlg.Entity.Natural | |
Multiplicative N' Source # | |
Oriented N' Source # | |
Total N' Source # | |
Defined in OAlg.Entity.Natural | |
type Root N' Source # | |
Defined in OAlg.Entity.Natural | |
type Point N' Source # | |
Defined in OAlg.Entity.Natural | |
type N0 * m Source # | |
Defined in OAlg.Entity.Natural | |
type N0 + (n :: N') Source # | |
Defined in OAlg.Entity.Natural | |
type ('S n :: N') * m Source # | |
type ('S n) + (m :: N') Source # | |
type family (n :: N') + (m :: k) :: N' infixr 6 Source #
addition of natural numbers.
Instances
type N0 + (n :: N') Source # | |
Defined in OAlg.Entity.Natural | |
type n + 0 Source # | |
Defined in OAlg.Entity.Natural type n + 0 = n | |
type n + 1 Source # | |
Defined in OAlg.Entity.Natural | |
type n + 2 Source # | |
Defined in OAlg.Entity.Natural | |
type n + 3 Source # | |
Defined in OAlg.Entity.Natural | |
type ('S n) + (m :: N') Source # | |
type family (n :: k) * (m :: N') :: N' infixr 7 Source #
multiplication of natural numbers.
Attest
class Typeable n => Attestable n where Source #
attest for any natural number.
Instances
Attestable N0 Source # | |
Attestable n => Attestable ('S n) Source # | |
nValue :: Attestable n => p n -> N Source #
the corresponding natural number in N
of a type parameterized by n
.
witness for a natural number and serves for inductively definable elements (see induction
).
Instances
Enum W' Source # | |
Show W' Source # | |
Eq W' Source # | |
Ord W' Source # | |
LengthN W' Source # | |
Validable W' Source # | |
Entity W' Source # | |
Defined in OAlg.Entity.Natural | |
Additive W' Source # | |
Distributive W' Source # | |
Defined in OAlg.Entity.Natural | |
Fibred W' Source # | |
FibredOriented W' Source # | |
Defined in OAlg.Entity.Natural | |
Commutative W' Source # | |
Defined in OAlg.Entity.Natural | |
Multiplicative W' Source # | |
Oriented W' Source # | |
Total W' Source # | |
Defined in OAlg.Entity.Natural | |
type Root W' Source # | |
Defined in OAlg.Entity.Natural | |
type Point W' Source # | |
Defined in OAlg.Entity.Natural |
data SomeNatural where Source #
witnesse of some natural.
SomeNatural :: Attestable n => W n -> SomeNatural |
Instances
Show SomeNatural Source # | |
Defined in OAlg.Entity.Natural showsPrec :: Int -> SomeNatural -> ShowS # show :: SomeNatural -> String # showList :: [SomeNatural] -> ShowS # | |
Eq SomeNatural Source # | |
Defined in OAlg.Entity.Natural (==) :: SomeNatural -> SomeNatural -> Bool # (/=) :: SomeNatural -> SomeNatural -> Bool # | |
Validable SomeNatural Source # | |
Defined in OAlg.Entity.Natural valid :: SomeNatural -> Statement Source # |
succSomeNatural :: SomeNatural -> SomeNatural Source #
successor of some natural number.
someNatural :: N -> SomeNatural Source #
mapping N
to SomeNatural
.
Note The implementation of this mapping is quite inefficent for high values of N
.
naturals :: [SomeNatural] Source #
the infinite list of some naturals.
Induction
induction :: Any n -> f N0 -> (forall i. f i -> f (i + 1)) -> f n Source #
induction for general type functions.
Propositions
The following propositions are based - for the most part - on induction.
To ensure that the proofs yield a terminal value, i.e. Refl
, we
used in the proof of the induction hypothesis only propositions which
are proofed before. So: if these propositions terminate, then also
the hypothesis will terminate.
Some basic Lemmas
sbstAdd :: (a :~: a') -> (b :~: b') -> (a + b) :~: (a' + b') Source #
substitution rule for addition.
Some abbreviations
Equivalence of Any
Injectivity of the Successor
Addition
Associativity
prpAddAssoc :: Any a -> Any b -> Any c -> ((a + b) + c) :~: (a + (b + c)) Source #
addition is associative.
Commutativity
Multiplication
Distributivity on the left
prpDstrL :: Any a -> Any b -> Any c -> ((a + b) * c) :~: ((a * c) + (b * c)) Source #
law of left distributivity holds.
Associativity
prpMltAssoc :: Any a -> Any b -> Any c -> ((a * b) * c) :~: (a * (b * c)) Source #
multiplication is associative.
Distributivity on the right
lemmaAdd2 :: Any a -> Any b -> Any c -> (a + (b + c)) :~: (b + (a + c)) Source #
lemma 2 for addition.
prpDstrR :: Any a -> Any b -> Any c -> (a * (b + c)) :~: ((a * b) + (a * c)) Source #
law of right distributivity holds.
Commutativity
Some attests
generating the Haskell code and interface for witnesses.
itfW :: N -> N -> String Source #
itfW n m
generates the haskell interface for the witnesses W
from n
to m
.
X
xSomeNatural :: X N -> X SomeNatural Source #
the induced random variable for some natural number.