compute recursively replace a with b