Automatic differentiation applied to the AIM algorithm