@@ -1,5 +1,11 @@
11# laop - Linear Algebra of Programming library
22
3+[](https://github.com/bolt12/laop/actions)
4+[](https://travis-ci.org/bolt12/laop)
5+[](https://hackage.haskell.org/package/laop)
6+[](http://stackage.org/lts/package/laop)
7+[](http://stackage.org/nightly/package/laop)
8+
39The LAoP discipline generalises relations and functions treating them as
410Boolean matrices and in turn consider these as arrows.
511
@@ -10,40 +16,38 @@ motivation behind the library, the underlying theory, and implementation details
1016This module offers many of the combinators mentioned in the work of
1117[Macedo (2012)](https://repositorium.sdum.uminho.pt/handle/1822/22894) and [Oliveira (2012)](https://pdfs.semanticscholar.org/ccf5/27fa9179081223bffe8067edd81948644fc0.pdf).
1218
13−See the package in hackage [here](https://hackage.haskell.org/package/laop-0.1.0.5)
14−
15−There are a couple of repos with a WIP of benchmarks comparing [matrix composition](https://github.com/bolt12/laop-benchmarks) and a real use case of [data analytics](https://github.com/bolt12/laop-analytics).
19+See the package in hackage [here](https://hackage.haskell.org/package/laop-0.1.1.0)
1620
1721A Functional Pearl has been written and can be regarded as the [reference document](https://github.com/bolt12/tymfgg-pearl) for this library.
1822
1923## Features
2024
21−This library offers:
22−
23−- An internal module representation that uses normal datatypes (`Void`, `()`, `Either`) for matrix dimensions and two
24− type families `FromNat` and `Count` to make it easier to work with these type of matrices.
25−- An interfacing module that uses generalised types for the dimensions and is just a newtype wrapper
26− around the internal matrix data type.
27−- An interfacing module that uses type level naturals for the dimensions and is just a newtype wrapper
28− around the internal matrix data type.
29−- An interfacing module that restricts the matrix contents to being only 0's or 1's (True
30− and False). This module is called 'Relation' and offers many of the combinators seen in
31− AoP and Relational Calculus/Algebra.
32−- A very simple Probabilistic Programming module and several functions and data types to
33− make it easier to deal with sample space.
34−
35−Given this, this new matrix formulation compared to other libraries one has much more advantages, such as:
36−
37−- Has an inductive definition enabling writing matrix manipulation functions in a much more elegant and calculational way;
38−- Statically typed dimensions;
39−- Polymorphic data type dimensions;
40−- Polymorphic matrix content;
41−- Awesome dimension type inference;
42−- Fast type natural conversion via `FromNat` type family;
43−- Matrix `Junc` and `Split`-ing in O(1);
44−- Matrix composition takes advantage of divide-and-conquer and fusion laws.
45−
46−Unfortunately, this approach does not solve the issue of type dimensions being in some way constrainted making it impossible to write Arrow instances, for example. Type inference isn't perfect, when it comes to infer the types of matrices which dimensions are computed using type level naturals multiplication, the compiler needs type annotations in order to succeed.
25+This library offers 4 main matrix programming modules:
26+
27+- One in which matrices are typed with type level natural numbers;
28+- One in which matrices are typed with arbitrary generic data types;
29+- One in which matrices are regarded as relations, i.e. boolean matrices;
30+
31+There's also an experimental module that uses matrices to represent probability
32+distributions.
33+
34+The most interesting feature is that matrices are represented as an inductive data type.
35+Given this formulation, matrix algorithms can be expressed in a much more elegant and
36+calculational style than the traditional vector of vectors representation. This data type
37+guarantees that a matrix will always have valid dimensions. It can also express block matrix
38+computations naturally, which leads to total, efficient and statically typed manipulation
39+and transformation functions.
40+
41+Like matrix multiplication, other common operations, such as matrix transposition, benefit from a block-oriented structure that leads to a simple and natural divide-and-conquer algorithmic solution. Performance wise, this means that without much effort we can obtain optimal cache-oblivious algorithms.
42+
43+Given this, this new matrix formulation compared to other libraries:
44+
45+- Is more compositional and polymorphic and does not have partial matrix manipulation functions (hence less chances for usage errors);
46+- Our implementation of matrices enables simple manipulation of submatrices, making it particularly suitable for formal verification and equation reasoning, using the mathematical framework defined by the linear algebra of programming. Furthermore, the data type constructors ensure that the matrices of this kind are sound, i.e. malformed matrices with incorrect dimensions of the sort, can not be constructed.
47+
48+## Known issues
49+
50+Unfortunately, due to the use of type-level programming features, this approach sometimes requires type dimensions to be constrainted, in some way, impossible to write idiomatic Arrow instances, for example. Type inference isn't perfect, when it comes to infer the types of matrices which dimensions are computed using type level naturals multiplication, the compiler needs type annotations in order to succeed. And not all kinds of programs can be modeled using matrices, namely programs that deal with arbitrary infinite data types such as lists or integers (although there are some workarounds).
4751
4852## Notes
4953