/*
First I have put a modified form of the solution to exercise 4 from Johan's page, modifed to store the intersection point rather than print it.
*/
put_in(L, a, b, c) = {
return(subst(subst(subst(L, x, a), y, b), z, c))
}
find_intersection(L1, L2, p) =
{
local(a, b, c, match);
match = 0;
a = 0;
b = 0;
c = 1;
while(a <= p - 1 && match!=1,
while(b <= p - 1 && match!=1,
while(c <= p - 1 && match!=1,
if(put_in(L1, a, b, c) % p == 0 && \
put_in(L2, a, b, c) %p == 0,
match = 1;
d = a;
e = b;
f = c;
);
c++;
);
b++;
c = 0);
a++;
b = 0;
c = 0
);
}
/*
Let C : F=0 be a conic in the variables x,y,z; and let p be an odd prime.
*/
classify_conic(F,p) = {
local(r,s,t);
r = deriv(F,x);
s = deriv(F,y);
t = deriv(F,z);
/*
If the conic is a doubled line, then the equation of that line is a common factor of all three partials.
*/
u = gcd(r,gcd(s,t));
if(poldegree(u,x) == 0,,print("The conic is a doubled line."); return);
if(poldegree(u,y) == 0,,print("The conic is a doubled line."); return);
if(poldegree(u,z) == 0,,print("The conic is a doubled line."); return);
/*
Here we use the program from exercise 4 which finds the intersection point of two lines. After it runs, the intersection point (a:b:c) should be stored. We can thus check if all partials vanish at a single point
*/
find_intersection(r,s,p);
if(d=put_in(t,d,e,f)*Mod(1,p) == 0,
print("The conic is a union of two lines."),
print("The conic is irreducible and meets any line in at most two points.");
);
}