| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Math.TriangularNumbers
Description
Triangular numbers and various helper functions.
Main use is for linearization of triangular array indexing.
Triangular numbers: @ T_n = Σ_{k=1)^n k = 1 + 2 + 3 + ... + n =
n * (n+1) / 2 = (n+1) choose 2
@
Documentation
triangularNumber :: Int -> Int Source #
Triangular numbers.
linearizeUppertri :: (Int, Int) -> Int Source #
Size of an upper triangle starting at i and ending at j. "(0,N)" what
be the normal thing to use.
toLinear :: Int -> (Int, Int) -> Int Source #
Subword indexing. Given the longest subword and the current subword, calculate a linear index "[0,..]". "(l,n)" in this case means "l"ower bound, length "n". And "(i,j)" is the normal index.
0 1 2 3 <- j = ...
0 1 2 3 i=0
_ 4 5 6 i=1
_ _ 7 8 i=2
9 i=3
i=2, j=3 -> (4+1) * i - tri i + j
_
_ _ the triangular number to subtract.