There is a tiny mistake in the formula at line 54:13. You can see it by setting i = 1, j = 2, and r = 1, which leads to the expression e[1, 0] + e[2, 2] + ..., where e[1, 0] is undefined. The correct formula can be found in CLRS, Section 15.5, on Optimal Binary Search Trees.
@gormelkumyan3573