
// Make newform 200.6.c.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_200_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_200_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_200_6_c_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_200_6_c_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_200_c();"
function MakeCharacter_200_c()
    N := 200;
    order := 2;
    char_gens := [151, 101, 177];
    v := [2, 2, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_200_c_Hecke();"
function MakeCharacter_200_c_Hecke(Kf)
    N := 200;
    order := 2;
    char_gens := [151, 101, 177];
    char_values := [[1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 6;
    raw_aps := [[0, 0], [0, 9], [0, 0], [0, 121], [656, 0], [0, 103], [0, 845], [1364, 0], [0, -1099], [2218, 0], [-1700, 0], [0, -423], [-1818, 0], [0, -5267], [0, 6037], [0, -16293], [-8668, 0], [-34670, 0], [0, -23783], [948, 0], [0, 31551], [-46536, 0], [0, 44389], [104934, 0], [0, -18127], [42486, 0], [0, -73967], [0, -9195], [145006, 0], [0, -41373], [0, -137223], [202608, 0], [0, -24071], [111156, 0], [-243178, 0], [368852, 0], [0, 159773], [0, -34931], [0, -171711], [0, 571], [86684, 0], [-651418, 0], [29140, 0], [0, 323203], [0, 215569], [131608, 0], [1210784, 0], [0, -17443], [0, -62091], [456386, 0], [0, -126333], [-65064, 0], [-1406002, 0], [-548400, 0], [0, -246915], [0, 535905], [-999394, 0], [1007604, 0], [0, 511429], [-1181722, 0], [0, 458753], [0, 256151], [0, 704729], [-2786036, 0], [0, -775429], [0, 188661], [-1630632, 0], [0, -1683583], [0, 418601], [1519098, 0], [0, 1759255], [3570888, 0], [0, -1791155], [0, -317765], [-67060, 0], [0, -2225643], [-5798250, 0], [0, 166937], [-2556894, 0], [3055106, 0], [3543468, 0], [1972938, 0], [1373956, 0], [0, -2594065], [2940824, 0], [0, 641733], [4952634, 0], [0, 3956573], [-6185298, 0], [0, -245967], [0, 223721], [-8184872, 0], [0, 3107621], [827856, 0], [10400404, 0], [0, -1019103], [-3661334, 0], [3247130, 0], [0, 2486785], [2425438, 0], [0, -365627], [0, 3859961], [0, -1552879], [482498, 0], [13850200, 0], [0, 3548821], [0, 784629], [0, 6523863], [5246880, 0], [-5573162, 0], [0, 991245], [0, -484905], [0, -5647299], [18072796, 0], [4626340, 0], [19905774, 0], [0, -6053919], [0, -1265619], [0, -6852173], [9833196, 0], [6686874, 0], [0, 363783], [0, 9347569], [0, 8992509], [1200056, 0], [-11519438, 0], [610738, 0], [-3972776, 0], [0, -6160991], [0, -4072893], [-7166532, 0], [0, 2825205], [9095004, 0], [0, -5644019], [15293322, 0], [-1774018, 0], [0, 7322055], [0, -2985371], [0, -17024979], [26354022, 0], [-9496576, 0], [-15988678, 0], [0, -15917339], [0, 6378729], [-6186130, 0], [5667536, 0], [0, 8800511], [0, 81081], [7105204, 0], [0, -2044779], [0, 404597], [3904110, 0], [0, -17914495], [0, 13878529], [0, 10095681], [27517868, 0], [-13178576, 0], [-40068758, 0], [0, 15212885], [-32634946, 0], [0, 15076705], [0, -151533], [0, -3699315], [-6184136, 0], [0, 819641], [0, 5650977], [3126428, 0], [0, -17791371]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_200_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_200_6_c_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_200_6_c_b(:prec:=2)
    chi := MakeCharacter_200_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_200_6_c_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_200_6_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_200_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![324, 0, 1]>],Snew);
    return Vf;
end function;