#OK to post homework #Joseph Koutsoutis, 04-07-2024, Assignment 20 read `C21.txt`: with(plots): # For this assignment, I changed the last line of our AddE function # to return the additive inverse of the line through P and Q since our # AddE from lecture 20 always returns a non-positive y value. 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,-(P[2]+(xR-P[1])*s)]: # this is the only line changed end: #1 Diag := proc(a,b) local A,B,C,A_label,B_label,C_label,AB_label,ecplot,points: A := RP(a,b): B := RP(a,b): while A[1] = B[1] do: B := RP(a,b): od: C := AddE(a,b,A,B): A_label := textplot([op(A), "A"]): B_label := textplot([op(B), "B"]): C_label := textplot([C[1],-C[2], "C"]): AB_label := textplot([op(C), "A+B"]): points := pointplot([A,B,[C[1],-C[2]],C], connect=true): ecplot := implicitplot(y^2 = x^3 + a*x + b): display([A_label, B_label, C_label,AB_label, points,ecplot]): end: #2 IntSol := proc(a,b,K) local x,y,S: S := {}: for x from -K to K do: y := x^3 + a*x + b: if y >= 0 then: y := sqrt(y): if trunc(y) = y then: S := S union {[x,trunc(y)], [x,-trunc(y)]}: fi: fi: od: S: end: #3 SolChain := proc(a,b,S1,S2,K) local L: L := [S1,S2]: while nops(L) < K+2 do: L := [op(L), AE(a,b,L[-2],L[-1])]: od: L: end: # SolChain ended up taking a long time to run so I started # using floats instead of keeping track of exact values for # testing larger K. SolChainFloat := proc(a,b,S1,S2,K) local L: L := [S1,S2]: while nops(L) < K+2 do: L := [op(L), evalf(AE(a,b,L[-2],L[-1]))]: od: L: end: # I didn't test too many values but I couldn't find two intial solutions # that gave an arbitrarily long chain of solutions.