Error Detection in Number-Theoretic and Algebraic Algorithms