Sketch validation algorithm for general recursion