Copyright | (C) 2013-2016 University of Twente |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Extensions |
|
- data SNat n where
- snatProxy :: KnownNat n => proxy n -> SNat n
- withSNat :: KnownNat n => (SNat n -> a) -> a
- snat :: KnownNat n => SNat n
- snatToInteger :: SNat n -> Integer
- snatToNum :: Num a => SNat n -> a
- addSNat :: SNat a -> SNat b -> SNat (a + b)
- mulSNat :: SNat a -> SNat b -> SNat (a * b)
- powSNat :: SNat a -> SNat b -> SNat (a ^ b)
- subSNat :: SNat (a + b) -> SNat b -> SNat a
- divSNat :: 1 <= b => SNat a -> SNat b -> SNat (Div a b)
- modSNat :: 1 <= b => SNat a -> SNat b -> SNat (Mod a b)
- flogBaseSNat :: (2 <= base, 1 <= x) => SNat base -> SNat x -> SNat (FLog base x)
- clogBaseSNat :: (2 <= base, 1 <= x) => SNat base -> SNat x -> SNat (CLog base x)
- logBaseSNat :: FLog base x ~ CLog base x => SNat base -> SNat x -> SNat (Log base x)
- pow2SNat :: SNat a -> SNat (2 ^ a)
- data UNat :: Nat -> * where
- toUNat :: SNat n -> UNat n
- fromUNat :: UNat n -> SNat n
- addUNat :: UNat n -> UNat m -> UNat (n + m)
- mulUNat :: UNat n -> UNat m -> UNat (n * m)
- powUNat :: UNat n -> UNat m -> UNat (n ^ m)
- predUNat :: UNat (n + 1) -> UNat n
- subUNat :: UNat (m + n) -> UNat n -> UNat m
- data BNat :: Nat -> * where
- toBNat :: SNat n -> BNat n
- fromBNat :: BNat n -> SNat n
- showBNat :: BNat n -> String
- succBNat :: BNat n -> BNat (n + 1)
- addBNat :: BNat n -> BNat m -> BNat (n + m)
- mulBNat :: BNat n -> BNat m -> BNat (n * m)
- powBNat :: BNat n -> BNat m -> BNat (n ^ m)
- predBNat :: BNat (n + 1) -> BNat n
- div2BNat :: BNat (2 * n) -> BNat n
- div2Sub1BNat :: BNat ((2 * n) + 1) -> BNat n
- log2BNat :: BNat (2 ^ n) -> BNat n
- stripZeros :: BNat n -> BNat n
Singleton natural numbers
Data type
Singleton value for a type-level natural number n
- CLaSH.Promoted.Nat.Literals contains a list of predefined
SNat
literals - CLaSH.Promoted.Nat.TH has functions to easily create large ranges of new
SNat
literals
Construction
withSNat :: KnownNat n => (SNat n -> a) -> a Source #
Supply a function with a singleton natural n
according to the context
Conversion
snatToInteger :: SNat n -> Integer Source #
Arithmetic
Partial
divSNat :: 1 <= b => SNat a -> SNat b -> SNat (Div a b) Source #
Division of two singleton natural numbers
modSNat :: 1 <= b => SNat a -> SNat b -> SNat (Mod a b) Source #
Modulo of two singleton natural numbers
Floor of the logarithm of a natural number
Ceiling of the logarithm of a natural number
Exact integer logarithm of a natural number
NB: Only works when the argument is a power of the base
Specialised
Unary/Peano-encoded natural numbers
Data type
data UNat :: Nat -> * where Source #
Unary representation of a type-level natural
NB: Not synthesisable
Construction
toUNat :: SNat n -> UNat n Source #
Convert a singleton natural number to its unary representation
NB: Not synthesisable
Conversion
fromUNat :: UNat n -> SNat n Source #
Convert a unary-encoded natural number to its singleton representation
NB: Not synthesisable
Arithmetic
addUNat :: UNat n -> UNat m -> UNat (n + m) Source #
Add two unary-encoded natural numbers
NB: Not synthesisable
mulUNat :: UNat n -> UNat m -> UNat (n * m) Source #
Multiply two unary-encoded natural numbers
NB: Not synthesisable
powUNat :: UNat n -> UNat m -> UNat (n ^ m) Source #
Power of two unary-encoded natural numbers
NB: Not synthesisable
Partial
predUNat :: UNat (n + 1) -> UNat n Source #
Predecessor of a unary-encoded natural number
NB: Not synthesisable
subUNat :: UNat (m + n) -> UNat n -> UNat m Source #
Subtract two unary-encoded natural numbers
NB: Not synthesisable
Base-2 encoded natural numbers
Data type
data BNat :: Nat -> * where Source #
Base-2 encoded natural number
- NB: The LSB is the left/outer-most constructor:
- NB: Not synthesisable
>>>
B0 (B1 (B1 BT))
b6
Constructors
Starting/Terminating element:
BT ::
BNat
0
Construction
toBNat :: SNat n -> BNat n Source #
Convert a singleton natural number to its base-2 representation
NB: Not synthesisable
Conversion
fromBNat :: BNat n -> SNat n Source #
Convert a base-2 encoded natural number to its singleton representation
NB: Not synthesisable
Pretty printing base-2 encoded natural numbers
showBNat :: BNat n -> String Source #
Show a base-2 encoded natural as a binary literal
NB: The LSB is shown as the right-most bit
>>>
d789
d789>>>
toBNat d789
b789>>>
showBNat (toBNat d789)
"0b1100010101">>>
0b1100010101 :: Integer
789
Arithmetic
succBNat :: BNat n -> BNat (n + 1) Source #
Successor of a base-2 encoded natural number
NB: Not synthesisable
addBNat :: BNat n -> BNat m -> BNat (n + m) Source #
Add two base-2 encoded natural numbers
NB: Not synthesisable
mulBNat :: BNat n -> BNat m -> BNat (n * m) Source #
Multiply two base-2 encoded natural numbers
NB: Not synthesisable
powBNat :: BNat n -> BNat m -> BNat (n ^ m) Source #
Power of two base-2 encoded natural numbers
NB: Not synthesisable
Partial
predBNat :: BNat (n + 1) -> BNat n Source #
Predecessor of a base-2 encoded natural number
NB: Not synthesisable
div2BNat :: BNat (2 * n) -> BNat n Source #
Divide a base-2 encoded natural number by 2
NB: Not synthesisable
div2Sub1BNat :: BNat ((2 * n) + 1) -> BNat n Source #
Subtract 1 and divide a base-2 encoded natural number by 2
NB: Not synthesisable
log2BNat :: BNat (2 ^ n) -> BNat n Source #
Get the log2 of a base-2 encoded natural number
NB: Not synthesisable
Normalisation
stripZeros :: BNat n -> BNat n Source #
Strip non-contributing zero's from a base-2 encoded natural number
>>>
B1 (B0 (B0 (B0 BT)))
b1>>>
showBNat (B1 (B0 (B0 (B0 BT))))
"0b0001">>>
showBNat (stripZeros (B1 (B0 (B0 (B0 BT)))))
"0b1">>>
stripZeros (B1 (B0 (B0 (B0 BT))))
b1
NB: Not synthesisable