infinite loop in Sage hnf code