K i-ddlmZddlmZddlmZmZmZmZddl m Z ddl m Z ddl mZddlmZdd lmZdd lmZGd d ZGd dZy))oo)symbols) FiniteFieldQQ RationalFieldFF)Poly)solve) is_sequence)as_int)divisors)polynomial_congruenceceZdZdZddZddZdZdZdZdZ dZ d Z e d Z e d Ze d Ze d Ze dZe dZy) EllipticCurvea_ Create the following Elliptic Curve over domain. `y^{2} + a_{1} x y + a_{3} y = x^{3} + a_{2} x^{2} + a_{4} x + a_{6}` The default domain is ``QQ``. If no coefficient ``a1``, ``a2``, ``a3``, is given then it creates a curve with the following form: `y^{2} = x^{3} + a_{4} x + a_{6}` Examples ======== References ========== .. [1] J. Silverman "A Friendly Introduction to Number Theory" Third Edition .. [2] https://mathworld.wolfram.com/EllipticDiscriminant.html .. [3] G. Hardy, E. Wright "An Introduction to the Theory of Numbers" Sixth Edition c|dk(rt}n t|}t|j|||||f\}}}}}||_||_|dzd|zz}d|z||zz} |dzd|zz} |dz|zd|z|zz||z|zz ||dzzz|dzz } || | | f\|_|_|_|_ |dz | zd| dzzz d| dzzz d|z| z| zz|_ ||_ ||_ ||_ ||_||_t!d\} } }| | |c|_|_|_t)| dz|z|| z| z|zz|| z|dzzz| dzz || dzz|zz || z|dzzz ||dzzz | |_t-|jt.rd|_yt-|jt2rd|_yy) Nr zx y z)domain)rrmapconvert_domainmodulus_b2_b4_b6_b8_discrim_a1_a2_a3_a4_a6rxyzr _poly isinstancer_rankr)selfa4a6a1a2a3rrb2b4b6b8r(r)r*s b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/ntheory/elliptic_curve.py__init__zEllipticCurve.__init__#s  a<F[F "b"b"1EFBB  UQV^ Vb2g  UQV^ URZ!b&2+ %R" 4rBEz ABE I13RR.$(DHdhQ a"a%i/"r1u*AqDJRPQTRSUVRVYVY[\]_`\`Y``iop dllK 0DJ  m 4DJ5ct||||SNEllipticCurvePoint)r.r(r)r*s r8__call__zEllipticCurve.__call__?s!!Q400r:ct|rt|dk(rd}n|d}|dd\}}n@t|tr%|j|j |j }}}n td|jdk(r|dk(ry|jj|j||j ||j |idk(S)Nrr zInvalid point.rT) r lenr,r>r(r)r* ValueErrorcharacteristicr+subs)r.pointz1x1y1s r8 __contains__zEllipticCurve.__contains__Bs u 5zQ1X2AYFB 1 2%''577BB-. .   ! #azzDFFBCDIIr:c6|jjSr<)r+__repr__r.s r8rKzEllipticCurve.__repr__Qszz""$$r:c|j}|dk(r|S|dk(r@t|jdz |jdz |jdz |j S|jdzd|jzz }|jdz d|jz|jzzd|jzz }td|zd |z|j S) a< Return minimal Weierstrass equation. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e1 = EllipticCurve(-10, -20, 0, -1, 1) >>> e1.minimal() Poly(-x**3 + 13392*x*z**2 + y**2*z + 1080432*z**3, x, y, z, domain='QQ') rrr)r2r$ii)r)rCrrr rr)r.charc4c6s r8minimalzEllipticCurve.minimalTs"" 19K 19 !TXXaZDHHQJPTP\P\] ] XXq[2dhh; &hhk\BtxxK0 03txx< ?SVSVT\\BBr:c:|j}t}|dk\rut|D]e|jj |j |j dij}t||}|jfd|Dg|Std)a5 Return points of curve over Finite Field. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e2 = EllipticCurve(1, 1, 1, 1, 1, modulus=5) >>> e2.points() {(0, 2), (1, 4), (2, 0), (2, 2), (3, 0), (3, 1), (4, 0)} r c3&K|]}|f ywr<).0numis r8 z'EllipticCurve.points..s63q#h6szInfinitely many points) rCsetranger+rDr(r*exprrupdaterB)r.rQall_pt congruence_eqsolrZs @r8pointszEllipticCurve.pointsks"" 194[ 7 $ DFFA0F G L L +M4@ 6#66 7M56 6r:cg}|jtk(rIt|jj |j |D]}|j ||f|S|jj |j ||jdij}t||jD]}|j ||f|S)z7Returns points on the curve for the given x-coordinate.r ) rrr r+rDr(appendr*r^rrC)r.r(ptr)ras r8points_xzEllipticCurve.points_xs  <<2 4::??466156 " 1a&! "  !JJOOTVVQ,BCHHM*=$:M:MN " 1a&! " r:c |jdkDr tdtj|g}t |j j |jd|jdiD]'}|js|j||d)t|jdD]}t|dz}|dz|k(st |j j |j||jdiD]D}|js|||}|jtk7s1|j!|| gF|S)al Return torsion points of curve over Rational number. Return point objects those are finite order. According to Nagell-Lutz theorem, torsion point p(x, y) x and y are integers, either y = 0 or y**2 is divisor of discriminent. According to Mazur's theorem, there are at most 15 points in torsion collection. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e2 = EllipticCurve(-43, 166) >>> sorted(e2.torsion_points()) [(-5, -16), (-5, 16), O, (3, -8), (3, 8), (11, -32), (11, 32)] rz"No torsion point for Finite Field.r T) generatorg?r)rCrBr>point_at_infinityr r+rDr)r* is_rationalrer discriminantintorderrextend)r.lxxrZjps r8torsion_pointszEllipticCurve.torsion_pointss&    "AB B  1 1$ 7 8 DFFA(>?@ &B~~b!% &$++t< *AArE A!tqy DFFA0F GH*B>> R AwwyB!aR) * *r:c6|jjS)z Return domain characteristic. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e2 = EllipticCurve(-43, 166) >>> e2.characteristic 0 )rrCrLs r8rCzEllipticCurve.characteristics||**,,r:c,t|jS)z Return curve discriminant. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e2 = EllipticCurve(0, 17) >>> e2.discriminant -124848 )rmr"rLs r8rlzEllipticCurve.discriminants4==!!r:c |jdk(S)zE Return True if curve discriminant is equal to zero. r)rlrLs r8 is_singularzEllipticCurve.is_singulars   A%%r:c|jdzd|jzz }|jj|dz|jz S)z Return curve j-invariant. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e1 = EllipticCurve(-2, 0, 0, 1, 1) >>> e1.j_invariant 1404928/389 rrNr)rrrto_sympyr")r.rRs r8 j_invariantzEllipticCurve.j_invariants@XXq[2dhh; &||$$RUT]]%:;;r:ch|jdk(r tdt|jS)z Number of points in Finite field. Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e2 = EllipticCurve(1, 0, modulus=19) >>> e2.order 19 rStill not implemented)rCNotImplementedErrorrArcrLs r8rnzEllipticCurve.orders/   ! #%&=> >4;;=!!r:cH|j |jStd)zj Number of independent points of infinite order. For Finite field, it must be 0. r})r-r~rLs r8rankzEllipticCurve.ranks$ :: !:: !"9::r:N)rrrr)r )__name__ __module__ __qualname____doc__r9r?rIrKrTrcrgrtpropertyrCrlrxr{rnrrWr:r8rr s,81 J%C.72 "H - - " "&& << """;;r:rcVeZdZdZedZdZdZdZdZ dZ dZ d Z d Z d Zy ) r>a Point of Elliptic Curve Examples ======== >>> from sympy.ntheory.elliptic_curve import EllipticCurve >>> e1 = EllipticCurve(-17, 16) >>> p1 = e1(0, -4, 1) >>> p2 = e1(1, 0) >>> p1 + p2 (15, -56) >>> e3 = EllipticCurve(-1, 9) >>> e3(1, -3) * 3 (664/169, 17811/2197) >>> (e3(1, -3) * 3).order() oo >>> e2 = EllipticCurve(-2, 0, 0, 1, 1) >>> p = e2(-1,1) >>> q = e2(0, -1) >>> p+q (4, 8) >>> p-q (1, 0) >>> 3*p-5*q (328/361, -2800/6859) ctddd|SNrr r=)curves r8rjz$EllipticCurvePoint.point_at_infinity's!!Q511r:c|jj}|||_|||_|||_||_|j j|_|j j |s tdy)Nz%The curve does not contain this point)rrr(r)r*_curverIrB)r.r(r)r*rdoms r8r9zEllipticCurvePoint.__init__+smmm##QQQ {{** {{''-DE E.r:c|jdk(r|S|jdk(r|S|j|jz |j|jz }}|j|jz |j|jz }}|jj}|jj }|jj }|jj} |jj} ||k7r||z ||z z } ||z||zz ||z z } ns||zdk(r|j|jSd|dzzd|z|zz| z||zz ||z|zd|zzz } |dz | |zzd| zz||zz ||z|zd|zzz } | dz|| zz|z |z |z } | |z | z| z |z }|j| |dS)Nrrrr ) r*r(r)rr#r$r%r&r'rj)r.rsrGrHx2y2r1r2r3r/r0slopeyintx3y3s r8__add__zEllipticCurvePoint.__add__5s 66Q;H 33!8Ktvv BQSS!##acc'B [[__ [[__ [[__ [[__ [[__ 8"Wb)EGb2g%"r'2DRA~--dkk::QY2b(2-25"r'B,R:OPEUFRUNQrT)BrE1bebj1R46GHD AX5 2 % *R /rz]R $ & +{{2r1%%r:c|j|j|jf|j|j|jfkSr<)r(r)r*r.others r8__lt__zEllipticCurvePoint.__lt__Ms3'577EGGUWW*EEEr:ct|}|j|j}|dk(r|S|dkr| | zS|}|r|dzr||z}|dz}||z}|r|Sr)r rjr)r.nrrss r8__mul__zEllipticCurvePoint.__mul__Psv 1I  " "4;; / 6H q55A2:  1uE !GAAA  r:c ||zSr<rW)r.rs r8__rmul__zEllipticCurvePoint.__rmul___s axr:ct|j|j |jj|jzz |jj z |j |jSr<)r>r(r)rr#r%r*rLs r8__neg__zEllipticCurvePoint.__neg__bsN!$&&466'DKKOODFF4J*JT[[__*\^b^d^dfjfqfqrrr:cB|jdk(ry|jj} dj|j |j |j |j S#t$rYnwxYwdj|j |j S)NrOz({}, {}))r*rrformatrzr(r) TypeError)r.rs r8rKzEllipticCurvePoint.__repr__es~ 66Q;kk!! $$S\\$&&%93<<;OP P     00sAA,, A87A8c&|j| Sr<)rrs r8__sub__zEllipticCurvePoint.__sub__os||UF##r:cr|jdk(ry|jdk(ry|dz}|j|j k(ryd}|jtk7rt |j |j k(rt |j|jk(r`||z}|dz }|jdk(r|St |j |j k(r#t |j|jk(r`t S|j j|j k(r|jj|jk(rm||z}|dz }|dkDrt S|jdk(r|S|j j|j k(r$|jj|jk(rmt S)z5 Return point order n where nP = 0. rr rr )r*r)rrrmr(r numerator)r.rsrZs r8rnzEllipticCurvePoint.orderrsH 66Q; 66Q; 1H 33466'>  <<2 acc(acc/c!##h!##o1HQ33!8H acc(acc/c!##h!##o Iccmmqss"qss}}';qA FA2v ssax ccmmqss"qss}}'; r:N)rrrr staticmethodrjr9rrrrrrKrrnrWr:r8r>r> sK822F&0F s1$r:r>N)sympy.core.numbersrsympy.core.symbolrsympy.polys.domainsrrrrsympy.polys.polytoolsr sympy.solvers.solversr sympy.utilities.iterablesr sympy.utilities.miscr factor_rresidue_ntheoryrrr>rWr:r8rs<!%BB&'1'2{;{;|CCr: