Skip to content

fix wrong results & huge slowdown due to broken caching in .multiplication_by_m() #33156

@yyyyx4

Description

@yyyyx4

On 9.5.rc0:

 sage: E = EllipticCurve(GF(65537), [5,5])
 sage: %prun _ = E.multiplication_by_m(127)
         5078 function calls (4879 primitive calls) in 0.406 seconds
         [...]
 sage: %prun _ = E.multiplication_by_m(127, x_only=True)
         327932 function calls (327450 primitive calls) in 21.238 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    32263   19.549    0.001   19.584    0.001 polynomial_ring.py:309(_element_constructor_)
         [...]

The main reason seems to be the same as that underlying #33164: The variables x of PolynomialRing(R,'x') and PolynomialRing(R,'x,y') compare equal, hence we obtain a multivariate polynomial when querying the cache with the univariate variable, and then we run into the multivariate incarnation of #33165.

This can also lead to incorrect results when using the ._multiple_x_{numerator,denominator}() methods directly:

sage: E = EllipticCurve(GF(65537), [5,5])
sage: R.<x> = E.base_field()[]
sage: E._multiple_x_numerator(5, x=R.quotient(x^2).gen())
10220*xbar + 42539
sage: E._multiple_x_numerator(5)
10220*xbar + 42539

Component: elliptic curves

Author: Lorenz Panny

Branch/Commit: 1f2fd60

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/33156

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions