MMonicVale
Workflows

Coding workflows · Monic polynomial division

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Monic polynomial division

A concrete starting point
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), a

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