// PostProcessingTM_GivenDiscriminant.m

/*
INPUT:
    C:= [c_1, c_2, c_3, c_4], the coefficients of the Thue-Mahler form, F, where
        F:= c_1*x^3 + c_2*x^2*y + c_3*x*y^2 + c_4*y^3, having discriminant DF:= +/- 2^{alpha_0} * 3^{beta_0} * N_1
    
    p:= a set of rational primes [2, 3 , ..., p_s] such that
        F(u,v) = 2^{alpha_1} * 3^{beta_1} * p_3^{k_3} * p_4^{k_4} *...* p_s^{k_s}
        
    Soln:= [sol_1, ..., sol_t], where
        sol_1:= [u,v, exp_3, ..., exp_s] such that
            F(u,v) = 2^{alpha_1} * 3^{beta_1} * p_3^{exp_3} * p_4^{exp_4} *...* p_s^{exp_s}
            
    RSolnFile:= text file storing the solutions of the form F which may lead to elliptic curves with good reduction outside p 
    
OUTPUT:
    Soln2:= [sol_1, ..., sol_t], where
        sol_1:= [u,v, exp_1, ..., exp_s] such that
            F(u,v) = 2^{alpha_1} * 3^{beta_1} * p_3^{k_3} * p_4^{k_4} *...* p_s^{k_s}
        such that GCD(u,v) = 1
                
COMMENTS:
    Given a Thue-Mahler form F, F:= c_1*x^3 + c_2*x^2*y + c_3*x*y^2 + c_4*y^3, having discriminant DF:= +/- 2^{alpha_0} * 3^{beta_0} * N_1, and primes p, one can compute solutions to 
        F(u,v) = 2^{alpha_1} * 3^{beta_1} * p_3^{k_3} * p_4^{k_4} *...* p_s^{k_s}
    with GCD(u,v), leading to elliptic curves having good reduction outside p
    
    This algorithm determines a potential upper bound on alpha_1, beta_1 as per Theorem 1 of the reference
    
REFERENCE:
    M. Bennett, A. Gherga, A. Rechnitzer. Computing Elliptic Curves over Q. Submitted, University of British Columbia, 2017.

EXAMPLE:
    > RSolnFile:= "RelevantSolutions.txt";
    > C:=[ 1, 1, 8, 6 ];
    > p:=[ 2, 3, 23 ]; 
    > A:=1;
    > Soln:= [
    >     [ -1, 0, 0, 0, 0 ],
    >     [ 3, -4, 0, 2, 0 ],
    >     [ -1, 1, 1, 0, 0 ],
    >     [ -3, 1, 2, 2, 0 ],
    >     [ -1, -1, 4, 0, 0 ],
    >     [ -7, 9, 6, 0, 0 ],
    >     [ 3, -13, 10, 2, 0 ],
    >     [ 1, 0, 0, 0, 0 ],
    >     [ -3, 4, 0, 2, 0 ],
    >     [ 1, -1, 1, 0, 0 ],
    >     [ 3, -1, 2, 2, 0 ],
    >     [ 1, 1, 4, 0, 0 ],
    >     [ 7, -9, 6, 0, 0 ],
    >     [ -3, 13, 10, 2, 0 ],
    >     [ 15, 1, 1, 4, 1 ],
    >     [ -1, 3, 2, 0, 1 ],
    >     [ -15, -1, 1, 4, 1 ],
    >     [ 1, -3, 2, 0, 1 ],
    >     [ 0, 1, 1, 1, 0 ],
    >     [ 6, -5, 1, 5, 0 ],
    >     [ 0, -1, 1, 1, 0 ],
    >     [ -6, 5, 1, 5, 0 ]
    > ];
    > Soln2:= PostProcessingTM_GivenDiscriminant(C,p,Soln, RSolnFile);
    
    > Soln2;
    [
        [ -15, -1, 1, 4, 1 ],
        [ -7, 9, 6, 0, 0 ],
        [ -6, 5, 1, 5, 0 ],
        [ -3, 1, 2, 2, 0 ],
        [ -3, 4, 0, 2, 0 ],
        [ -3, 13, 10, 2, 0 ],
        [ -1, -1, 4, 0, 0 ],
        [ -1, 0, 0, 0, 0 ],
        [ -1, 1, 1, 0, 0 ],
        [ -1, 3, 2, 0, 1 ],
        [ 0, -1, 1, 1, 0 ],
        [ 0, 1, 1, 1, 0 ],
        [ 1, -3, 2, 0, 1 ],
        [ 1, -1, 1, 0, 0 ],
        [ 1, 0, 0, 0, 0 ],
        [ 1, 1, 4, 0, 0 ],
        [ 3, -13, 10, 2, 0 ],
        [ 3, -4, 0, 2, 0 ],
        [ 3, -1, 2, 2, 0 ],
        [ 6, -5, 1, 5, 0 ],
        [ 7, -9, 6, 0, 0 ],
        [ 15, 1, 1, 4, 1 ]
    ]

*/

function PostProcessingTM_GivenDiscriminant(C,p,Soln,RSolnFile)
    
    Soln2:= [];
    for s in Soln do
        if GCD(s[1],s[2]) eq 1 then
            Append(~Soln2,s);
        end if;
    end for;
    
    Sort(~Soln2);
    
    fprintf RSolnFile, "Relevant solutions corresponding to primes p:= %o, and form C:=%o \n ", p, C;
    fprintf RSolnFile, "=========================================================================== \n";
    
    fprintf RSolnFile, "Soln:= %o", Soln2;
    
    return Soln2;
end function;






