
// Make newform 304.7.e.d 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_7_e_d();".
// 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_7_e_d();".
// 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 := [71047680, 0, 4242376, 0, 75582, 0, 483, 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, -25301016, 0, -753578, 0, -5377, 0, -11], [0, -6097944, 0, -753578, 0, -5377, 0, -11], [-42403752, 0, -903602, 0, -5377, 0, -11, 0], [-18249888, 0, -703570, 0, -5377, 0, -11, 0], [91312392, 0, 3811514, 0, 38665, 0, 107, 0], [0, 1540258488, 0, 26654530, 0, 155933, 0, 319], [0, 255721320, 0, 11090870, 0, 104215, 0, 269]];
    Rf_basisdens := [1, 1200192, 1200192, 150024, 50008, 150024, 1200192, 300048];
    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 := 7;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [13, 0, 0, 0, 0, -1, 0, 0], [18, 0, 0, -2, 1, 1, 0, 0], [253, 0, 0, 7, -6, 0, 0, 0], [0, 6, 3, 0, 0, 0, 0, 1], [745, 0, 0, -42, -14, -12, 0, 0], [-2575, 26, 8, 3, 44, -12, -1, 1], [6275, 0, 0, 93, 103, -13, 0, 0], [0, 402, 40, 0, 0, 0, 5, 12], [0, -201, -98, 0, 0, 0, 3, 11], [0, 1360, -147, 0, 0, 0, -5, -13], [0, 356, -109, 0, 0, 0, -27, 1], [-32611, 0, 0, -409, 6, -22, 0, 0], [12543, 0, 0, 1133, 340, 24, 0, 0], [0, -1458, -132, 0, 0, 0, 15, 54], [0, -48, -752, 0, 0, 0, 61, 119], [-7105, 0, 0, 1434, 2082, -573, 0, 0], [0, -3277, -1298, 0, 0, 0, -100, -102], [0, -3620, 354, 0, 0, 0, 28, -154], [58875, 0, 0, -3088, -1368, -2242, 0, 0], [0, -5311, 3264, 0, 0, 0, -1, -79], [-59824, 0, 0, 480, 3718, 1112, 0, 0], [0, 13024, 303, 0, 0, 0, 55, -295], [0, -5784, -1898, 0, 0, 0, 396, 152], [296978, 0, 0, -3580, 6640, 2848, 0, 0], [0, -54, -2238, 0, 0, 0, 396, 2], [0, 23230, -1932, 0, 0, 0, 79, -499], [0, 7498, -314, 0, 0, 0, -89, -574], [0, -7440, -79, 0, 0, 0, 107, 703], [0, -48281, 1734, 0, 0, 0, 481, -343], [-1128119, 0, 0, 3751, -8806, 218, 0, 0], [-1212773, 0, 0, 11232, 20888, -4478, 0, 0], [-2683639, 0, 0, -349, 10198, -7996, 0, 0], [1076593, 0, 0, -6888, 22128, -8107, 0, 0], [0, -93914, 2516, 0, 0, 0, -1100, 348], [-2489988, 0, 0, 38702, 698, 11012, 0, 0], [-77884, 0, 0, 20480, -1018, -16630, 0, 0], [0, 98915, 15676, 0, 0, 0, -839, -293], [0, 34720, 7978, 0, 0, 0, -660, -1660], [0, 223301, -16410, 0, 0, 0, -659, 537], [0, -76632, 7134, 0, 0, 0, -696, -660], [1694548, 0, 0, -61496, 2663, 16715, 0, 0], [0, 147528, 10121, 0, 0, 0, 639, 1405], [-3141056, 0, 0, -24114, 41086, -19152, 0, 0], [-3545608, 0, 0, -700, -77257, -6439, 0, 0], [0, 43228, -20826, 0, 0, 0, -359, 1417], [0, -137467, -27616, 0, 0, 0, 1877, -2773], [0, -17746, 24296, 0, 0, 0, 1797, 3139], [3275643, 0, 0, -42118, -88298, 4751, 0, 0], [3795587, 0, 0, -6994, -6574, 8141, 0, 0], [5815102, 0, 0, 125806, -9447, 4827, 0, 0], [0, 309828, -27765, 0, 0, 0, -2631, -4843], [-7571245, 0, 0, -50427, -27616, -6648, 0, 0], [0, 76232, 92750, 0, 0, 0, 2634, 2332], [12082939, 0, 0, -87299, -102136, -91936, 0, 0], [0, -61740, -42669, 0, 0, 0, -2703, 6789], [-1557679, 0, 0, -43117, -15247, 74573, 0, 0], [-9086345, 0, 0, 31858, -56346, -54311, 0, 0], [0, 141196, -127034, 0, 0, 0, 3506, 514], [15995709, 0, 0, 165931, -24386, 56554, 0, 0], [0, 97890, -3661, 0, 0, 0, -8758, 511], [0, 913925, 34122, 0, 0, 0, 10121, 6481], [16117608, 0, 0, 259412, -21025, -78263, 0, 0], [5491662, 0, 0, 151226, 109930, -139591, 0, 0], [0, 578254, -42419, 0, 0, 0, 2258, 5533], [0, -749743, -46146, 0, 0, 0, -13960, -14950], [0, -855260, 44484, 0, 0, 0, -6872, 210], [7593327, 0, 0, -112879, -268720, 110494, 0, 0], [13116709, 0, 0, -31868, -210004, -137543, 0, 0], [-17860832, 0, 0, 259488, -210456, -259153, 0, 0], [-79642, 0, 0, -430410, -310027, 35169, 0, 0], [29240954, 0, 0, 241190, 356476, 165506, 0, 0], [0, 464902, -51019, 0, 0, 0, -13892, 13293], [0, -745464, -235362, 0, 0, 0, 21015, 1107], [0, 434311, -165584, 0, 0, 0, -15193, -15359], [13831039, 0, 0, 126906, -305914, 64141, 0, 0], [-20690353, 0, 0, -35058, 199262, 213165, 0, 0], [0, 74200, -99991, 0, 0, 0, -583, -32575], [0, 1417044, 179195, 0, 0, 0, -15135, -5441], [-37181540, 0, 0, -110948, 207890, -63904, 0, 0], [0, -182494, 109666, 0, 0, 0, -1291, 14232], [0, 2103316, -78708, 0, 0, 0, 14152, 31652], [0, 900544, -36297, 0, 0, 0, 31435, -16951], [0, 821123, 50426, 0, 0, 0, -9199, -8059], [-34614891, 0, 0, -480229, -372686, -111996, 0, 0], [0, -1489600, -339564, 0, 0, 0, 6958, -14040], [20630755, 0, 0, 1119748, 903696, 156958, 0, 0], [-48748901, 0, 0, 108294, -315378, 457199, 0, 0], [75589975, 0, 0, -19527, 17060, -438204, 0, 0], [87970455, 0, 0, -223243, -78404, -558564, 0, 0], [-39458418, 0, 0, 1067498, 550856, 677830, 0, 0], [0, -1361152, -209394, 0, 0, 0, -33922, -21416], [-15220278, 0, 0, 1073522, -200024, -389784, 0, 0], [60079237, 0, 0, 99183, 1262478, 599514, 0, 0], [-111165507, 0, 0, -219721, 281529, -247381, 0, 0], [0, -1327364, 306116, 0, 0, 0, -33558, 49950], [0, 1547204, -554355, 0, 0, 0, -32753, -33609], [0, 870912, -312966, 0, 0, 0, -23085, 45699], [13887469, 0, 0, -241868, -874232, -11801, 0, 0], [0, 1003818, -813612, 0, 0, 0, -18408, 26800], [51394773, 0, 0, -1712396, -1898552, -506413, 0, 0], [0, -1262019, -1198394, 0, 0, 0, 41981, 28173], [0, -1226816, 527218, 0, 0, 0, -50824, 93376], [-107595606, 0, 0, 640294, 275156, 1834, 0, 0], [-124939079, 0, 0, 893170, 1524658, -511388, 0, 0], [-22193389, 0, 0, 1624989, 196060, 631334, 0, 0], [102388246, 0, 0, -9816, -1102052, 1366560, 0, 0], [0, -2031551, 502882, 0, 0, 0, 15959, -1433], [0, 548916, 873882, 0, 0, 0, 45828, -43702], [0, -5903828, 613702, 0, 0, 0, 19840, 78262], [-33179539, 0, 0, 957504, -1776280, -142101, 0, 0], [103200035, 0, 0, -756322, 853450, -264179, 0, 0], [64327230, 0, 0, -1738706, -4612, -778376, 0, 0], [-53696549, 0, 0, -82347, 235696, 966024, 0, 0], [0, -7506568, 312946, 0, 0, 0, -24330, -92856], [-102681705, 0, 0, 27853, -238948, -643040, 0, 0], [-72314092, 0, 0, -3027132, -1898701, 780717, 0, 0], [76852339, 0, 0, -828210, -562438, 1242733, 0, 0], [0, 5566520, -715354, 0, 0, 0, -56819, -116347], [0, -4197818, 1597281, 0, 0, 0, 6904, 84213], [0, -3968536, 1656166, 0, 0, 0, 35672, 26892], [0, -4116414, 201172, 0, 0, 0, -37373, -13972], [0, -6689240, -680820, 0, 0, 0, -25598, 41186], [304189135, 0, 0, 1733541, 291432, 812046, 0, 0], [-37058310, 0, 0, 48184, 1460196, 1338130, 0, 0], [26934066, 0, 0, 4504736, 228092, -447286, 0, 0], [30096060, 0, 0, -4551916, -1251969, -942985, 0, 0], [12797988, 0, 0, -1109492, -4189309, 302521, 0, 0], [-246376620, 0, 0, -5641198, -2300146, 303062, 0, 0], [110248147, 0, 0, -1208595, -3045588, -1289766, 0, 0], [0, 11104531, 1504666, 0, 0, 0, -72045, -78913], [0, 2162840, -16182, 0, 0, 0, -118036, -335130], [-98060977, 0, 0, 1095054, -2812942, -2086533, 0, 0], [118251475, 0, 0, 2536884, -2471272, -604286, 0, 0], [-69698585, 0, 0, -873764, -752880, 364492, 0, 0], [0, 20378446, 762021, 0, 0, 0, -35404, -36027], [0, 4280824, -1102860, 0, 0, 0, -39593, 199585], [0, -2123022, -1872400, 0, 0, 0, 202069, 53388], [7251201, 0, 0, 4348966, -2903882, 1679606, 0, 0], [0, 4435838, -1026102, 0, 0, 0, 111533, -138083], [189512035, 0, 0, -5070414, -390622, 132361, 0, 0], [256768758, 0, 0, 341434, 774181, -3309827, 0, 0], [0, 12325823, 1704384, 0, 0, 0, 33104, 77764], [0, -15585066, 797937, 0, 0, 0, 10770, 83073], [0, 4116552, 113978, 0, 0, 0, 9410, 124888], [-328643068, 0, 0, 2134386, -2026322, -1285770, 0, 0], [0, 14217144, 661312, 0, 0, 0, 51884, 123888], [-158612531, 0, 0, 96435, 5719742, 1034730, 0, 0], [0, 334961, 2199810, 0, 0, 0, -26377, -74657], [0, 15889742, -1117845, 0, 0, 0, -76252, -366499], [300757143, 0, 0, -1150190, 1206486, 2353705, 0, 0], [-426818461, 0, 0, -8279719, -4246636, 1175954, 0, 0], [0, 17655068, 1191208, 0, 0, 0, -83376, 154344], [0, -7834307, 2874008, 0, 0, 0, -90590, -27450], [0, -8619974, -1779730, 0, 0, 0, 144260, -65074], [49863977, 0, 0, -6685669, 1860989, -2823961, 0, 0], [488299970, 0, 0, -2997526, -763694, -2868713, 0, 0], [-92966639, 0, 0, -203450, 46750, 850246, 0, 0], [0, -1741466, 4234511, 0, 0, 0, 108924, -116415], [510527268, 0, 0, -4866232, -5059142, -279420, 0, 0], [0, 13160716, -1962057, 0, 0, 0, -144377, -379399], [-4060602, 0, 0, -1368722, -1493552, -4679390, 0, 0], [0, -4487834, 1896960, 0, 0, 0, -176972, -27976], [0, 1327920, -1823017, 0, 0, 0, -50327, 60603], [0, 3073042, 1493384, 0, 0, 0, -200742, -136686], [0, 5432569, 1735176, 0, 0, 0, 205033, -127141], [-896290305, 0, 0, 1051898, 571262, -3755455, 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_7_e_d();".
// 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_7_e_d(:prec:=8)
    chi := MakeCharacter_304_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_7_e_d();".
// 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_7_e_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_304_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<3,R![432254085120, 0, 2281096296, 0, 4292649, 0, 3442, 0, 1]>,<5,R![292006000, 3367200, -49415, -54, 1]>],Snew);
    return Vf;
end function;