# OK to post homework # Alex Varjabedian, 6-Apr-2024, Homework 20 Help := proc() print(`Diag(a, b)\nIntSol(a, b, K)\nSolChain(a, b, S1, S2, K)`) end: with(plottools): with(plots): with(plots, implicitplot): 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 printf("Something bad happened\n"): return FAIL: fi: sol := sol minus {P[1],Q[1]}: xR := sol[1]: return [xR, -sqrt(xR^3 + a * xR + b)]: end: ####################### # ------------------- # # PART 1 - Diag(a, b) # # ------------------- # ####################### print(`PART 1`); toPlot := proc(point, name): op([plot(< | >, style = "point", color = "Black", symbol = "solidcircle"), textplot([op(point), name], `align`={`above`,`right`})]): end: Diag := proc(a, b) local A, B, C, AB, graph: do: A := RP(a, b): B := RP(a, b): until A[1] <> B[1]: AB := AddE(a, b, A, B): C := [AB[1], -AB[2]]: graph := implicitplot({y^2 = x^3 + a*x + b}): display({graph, toPlot(A, "A"), toPlot(B, "B"), toPlot(C, "C"), toPlot(AB, "A+B"), line(A, C, color = "blue", linestyle = "solid"), line(C, AB, color = "blue", linestyle = "solid")}): end: # Testing print(Diag(5, 8)); ############################ # ------------------------ # # PART 2 - IntSol(a, b, K) # # ------------------------ # ############################ print(`PART 2`); IntSol := proc(a, b, K) local S, x, y: S := {}: for x from -K to K do: y := sqrt(x^3 + a * x + b): if x^3 + a * x + b >= 0 and y = floor(y) then: S := S union {[x, y], [x, -y]}: fi: od: S: end: # Testing printf("IntSol(1, 1, 1000): %a\n", IntSol(1, 1, 1000)); # {[0, -1], [0, 1], [72, -611], [72, 611]} printf("IntSol(-5, 3, 1000): %a\n", IntSol(-5, 3, 1000)); # {[2, -1], [2, 1]} printf("IntSol(7, 4, 1000): %a\n", IntSol(7, 4, 1000)); # {[0, -2], [0, 2]} ###################################### # ---------------------------------- # # PART 3 - SolChain(a, b, S1, S2, K) # # ---------------------------------- # ###################################### SolChain := proc(a, b, S1, S2, K) local L, i: L := [S1, S2]: for i from 1 to K do L := [op(L), AddE(a, b, L[-2], L[-1])] od: L: end: