CConvergeHazel
Workflows

Coding workflows · Continued-fraction convergents

03
Built around your work

A concrete starting point

Return every convergent of a continued fraction with one through 32 integer coefficients bounded by 1000 in magnitude. Test a negative first term and 3-7-16, rejecting nonpositive later terms and keeping numerator-denominator pairs exact.

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.

Continued-fraction convergents

A concrete starting point
def convergents(terms):
    terms = tuple(terms)
    if not 1 <= len(terms) <= 32 or any(type(a) is not int or abs(a) > 1000 for a in terms):
        raise ValueError("fraction.terms")
    if any(a <= 0 for a in terms[1:]):
        raise ValueError("fraction.tail")
    p0, p1, q0, q1, out = 0, 1, 1, 0, []
    for a in terms:
        p, q = a*p1+p0, a*q1+q0
        out.append((p, q))
        p0, p1, q0, q1 = p1, p, q1, q
    return out

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 ↗