Computation termination

I’d love to see a minimal working example of the thing you’re trying to achieve. It doesn’t have to be a real-life example, but some small working code that shows the behavior you want for functions f and g.