Skip to content

Annotate return types of bsgs and discrete_log_rho - #42987

Merged
vbraun merged 4 commits into
sagemath:developfrom
starnotes-xj:annotate-groups-generic-returns
Oct 18, 2026
Merged

vbraun merged 4 commits into
sagemath:developfrom
starnotes-xj:annotate-groups-generic-returns

Conversation

@starnotes-xj

Copy link
Copy Markdown
Contributor

Motivation

The generic discrete-log helpers in sage.groups.generic carry no return annotations, so static checkers infer nothing for the baby-step/giant-step and Pollard-rho entry points.

Changes

  • bsgs(...) -> Integer and discrete_log_rho(...) -> Integer — every return path builds the result through Z(...), where Z is bound to integer_ring.ZZ, so the result is a Sage Integer regardless of the group or the bounds type.
  • Adds a module-level from sage.rings.integer import Integer (the module currently only imports the sage.rings.integer module object and function-local Integers). Verified import sage.rings.integer completes without loading sage.groups.generic, so no cycle is introduced.
  • discrete_log and discrete_log_lambda are deliberately left unannotated: the lambda walk accumulates its counter from the raw bounds values (c = ub, d = 0), so its return type follows the bounds input type (int bounds produce a Python int), and discrete_log(algorithm='lambda') can propagate that.

Also adds a checker-only probe src/sage/tests/type_checking/group_discrete_log.py (same form as finite_fields.py from #42672).

Verification

Against Sage 10.9 (Python 3.13): both functions executed over GF(11) with int and Sage Integer bounds (results Integer in all shapes); py_compile passes; annotations AST-verified name-resolvable.

Both functions return ZZ(i)-built Sage Integers on every path (Z is
aliased to integer_ring.ZZ in their bodies), so -> Integer is universally
true. discrete_log and discrete_log_lambda are deliberately left
unannotated: the lambda walk accumulates c/d from the raw bounds values,
so its return type follows the bounds input type (int bounds -> int).

Adds a checker-only probe under src/sage/tests/type_checking/ following
finite_fields.py.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 11:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Documentation preview for this PR (built with commit b16572a; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@starnotes-xj

Copy link
Copy Markdown
Contributor Author

The failing test-long (src/sage/[p-z]*) job is a timeout flake in an unrelated module (Polynomial.any_root hit the --warn-long 30 alarm on a slow runner); this PR only touches src/sage/groups/generic.py ([g-o]). All other test-long shards and the ubuntu/windows conda jobs are green.

@starnotes-xj

Copy link
Copy Markdown
Contributor Author

The Conda minimal (Python 3.14) failure is a cysignals segfault inside the test runner infra (stack frames only in signals.cpython-314), not a test failure of this branch.

@vbraun
vbraun merged commit 9bb4b80 into sagemath:develop Oct 18, 2026
23 checks passed
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.

3 participants