(work in progress) inference algorithm with immediate resolution ; trying an efficient approach
Clean up the new inference algorithm and fix the substituion merge function that was lacking a recursive call.