Question: Make a list of ex, and in each of ex contains some item of enumerare

I want to make a list of ex, and in each of ex contains some item of enumerare. This is my code:

restart;
with(geometry);
mylist := [[-1, 9, -15], [1, -6, -15], [1, -6, 9], [1, 6, 12], [-2, 3, 12], [2, -9, 12], [-1, -6, -9], [-1, -9, -15], [1, 6, -15], [-2, 9, -12], [1, 3, 3], [-1, 6, -9], [3, -4, 2], [-5, 5, -2], [-3, -5, -4], [-2, 1, -3], [-5, -4, -2], [5, 5, 4], [-1, -2, -2], [-3, 1, -5]];
toX := s -> latex(s, output = string);
s := "";
for item in mylist do
    a := item[1];
    b := item[2];
    c := item[3];
    f := x -> a*x^3 + b*x^2 + c*x;
    sol := solve(diff(f(x), x) = 0, x);
    x1 := sol[1];
    x2 := sol[2];
    f2 := diff(f(x), x, x);
    if subs(x = x1, f2) < 0 then
        max_point := [x1, f(x1)];
    elif subs(x = x2, f2) < 0 then
        max_point := [x2, f(x2)];
    else
        max_point := "No maximum";
    end if;
    point(o, 0, 0);
    point(A, x1, f(x1));
    point(B, x2, f(x2));
    AB := simplify(distance(A, B));
    d := Equation(line(k, [A, B], [x, y]));
    lined := sort(sign(coeff(lhs(d), x))*d/igcd(coeff(lhs(d), x), coeff(lhs(d), y)));
    myr := distance(o, k);
    circle_eq := x^2 + y^2 = myr^2;
    s := cat(s, "\\begin{ex}\n", "  Given the function $y = ", toX(f(x)), "$.\n", "  \\begin{enumerate}[label=\\alph*)]\n", "    \\item The derivative of the function is $y'=", toX(diff(f(x), x)), "$.\n", "    \\item The maximum point of the function's graph is $P(", toX(max_point[1]), ", ", toX(max_point[2]), ")$.\n", "    \\item The equation of the line passing through the two extremum points of the graph is $", toX(lined), "$.\n", "    \\item The distance between the two extremum points $A$ and $B$ is $", toX(AB), "$.\n", "    \\item The equation of the circle with center at the origin and tangent to the line passing through the two extremum points is $", toX(circle_eq), "$.\n", "  \\end{enumerate}\n", "\\end{ex}\n\n");
end do;
printf("%s", s);


It seems there is a bug, I get a massage Error, (in geometry:-line) the line is not defined. 

How can I prepare it? and how can I reduce the code? 

Please Wait...