Hacker News new | ask | show | jobs
by rotifer 2111 days ago
While playing around with a problem at work involving Markov chains and graph connectivity, I found it useful to know that I could write (in Java) a generic method that performed "exponentiation by squaring" on semigroups.

So, in addition to being able to raise numbers to powers I could also use it on matrices whose elements belonged to a semiring.

That is, I could use the same code on a matrix of doubles with "times" and "plus" (for the Markov chains), as well as a matrix of booleans with "and" and "or" (for the graph connectivity).

(Of course, I could have used special purpose libraries, but these were small problems and it was fun. :)