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

  • Authors:
  • Stephen Dolan

  • Affiliations:
  • University of Cambridge, Cambridge, United Kingdom

  • Venue:
  • Proceedings of the 18th ACM SIGPLAN international conference on Functional programming
  • Year:
  • 2013

Quantified Score

Hi-index 0.00

Visualization

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.