
// Make newform 45.5.g.e in Magma, downloaded from the LMFDB on 07 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_45_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_45_g_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_45_5_g_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_45_5_g_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 := [276676, 31560, 1800, -3300, 1973, -60, 0, 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, 1, 0, 0, 0, 0, 0, 0], [-368125308, -716887878, 934582407, -60124233, 1295568, 190938, 350053, -19857], [20889564, 983124, -2589906, 3304389, -79644, 396, 726, 1331], [764156808, -59830922, -4002582, 5106783, 598682, 612, 1122, 2057], [-15801463956, -30771798946, 16409075924, -2552532831, 57222276, 5242116, 9610546, -906049], [-63057956196, -122799175786, -21987844716, -7926100271, 357258816, -215406994, -46900264, -7912559], [-1668076832, -604840562, -44207622, 44332543, -6749628, -711698, 18462, 33847]];
    Rf_basisdens := [1, 1, 10440376750, 39697250, 39697250, 10440376750, 41761507000, 158789000];
    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_45_g();"
function MakeCharacter_45_g()
    N := 45;
    order := 4;
    char_gens := [11, 37];
    v := [4, 3];
    // 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_45_g_Hecke();"
function MakeCharacter_45_g_Hecke(Kf)
    N := 45;
    order := 4;
    char_gens := [11, 37];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, -1, 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]];
    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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [11, 1, -8, 2, 0, 0, -2, -1], [0, 0, 0, 2, 2, -2, -3, 3], [34, -1, 0, 1, -6, 0, 0, 10], [-45, -20, -45, 0, -1, -1, 6, 6], [-115, 0, 115, 22, -6, 6, -11, 11], [0, -18, 48, -18, 0, 12, -30, 0], [210, -28, 210, 0, 3, 3, -33, -33], [0, -9, -386, -9, 0, 36, 10, 0], [-40, 162, 0, -162, 12, 0, 0, -60], [-515, 0, 515, 72, -33, 33, -108, 108], [280, 98, 0, -98, 48, 0, 0, 70], [-160, 74, -160, 0, 13, 13, -3, -3], [-570, 0, 570, -56, 27, -27, 87, -87], [-115, 392, -115, 0, 78, 78, -103, -103], [0, 357, -382, 357, 0, -48, -100, 0], [-712, -36, 0, 36, 234, 0, 0, 0], [-1000, 0, 1000, -842, 1, -1, 231, -231], [-752, -190, 0, 190, -330, 0, 0, -50], [1525, -192, 1525, 0, -168, -168, 18, 18], [0, 560, 2000, 560, 0, 170, 90, 0], [3850, -136, 3850, 0, 165, 165, 235, 235], [0, 408, -2388, 408, 0, -12, -570, 0], [7365, 0, -7365, 608, -304, 304, -234, 234], [664, -511, 0, 511, 84, 0, 0, 580], [3420, -2066, 3420, 0, -172, -172, 207, 207], [4670, 0, -4670, -56, 117, -117, -323, 323], [0, 282, -6762, 282, 0, -168, 840, 0], [225, -2086, 225, 0, -330, -330, 285, 285], [-3380, 0, 3380, -1242, 516, -516, 651, -651], [-4718, 2171, 0, -2171, -354, 0, 0, -1430], [7455, 0, -7455, 346, 870, -870, 645, -645], [0, -572, 6292, -572, 0, 268, 330, 0], [0, 3369, -2584, 3369, 0, 204, 260, 0], [-7408, 630, 0, -630, -330, 0, 0, -2760], [3575, 0, -3575, -2036, 595, -595, -900, 900], [1900, 1782, 1900, 0, -339, -339, -861, -861], [9430, 0, -9430, -3272, -987, 987, 323, -323], [12295, 2114, 12295, 0, -1470, -1470, -65, -65], [0, -2265, -16890, -2265, 0, -2040, 2520, 0], [350, -4218, 0, 4218, -228, 0, 0, 3840], [-23156, -3316, 0, 3316, 234, 0, 0, -110], [8295, 6136, 8295, 0, -280, -280, 1200, 1200], [6845, 0, -6845, 3220, -444, 444, -1739, 1739], [0, 2436, 10224, 2436, 0, 1776, -5130, 0], [-24820, -618, 0, 618, 642, 0, 0, -1140], [18560, 3110, 18560, 0, 1174, 1174, -2859, -2859], [-20760, 0, 20760, 9118, -1557, 1557, -1317, 1317], [0, -7322, -21908, -7322, 0, -3962, 3540, 0], [17765, -2134, 17765, 0, 1002, 1002, 4343, 4343], [0, 408, 39032, 408, 0, -3852, -2500, 0], [13376, -1164, 0, 1164, -3204, 0, 0, -540], [31738, -2425, 0, 2425, -1050, 0, 0, 3610], [-15095, 0, 15095, -10226, 1122, -1122, 3467, -3467], [-1790, 10808, -1790, 0, 219, 219, -1409, -1409], [0, -927, -57768, -927, 0, 5568, 1620, 0], [11576, 5886, 0, -5886, 4866, 0, 0, 960], [-4545, 0, 4545, 13880, 2039, -2039, 174, -174], [3736, -2818, 0, 2818, -288, 0, 0, -3230], [33660, -9110, 33660, 0, -961, -961, 4671, 4671], [38415, -592, 38415, 0, 1704, 1704, -1719, -1719], [40600, 0, -40600, 1446, 3, -3, 4653, -4653], [-71696, 854, 0, -854, -2046, 0, 0, 4930], [39995, 5012, 39995, 0, -614, -614, 3744, 3744], [-5475, 0, 5475, -446, 3672, -3672, 1557, -1557], [33152, -4740, 0, 4740, 3270, 0, 0, -3300], [2345, 0, -2345, -1100, -3926, 3926, -3546, 3546], [40180, 0, -40180, -13118, -1761, 1761, 4619, -4619], [0, -5596, 39656, -5596, 0, -826, 6600, 0], [6535, 2090, 6535, 0, 1386, 1386, -4151, -4151], [0, 6222, -7692, 6222, 0, 792, -6780, 0], [-21420, 0, 21420, -370, 1694, -1694, -8631, 8631], [64845, 12064, 64845, 0, 7073, 7073, -8568, -8568], [0, 11580, 92460, 11580, 0, -2580, -5370, 0], [-54570, 1388, -54570, 0, 699, 699, -6699, -6699], [0, 8007, 130888, 8007, 0, 3792, 1180, 0], [-51935, 0, 51935, -26964, -2727, 2727, 1068, -1068], [62662, -724, 0, 724, -8604, 0, 0, -15440], [0, 2938, -82358, 2938, 0, -5882, -7080, 0], [0, -2787, 40802, -2787, 0, 3348, -1180, 0], [-73516, 9858, 0, -9858, -8322, 0, 0, 6780], [-84860, 16028, 0, -16028, 78, 0, 0, 10570], [-62435, -25068, -62435, 0, -3744, -3744, -3816, -3816], [0, 12980, -5320, 12980, 0, -2440, -10110, 0], [-7280, 2690, -7280, 0, 4011, 4011, 7729, 7729], [0, 8754, -41094, 8754, 0, -6816, -22560, 0], [-26145, 0, 26145, -40108, -358, 358, 9642, -9642], [43588, 13835, 0, -13835, 14400, 0, 0, -8780], [-25020, 40294, -25020, 0, 7238, 7238, -20523, -20523], [46430, 0, -46430, 17044, 1497, -1497, -1703, 1703], [0, 13800, -18200, 13800, 0, -9540, 11080, 0], [-130820, 0, 130820, 10518, -4164, 4164, -10209, 10209], [-43178, 15221, 0, -15221, 8046, 0, 0, -14210], [0, 10342, -76112, 10342, 0, 8872, 24330, 0], [-180370, -17320, -180370, 0, 6231, 6231, 6749, 6749], [0, -44193, -2122, -44193, 0, -9588, 21830, 0], [251230, 21578, 0, -21578, -5172, 0, 0, 3520], [-50780, -33846, -50780, 0, 6453, 6453, 8337, 8337], [278090, -8538, 0, 8538, -5688, 0, 0, 18000], [193980, 0, -193980, -35938, -10993, 10993, 3477, -3477], [-115795, 0, 115795, 8152, -4566, 4566, -13361, 13361], [-8580, 8114, -8580, 0, -15075, -15075, 6675, 6675], [0, 56388, 96022, 56388, 0, 1368, -16520, 0], [124256, -39444, 0, 39444, 966, 0, 0, 11280], [-194585, 0, 194585, 36408, 12126, -12126, -504, 504], [168450, 0, -168450, -33296, 3447, -3447, 10827, -10827], [189455, 7886, 189455, 0, 6582, 6582, -5977, -5977], [0, -17286, 145076, -17286, 0, 25044, -35140, 0], [-96844, -37194, 0, 37194, 19326, 0, 0, 24240], [29000, 0, -29000, -45962, -6344, 6344, -17769, 17769], [27655, 54036, 27655, 0, -13905, -13905, 3660, 3660], [-62195, 0, 62195, 49246, -8430, 8430, 19025, -19025], [0, -27772, 234452, -27772, 0, -14932, 29430, 0], [-77968, 4530, 0, -4530, -12600, 0, 0, -37260], [49420, -41932, 0, 41932, -34452, 0, 0, 40330], [203160, 51694, 203160, 0, 5543, 5543, 9657, 9657], [26630, 0, -26630, -52628, 8109, -8109, 27949, -27949], [125895, -23722, 125895, 0, 864, 864, -5799, -5799], [0, 52725, 223810, 52725, 0, -1920, -14060, 0], [68552, -15420, 0, 15420, -18030, 0, 0, -14880], [-171055, -10552, -171055, 0, -1478, -1478, 2028, 2028], [-165765, 0, 165765, 12070, -4164, 4164, -25749, 25749], [-124150, -47572, -124150, 0, 22599, 22599, -8959, -8959], [68096, 15036, 0, -15036, 8226, 0, 0, -18540], [-155918, 35081, 0, -35081, -4464, 0, 0, -28850], [0, 22142, -164692, 22142, 0, 26282, -32580, 0], [0, -15996, 467376, -15996, 0, 3024, -5460, 0], [32460, 0, -32460, 133694, 14000, -14000, -5805, 5805], [-115215, -60656, -115215, 0, 893, 893, 32802, 32802], [0, -80202, 98712, -80202, 0, -16692, 29070, 0], [-385290, 57716, -385290, 0, -2853, -2853, 6873, 6873], [-416104, 57666, 0, -57666, 2856, 0, 0, 120], [125155, 0, -125155, -16236, 10155, -10155, -36030, 36030], [-46694, -53398, 0, 53398, -62508, 0, 0, 70000], [0, -62054, -164276, -62054, 0, -6734, 120, 0], [104225, -67702, 104225, 0, -21936, -21936, 27611, 27611], [-223720, 0, 223720, -194, 3463, -3463, 6153, -6153], [180385, 0, -180385, 66634, -2658, 2658, -30193, 30193], [0, -47880, 175380, -47880, 0, 18480, -51030, 0], [-268708, -87870, 0, 87870, -36630, 0, 0, -18720], [200686, -60973, 0, 60973, 9672, 0, 0, -55850], [18840, 22186, 18840, 0, -22480, -22480, -40185, -40185], [431720, 0, -431720, 27262, 969, -969, 19189, -19189], [0, 11010, -443790, 11010, 0, 38940, -24840, 0], [0, 2970, 87220, 2970, 0, 49680, -8180, 0], [206795, 61112, 206795, 0, 20851, 20851, -23616, -23616], [-256125, 0, 256125, -23606, 23202, -23202, -34053, 34053], [0, -24500, 41860, -24500, 0, -11120, 94830, 0], [212090, 15956, 212090, 0, -11103, -11103, -71647, -71647], [-296185, 0, 296185, 10132, 2107, -2107, 6792, -6792], [469276, 3512, 0, -3512, 17712, 0, 0, -8570], [385060, -34986, 385060, 0, 17313, 17313, 9507, 9507], [15610, 0, -15610, -51536, -393, 393, -41743, 41743], [151620, 0, -151620, -20014, -3157, 3157, 21123, -21123], [-165812, -116500, 0, 116500, 22110, 0, 0, 74410], [0, 58140, 596880, 58140, 0, -34050, -70590, 0], [0, 2598, -970538, 2598, 0, -8532, 64720, 0], [428155, 0, -428155, 72060, 14454, -14454, -16176, 16176], [866740, 103673, 0, -103673, 31788, 0, 0, -9980], [426300, 0, -426300, 28366, 615, -615, 62715, -62715], [209825, -47230, 209825, 0, 23406, 23406, -20911, -20911], [-59920, 0, 59920, -112682, 32266, -32266, 1521, -1521], [-382970, 94073, 0, -94073, -1962, 0, 0, -88190], [-49505, 0, 49505, -36098, 11994, -11994, 59879, -59879], [326830, 58892, 326830, 0, 9003, 9003, 41257, 41257], [-110848, 70890, 0, -70890, 32670, 0, 0, -84960], [18615, 0, -18615, 524, 12005, -12005, 22740, -22740]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_45_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_45_5_g_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_45_5_g_e(:prec:=8)
    chi := MakeCharacter_45_g();
    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_45_5_g_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_45_5_g_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_45_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<2,R![276676, -31560, 1800, 3300, 1973, 60, 0, 0, 1]>],Snew);
    return Vf;
end function;