There are formulas to phase out the tax credit as your income goes up, equations to calculate what expenses you have left after claiming the credit, formulas to apportion a 529 withdrawal between the remaining education expenses and ineligible uses, and then formulas to apportion the ineligible portion between principal and interest.