10 ' torsion.ub 20 print "y^2 = x^3 + ax + b" 30 input "A=";A:input "B=";B:D=4*A^3+27*B^2 40 if D=0 then print "singular curve":goto 30 50 def fnE(X)=X^3+A*X+B 60 print "A=";A;", B=";B;", Disc=";D 70 ' phase 1 : y=0, b<>0 80 if B=0 then R%=fnSub(0,0):goto 140 90 for I=1 to abs(B):if B@I>0 then 120 100 if fnE(I)=0 then R%=fnSub(I,0) 110 if fnE(-I)=0 then R%=fnSub(-I,0) 120 next I:goto 170 130 ' phase 1 : b=0 140 if A>=0 then 170 150 C=isqrt(-A):if res=0 then R%=fnSub(A,0):R%=fnSub(-A,0) 160 ' phase 2 : y^2 | D 170 for J=1 to isqrt(abs(D)):J2=J^2:if D@(J2)>0 then 230 180 C=B-J2:if C=0 then 230 190 for I=1 to abs(C):if C@I>0 then 220 200 if fnE(I)=J2 then R%=fnSub(I,J):R%=fnSub(I,-J) 210 if fnE(-I)=J2 then R%=fnSub(-I,J):R%=fnSub(-I,-J) 220 next I 230 next J 240 end 250 ' 260 fnSub(X,Y) 270 local C%,M,X1,Y1,Xn,Yn 280 print "(";X;",";Y;")"; 290 if Y=0 then print " order 2":return(0) 300 C%=2 310 M=(3*X^2+A)//(2*Y):if den(M)<>1 then print " not torsion":return(0) 320 X1=M^2-2*X:Y1=M*(X-X1)-Y 330 if and{X=X1,Y=(-Y1)} then print " order";C%+1:return(0) 340 M=(Y1-Y)//(X1-X):if den(M)<>1 then print " not torsion":return(0) 350 Xn=M^2-X-X1:Yn=M*(X-Xn)-Y:inc C%:X1=Xn:Y1=Yn:goto 330