Open the context
Choose the project folder and name the files or behavior involved.
Divide integer polynomials of at most 21 coefficients by a monic divisor. Check zero polynomials and a constant divisor, rejecting non-integer coefficients or a non-monic divisor and verifying the quotient-remainder identity.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def divide_monic(dividend, divisor):
for row in (dividend, divisor):
if type(row) not in (list, tuple) or len(row) > 21:
raise ValueError("at most 21 coefficients")
if any(type(x) is not int for x in row): raise ValueError("integers")
def trim(row):
row = list(row)
while row and row[0] == 0: row.pop(0)
return row
a, b = trim(dividend), trim(divisor)
if not b or b[0] != 1: raise ValueError("monic divisor")
quotient = [0] * max(0, len(a) - len(b) + 1)
while a and len(a) >= len(b):
degree, factor = len(a) - len(b), a[0]
quotient[len(quotient)-1-degree] = factor
a = trim([x-factor*y for x,y in zip(a,b)] + a[len(b):])
return trim(quotient), aThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.