#13692: factor_trial_division returns Python longs as exponents
---------------------------------+------------------------------------------
Reporter: dimpase | Owner: was
Type: defect | Status: positive_review
Priority: major | Milestone: sage-5.5
Component: number theory | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers: Dmitrii Pasechnik
Authors: Nils Bruin | Merged in:
Dependencies: | Stopgaps:
---------------------------------+------------------------------------------
Changes (by dimpase):
* status: needs_review => positive_review
* reviewer: => Dmitrii Pasechnik
Old description:
> unlike the rest (?) of Sage, factor_trial_division returns exponents of
> primes as Python longs:
> {{{
> sage: from sage.rings.factorint import factor_trial_division
> sage: [t for t in factor_trial_division(8)]
> [(2, 3L)]
> }}}
> It is a bug or a feature? It leads to this kind of data also being
> returned by factor():
> {{{
> sage: [t for t in Integer(8).factor(limit=1000)]
> [(2, 3L)]
> }}}
> as opposed to
> {{{
> sage: [t for t in Integer(8).factor()]
> [(2, 3)]
> }}}
> See this [https://groups.google.com/d/topic/sage-
> support/whnvwlDrAEo/discussion sage-support thread].
> Something should be fixed - either factor(), or factor_trial_division()
New description:
unlike the rest (?) of Sage, factor_trial_division returns exponents of
primes as Python longs:
{{{
sage: from sage.rings.factorint import factor_trial_division
sage: [t for t in factor_trial_division(8)]
[(2, 3L)]
}}}
It is a bug or a feature? It leads to this kind of data also being
returned by factor():
{{{
sage: [t for t in Integer(8).factor(limit=1000)]
[(2, 3L)]
}}}
as opposed to
{{{
sage: [t for t in Integer(8).factor()]
[(2, 3)]
}}}
See this [https://groups.google.com/d/topic/sage-
support/whnvwlDrAEo/discussion sage-support thread].
Something should be fixed - either factor(), or factor_trial_division()
Apply
* [attachment:trac_13692-no_unsigned_long.patch]
--
Comment:
Replying to [comment:2 nbruin]:
> Problem was that exponent was a `cdef unsigned long`, which doesn't
necessarily fit in a python int, so apparently cython converts that to a
python long automatically.
>
> By defining it to be a `cdef long` instead I don't think we'll get any
overflow (it's an exponent of a prime in the factorization of an integer!)
and now the exponent is returned as a `python int` instead. Unless people
feel strongly that this should be cast to a `Integer` instead, I think
this should be sufficient.
To have the exponents of type int() is consistent, it seem. Looks good,
positive review.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13692#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.