Skip to content

fix: allow equal-prime pairs in primelib Goldbach decomposition - #15555

Draft
mohammmad357 wants to merge 1 commit into
TheAlgorithms:masterfrom
mohammmad357:fix-goldbach-repeated-prime
Draft

mohammmad357 wants to merge 1 commit into
TheAlgorithms:masterfrom
mohammmad357:fix-goldbach-repeated-prime

Conversation

@mohammmad357

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Please avoid changing code and tests in one PR.
  • Documentation change?

maths.primelib.goldbach accepts even integers greater than two, but its
inner search begins at i + 1, excluding pairs with the same prime twice.
Consequently 4 and 6 reach the final assertion with an empty answer instead of
returning [2, 2] and [3, 3]. Start j at i so equal-prime pairs are
considered. This is a one-line correctness fix; existing doctests are unchanged.
The existing result for 8 remains [3, 5].

Validation and limitations

Base 215c1f0710f610aaf5ebaeab04edacec3f5308cd, independent branch
fix-goldbach-repeated-prime, one algorithm file only. I checked the open
PR list and searched Goldbach issues before preparing this fix; no open PR
addressing this case was found.

On Python 3.13.7, a full import is blocked by unrelated unparenthesized
multi-exception syntax in maths/greatest_common_divisor.py (requires 3.14+).
For local evidence I compiled the unchanged function ASTs of goldbach,
get_prime_numbers, is_prime and is_even, with their real math.sqrt
dependency. No function body was adapted or mocked:

  • Before: 4 and 6 each raise the final AssertionError.
  • After: every even input from 4 through 500 (249 cases) returns two primes
    with the requested sum; primality was checked with a separate isqrt-based
    trial-division oracle.
  • All 19 existing doctests belonging to these four functions pass.
  • git diff --check passes.

This isolated check is not the full module or upstream Python 3.15t suite.
Ruff/pre-commit installation timed out downloading from files.pythonhosted.org;
these tools are unavailable locally. Kept as a draft pending upstream CI and
review. Prepared with AI coding assistance, with the test scope disclosed.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory. (No new files.)
  • All filenames are lowercase, without spaces or dashes.
  • Functions and variables follow Python naming conventions.
  • All function parameters and return values are annotated with type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include an explanatory URL.
  • Open issues resolved by this PR have a closing keyword.

No new algorithm or open issue is claimed. Full upstream automated testing
has not yet run; the scoped local doctest result is above.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant