
// Make newform 576.7.e.r in Magma, downloaded from the LMFDB on 09 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_576_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_576_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_576_7_e_r();".
// 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_576_7_e_r();".
// 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 := [1446, 68, -67, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [30, -59, -3, 2], [-1704, 3392, 48, -32], [-408, -12, 12, 0]];
    Rf_basisdens := [1, 153, 51, 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_576_e();"
function MakeCharacter_576_e()
    N := 576;
    order := 2;
    char_gens := [127, 325, 65];
    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_576_e_Hecke();"
function MakeCharacter_576_e_Hecke(Kf)
    N := 576;
    order := 2;
    char_gens := [127, 325, 65];
    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]];
    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, -25, 0, -1], [108, 0, 1, 0], [0, -524, 0, -6], [1088, 0, -7, 0], [0, -1633, 0, 2], [-6736, 0, -8, 0], [0, 9188, 0, -50], [0, 7761, 0, 67], [14044, 0, -131, 0], [59250, 0, -76, 0], [0, 34905, 0, 250], [712, 0, -514, 0], [0, 50292, 0, -298], [0, -127975, 0, 175], [0, -32504, 0, -708], [-36706, 0, 556, 0], [386552, 0, 302, 0], [0, 76300, 0, -1374], [70480, 0, -564, 0], [-314620, 0, 1067, 0], [0, 126668, 0, 686], [0, -275415, 0, -1716], [-330592, 0, 2350, 0], [0, 406215, 0, -531], [981044, 0, 3215, 0], [0, 176640, 0, 7552], [762464, 0, 4099, 0], [0, -705375, 0, 6764], [595340, 0, 1001, 0], [0, 2172920, 0, -4868], [0, -76857, 0, -4102], [-2184600, 0, -4934, 0], [0, -1199831, 0, -21683], [-3556004, 0, 2413, 0], [-3503998, 0, 5028, 0], [-684888, 0, -13314, 0], [0, -90600, 0, -10404], [0, -3386913, 0, 13939], [0, -836304, 0, -15376], [-1467744, 0, -8681, 0], [0, 2742696, 0, -25676], [-143218, 0, 17464, 0], [0, 2644407, 0, -27631], [-3596956, 0, -7125, 0], [-9835496, 0, -15250, 0], [-7748548, 0, 31757, 0], [0, 4087380, 0, -47646], [8320736, 0, -51107, 0], [0, -5950505, 0, 24508], [0, 12659200, 0, 18968], [-9143856, 0, 39238, 0], [0, -3239140, 0, 31518], [0, 3958175, 0, -33848], [0, -2758360, 0, -5700], [0, 16198639, 0, 21449], [-13162580, 0, 32513, 0], [-5542432, 0, -37005, 0], [0, 15093401, 0, 6136], [-1376752, 0, 36700, 0], [0, -12843927, 0, 1111], [-13156152, 0, -50998, 0], [0, -10911144, 0, 130788], [14890818, 0, 132264, 0], [0, -1956705, 0, -103771], [-1908760, 0, -116806, 0], [28700208, 0, -7744, 0], [0, 9378132, 0, -112958], [46763070, 0, 19692, 0], [0, -15868207, 0, -233780], [0, 26647620, 0, -122202], [-4705972, 0, -185047, 0], [2531758, 0, 83004, 0], [-62933056, 0, -52116, 0], [0, 7348320, 0, 276264], [0, 6520265, 0, 84101], [-20678018, 0, -271524, 0], [0, 2448735, 0, 314262], [-40419456, 0, 205618, 0], [0, -56941620, 0, -13090], [52466560, 0, 72075, 0], [0, -38860604, 0, 260350], [81172318, 0, -14208, 0], [-17217684, 0, 270609, 0], [0, -42089860, 0, -157178], [0, 9433585, 0, -487770], [-67936096, 0, 17750, 0], [0, -13914175, 0, 40593], [-66291980, 0, -74601, 0], [0, 3934692, 0, 437098], [0, 14649796, 0, -411050], [28861412, 0, 383651, 0], [0, -11814240, 0, 857368], [-87412704, 0, 45992, 0], [0, -129508620, 0, 219598], [0, 123394161, 0, -107985], [0, 60190391, 0, -75186], [36617152, 0, -300044, 0], [-101725056, 0, -178917, 0], [100783496, 0, -44450, 0], [0, 15820913, 0, -1006779], [0, -71581148, 0, 824306], [0, -186676169, 0, 248334], [-100360944, 0, -643532, 0], [-1930318, 0, -1146296, 0], [0, -76352360, 0, -398940], [0, 83209375, 0, 947052], [0, -25647900, 0, -1018082], [-82042754, 0, -706664, 0], [179542780, 0, -662907, 0], [-223645970, 0, -580196, 0], [0, -6901815, 0, -1631656], [-110235584, 0, -220968, 0], [-142315036, 0, -798645, 0], [0, -83695745, 0, 868674], [345632520, 0, 40950, 0], [0, -213204980, 0, -383398], [0, 22016127, 0, 1166175], [0, -60928440, 0, 334572], [-124276910, 0, -362108, 0], [291091810, 0, -624464, 0], [0, -142798393, 0, -1514717], [0, 147498220, 0, -418402], [295196552, 0, -91770, 0], [0, -37568319, 0, 1684183], [630528064, 0, -245407, 0], [0, 274145516, 0, 550082], [-302781612, 0, -757209, 0], [-60636800, 0, 1427185, 0], [-396343120, 0, 758940, 0], [0, 159461720, 0, 654652], [156896940, 0, 587305, 0], [201359968, 0, -323503, 0], [0, 90625145, 0, -337314], [-381134926, 0, -1044600, 0], [0, -303670215, 0, -406253], [-573203408, 0, -265552, 0], [0, 39952895, 0, -2088065], [0, 24309785, 0, -1033514], [-299189696, 0, -126276, 0], [0, -185935881, 0, 891145], [-762109892, 0, 390213, 0], [0, 199246520, 0, -2354596], [519431648, 0, 354715, 0], [0, 372031764, 0, 2210398], [-132631598, 0, 19812, 0], [0, 204517545, 0, 411402], [-592345272, 0, -854450, 0], [0, 123805880, 0, -5117572], [-564163938, 0, 1043372, 0], [0, -444928465, 0, 1838312], [315438008, 0, -1624414, 0], [0, -298148408, 0, -3998804], [44959240, 0, -1465602, 0], [0, -780236776, 0, 1267788], [-71200276, 0, -2275983, 0], [0, -501951121, 0, -3764634], [128538798, 0, -8400, 0], [0, 864208929, 0, 35681], [0, 631236648, 0, -1910804], [0, 437005575, 0, 3902454], [-351779660, 0, 1088663, 0], [0, 202317084, 0, -3030730], [0, -410416383, 0, -810782], [0, 463722360, 0, 2728692], [-734691604, 0, 541289, 0], [803410670, 0, 2266668, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_576_7_e_r();".
// 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_576_7_e_r(:prec:=4)
    chi := MakeCharacter_576_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_576_7_e_r();".
// 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_576_7_e_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_576_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<5,R![1641060100, 0, 86020, 0, 1]>,<7,R![-71856, -216, 1]>],Snew);
    return Vf;
end function;