[Edit]
The general question seems incredibly hard to solve. Here is a significantly restricted version of this question.
How do I dete
Proof verification systems like Coq and Agda may be able to do what you're looking for.