@@ -3908,10 +3908,11 @@ def _acted_upon_(self, other, side):
39083908
39093909 return Q
39103910
3911- def discrete_log (self , Q ):
3911+ def log (self , base ):
39123912 r"""
3913- Return the discrete logarithm of `Q` to base `P` = ``self``,
3914- that is, an integer `x` such that `xP = Q`.
3913+ Return the discrete logarithm of this point to the given ``base``.
3914+ In other words, return an integer `x` such that `xP = Q` where
3915+ `P` is ``base`` and `Q` is this point.
39153916
39163917 A :class:`ValueError` is raised if there is no solution.
39173918
@@ -3939,7 +3940,7 @@ def discrete_log(self, Q):
39393940
39403941 INPUT:
39413942
3942- - ``Q `` (point) -- another point on the same curve as ``self``.
3943+ - ``base `` (point) -- another point on the same curve as ``self``.
39433944
39443945 OUTPUT:
39453946
@@ -3962,7 +3963,7 @@ def discrete_log(self, Q):
39623963 762
39633964 sage: P = E.gens()[0]
39643965 sage: Q = 400*P
3965- sage: P.discrete_log(Q )
3966+ sage: Q.log(P )
39663967 400
39673968
39683969 TESTS:
@@ -3976,27 +3977,53 @@ def discrete_log(self, Q):
39763977 sage: E = EllipticCurve(j=GF((p,e),'a').random_element())
39773978 sage: P = E.random_point()
39783979 sage: Q = randrange(2**999) * P
3979- sage: x = P.discrete_log(Q )
3980+ sage: x = Q.log(P )
39803981 sage: x*P == Q
39813982 True
39823983 """
3983- if Q not in self .parent ():
3984+ if base not in self .parent ():
39843985 raise ValueError ('not a point on the same curve' )
3985- n = self .order ()
3986- if n * Q :
3987- raise ValueError ('ECDLog problem has no solution (order of Q does not divide order of P )' )
3986+ n = base .order ()
3987+ if n * self :
3988+ raise ValueError ('ECDLog problem has no solution (order does not divide order of base )' )
39883989 E = self .curve ()
39893990 F = E .base_ring ()
39903991 p = F .cardinality ()
39913992 if F .is_prime_field () and n == p :
39923993 # Anomalous case
3993- return self .padic_elliptic_logarithm (Q , p )
3994+ return base .padic_elliptic_logarithm (self , p )
39943995 elif hasattr (E , '_order' ) and E ._order .gcd (n ** 2 ) == n :
39953996 pass # cyclic rational n-torsion -> okay
3996- elif self .weil_pairing (Q , n ) != 1 :
3997+ elif base .weil_pairing (self , n ) != 1 :
39973998 raise ValueError ('ECDLog problem has no solution (non-trivial Weil pairing)' )
39983999
3999- return ZZ (pari .elllog (self .curve (), Q , self , n ))
4000+ return ZZ (pari .elllog (self .curve (), self , base , n ))
4001+
4002+ def discrete_log (self , Q ):
4003+ r"""
4004+ Legacy version of :meth:`log` with its arguments swapped.
4005+
4006+ Note that this method uses the opposite argument ordering
4007+ of all other logarithm methods in Sage; see :issue:`37150`.
4008+
4009+ EXAMPLES::
4010+
4011+ sage: E = EllipticCurve(j=GF(101)(5))
4012+ sage: P, = E.gens()
4013+ sage: (2*P).log(P)
4014+ 2
4015+ sage: (2*P).discrete_log(P)
4016+ doctest:warning ...
4017+ DeprecationWarning: The syntax P.discrete_log(Q) ... Please update your code. ...
4018+ 45
4019+ sage: P.discrete_log(2*P)
4020+ 2
4021+ """
4022+ from sage .misc .superseded import deprecation
4023+ deprecation (37150 , 'The syntax P.discrete_log(Q) is being replaced by '
4024+ 'Q.log(P) to make the argument ordering of logarithm'
4025+ ' methods in Sage uniform. Please update your code.' )
4026+ return Q .log (self )
40004027
40014028 def padic_elliptic_logarithm (self ,Q , p ):
40024029 r"""
0 commit comments