# Please do not post homework # Aurora Hiveley, 04/01/24, Assignment 20 Help:= proc(): print(` farFromC(A,B,C), IntSol(a,b,K), SolChain(a,b,S1,S2,K) `): end: ### plot figure 3 activity # helper function which returns which of A or B is further from C on the plot # will be used to draw the line through A-B-C farFromC := proc(A,B,C) : if evalf(abs(A[1] - C[1])) < evalf(abs(B[1] - C[1])) then B: elif evalf(abs(A[1] - C[1])) > evalf(abs(B[1] - C[1])) then A: else RETURN(FAIL): fi: end: ### build plot # with(plots): # with(plottools): ## create elliptic curve # a := 10: # b := 50: # f := implicitplot(y^2 = x^3 + a*x + b): ## pick two points A,B and build A+B and C accordingly # A := RP(a,b): # B := RP(a,b): # AplusB := AddE(a,b,A,B): # C := [AplusB[1], -AplusB[2]]: ## text labels for each point # tA := textplot([op(A + [0,0.25]),'A'],'align'={'above'}, 'font' = ['times', 'new', 16]): # tB := textplot([op(B + [0,0.25]),'B'],'align'={'above'}, 'font' = ['times', 'new', 16]): # tAB := textplot([op(AplusB + [0,-0.25]),'A+B'],'align'={'below'}, 'font' = ['times', 'new', 16]): # tC := textplot([op(C + [0,0.25]),'C'],'align'={'above'}, 'font' = ['times', 'new', 16]): ## lines through A-B-C and from A+B to C # l1 := line(AplusB,C,color="Blue"): # l2 := line(C,farFromC(A,B,C), color="Green"): ## display all of the above on one plot # display({f,tA,tB,tC,tAB,l1,l2,pointplot([A,B,C,AplusB])}, 'view' = [-5..5,-15..15]); ### integer solutions to diophantine activity # finds all integer solutions to y^2 = x^3 + a*x + b # between -K and K given input a and b IntSol := proc(a,b,K) local x,y,sols: sols := {}: for x from -K to K do y := sqrt(x^3 + a*x + b): if type(y,integer) then sols := sols union {[x,y]}: fi: od: sols: end: # testing: # IntSol(1,2,5); # = {[-1,0], [1,2]}: # IntSol(10,50,100); # = {[5,15]}: # IntSol(3,5,100); # = {[-1,1], [1,3], [4,9], [11,37]} ### solchain activity # takes two solutions S1 and S2 of y^2 = x^3 + a*x + b # repeatedly uses AddE(a,b,L[-2],L[-1]) to get a list # of K+2 total solutions in the rationals SolChain := proc(a,b,S1,S2,K) local sols: sols := [S1,S2]: while nops(sols) < K+2 do sols := [op(sols), AddE(a,b,sols[-2],sols[-1])]: od: sols: end: ## test calls # SolChain(3,5,RP(3,5),RP(3,5),6); # SolChain(2,4,RP(2,4),RP(2,4),3); # there are definitely some solutions which do not produce a third # for example, the integer solutions from above caused errors in AddE # but this doesn't gel with the idea that any line through the curve # intersects at three points. if this claim is true, then we could # go on infinitely. the integer error is probably because at some point # you get two points which are reflections of each other over the x-axis # i.e. P[2] = -Q[2], so there is no third point of intersection. # obviously we remedied this in class on thursday. ### COPIED FROM CLASS Help20:=proc(): print(`RP(a,b), DoesLie(a,b,P), AddE(a,b,P,Q) `):end: #Elliptic curve: y^2=x^3+a*x+b RP:=proc(a,b) local x: x:=rand(0..200)()/100: [x,sqrt(x^3+a*x+b)]:end: DoesLie:=proc(a,b,P): P[2]^2-P[1]^3-a*P[1]-b:end: AddE:=proc(a,b,P,Q) local x,y,s,eq,sol,R,xR: s:=(P[2]-Q[2])/(P[1]-Q[1]): y:=P[2]+(x-P[1])*s: sol:={solve(y^2-x^3-a*x-b,x)}; if not (nops(sol)=3 and member(P[1],sol) and member(Q[1],sol)) then print(`Something bad happened`): RETURN(FAIL): fi: sol:=sol minus {P[1],Q[1]}: xR:=sol[1]: [xR,-sqrt(xR^3+a*xR+b)]: end: