Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard abstraction for semirings or monoids in C++?

Does boost, or any other common C++ library, provide semiring or monoid abstractions (such as a template class)?

I have some algorithms that I would like to express in terms of these abstract structures, but so far I haven't come across anything. I can write my own, but ideally these would be in a library I'm already using such as boost.

Thanks!

like image 611
Jason Dagit Avatar asked Apr 10 '13 00:04

Jason Dagit


2 Answers

SGI STL has MonoidOperation concept. For instance power function is implemented for MonoidOperation.

Boost.Graph library also defines Monoid concept.

In addition to already suggested Elements of Programming you may look to Notes on Programming by Alexander Stepanov (one of authors of EoP). Notes are freely available, and have some overlap with EoP book.

There are style difference between EoP and Notes - EoP is very terse like math textbook, but Notes are more "informal" - there some small stories, etc.

By the way, both have some discussion of referenced above power function implementation.

P.S. there are great talks by Alexander Stepanov:

  • Elements of Programming
  • STL and Its Design Principles
  • A9 lectures
  • Greatest Common Measure

P.P.S. Collected Papers of Alexander A. Stepanov

like image 168
Evgeny Panasyuk Avatar answered Sep 30 '22 15:09

Evgeny Panasyuk


To the best of my knowledge the C++ standard library doesn't have any abstractions around these structures. However, Alex Stepanov, inventor of the STL, wrote a book entitled Elements of Programming in which he writes a variety of useful functions that operate on monoids, groups, binary operators, unary functions, etc. It's not necessarily a standard, but it might be a good starting point for further exploration.

Hope this helps!

like image 36
templatetypedef Avatar answered Sep 30 '22 16:09

templatetypedef