Repository navigation
Annotate return types of bsgs and discrete_log_rho - #42987
Conversation
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.
There was a problem hiding this comment.
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.
|
Documentation preview for this PR (built with commit b16572a; changes) is ready! 🎉 |
|
The failing |
|
The |
Motivation
The generic discrete-log helpers in
sage.groups.genericcarry no return annotations, so static checkers infer nothing for the baby-step/giant-step and Pollard-rho entry points.Changes
bsgs(...) -> Integeranddiscrete_log_rho(...) -> Integer— every return path builds the result throughZ(...), whereZis bound tointeger_ring.ZZ, so the result is a SageIntegerregardless of the group or the bounds type.from sage.rings.integer import Integer(the module currently only imports thesage.rings.integermodule object and function-localIntegers). Verifiedimport sage.rings.integercompletes without loadingsage.groups.generic, so no cycle is introduced.discrete_loganddiscrete_log_lambdaare deliberately left unannotated: the lambda walk accumulates its counter from the rawboundsvalues (c = ub,d = 0), so its return type follows the bounds input type (intbounds produce a Pythonint), anddiscrete_log(algorithm='lambda')can propagate that.Also adds a checker-only probe
src/sage/tests/type_checking/group_discrete_log.py(same form asfinite_fields.pyfrom #42672).Verification
Against Sage 10.9 (Python 3.13): both functions executed over
GF(11)withintand SageIntegerbounds (resultsIntegerin all shapes);py_compilepasses; annotations AST-verified name-resolvable.