It would be nice if there was a guarantee that primeFactors are sorted. The user code may then take advantage of it, eschewing sorts and thus speeding up. This property seems to hold, and it probably should not take much effort to prove and add some automated property checking.