In CalculatingVisitor, cache results

This avoids recomputation because the witness "tree" is actually a DAG.

Thanks to Rich Joiner for discovering this issue and contributing to the patch.