Add source code for diverge calculator.

Left out from previous commit.