qs = [R.zero()]*s
while p != R.zero():
- for i in range(0,s):
- division_occurred = false
+ i = 0
+ division_occurred = false
+ while i < s:
# If gs[i].lt() divides p.lt(), then this remainder will
# be zero and the quotient will be in R (and not the
# fraction ring, which is important).
qs[i] += factor
p -= factor*gs[i]
division_occurred = true
- break
+ # Don't increment "i" here because we want to try
+ # again with this "denominator" g[i]. We might
+ # get another factor out of it, but we know that
+ # we can't get another factor out of an *earlier*
+ # denominator g[i-k] for some k.
+ else:
+ i += 1
if not division_occurred:
r += p.lt()