
// Make newform 320.6.c.j in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_320_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_320_c_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_320_6_c_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_320_6_c_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 := [9, 0, 969, 0, 460, 0, 41, 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, 160458, 0, 82106, 0, 7420, 0, 182], [-29412, -203676, -19752, -86042, -2232, -7372, -66, -176], [-106884, 203676, 113112, 86042, 15432, 7372, 438, 176], [29412, -646692, 19752, -295142, 2232, -26548, 66, -656], [390564, 203676, 259752, 86042, 17592, 7372, 282, 176], [29412, -991374, 19752, -454172, 2232, -40168, 66, -974], [-147060, 1339296, -98760, 594422, -11160, 51700, -330, 1244]];
    Rf_basisdens := [1, 639, 639, 639, 639, 639, 639, 639];
    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_320_c();"
function MakeCharacter_320_c()
    N := 320;
    order := 2;
    char_gens := [191, 261, 257];
    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_320_c_Hecke();"
function MakeCharacter_320_c_Hecke(Kf)
    N := 320;
    order := 2;
    char_gens := [191, 261, 257];
    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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [-1, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1, 0], [92, 0, 1, 0, 0, 1, 0, 0], [0, 2, 2, 0, 1, 0, -4, -1], [0, -40, -9, 0, 1, 0, 0, 2], [-172, -8, 19, 0, 0, -1, 0, 4], [0, -22, 1, 0, -10, 0, -9, -4], [-734, 12, -28, 6, 0, -4, 0, -6], [528, 0, -12, -12, 0, 0, 0, 0], [0, 410, -5, 0, -26, 0, 16, -1], [2950, 28, -39, 15, 0, 16, 0, -14], [0, 243, 54, 0, 108, 0, -54, 0], [0, 532, -81, 0, 50, 0, 9, 28], [0, 134, 70, 0, 191, 0, -36, 17], [-11460, 8, 41, 48, 0, 13, 0, -4], [-15482, -118, 269, -18, 0, -8, 0, 59], [0, 115, -214, 0, -124, 0, -10, 16], [-15704, -240, 494, -108, 0, 2, 0, 120], [0, 1124, -103, 0, -311, 0, 8, -40], [5408, -208, 608, 60, 0, 28, 0, 104], [0, -1669, -302, 0, 236, 0, 342, 176], [-5238, -156, 312, -126, 0, 48, 0, 78], [0, 1544, 107, 0, 49, 0, 488, 86], [-84006, 356, -940, -30, 0, -20, 0, -178], [0, 770, -115, 0, 106, 0, 599, 164], [0, 3329, -1564, 0, 144, 0, -108, 320], [67494, 78, -99, -96, 0, 192, 0, -39], [0, 4488, -548, 0, 520, 0, -288, 156], [0, -2594, -2133, 0, -244, 0, -129, 352], [103716, -808, 1775, 168, 0, -413, 0, 404], [0, -4332, -1310, 0, -620, 0, -1800, -222], [-106724, 816, -1791, 120, 0, 129, 0, -408], [-22914, 554, -463, 834, 0, 88, 0, -277], [-136760, -1072, 3038, 168, 0, 190, 0, 536], [0, 702, -4531, 0, 138, 0, -904, 753], [0, 2781, 2992, 0, -1356, 0, 868, -696], [0, 13654, 153, 0, -886, 0, 819, -44], [0, 18398, -2547, 0, -1514, 0, -288, 149], [-156668, 112, -537, -336, 0, 79, 0, -56], [-8854, -180, 516, -330, 0, 396, 0, 90], [47712, 1312, -4328, -408, 0, -640, 0, -656], [0, 15112, -403, 0, -433, 0, 440, 82], [0, -930, 4644, 0, 669, 0, -1620, -1119], [-278296, 240, -1314, -204, 0, -510, 0, -120], [81908, 1368, -5541, -1320, 0, -801, 0, -684], [0, 23810, -441, 0, -4100, 0, -1221, -976], [0, 6437, -1112, 0, 116, 0, -1188, 8], [-359526, 2020, -3212, 1842, 0, -4, 0, -1010], [0, -3372, -4599, 0, -3375, 0, -504, 144], [-523648, 3008, -8232, -396, 0, -316, 0, -1504], [-354946, 988, -1043, 75, 0, 1352, 0, -494], [31468, -560, -1443, -2496, 0, -347, 0, 280], [0, 29800, -6444, 0, -316, 0, 2232, 1672], [0, 21868, 1665, 0, -5548, 0, 4293, -584], [89814, -2054, 6517, -642, 0, 2024, 0, 1027], [1080704, -1680, 2328, -1068, 0, -804, 0, 840], [0, -25774, -6633, 0, -6842, 0, 3504, 659], [-972474, 5928, -12951, 2397, 0, -528, 0, -2964], [0, -27575, 21168, 0, 6500, 0, -2172, -3368], [0, 29402, 773, 0, 1956, 0, -9648, -1693], [0, -23769, -242, 0, -7740, 0, -4022, -2304], [793896, -1792, 7862, 3792, 0, -410, 0, 896], [0, -66580, 7442, 0, -3848, 0, -7000, -3658], [0, 40034, -6516, 0, 3619, 0, 180, 2063], [-868948, 1528, -371, 4176, 0, -727, 0, -764], [0, 17008, -1766, 0, 9602, 0, -4568, 1360], [0, 17435, 6490, 0, 8456, 0, 16794, 3752], [-739966, -3932, 9364, 930, 0, -1396, 0, 1966], [0, -92384, -18558, 0, 11006, 0, -8784, 4156], [-1341128, -3712, 5938, -3120, 0, -222, 0, 1856], [0, -994, 20807, 0, 12568, 0, 3719, -904], [0, -72846, 26651, 0, -6534, 0, 4160, -5805], [-1094740, -11648, 18685, -8520, 0, -1915, 0, 5824], [0, 27894, 3447, 0, 19944, 0, -9657, 1368], [812334, 4970, -20407, -3510, 0, -4472, 0, -2485], [0, 55690, -24840, 0, -12373, 0, -12972, -101], [427394, -7684, 18168, -402, 0, -640, 0, 3842], [-679178, 308, -6655, 867, 0, -6752, 0, -154], [-4364652, -8192, 20803, 144, 0, 179, 0, 4096], [-500050, 14594, -30967, -282, 0, 5800, 0, -7297], [373472, -13120, 36240, -2388, 0, 5828, 0, 6560], [0, -189896, -5211, 0, 2579, 0, 21840, 5926], [-2710680, 10784, -21082, -816, 0, 6694, 0, -5392], [0, -212315, -17856, 0, -14920, 0, 14184, 3424], [-1089234, 4748, -8779, -2037, 0, 5128, 0, -2374], [0, 177412, 20268, 0, 23762, 0, -24024, -4106], [-3066222, -13100, 40276, 8154, 0, -628, 0, 6550], [0, 205540, -15005, 0, -20962, 0, 14377, 1684], [0, -159663, 20376, 0, 6576, 0, 28440, 2928], [-1750048, -9872, 37208, 4440, 0, 8088, 0, 4936], [0, 19644, 70033, 0, 45252, 0, -59, -4968], [4345964, 21528, -40787, 8472, 0, 4561, 0, -10764], [-3656860, -11136, 6255, -13632, 0, -7953, 0, 5568], [0, -52110, -37267, 0, -18286, 0, 2079, 4212], [1395650, 300, 24820, 18582, 0, 6988, 0, -150], [4420010, 3152, -17856, -2664, 0, -7312, 0, -1576], [0, -130883, 26996, 0, 44036, 0, -16360, 136], [1404962, 11036, -41596, -17154, 0, 3148, 0, -5518], [0, -91719, -21916, 0, -48972, 0, -1864, -5784], [0, 57110, 38817, 0, 15274, 0, 43848, 4061], [0, 31173, 42624, 0, 40212, 0, -25308, -5544], [-4986666, -1276, 11297, 6315, 0, 1792, 0, 638], [2741324, 10368, -24795, 4608, 0, -3483, 0, -5184], [0, -237200, -17618, 0, 37610, 0, 35632, 18172], [0, 340723, -42142, 0, -4880, 0, -29862, 1480], [0, 121008, -8908, 0, 7280, 0, -15768, 84], [2138776, -9696, -862, -24036, 0, -1066, 0, 4848], [4385766, -18256, 33785, -13839, 0, 1984, 0, 9128], [0, 42596, 167663, 0, 39850, 0, -23647, -30292], [0, 106630, 110480, 0, 49793, 0, 45812, -2975], [0, -451236, 59579, 0, -2545, 0, 18144, -8796], [-3004628, 56584, -121043, 11184, 0, 9233, 0, -28292], [1681064, 35088, -78330, 8568, 0, 822, 0, -17544], [-980850, -14476, 20405, -11553, 0, -4232, 0, 7238], [0, 2495, 48258, 0, -10256, 0, -23046, -16312], [0, 317416, -47747, 0, -32676, 0, 25209, 8056], [0, -91870, -76716, 0, -15593, 0, -44388, 3347], [-6544380, 35440, -97673, -18360, 0, 9287, 0, -17720], [976750, -24722, 64057, 1596, 0, 656, 0, 12361], [0, 403464, 32471, 0, 14661, 0, -30520, -9666], [0, 270438, 92430, 0, 77163, 0, 18612, 669], [0, 336111, -17602, 0, -86824, 0, 15102, -10824], [-8226828, 53912, -114901, 24912, 0, -5033, 0, -26956], [9234742, -17698, 30325, -30672, 0, 16752, 0, 8849], [-5885414, -18452, 47188, 11910, 0, -10852, 0, 9226], [1154656, -31312, 41584, -10740, 0, -25956, 0, 15656], [0, 439268, 73377, 0, -5228, 0, -7035, -17128], [0, -103010, -33237, 0, -84268, 0, 25656, -5075], [5283828, 65360, -146005, 9792, 0, 7603, 0, -32680], [0, -17200, -62955, 0, 99244, 0, -35199, 25400], [9272432, 31952, -99388, -17616, 0, -1892, 0, -15976], [0, -222774, -124187, 0, 17712, 0, -44024, 19575], [-1163830, 7676, 32928, 24558, 0, 27560, 0, -3838], [6948098, -38304, 106968, 12864, 0, -1656, 0, 19152], [0, 294510, -141946, 0, -42781, 0, -87300, 2373], [0, 190307, 63106, 0, -67244, 0, 85870, -8896], [0, -469262, 155898, 0, 2885, 0, -5292, -31661], [-7998774, -124112, 263872, -36984, 0, -9424, 0, 62056], [-5356836, -34192, 30401, -52560, 0, -2519, 0, 17096], [-5565522, 26886, -56439, 13704, 0, -2928, 0, -13443], [0, -247586, -85655, 0, -30934, 0, -90941, -7244], [0, 316751, -53658, 0, 100840, 0, -50778, 20744], [-8332538, 39802, -63299, -4362, 0, 40568, 0, -19901], [6436632, 18576, -13398, 36120, 0, -3078, 0, -9288], [0, -906498, 79334, 0, 93999, 0, 58580, 14649], [0, -14948, -95008, 0, -26918, 0, 60840, 25786], [12298396, 34680, -85407, -10008, 0, 11301, 0, -17340], [0, -68424, -137457, 0, -120330, 0, 58653, 15156], [0, 1151006, 81551, 0, 89548, 0, -101632, -18727], [-790450, 21904, -151339, -57531, 0, -39048, 0, -10952], [0, 1195937, 111136, 0, -8312, 0, -207272, -65344], [0, 170896, -133299, 0, 87404, 0, -94023, 25336], [0, -445663, 300016, 0, 16276, 0, 101380, -36472], [1038816, -152928, 306144, -59868, 0, -16308, 0, 76464], [-1568424, 59712, -35502, 67596, 0, 46182, 0, -29856], [-12180850, -95444, 244757, 13179, 0, -7032, 0, 47722], [0, 407740, 113917, 0, 126245, 0, 80992, 18664], [-4883182, 8108, 49908, 75846, 0, -5668, 0, -4054], [0, -614173, -105642, 0, -25040, 0, 171198, 50360], [0, 447228, -91620, 0, -127194, 0, -147816, -36678], [0, 1815302, -95195, 0, 75454, 0, 37171, 41564], [5946252, -101992, 246341, 23016, 0, -31655, 0, 50996], [0, 140488, 424333, 0, -26301, 0, -70416, -104210], [0, -127180, -80195, 0, 13544, 0, -14859, 15776], [-15708704, 24768, 5736, 60240, 0, 7416, 0, -12384], [0, 202910, -127314, 0, 29491, 0, 231420, 77645]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_320_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_320_6_c_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_320_6_c_j(:prec:=8)
    chi := MakeCharacter_320_c();
    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_320_6_c_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_320_6_c_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_320_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![324000000, 0, 26394624, 0, 562528, 0, 1472, 0, 1]>,<11,R![37397137664, 126641408, -468000, -368, 1]>],Snew);
    return Vf;
end function;