@@ -3888,10 +3888,11 @@ def _acted_upon_(self, other, side):
38883888
38893889 return Q
38903890
3891- def discrete_log (self , Q ):
3891+ def log (self , base ):
38923892 r"""
3893- Return the discrete logarithm of `Q` to base `P` = ``self``,
3894- that is, an integer `x` such that `xP = Q`.
3893+ Return the discrete logarithm of this point to the given ``base``.
3894+ In other words, return an integer `x` such that `xP = Q` where
3895+ `P` is ``base`` and `Q` is this point.
38953896
38963897 A :class:`ValueError` is raised if there is no solution.
38973898
@@ -3919,7 +3920,7 @@ def discrete_log(self, Q):
39193920
39203921 INPUT:
39213922
3922- - ``Q `` (point) -- another point on the same curve as ``self``.
3923+ - ``base `` (point) -- another point on the same curve as ``self``.
39233924
39243925 OUTPUT:
39253926
@@ -3942,7 +3943,7 @@ def discrete_log(self, Q):
39423943 762
39433944 sage: P = E.gens()[0]
39443945 sage: Q = 400*P
3945- sage: P.discrete_log(Q )
3946+ sage: Q.log(P )
39463947 400
39473948
39483949 TESTS:
@@ -3956,27 +3957,53 @@ def discrete_log(self, Q):
39563957 sage: E = EllipticCurve(j=GF((p,e),'a').random_element())
39573958 sage: P = E.random_point()
39583959 sage: Q = randrange(2**999) * P
3959- sage: x = P.discrete_log(Q )
3960+ sage: x = Q.log(P )
39603961 sage: x*P == Q
39613962 True
39623963 """
3963- if Q not in self .parent ():
3964+ if base not in self .parent ():
39643965 raise ValueError ('not a point on the same curve' )
3965- n = self .order ()
3966- if n * Q :
3967- raise ValueError ('ECDLog problem has no solution (order of Q does not divide order of P )' )
3966+ n = base .order ()
3967+ if n * self :
3968+ raise ValueError ('ECDLog problem has no solution (order does not divide order of base )' )
39683969 E = self .curve ()
39693970 F = E .base_ring ()
39703971 p = F .cardinality ()
39713972 if F .is_prime_field () and n == p :
39723973 # Anomalous case
3973- return self .padic_elliptic_logarithm (Q , p )
3974+ return base .padic_elliptic_logarithm (self , p )
39743975 elif hasattr (E , '_order' ) and E ._order .gcd (n ** 2 ) == n :
39753976 pass # cyclic rational n-torsion -> okay
3976- elif self .weil_pairing (Q , n ) != 1 :
3977+ elif base .weil_pairing (self , n ) != 1 :
39773978 raise ValueError ('ECDLog problem has no solution (non-trivial Weil pairing)' )
39783979
3979- return ZZ (pari .elllog (self .curve (), Q , self , n ))
3980+ return ZZ (pari .elllog (self .curve (), self , base , n ))
3981+
3982+ def discrete_log (self , Q ):
3983+ r"""
3984+ Legacy version of :meth:`log` with its arguments swapped.
3985+
3986+ Note that this method uses the opposite argument ordering
3987+ of all other logarithm methods in Sage; see :issue:`37150`.
3988+
3989+ EXAMPLES::
3990+
3991+ sage: E = EllipticCurve(j=GF(101)(5))
3992+ sage: P, = E.gens()
3993+ sage: (2*P).log(P)
3994+ 2
3995+ sage: (2*P).discrete_log(P)
3996+ doctest:warning ...
3997+ DeprecationWarning: The syntax P.discrete_log(Q) ... Please update your code. ...
3998+ 45
3999+ sage: P.discrete_log(2*P)
4000+ 2
4001+ """
4002+ from sage .misc .superseded import deprecation
4003+ deprecation (37150 , 'The syntax P.discrete_log(Q) is being replaced by '
4004+ 'Q.log(P) to make the argument ordering of logarithm'
4005+ ' methods in Sage uniform. Please update your code.' )
4006+ return Q .log (self )
39804007
39814008 def padic_elliptic_logarithm (self ,Q , p ):
39824009 r"""
0 commit comments