##!!! Input "common.txt" first
#read "/texts/papers/sextics/equations/Maple/common.txt"; read "/texts/papers/sextics/equations/Maple/A5A1.txt";
lp("\
#######################################################################","\n\
# Ramification locus A_5 + A_1 \n\
#######################################################################");
u1 := (alpha*x[1]-beta*x[2])*x[3]^2
     -(x[2]^2+(beta+1)*x[1]*x[2])*x[3]
     -x[1]*x[2]^2;
u2 := ((beta+2*alpha)*x[1]+alpha*x[2])*x[3]^2
     +((2*alpha+1)*x[1]*x[2]+(2*alpha+beta+1)*x[1]^2)*x[3]
     +(alpha+1)*x[1]^2*x[2];
init_sextics(u1, u2);

lp("\
# Prohibited values of the parameters");
alpha=0, 'u1'=factor(subs(alpha=0, u1));
alpha=-1, 'u2'=factor(subs(alpha=-1, u2));
alpha=-beta, 'u1'=factor(subs(alpha=-beta, u1));

lp("\
## A rational parameterization of 'K' (not used)");
##yt := t*(-2*mu^4*nu^4+t*mu^4+t*nu^4-2*t^2*nu*mu+nu^5*mu*t+nu*mu^5*t)^2/(nu*mu+1)^2/(mu-nu)^4/(mu+nu)^4/(-t+mu^4)^2/(-t+nu^4)^2/(t-1)^2;
##xt := t*(t-mu^2*nu^2)/(t-mu^4)/(t-nu^4)/(t-1);

params := [alpha=-4/(sigma+2*pi^2)*pi^2,
           beta=-4*pi*(sigma-2*pi^3+2*pi^2-2*pi)/(sigma+2*pi^2)/(pi-1)^2-1];
xt := 4*pi^2*(t^2-sigma*t+pi^4)*(t-1)/(sigma+2*pi^2)/(pi-1)^2/t/(-t+pi^2);
yt := 4*pi^2*(-2*pi*t^2+(pi+1)*sigma*t-2*pi^4)^2/(pi-1)^2/t/(-t+pi^2)^2/(sigma+2*pi^2)^2;
'KS(xt, yt)'=simplify(subs(params, KS(xt, yt)));

lp("\
#######################################################################","\n\
# A singular point adjacent to A_14 \n\
#######################################################################");
lp("\
## Express 'alpha', 'beta' in terms of 'mu', 'nu'");
section0 := the_factor(KS(t, 0), 2, t);
solutions([subs(t=mu, section0), subs(t=nu, section0)], [alpha, beta]);
ab0 := op(1, %); ab := ab0:
alpha0 := factor(subs(ab, alpha));
beta0 := factor(subs(ab, beta));

lp("\
## Look for a section in the form 'y=a*(t-mu)^2' inflection tangent to 'K'");
a := get_a():

lp("\
## Invalid values:");
bad_factors := { all_factors(alpha0), all_factors(alpha0 + 1),
                 all_factors(alpha0 + beta0), all_factors(a_1) };
print2();

## Case 1
set_set("\
## The set of singularities", 4=A_16 + A_3);
lp("\
## Equations: ", 'Eq_Ak(2)');
alias(epsilon1=epsilon1):
select_solution(analyze([Eq_Ak(2)], [mu, nu])):
print_solution(epsilon1=RootOf(16*_Z^2-59*_Z+52), radical):

## Case 2
set_set("\
## The set of singularities", 6=A_15 + A_4);
lp("\
## Equations: ", 'Eq_Ak(1)', 'Eq_P2()');
select_solution(analyze([Eq_Ak(1), Eq_P2()], [mu, nu])):
print_solution(complex):
lp("\
## The conic maximally tangent to the curve at P_1 and its intersection with the curve");
v := 'v':
ff := collect(subs(y=v[0]+v[1]*x+v[2]*x^2, curve[6]), x):
'degree'=degree(ff, x), 'coeff'=factor(coeff(ff, x, 8)); v[2] := 1;
'degree'=degree(simplify(ff), x), 'coeff'=factor(coeff(ff, x, 6));
v[1] := solve(coeff(ff, x, 6), v[1])[1];
'degree'=degree(simplify(ff), x), 'coeff'=factor(coeff(ff, x, 4));
v[0] := solve(coeff(ff, x, 4), v[0])[1];
'intersection'=factor(ff);
lp("\
## The conic is not a component. Hence, the curve is irreducible!!");
v := 'v':
print2();

lp("\
## A set of singularities adjacent to A_14 + A_4");
lp("\
## Equations: ", 'Eq_A1(1)', 'Eq_P2()');
alias(epsilon3=epsilon3):
alias(epsilon11=epsilon11):
mn := analyze([Eq_A1(1), Eq_P2()], [mu, nu]):

