A Rigorous Approach to Formal Methods