
// Make newform 304.5.e.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_304_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_304_e_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_304_5_e_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_304_5_e_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 := [77475204, 0, 4001228, 0, 68229, 0, 450, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, -3270662, 0, -59427, 0, -450, 0, -1], [0, -4041556, 0, -118854, 0, -900, 0, -2], [8802, 0, 225, 0, 1, 0, 0, 0], [-733602, 0, -33685, 0, -352, 0, -1, 0], [1115298, 0, 37093, 0, 352, 0, 1, 0], [0, -75675850, 0, -2337687, 0, -20799, 0, -56], [0, -401259422, 0, -17075691, 0, -169740, 0, -475]];
    Rf_basisdens := [1, 1249884, 104157, 71, 3408, 3408, 312471, 2499768];
    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_304_e();"
function MakeCharacter_304_e()
    N := 304;
    order := 2;
    char_gens := [191, 229, 97];
    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_304_e_Hecke();"
function MakeCharacter_304_e_Hecke(Kf)
    N := 304;
    order := 2;
    char_gens := [191, 229, 97];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 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 := 5;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, -1, 0, 0], [20, 0, 0, 0, -1, 0, 0, 0], [2, 0, 0, 2, 2, 3, 0, 0], [0, 7, 0, 0, 0, 0, 1, 0], [64, 0, 0, 7, 1, 0, 0, 0], [1, -14, -4, 3, 1, -3, 0, 1], [48, 0, 0, -14, 1, -7, 0, 0], [0, 15, -1, 0, 0, 0, -1, 4], [0, 30, -21, 0, 0, 0, 0, 0], [0, -76, -13, 0, 0, 0, 4, -2], [0, 42, -25, 0, 0, 0, -4, 4], [1078, 0, 0, -48, 0, -15, 0, 0], [-398, 0, 0, 24, -18, 31, 0, 0], [0, -183, 5, 0, 0, 0, 11, 4], [0, -159, 53, 0, 0, 0, -2, -4], [178, 0, 0, 150, -20, 75, 0, 0], [0, 275, 56, 0, 0, 0, 10, 16], [0, -66, 72, 0, 0, 0, -34, 16], [2972, 0, 0, -69, 39, 150, 0, 0], [0, -218, -61, 0, 0, 0, -18, 16], [1362, 0, 0, 64, 70, 158, 0, 0], [0, 480, 153, 0, 0, 0, 10, 8], [0, 194, -272, 0, 0, 0, -24, 20], [5754, 0, 0, 20, 140, -20, 0, 0], [0, 308, 20, 0, 0, 0, -38, -20], [0, 513, -265, 0, 0, 0, -6, 12], [0, 435, -131, 0, 0, 0, -53, -4], [0, -630, 173, 0, 0, 0, 12, 24], [0, -456, -347, 0, 0, 0, -8, -4], [-7490, 0, 0, 216, 84, -251, 0, 0], [-1948, 0, 0, -585, -93, -574, 0, 0], [7802, 0, 0, 546, 110, -321, 0, 0], [-16106, 0, 0, 502, 142, 93, 0, 0], [0, 682, -236, 0, 0, 0, -88, 56], [9658, 0, 0, -582, 160, -480, 0, 0], [-4498, 0, 0, -138, -376, 192, 0, 0], [0, -690, -311, 0, 0, 0, -26, -100], [0, 1464, -590, 0, 0, 0, 128, -74], [0, 2256, 499, 0, 0, 0, 8, 94], [0, 1244, -78, 0, 0, 0, -196, -54], [-848, 0, 0, -480, 237, -482, 0, 0], [0, 2126, -367, 0, 0, 0, -38, -32], [24714, 0, 0, -154, 128, 448, 0, 0], [37420, 0, 0, 78, -417, -240, 0, 0], [0, -1445, 837, 0, 0, 0, 16, -132], [0, -804, 285, 0, 0, 0, 210, 60], [0, -2421, 205, 0, 0, 0, 90, -228], [-4718, 0, 0, 810, 772, -333, 0, 0], [58774, 0, 0, 868, 346, -327, 0, 0], [18160, 0, 0, 1998, -255, -62, 0, 0], [0, -1118, -705, 0, 0, 0, 124, 96], [13994, 0, 0, -1672, -310, -1413, 0, 0], [0, 900, -1066, 0, 0, 0, 126, 72], [35498, 0, 0, 920, -22, 795, 0, 0], [0, 3636, 729, 0, 0, 0, 336, -30], [-59300, 0, 0, -1098, 879, -729, 0, 0], [38110, 0, 0, -1548, 742, 837, 0, 0], [0, 4452, -686, 0, 0, 0, -448, 196], [-16658, 0, 0, -1428, 132, -1227, 0, 0], [0, 4461, 670, 0, 0, 0, 209, -248], [0, 5832, -113, 0, 0, 0, 268, 14], [-60980, 0, 0, -1482, -1185, 256, 0, 0], [-8000, 0, 0, 2127, 1657, 2841, 0, 0], [0, 4119, -234, 0, 0, 0, -481, -152], [0, -1087, -2212, 0, 0, 0, -218, 184], [0, -5960, 704, 0, 0, 0, -234, 448], [49318, 0, 0, 2502, -756, 109, 0, 0], [16478, 0, 0, 3270, -510, 753, 0, 0], [-42852, 0, 0, -2557, 479, 895, 0, 0], [-94340, 0, 0, 552, 3, -1676, 0, 0], [-54410, 0, 0, 1620, -480, 2088, 0, 0], [0, -1807, -1644, 0, 0, 0, -475, 192], [0, -11195, 587, 0, 0, 0, 228, 292], [0, 2244, 215, 0, 0, 0, 46, -124], [95398, 0, 0, 304, -1166, -2127, 0, 0], [86558, 0, 0, 756, -1290, -1611, 0, 0], [0, 11988, 3779, 0, 0, 0, -12, -60], [0, -9154, 3123, 0, 0, 0, 1202, 60], [190578, 0, 0, -1868, -98, -1834, 0, 0], [0, 9037, -5041, 0, 0, 0, 495, -356], [0, 9840, 1944, 0, 0, 0, -668, -232], [0, -19680, -423, 0, 0, 0, -258, -324], [0, 14868, -2663, 0, 0, 0, 868, -232], [13042, 0, 0, 4026, -438, -3221, 0, 0], [0, 7038, -1802, 0, 0, 0, -198, -276], [56900, 0, 0, 1719, -1389, 18, 0, 0], [-38438, 0, 0, -122, -992, -3633, 0, 0], [26914, 0, 0, 1272, 102, 4263, 0, 0], [-70198, 0, 0, 116, 4370, 915, 0, 0], [-26706, 0, 0, 3220, 1372, 3620, 0, 0], [0, 1372, 2094, 0, 0, 0, -698, -252], [164826, 0, 0, 1978, -3290, 3902, 0, 0], [3062, 0, 0, -744, -2704, -1119, 0, 0], [-135912, 0, 0, -3380, 1009, -823, 0, 0], [0, -3600, -2524, 0, 0, 0, 828, -378], [0, 12402, 1789, 0, 0, 0, 360, -132], [0, -859, -161, 0, 0, 0, -192, -196], [-69622, 0, 0, -6516, -3780, -1125, 0, 0], [0, 13220, -246, 0, 0, 0, -772, -702], [181394, 0, 0, 3096, -3192, 6215, 0, 0], [0, 10296, 4523, 0, 0, 0, 1524, -450], [0, -11418, 2304, 0, 0, 0, -572, -1168], [-105194, 0, 0, 4212, 1536, 12888, 0, 0], [-144824, 0, 0, -549, 2509, 3708, 0, 0], [6614, 0, 0, -10894, 476, -3315, 0, 0], [-166134, 0, 0, 11144, 3524, 6436, 0, 0], [0, 15180, 5215, 0, 0, 0, 1016, -656], [0, 12966, 3220, 0, 0, 0, -74, 152], [0, -22022, -4528, 0, 0, 0, -1206, 76], [74650, 0, 0, -6852, 1300, 5619, 0, 0], [219446, 0, 0, -4740, 3210, -2887, 0, 0], [125594, 0, 0, 6198, 494, 9030, 0, 0], [-137686, 0, 0, 7680, -3622, -3045, 0, 0], [0, 22908, -4734, 0, 0, 0, -626, 1064], [-203678, 0, 0, 1248, -1674, -8601, 0, 0], [72476, 0, 0, -3310, 6671, 288, 0, 0], [59030, 0, 0, -7836, 2130, -7279, 0, 0], [0, -2733, -4191, 0, 0, 0, -2120, -964], [0, -3647, 5528, 0, 0, 0, -2583, 592], [0, 10774, -4676, 0, 0, 0, 1640, -1108], [0, -3687, 5393, 0, 0, 0, -1703, 1652], [0, 12300, 3736, 0, 0, 0, -1876, 934], [862, 0, 0, -13518, 5808, -7983, 0, 0], [50310, 0, 0, 2762, -1978, 16486, 0, 0], [125654, 0, 0, -4086, -7746, -1890, 0, 0], [37184, 0, 0, -10840, -91, -21354, 0, 0], [90340, 0, 0, -3114, 2955, 972, 0, 0], [153158, 0, 0, -3456, -3510, -10422, 0, 0], [-162658, 0, 0, -570, -184, 13737, 0, 0], [0, -22374, 1967, 0, 0, 0, 3252, -2412], [0, -59834, 6476, 0, 0, 0, -186, 700], [128794, 0, 0, 9642, -4760, 663, 0, 0], [92812, 0, 0, -20405, -3569, -9042, 0, 0], [335368, 0, 0, 3285, 3721, -936, 0, 0], [0, -38487, 15700, 0, 0, 0, -1867, 1096], [0, -53137, 13047, 0, 0, 0, 974, 372], [0, -57, -10985, 0, 0, 0, 2927, -1004], [-434924, 0, 0, 3985, -4505, 6390, 0, 0], [0, -12927, -8311, 0, 0, 0, -352, -68], [-283834, 0, 0, -19668, -3798, -1639, 0, 0], [-173332, 0, 0, -14232, -3877, -9492, 0, 0], [0, -21951, 5312, 0, 0, 0, 1788, 1224], [0, -5293, 19862, 0, 0, 0, -2861, 112], [0, 9708, -4110, 0, 0, 0, -2470, -524], [-278842, 0, 0, -23184, -6054, 1818, 0, 0], [0, 8664, 3048, 0, 0, 0, -916, 580], [-175042, 0, 0, 9300, -1252, 3597, 0, 0], [0, 1920, 131, 0, 0, 0, 1912, 164], [0, -25277, -1916, 0, 0, 0, -1087, -136], [-159874, 0, 0, 14460, -9474, -13075, 0, 0], [159062, 0, 0, -14094, 4844, -20979, 0, 0], [0, 15360, -4324, 0, 0, 0, -400, 52], [0, 44885, -24854, 0, 0, 0, 1932, -736], [0, 54780, -4472, 0, 0, 0, -1042, 2056], [44816, 0, 0, 6900, 125, 29397, 0, 0], [296532, 0, 0, 19373, 16631, -5705, 0, 0], [292052, 0, 0, -8343, 7623, -4698, 0, 0], [0, 30999, 1844, 0, 0, 0, 5197, 1904], [-149742, 0, 0, 16996, 1486, 23750, 0, 0], [0, -35628, 9313, 0, 0, 0, 2866, -2080], [224078, 0, 0, -2316, -6772, 3828, 0, 0], [0, -2508, -8790, 0, 0, 0, 1624, 2318], [0, 39306, 14343, 0, 0, 0, 550, -2392], [0, 26244, 17062, 0, 0, 0, -1824, -3228], [0, -105644, 15145, 0, 0, 0, 2774, 908], [318478, 0, 0, -20652, 1438, 16125, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_304_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_304_5_e_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_304_5_e_e(:prec:=8)
    chi := MakeCharacter_304_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_304_5_e_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_304_5_e_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_304_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<3,R![74649600, 0, 3860640, 0, 67449, 0, 458, 0, 1]>,<5,R![964896, 6624, -2074, -9, 1]>],Snew);
    return Vf;
end function;