convergents(x, n) returns n+1 convergents, not the documented first n

Open Beginner friendly
#269 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, rust
Domain
backend

Research direction

Start with the Python binding for convergents(x, n) and compare its count handling with the documented behavior in the docstring. Reproduce the examples with rssn.Session().compute(...), then add or update tests covering positive counts and n = 0. The change is done when the function returns exactly the requested number of convergents, including an empty list for zero.

Written by the indexing model from the issue text.

Description

area/number-theory good first issue help wanted kind/contract severity/4-minor

convergents(x, n) returns n + 1 convergents instead of the first n.

import rssn
s = rssn.Session()

s.compute("convergents(355/113, 1)").text   # 'list(3, 22/7)'              <- 2 values
s.compute("convergents(355/113, 2)").text   # 'list(3, 22/7, 355/113)'     <- 3 values

The docstring says "first n continued-fraction convergents p_k / q_k of x", so n = 1 should give list(3) and n = 2 should give list(3, 22/7).

Every call is off by one, which means the count argument cannot be used to request a specific prefix length — the usual reason to pass n at all. It also means convergents(x, 0) returns one convergent rather than an empty list, which is the natural reading of "first 0".

Expected: n values, i.e. list(3) for n = 1 and list(3, 22/7) for n = 2.

rssn 0.3.0, Python binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
18h 51m
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.