## Case 3
set_set("\
## The set of singularities", 7=A_14 + A_4 + A_1);
select_solution(mn):
print_solution(epsilon3=RootOf(276-372*_Z-20*_Z^2+195*_Z^3-45*_Z^4-27*_Z^5+9*_Z^6)):
j_check(found_d, epsilon3, 6):
print2();

## Case t1
set_set("\
## Triple point:", t1=D_5 + A_14);
select_solution(mn):
print_solution(complex):
tcurve[idx] := trigonal(complex);
print2();

lp("\
#######################################################################","\n\
# A singular point A_13 \n\
#######################################################################");
lp("\
## Look for a section in the form 'y=a*(t-mu)^2' tangent to 'L_2'");
lp("\
## Equations: ", 'Eq_P2()');
a := 'a': a_2 := factor(solve(Eq_P2(), a)); a := a_2:
lp("\
## Invalid values:");
bad_factors := { all_factors(alpha0), all_factors(alpha0 + 1),
                 all_factors(alpha0 + beta0), all_factors(a_2) };
print2();

lp("\
## Make it inflection tangent to 'K'");
lp("\
## Equations: ", 'Eq_A2(0, nu, gcd)');
alias(epsilon4=epsilon4):
alias(epsilon5=epsilon5):
mn := analyze([Eq_A2(0, nu, gcd)], [mu, nu]):
print2();

## Case 4
set_set("\
## Tangency point on 'L_2'", 10=A_13 + A_6);
select_solution(mn):
print_solution(epsilon4=RootOf(9*_Z^4-63*_Z^3+175*_Z^2-224*_Z+112)):
j_check(found_d, epsilon4, 4):
print2();

## Case 5
set_set("\
## Tangency point not on 'L_2'", 11=A_13 + A_4 + A_2);
select_solution(mn):
print_solution(epsilon5=RootOf(_Z^2-7*_Z+7), radical):

## Case t2
set_set("\
## Triple point:", t2=E_6 + A_13);
select_solution(mn):
print_solution(complex):
tcurve[idx] := trigonal(complex);
print2();

lp("\
#######################################################################","\n\
# The set of singularities A_12 + A_6 + A_1 \n\
#######################################################################");
lp("\
## Look for a section in the form 'y=a*(t-mu)^2' tangent to 'L_2'");
a := 'a': lambda := 'lambda': bad_factors := {}:
a_2 := factor(solve(discrim(parabola + S(t, 1), t), a)); a := a_2:
lp("\
## The point of tangency is 'lambda'");
lambda := factor(solve(the_factor(parabola + S(t, 1), 1, t), t));

lp("\
## Invalid values:");
bad_factors := { all_factors(alpha), all_factors(alpha + 1),
                 all_factors(alpha + beta), all_factors(a_2),
                 all_factors(lambda) };
lp("\
## !!! Cheating !!!");
lp("\
## Since an algebraic number field of degree three is expected,","\n\
## we ignore all factors depending on 'alpha' only and of degree other than 3");
eqn_filter := e -> evalb((degree(e, beta) > 0) or (degree(e, mu) > 0) or
                         (degree(e, alpha) = 3));
                 
lp("\
# The point 'lambda' should be on 'K'");
eqn1 := simplified(subs(t=lambda, the_factor(KS(t, -S(t, 1)), 2, t)));

lp("\
# Intersection with 'K' about 't=lambda'");
intr := the_factor(KS(u+lambda, subs(t=u+lambda, parabola)), 6, u):
lp("\
# Eliminate an extra factor in 'u'");
f := (beta-2+2*mu+2*mu*alpha);
n := table([seq(i=factor(coeff(intr, u, i)/f^i), i=0..6)]):
lp("\
# The coefficients 'n[0]', 'n[1]' must vanish; compute the rest and make 'n[2]=0'");
intr := the_factor(KS(u+lambda, subs(t=u+lambda, parabola)), 6, u):
eqn2 := simplified(n[2]):
res2 := simplified(resultant(eqn1, eqn2, beta));
lp("\
## A 'template' for the discriminant:");
eqn3 := discrim(add(nn[i]*u^(i-2), i=3..6), u);
eqn3 := subs(nn=n, eqn3):
eqn3 := simplified(eqn3):
lp("\
## Resultants:");
res3 := simplified(resultant(eqn1, eqn3, beta)):
g23 := gcd(res2, res3);
res0 := simplified(resultant(res2/g23, res3/g23, mu));
## Case 6
set_set("\
## The set of singularities", 13=A_12 + A_6 + A_1);
alias(epsilon6=epsilon6):
get_ab := mn -> copy(mn):
select_solution(analyze([res0, res2, res3, eqn1, eqn2, eqn3], [alpha, beta, mu])):
print_solution(epsilon6=op(2, op(1, found_mn))/4):
j_check(found_d, epsilon6, 3):
print2();
