oalg-base-1.1.4.0: Algebraic structures on oriented entities and limits as a tool kit to solve algebraic problems.
Copyright(c) Erich Gut
LicenseBSD3
Maintainerzerich.gut@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

OAlg.Entity.Natural

Description

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

Natrual Numbers

data N' Source #

natural number promotable to type-level.

Constructors

N0 
S N' 

Instances

Instances details
Enum N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

succ :: N' -> N' #

pred :: N' -> N' #

toEnum :: Int -> N' #

fromEnum :: N' -> Int #

enumFrom :: N' -> [N'] #

enumFromThen :: N' -> N' -> [N'] #

enumFromTo :: N' -> N' -> [N'] #

enumFromThenTo :: N' -> N' -> N' -> [N'] #

Show N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

showsPrec :: Int -> N' -> ShowS #

show :: N' -> String #

showList :: [N'] -> ShowS #

Eq N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

(==) :: N' -> N' -> Bool #

(/=) :: N' -> N' -> Bool #

Ord N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

compare :: N' -> N' -> Ordering #

(<) :: N' -> N' -> Bool #

(<=) :: N' -> N' -> Bool #

(>) :: N' -> N' -> Bool #

(>=) :: N' -> N' -> Bool #

max :: N' -> N' -> N' #

min :: N' -> N' -> N' #

LengthN N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

lengthN :: N' -> N Source #

Validable N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

valid :: N' -> Statement Source #

Entity N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Additive N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

zero :: Root N' -> N' Source #

(+) :: N' -> N' -> N' Source #

ntimes :: N -> N' -> N' Source #

Distributive N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Fibred N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Associated Types

type Root N' Source #

Methods

root :: N' -> Root N' Source #

FibredOriented N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Commutative N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Multiplicative N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

one :: Point N' -> N' Source #

(*) :: N' -> N' -> N' Source #

npower :: N' -> N -> N' Source #

Oriented N' Source # 
Instance details

Defined in OAlg.Entity.Natural

Associated Types

type Point N' Source #

Total N' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Root N' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Root N' = Orientation ()
type Point N' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Point N' = ()
type N0 * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type N0 * m = N0
type N0 + (n :: N') Source # 
Instance details

Defined in OAlg.Entity.Natural

type N0 + (n :: N') = n
type ('S n :: N') * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type ('S n :: N') * m = m + (n * m)
type ('S n) + (m :: N') Source # 
Instance details

Defined in OAlg.Entity.Natural

type ('S n) + (m :: N') = 'S (n + m)

toN' :: N -> N' Source #

mapping a natural number in N to N'.

type family (n :: N') + (m :: k) :: N' infixr 6 Source #

addition of natural numbers.

Instances

Instances details
type N0 + (n :: N') Source # 
Instance details

Defined in OAlg.Entity.Natural

type N0 + (n :: N') = n
type n + 0 Source # 
Instance details

Defined in OAlg.Entity.Natural

type n + 0 = n
type n + 1 Source # 
Instance details

Defined in OAlg.Entity.Natural

type n + 1 = 'S n
type n + 2 Source # 
Instance details

Defined in OAlg.Entity.Natural

type n + 2 = 'S ('S n)
type n + 3 Source # 
Instance details

Defined in OAlg.Entity.Natural

type n + 3 = 'S ('S ('S n))
type ('S n) + (m :: N') Source # 
Instance details

Defined in OAlg.Entity.Natural

type ('S n) + (m :: N') = 'S (n + m)

type family (n :: k) * (m :: N') :: N' infixr 7 Source #

multiplication of natural numbers.

Instances

Instances details
type N0 * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type N0 * m = N0
type 0 * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type 0 * m = N0
type 1 * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type 1 * m = m
type 2 * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type 2 * m = m + m
type ('S n :: N') * m Source # 
Instance details

Defined in OAlg.Entity.Natural

type ('S n :: N') * m = m + (n * m)

Attest

class Typeable n => Attestable n where Source #

attest for any natural number.

Methods

attest :: W n Source #

Instances

Instances details
Attestable N0 Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

attest :: W N0 Source #

Attestable n => Attestable ('S n) Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

attest :: W ('S n) Source #

data Ats n where Source #

witness of being attestable.

Constructors

Ats :: Attestable n => Ats n 

nValue :: Attestable n => p n -> N Source #

the corresponding natural number in N of a type parameterized by n.

data W n where Source #

witness for a natural number and serves for inductively definable elements (see induction).

Constructors

W0 :: W N0 
SW :: W n -> W (n + 1) 

Instances

Instances details
Show (W n) Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

showsPrec :: Int -> W n -> ShowS #

show :: W n -> String #

showList :: [W n] -> ShowS #

Eq (W n) Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

(==) :: W n -> W n -> Bool #

(/=) :: W n -> W n -> Bool #

LengthN (W n) Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

lengthN :: W n -> N Source #

Validable (W n) Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

valid :: W n -> Statement Source #

cmpW :: W n -> W m -> Ordering Source #

comparing of two witnesses.

(++) :: W n -> W m -> W (n + m) infixr 6 Source #

addition of witnesses.

(**) :: W n -> W m -> W (n * m) infixr 7 Source #

multiplication of witnesses.

data W' Source #

union of all witnesses, which is isomorphic to N and N'.

Constructors

forall n. W' (W n) 

Instances

Instances details
Enum W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

succ :: W' -> W' #

pred :: W' -> W' #

toEnum :: Int -> W' #

fromEnum :: W' -> Int #

enumFrom :: W' -> [W'] #

enumFromThen :: W' -> W' -> [W'] #

enumFromTo :: W' -> W' -> [W'] #

enumFromThenTo :: W' -> W' -> W' -> [W'] #

Show W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

showsPrec :: Int -> W' -> ShowS #

show :: W' -> String #

showList :: [W'] -> ShowS #

Eq W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

(==) :: W' -> W' -> Bool #

(/=) :: W' -> W' -> Bool #

Ord W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

compare :: W' -> W' -> Ordering #

(<) :: W' -> W' -> Bool #

(<=) :: W' -> W' -> Bool #

(>) :: W' -> W' -> Bool #

(>=) :: W' -> W' -> Bool #

max :: W' -> W' -> W' #

min :: W' -> W' -> W' #

LengthN W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

lengthN :: W' -> N Source #

Validable W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

valid :: W' -> Statement Source #

Entity W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Additive W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

zero :: Root W' -> W' Source #

(+) :: W' -> W' -> W' Source #

ntimes :: N -> W' -> W' Source #

Distributive W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Fibred W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Associated Types

type Root W' Source #

Methods

root :: W' -> Root W' Source #

FibredOriented W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Commutative W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Multiplicative W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Methods

one :: Point W' -> W' Source #

(*) :: W' -> W' -> W' Source #

npower :: W' -> N -> W' Source #

Oriented W' Source # 
Instance details

Defined in OAlg.Entity.Natural

Associated Types

type Point W' Source #

Total W' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Root W' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Root W' = Orientation ()
type Point W' Source # 
Instance details

Defined in OAlg.Entity.Natural

type Point W' = ()

toW' :: N -> W' Source #

mapping a natural value in N to W'.

data SomeNatural where Source #

witnesse of some natural.

Constructors

SomeNatural :: Attestable n => W n -> SomeNatural 

Instances

Instances details
Show SomeNatural Source # 
Instance details

Defined in OAlg.Entity.Natural

Eq SomeNatural Source # 
Instance details

Defined in OAlg.Entity.Natural

Validable SomeNatural Source # 
Instance details

Defined in OAlg.Entity.Natural

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.

type Any = W Source #

predicate for any natural number.

type Some = W' Source #

some witness.

Some basic Lemmas

refl :: Any x -> x :~: x Source #

reflexivity.

lemma1 :: (x :~: y) -> f x :~: f y Source #

well definition of parameterized types.

sbstAdd :: (a :~: a') -> (b :~: b') -> (a + b) :~: (a' + b') Source #

substitution rule for addition.

Some abbreviations

prpAdd0 :: (a + 0) :~: a Source #

0 is right neural for the addition.

prpAdd1 :: (a + 1) :~: S a Source #

adding 1 is equal to the successor.

prpAdd2 :: (a + 2) :~: S (S a) Source #

adding 2 is equal to the successor of the successor.

Equivalence of Any

prpEqlAny :: (Any n :~: Any m) -> n :~: m Source #

equality of the underlying natural number.

prpEqlAny' :: (n :~: m) -> Any n :~: Any m Source #

Any is as parameterized type is well defined.

Injectivity of the Successor

prpSuccInjective :: (S n :~: S m) -> n :~: m Source #

successor is injective.

Addition

Neutral Element

N0 is the neutral element of +.

prpAddNtrlL :: p a -> (N0 + a) :~: a Source #

N0 is left neutral for the addition.

prpAddNtrlR :: Any a -> (a + N0) :~: a Source #

N0 is the right neutral for the addition.

Associativity

prpAddAssoc :: Any a -> Any b -> Any c -> ((a + b) + c) :~: (a + (b + c)) Source #

addition is associative.

Commutativity

lemmaAdd1 :: Any a -> Any b -> (S a + b) :~: (a + S b) Source #

lemma 1 for the addition.

prpAddComm :: Any a -> Any b -> (a + b) :~: (b + a) Source #

addition is commutative.

Multiplication

Neutral Element

N1 = S N0 is the neutral element of *.

prpMltNtrlL :: Any a -> (N1 * a) :~: a Source #

N1 is left neutral for the multiplication.

prpMltNtrlR :: Any a -> (a * N1) :~: a Source #

N1 is right neutral for the 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

lemmaMlt1 :: Any a -> (a * N0) :~: N0 Source #

right multiplication of N0 is N0.

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

prpMltComm :: Any a -> Any b -> (a * b) :~: (b * a) Source #

multiplication is commutative.

Some attests

generating the Haskell code and interface for witnesses.

codeW :: N -> N -> String Source #

codeW n m generates the haskell code for the witnesses W of N' from n to m.

itfW :: N -> N -> String Source #

itfW n m generates the haskell interface for the witnesses W from n to m.

type N0 = 'N0 Source #

0.

type N1 = S N0 Source #

1.

type N2 = S N1 Source #

2.

type N3 = S N2 Source #

3.

type N4 = S N3 Source #

4.

type N5 = S N4 Source #

5.

type N6 = S N5 Source #

6.

type N7 = S N6 Source #

7.

type N8 = S N7 Source #

8.

type N9 = S N8 Source #

9.

type N10 = S N9 Source #

10.

X

xSomeNatural :: X N -> X SomeNatural Source #

the induced random variable for some natural number.