
// Make newform 324.6.e.j in Magma, downloaded from the LMFDB on 06 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_324_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_324_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_324_6_e_j();".
// 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_324_6_e_j();".
// 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 := [279841, 0, 23805, 0, 1496, 0, 45, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [1071225, 0, 67320, 0, 1496, 0, 45, 0], [0, -2090079, 0, -91278, 0, -4356, 0, 9], [-100338075, 0, -4339896, 0, -201960, 0, 273, 0], [0, 298719423, 0, 4137936, 0, 197472, 0, 1179], [0, 154175463, 0, 12413808, 0, 592416, 0, 13059], [-142830, 0, -11604, 0, -540, 0, -12, 0], [0, 365519427, 0, 24787224, 0, 709104, 0, 19743]];
    Rf_basisdens := [1, 791384, 267674, 395692, 18201832, 18201832, 529, 18201832];
    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_324_e();"
function MakeCharacter_324_e()
    N := 324;
    order := 3;
    char_gens := [163, 245];
    v := [3, 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_324_e_Hecke();"
function MakeCharacter_324_e_Hecke(Kf)
    N := 324;
    order := 3;
    char_gens := [163, 245];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, -1, 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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1, 2, 0, 0], [-44, 44, 0, -1, 0, 0, 0, 0], [0, 0, 11, 0, 0, 11, 0, -5], [0, 343, 0, -7, 0, 0, 7, 0], [0, 0, -33, 0, -22, 0, 0, 22], [-736, 0, 0, 0, 0, 0, -13, 0], [0, 0, 0, 0, 25, -67, 0, 0], [0, 0, 142, 0, 0, 142, 0, -29], [0, 1036, 0, 6, 0, 0, -6, 0], [419, 0, 0, 0, 0, 0, 73, 0], [0, 0, 0, 0, -16, -140, 0, 0], [9580, -9580, 0, 99, 0, 0, 0, 0], [0, 0, 20, 0, 0, 20, 0, 288], [0, 0, 1382, 0, -26, 0, 0, 26], [0, 0, 0, 0, -356, -132, 0, 0], [30049, -30049, 0, 225, 0, 0, 0, 0], [0, 26824, 0, -51, 0, 0, 51, 0], [0, 0, 3735, 0, -199, 0, 0, 199], [-23095, 0, 0, 0, 0, 0, 288, 0], [-1256, 1256, 0, -911, 0, 0, 0, 0], [0, 0, 2762, 0, 0, 2762, 0, 558], [0, 0, 6867, 0, -40, 0, 0, 40], [82966, -82966, 0, 76, 0, 0, 0, 0], [0, 0, 6690, 0, 0, 6690, 0, -94], [0, 41332, 0, 594, 0, 0, -594, 0], [0, 0, 11918, 0, 430, 0, 0, -430], [-64591, 0, 0, 0, 0, 0, 759, 0], [0, 0, 0, 0, -984, 113, 0, 0], [-45016, 0, 0, 0, 0, 0, 207, 0], [0, 0, 0, 0, -5443, 3977, 0, 0], [0, 0, -2541, 0, 0, -2541, 0, 4726], [0, 80980, 0, -926, 0, 0, 926, 0], [0, 0, 0, 0, 4135, -3980, 0, 0], [30832, -30832, 0, 714, 0, 0, 0, 0], [0, 106525, 0, -699, 0, 0, 699, 0], [205952, 0, 0, 0, 0, 0, 3304, 0], [0, 0, 0, 0, 6321, -19775, 0, 0], [0, 0, 10656, 0, 0, 10656, 0, -6555], [0, 0, -18268, 0, -5600, 0, 0, 5600], [-122278, 0, 0, 0, 0, 0, -3548, 0], [0, 0, -18939, 0, 0, -18939, 0, -1075], [0, 13765, 0, -1266, 0, 0, 1266, 0], [0, 0, -17722, 0, 12035, 0, 0, -12035], [479252, 0, 0, 0, 0, 0, 152, 0], [0, -150092, 0, -6601, 0, 0, 6601, 0], [-337928, 337928, 0, 9537, 0, 0, 0, 0], [0, 0, -52475, 0, 0, -52475, 0, 2049], [0, -489221, 0, 3183, 0, 0, -3183, 0], [0, 0, -76877, 0, 556, 0, 0, -556], [0, 0, 0, 0, -6318, -1122, 0, 0], [-13193, 13193, 0, 4010, 0, 0, 0, 0], [0, 0, 2449, 0, 18751, 0, 0, -18751], [0, 0, 0, 0, 2772, 61519, 0, 0], [0, 0, -45144, 0, 0, -45144, 0, -1780], [0, 0, -86760, 0, 2623, 0, 0, -2623], [61496, 0, 0, 0, 0, 0, -11337, 0], [-476978, 476978, 0, -5808, 0, 0, 0, 0], [0, 0, -6141, 0, 0, -6141, 0, -2852], [0, -333260, 0, -19428, 0, 0, 19428, 0], [0, 0, 0, 0, 20029, 43448, 0, 0], [1216028, 0, 0, 0, 0, 0, 3702, 0], [0, 0, 0, 0, -7174, -62694, 0, 0], [901477, -901477, 0, -6946, 0, 0, 0, 0], [0, 0, 70864, 0, 0, 70864, 0, -18181], [-1543136, 1543136, 0, -13571, 0, 0, 0, 0], [0, 1044430, 0, -14036, 0, 0, 14036, 0], [0, 0, 0, 0, -33123, -86391, 0, 0], [2348830, -2348830, 0, 20840, 0, 0, 0, 0], [0, 0, 145504, 0, 0, 145504, 0, -17192], [0, 0, 116359, 0, -37563, 0, 0, 37563], [1342456, -1342456, 0, 8814, 0, 0, 0, 0], [0, 2998810, 0, -8704, 0, 0, 8704, 0], [-614092, 0, 0, 0, 0, 0, 23362, 0], [0, 0, 0, 0, 7649, -180047, 0, 0], [0, 0, -16850, 0, 0, -16850, 0, 87266], [-1977685, 0, 0, 0, 0, 0, 6675, 0], [0, 0, 0, 0, 55886, -36255, 0, 0], [0, 3808519, 0, 1438, 0, 0, -1438, 0], [0, 0, 0, 0, -64242, -129178, 0, 0], [4104487, -4104487, 0, -17173, 0, 0, 0, 0], [0, 0, 332650, 0, 7178, 0, 0, -7178], [-4786657, 0, 0, 0, 0, 0, -342, 0], [-3227972, 3227972, 0, -24816, 0, 0, 0, 0], [0, 0, 76112, 0, 0, 76112, 0, -16884], [0, 0, 18064, 0, -27012, 0, 0, 27012], [1681663, -1681663, 0, -16122, 0, 0, 0, 0], [0, 0, 281162, 0, 0, 281162, 0, -72914], [0, 2406952, 0, -40744, 0, 0, 40744, 0], [0, 0, 31190, 0, -98246, 0, 0, 98246], [0, 0, 119161, 0, 0, 119161, 0, -17823], [-1648924, 0, 0, 0, 0, 0, 12218, 0], [0, 0, 0, 0, 67669, -412339, 0, 0], [0, -1967012, 0, -45981, 0, 0, 45981, 0], [0, 0, 310366, 0, 68058, 0, 0, -68058], [0, 0, 0, 0, -49066, 267834, 0, 0], [0, 0, 93296, 0, 145220, 0, 0, -145220], [5225444, 0, 0, 0, 0, 0, 5211, 0], [-756931, 0, 0, 0, 0, 0, 92413, 0], [-3033164, 3033164, 0, 63612, 0, 0, 0, 0], [0, 0, -288036, 0, 34049, 0, 0, -34049], [0, 0, 0, 0, -53604, 67712, 0, 0], [0, 0, -43679, 0, 0, -43679, 0, -64726], [0, 189808, 0, 24532, 0, 0, -24532, 0], [3953987, 0, 0, 0, 0, 0, -44772, 0], [0, 0, -495305, 0, 0, -495305, 0, -6649], [0, 0, -281089, 0, 83360, 0, 0, -83360], [0, 0, 0, 0, -13550, 219046, 0, 0], [-4992143, 4992143, 0, 68340, 0, 0, 0, 0], [0, -9682292, 0, -63719, 0, 0, 63719, 0], [5049494, 0, 0, 0, 0, 0, -29436, 0], [0, 0, 0, 0, -24952, 201399, 0, 0], [-6547880, 6547880, 0, -89490, 0, 0, 0, 0], [12255008, 0, 0, 0, 0, 0, 8446, 0], [0, 0, -424553, 0, 0, -424553, 0, -24242], [0, 1455436, 0, -8154, 0, 0, 8154, 0], [0, 0, -411811, 0, 31299, 0, 0, -31299], [0, 0, 0, 0, -55106, 357690, 0, 0], [0, 0, 41585, 0, 0, 41585, 0, -321259], [0, -9937715, 0, -69291, 0, 0, 69291, 0], [-9660947, 9660947, 0, -36326, 0, 0, 0, 0], [0, 0, -429718, 0, 0, -429718, 0, 24974], [0, 0, -327008, 0, 95652, 0, 0, -95652], [8697640, -8697640, 0, -82575, 0, 0, 0, 0], [0, 0, -441032, 0, -104285, 0, 0, 104285], [-8037509, 8037509, 0, 91813, 0, 0, 0, 0], [0, 0, 374957, 0, 294927, 0, 0, -294927], [-1445972, 1445972, 0, 9297, 0, 0, 0, 0], [0, -2037482, 0, 112116, 0, 0, -112116, 0], [-763900, 0, 0, 0, 0, 0, -115872, 0], [0, 0, 0, 0, -22416, 802948, 0, 0], [0, 13454620, 0, -103157, 0, 0, 103157, 0], [-6996790, 0, 0, 0, 0, 0, 108636, 0], [0, 0, 0, 0, -338898, 68953, 0, 0], [0, -14250491, 0, -56914, 0, 0, 56914, 0], [0, 0, 280262, 0, -208329, 0, 0, 208329], [0, 11916436, 0, 208893, 0, 0, -208893, 0], [0, 0, 0, 0, 19851, -873052, 0, 0], [0, 0, 1462809, 0, 183974, 0, 0, -183974], [-34282456, 0, 0, 0, 0, 0, -1476, 0], [0, 0, 889984, 0, 0, 889984, 0, -451417], [0, -8386820, 0, -139576, 0, 0, 139576, 0], [0, 0, 12731, 0, -80563, 0, 0, 80563], [-8670886, 0, 0, 0, 0, 0, -227308, 0], [0, 0, 1155421, 0, 0, 1155421, 0, 155649], [6019090, -6019090, 0, -229488, 0, 0, 0, 0], [0, 0, 196207, 0, 0, 196207, 0, 38886], [0, 27458908, 0, 40948, 0, 0, -40948, 0], [0, 0, -248383, 0, -608293, 0, 0, 608293], [0, -16628915, 0, -1589, 0, 0, 1589, 0], [0, 0, 315604, 0, -544832, 0, 0, 544832], [-9319372, 0, 0, 0, 0, 0, 64238, 0], [0, 0, 0, 0, 220085, 449121, 0, 0], [36932872, -36932872, 0, -102158, 0, 0, 0, 0], [0, 0, 1353559, 0, 0, 1353559, 0, 10467], [-16688824, 0, 0, 0, 0, 0, 314319, 0], [0, 0, 25725, 0, 0, 25725, 0, 93006], [13047791, 0, 0, 0, 0, 0, 212044, 0], [0, 0, 0, 0, -463757, -457888, 0, 0], [0, 0, 92299, 0, 0, 92299, 0, -295977], [0, 0, 1577645, 0, -134094, 0, 0, 134094], [0, 13851292, 0, 41109, 0, 0, -41109, 0], [0, 0, -553467, 0, 98991, 0, 0, -98991], [0, 0, 0, 0, -455156, -588944, 0, 0], [0, 0, 2545262, 0, 0, 2545262, 0, 185006], [-5904100, 0, 0, 0, 0, 0, -133437, 0], [-12275087, 12275087, 0, -108687, 0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_324_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_324_6_e_j();".
// 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_324_6_e_j(:prec:=8)
    chi := MakeCharacter_324_e();
    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_324_6_e_j();".
// 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_324_6_e_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_324_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![45767944570401, 0, 53458618302, 0, 55676403, 0, 7902, 0, 1]>,<7,R![62283664, -694496, 15636, 88, 1]>,<11,R![13604116219067678976, 0, 760307038856064, 0, 38803674672, 0, 206136, 0, 1]>],Snew);
    return Vf;
end function;