Repository navigation
R23-T055: Add extended_euclid trace and non-coprime doctests to chinese_remainder_theorem - #65
Open
code-paul-creator wants to merge 1 commit into
Open
code-paul-creator wants to merge 1 commit into
code-paul-creator wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Traces
extended_euclid(10, 6)andchinese_remainder_theorem(5, 1, 7, 3)step by step (by hand and with pdb) and turns the observations into doctests: intermediate results of the recursion, the gcd identity, and the documented behaviour for non-coprime moduli.Related Issue
Fixes: #55
Type of Change
Changes Made
extended_euclid: intermediate results(2,0)->(1,0),(4,2)->(0,1),(6,4)->(1,-1), the identity ax + by == gcd (2 for (10, 6)), and the a < b swap case (5, 7).chinese_remainder_theorem: the result satisfies both congruences for coprime moduli, and a non-coprime input (6, 1, 4, 3) documented as unsupported.work/R23-T055/TRACE.md(tables of both traces, pdb steps, the surprise) andtrace_driver.py.Screenshots / Recordings
Testing
python -m pytest --doctest-modules maths/chinese_remainder_theorem.py-> passed (21 doctests)ruff check maths/chinese_remainder_theorem.py-> all checks passedwork/R23-T055/TRACE.mdand checked by handChecklist
Additional Notes
Finding: the existing doctest
chinese_remainder_theorem(6, 1, 4, 3) -> 14passes but 14 is not a valid solution (14 % 6 = 2, 14 % 4 = 2). 6 and 4 are not coprime, soextended_euclid(6, 4)gives ax + by = 2 instead of 1 and the formula breaks silently. A valid answer exists (7, modulo 12). Not fixed here (doctests only); documented in the new doctests and inwork/R23-T055/TRACE.md. A follow-up could raise ValueError when gcd(n1, n2) != 1.