scispace - formally typeset
Proceedings ArticleDOI

Fun with semirings: a functional pearl on the abuse of linear algebra

Stephen K. Dolan
- Vol. 48, Iss: 9, pp 101-110
TLDR
A typeclass in Haskell is defined for describing closed semirings, and a few functions for manipulating matrices and polynomials over them are implemented, which can be used to calculate transitive closures, find shortest or longest or widest paths in a graph, analyse the data flow of imperative programs, optimally pack knapsacks, and perform discrete event simulations.
Abstract
Describing a problem using classical linear algebra is a very well-known problem-solving technique. If your question can be formulated as a question about real or complex matrices, then the answer can often be found by standard techniques. It's less well-known that very similar techniques still apply where instead of real or complex numbers we have a closed semiring, which is a structure with some analogue of addition and multiplication that need not support subtraction or division. We define a typeclass in Haskell for describing closed semirings, and implement a few functions for manipulating matrices and polynomials over them. We then show how these functions can be used to calculate transitive closures, find shortest or longest or widest paths in a graph, analyse the data flow of imperative programs, optimally pack knapsacks, and perform discrete event simulations, all by just providing an appropriate underlying closed semiring.

read more

Citations
More filters
Book ChapterDOI

I got plenty o’ nuttin’

TL;DR: This paper defines and establishes the basic metatheory of a type theory supporting a ‘dependent lollipop’ \((x\!:\!S)\multimap T[x]\), where what the input used to be is in some way commemorated by the type of the output.
Proceedings ArticleDOI

Algebraic graphs with class (functional pearl)

TL;DR: A minimalistic and elegant approach to working with graphs in Haskell that is built on a rigorous mathematical foundation --- an algebra of graphs --- that allows us to apply equational reasoning for proving the correctness of graph transformation algorithms.
Posted Content

Aggregations over Generalized Hypertree Decompositions.

TL;DR: It is shown that straightforward extensions of standard multiway join algorithms and generalized hypertree decompositions (GHDs) provide best-known runtime guarantees, and a pair of simple tests that determine if two orderings of aggregation operators are equivalent and if a GHD is compatible with a given ordering are provided.
Journal ArticleDOI

Certified Context-Free Parsing: A formalisation of Valiant's Algorithm in Agda

TL;DR: This paper presents an algebraic specification, implementation, and proof of correctness of a generalisation of Valiant's algorithm that can be used for recognition, parsing or generic calculation of the transitive closure of upper triangular matrices.
References
More filters
Book

The Design and Analysis of Computer Algorithms

TL;DR: This text introduces the basic data structures and programming techniques often used in efficient algorithms, and covers use of lists, push-down stacks, queues, trees, and graphs.
Journal ArticleDOI

Algorithm 97: Shortest path

TL;DR: The procedure was originally programmed in FORTRAN for the Control Data 160 desk-size computer and was limited to te t ra t ion because subroutine recursiveness in CONTROL Data 160 FORTRan has been held down to four levels in the interests of economy.
Book

Semirings and their Applications

TL;DR: In this paper, the authors define Hemirings and semirings as "sets and relations with values with values in a semiring" and define a set of conditions on semimodal construction.
Journal ArticleDOI

Regular Expressions and State Graphs for Automata

TL;DR: Algorithms are presented for converting a state graph describing thebehavior of an automaton to a regular expression describing the behavior of the same automaton, and for converting an regular expression into a stategraph.
Related Papers (5)