
// Make newform 200.6.c.e in Magma, downloaded from the LMFDB on 25 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_e();".
// 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_e();".
// 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 := [1024, 0, 65, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 33, 0, 1], [0, 97, 0, 1], [260, 0, 8, 0]];
    Rf_basisdens := [1, 16, 16, 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, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 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, 0], [0, -3, 1, 0], [0, 0, 0, 0], [0, -13, -3, 0], [280, 0, 0, -3], [0, 347, -12, 0], [0, -37, -84, 0], [500, 0, 0, 18], [0, -613, -123, 0], [-670, 0, 0, 156], [-1124, 0, 0, -27], [0, 1485, 216, 0], [11538, 0, 0, 78], [0, 4421, -339, 0], [0, 727, 885, 0], [0, -1353, 540, 0], [-31292, 0, 0, -252], [7054, 0, 0, 552], [0, 21353, -543, 0], [23604, 0, 0, 273], [0, -16863, -1308, 0], [32952, 0, 0, 1254], [0, 27181, -711, 0], [27510, 0, 0, -732], [0, -36917, -4620, 0], [51366, 0, 0, 2220], [0, -32737, 1305, 0], [0, -39615, 405, 0], [-13934, 0, 0, -540], [0, 68769, -4296, 0], [0, 83943, 2877, 0], [52920, 0, 0, 51], [0, -77333, -4704, 0], [-36588, 0, 0, -5652], [74986, 0, 0, 5052], [-396652, 0, 0, 1293], [0, -107519, 6456, 0], [0, 21593, -19707, 0], [0, -53865, -13383, 0], [0, 5287, -7608, 0], [-172868, 0, 0, -4656], [8966, 0, 0, 12552], [203924, 0, 0, -1353], [0, 282605, -13116, 0], [0, -74015, 5892, 0], [11800, 0, 0, -3984], [-181480, 0, 0, -4977], [0, -252053, 17625, 0], [0, 457641, -4911, 0], [-629014, 0, 0, -16080], [0, -234135, -6804, 0], [1086888, 0, 0, -9774], [812570, 0, 0, 6726], [109704, 0, 0, 13677], [0, 505575, 33240, 0], [0, 583443, -6939, 0], [1102786, 0, 0, -7200], [253764, 0, 0, 21135], [0, -24043, 11736, 0], [-377006, 0, 0, 1338], [0, -752603, 25413, 0], [0, 88427, 3792, 0], [0, -396335, -60063, 0], [132188, 0, 0, -54213], [0, -408251, -13464, 0], [0, 1162461, -46020, 0], [853008, 0, 0, -64905], [0, -373745, 58056, 0], [0, -1147831, 2421, 0], [-901326, 0, 0, 16968], [0, 917017, 5304, 0], [2354136, 0, 0, -33096], [0, 1171955, -36855, 0], [0, -471733, 169464, 0], [-2587060, 0, 0, -56790], [0, 789195, 100041, 0], [-2722518, 0, 0, -61104], [0, -655547, -17748, 0], [1559442, 0, 0, 45648], [-2117842, 0, 0, 77046], [-1631364, 0, 0, -20316], [-2799258, 0, 0, 24612], [1048628, 0, 0, -74229], [0, -2020883, -996, 0], [-487384, 0, 0, -129984], [0, -995007, 230025, 0], [1475958, 0, 0, 28002], [0, 2207419, 42192, 0], [-896658, 0, 0, -160740], [0, -956469, 250161, 0], [0, -363115, -233667, 0], [126056, 0, 0, 113094], [0, 1076623, 2049, 0], [5953176, 0, 0, 11445], [-9136364, 0, 0, 11346], [0, 2361279, 148929, 0], [894194, 0, 0, 121104], [863530, 0, 0, 146880], [0, -490243, 125829, 0], [4366558, 0, 0, -42300], [0, 1601201, 341001, 0], [0, -2812711, 281496, 0], [0, -2770291, -404919, 0], [3069550, 0, 0, 5886], [4328272, 0, 0, 244611], [0, 1327631, 61680, 0], [0, 2882565, 285777, 0], [0, 2380857, 168528, 0], [1938432, 0, 0, -237654], [-7688846, 0, 0, -17982], [0, 1756527, -15771, 0], [0, 204663, 123156, 0], [0, 1098039, -38604, 0], [-2580980, 0, 0, 130782], [-3056492, 0, 0, -255291], [-932694, 0, 0, -104394], [0, -1022655, -708627, 0], [0, -358689, 10785, 0], [0, 2345107, 224700, 0], [14536284, 0, 0, -103536], [-9311994, 0, 0, 245496], [0, -4854963, -25932, 0], [0, 4145065, -204948, 0], [0, -4587699, -26811, 0], [-2718400, 0, 0, 162837], [-10069186, 0, 0, 209196], [-11308070, 0, 0, 271116], [-9238072, 0, 0, 335922], [0, 4957043, -334827, 0], [0, 1595031, -867792, 0], [-18651684, 0, 0, -120036], [0, -6838329, -518703, 0], [-14853060, 0, 0, 51633], [0, -3730147, 563904, 0], [-12292902, 0, 0, -126432], [305774, 0, 0, -539244], [0, 4884063, -572004, 0], [0, -3631771, 369165, 0], [0, 9374181, -170460, 0], [1946550, 0, 0, -453216], [2048408, 0, 0, 54117], [-3190538, 0, 0, -428460], [0, -7077373, -595443, 0], [0, 6716769, -264435, 0], [-34042894, 0, 0, -2952], [-3500912, 0, 0, 73626], [0, -13015769, 33180, 0], [0, -2682981, 174216, 0], [-18529676, 0, 0, 413280], [0, 1628895, 371733, 0], [0, 3371425, 48816, 0], [-2831670, 0, 0, 64650], [0, 10109749, -257247, 0], [0, -14915333, 117021, 0], [0, 9106845, -570567, 0], [31315564, 0, 0, -99267], [22033168, 0, 0, -207738], [15899798, 0, 0, 361698], [0, -10055057, -16644, 0], [-13538690, 0, 0, 168768], [0, -6837647, 1424001, 0], [0, 15810525, -705744, 0], [0, 13854411, 208677, 0], [29794592, 0, 0, 166659], [0, 22311371, 341820, 0], [0, -23206893, -48435, 0], [-6065236, 0, 0, 677793], [0, 7352649, -1198260, 0]];
    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_e();".
// 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_e(:prec:=4)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_200_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![230400, 0, 1104, 0, 1]>],Snew);
    return Vf;
end function;