
// Make newform 392.6.a.h in Magma, downloaded from the LMFDB on 23 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_392_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_392_6_a_h();".
// 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_392_6_a_h();".
// 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 := [882, 0, -113, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -58, 0, 2], [0, -226, 0, 2], [-452, 0, 8, 0]];
    Rf_basisdens := [1, 21, 21, 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_392_a();"
function MakeCharacter_392_a()
    N := 392;
    order := 1;
    char_gens := [295, 197, 297];
    v := [1, 1, 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;

function MakeCharacter_392_a_Hecke(Kf)
    return MakeCharacter_392_a();
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, 1, 0], [0, -1, -2, 0], [0, 0, 0, 0], [-208, 0, 0, 1], [0, 5, 14, 0], [0, 26, -4, 0], [0, -4, -93, 0], [-1420, 0, 0, 5], [2226, 0, 0, -16], [0, 40, -122, 0], [-1582, 0, 0, -2], [0, -170, -268, 0], [-7032, 0, 0, 7], [0, 256, -750, 0], [2286, 0, 0, 30], [0, -644, -13, 0], [0, -109, 398, 0], [-13160, 0, 0, 103], [-5400, 0, 0, -150], [0, -48, -1744, 0], [-70648, 0, 0, 24], [0, 104, 1587, 0], [0, 360, 5080, 0], [0, 1406, -1300, 0], [0, 423, 3586, 0], [0, -2064, -518, 0], [-152000, 0, 0, -113], [47034, 0, 0, 322], [-157882, 0, 0, -177], [-104644, 0, 0, -147], [0, 1928, -141, 0], [177622, 0, 0, 192], [0, -6628, -9959, 0], [-15946, 0, 0, 244], [50380, 0, 0, -681], [0, -3599, 4878, 0], [-357104, 0, 0, -469], [0, 9056, 15086, 0], [0, 2413, -3162, 0], [-248120, 0, 0, 155], [0, -5379, 8346, 0], [-22608, 0, 0, -1602], [67342, 0, 0, 1137], [-263762, 0, 0, 506], [0, 12936, 12814, 0], [149000, 0, 0, 1239], [0, 9464, 13668, 0], [0, -12948, 3799, 0], [0, -14859, 30854, 0], [1179878, 0, 0, -92], [610836, 0, 0, 2119], [0, 1198, 22244, 0], [0, 2776, -2947, 0], [0, 19368, 7704, 0], [-1063000, 0, 0, -434], [0, -18487, 62614, 0], [0, -504, -2312, 0], [-208858, 0, 0, 912], [157334, 0, 0, 2588], [0, -5800, 64599, 0], [0, 6779, 7138, 0], [0, -27264, -8349, 0], [0, -14632, 76896, 0], [0, -17346, -108764, 0], [290166, 0, 0, 7614], [86680, 0, 0, -4545], [749386, 0, 0, 821], [-441272, 0, 0, 683], [0, 33441, 71754, 0], [0, 30884, -139024, 0], [660980, 0, 0, 2405], [0, 14640, 104252, 0], [-464842, 0, 0, -12], [-739448, 0, 0, 551], [0, -24376, -111278, 0], [1640754, 0, 0, -4354], [0, -67347, -56198, 0], [612402, 0, 0, -5589], [0, -44394, -92788, 0], [0, 45488, 3345, 0], [-2040858, 0, 0, 5676], [2798796, 0, 0, -7683], [0, -22690, 217932, 0], [0, 104736, 189408, 0], [678696, 0, 0, -8603], [143362, 0, 0, -9120], [-4113562, 0, 0, -8995], [0, -83011, -181758, 0], [1753120, 0, 0, -11130], [0, -66300, -98657, 0], [0, -94928, -127434, 0], [1776676, 0, 0, -5039], [-8545592, 0, 0, -4051], [-3928240, 0, 0, -9263], [0, -79840, -327996, 0], [0, -92515, -59070, 0], [0, -19846, 329020, 0], [0, -45596, 271539, 0], [-9758162, 0, 0, -3568], [-3207760, 0, 0, -23085], [-2093066, 0, 0, 13474], [0, 98580, 39165, 0], [-2995334, 0, 0, -10049], [1588808, 0, 0, 11563], [0, 32172, -32752, 0], [0, -38700, -114675, 0], [0, 53596, 472464, 0], [-655840, 0, 0, 18208], [0, 214048, 162936, 0], [0, -28408, -261056, 0], [-12793862, 0, 0, 9484], [-2764126, 0, 0, 21689], [0, -67808, -278549, 0], [5377216, 0, 0, 23012], [-2706670, 0, 0, 12055], [0, -116580, 67309, 0], [0, -131928, 133102, 0], [-201214, 0, 0, 5880], [-3484960, 0, 0, -26233], [0, -25897, -614566, 0], [12467230, 0, 0, -17120], [0, 78165, -295262, 0], [5481152, 0, 0, -5753], [0, 196984, -607773, 0], [6956738, 0, 0, 9804], [-9371710, 0, 0, 17442], [0, -91592, 417774, 0], [0, 294544, -770518, 0], [0, -311289, 322382, 0], [-6982160, 0, 0, 21067], [9942804, 0, 0, 28385], [3364300, 0, 0, 12889], [-748998, 0, 0, 63272], [0, -358742, 356324, 0], [0, -152046, -832532, 0], [0, 243451, -940546, 0], [0, -257604, 454631, 0], [0, 487209, 420670, 0], [13332950, 0, 0, -11623], [0, -102440, -496845, 0], [1844822, 0, 0, 77228], [-18567000, 0, 0, -48434], [-14394704, 0, 0, -3069], [0, 196123, -964362, 0], [0, 115016, -986702, 0], [0, -253419, 939518, 0], [0, -273106, -233468, 0], [0, -498240, -647295, 0], [12223408, 0, 0, 61054], [8027466, 0, 0, -68186], [0, 245640, -283080, 0], [-16100192, 0, 0, 53313], [0, 268304, -513238, 0], [-14321320, 0, 0, 7005], [3296708, 0, 0, 29563], [-28669960, 0, 0, 18742], [0, 619474, 522516, 0], [0, -196640, 656312, 0], [0, -780329, -1014262, 0], [-3713984, 0, 0, -101537], [-25728390, 0, 0, 11976], [35938484, 0, 0, -23239], [0, 272276, -750205, 0], [41467342, 0, 0, -3800], [0, -145768, -1671478, 0], [-36660168, 0, 0, 6724], [0, 919051, 1821646, 0], [-10056354, 0, 0, 12233], [0, -158575, 1698750, 0], [11034168, 0, 0, 16473], [0, 295897, -2074142, 0], [17334728, 0, 0, -29778], [-30479402, 0, 0, 55328], [0, -712624, -1143378, 0], [0, 166012, 114536, 0], [-7766768, 0, 0, -98709], [26397690, 0, 0, 51276], [0, 264792, 47828, 0], [0, 89331, 424618, 0], [-52321412, 0, 0, 35993], [0, 737932, -1942279, 0], [-24809646, 0, 0, -52722], [0, -604412, -1133536, 0], [-32951692, 0, 0, 5763], [0, 150713, 424214, 0], [-11454874, 0, 0, 3674], [0, 712532, 1493995, 0], [-36634538, 0, 0, 22984], [0, -135328, 769466, 0], [0, 136132, 268696, 0], [-58035200, 0, 0, -47741], [-57147264, 0, 0, -87515], [0, -203947, 2947526, 0], [-19734064, 0, 0, 84521], [0, 172940, -609656, 0], [-26049094, 0, 0, -38623], [-30945374, 0, 0, -17148], [0, -402208, -2289992, 0], [0, 486568, -137272, 0], [60188790, 0, 0, 40290], [0, -938064, 3050866, 0], [0, 627447, 18830, 0], [0, 379152, -812488, 0], [0, -414404, 2802707, 0], [0, 549475, -2067718, 0], [0, 1449520, 3237610, 0], [9819912, 0, 0, 149757], [62485998, 0, 0, -55797], [0, 385456, 335193, 0], [-47021246, 0, 0, 109031], [0, 619699, -836578, 0], [69486060, 0, 0, -94649], [0, -880624, 1364135, 0], [0, 1263632, 1889152, 0], [0, 1220522, -741084, 0], [-38716864, 0, 0, 83346], [0, 723546, 2207980, 0], [96499184, 0, 0, 25012], [20821538, 0, 0, 181268], [35371626, 0, 0, -185864], [0, 1392448, 3294800, 0], [-10010782, 0, 0, -91304], [13054484, 0, 0, 225783], [0, -923692, -2474669, 0], [20501434, 0, 0, 262824], [0, 1250560, -2818896, 0], [45631300, 0, 0, -106577], [0, 2025384, 2904620, 0], [99428400, 0, 0, -30403], [-102915054, 0, 0, 60556], [0, 555632, 152477, 0], [31747760, 0, 0, 71310], [-2825430, 0, 0, -185616], [0, -1303752, -1109757, 0], [0, -275560, 4939552, 0], [0, -1896726, -3726572, 0], [35535542, 0, 0, -114188], [19663176, 0, 0, -105087], [0, -862576, -5041028, 0], [-13813832, 0, 0, -213527], [0, 1534380, 1413715, 0], [0, -1272040, 4084356, 0], [-21086458, 0, 0, -190138], [0, -2082168, 1078272, 0], [0, -1003216, 794246, 0], [0, 2260632, 3176296, 0], [0, -1995112, -5752553, 0], [30193408, 0, 0, 275565], [-18987912, 0, 0, -333216], [56346206, 0, 0, -167372], [0, -765732, 1507112, 0], [-76962832, 0, 0, 253760], [0, -2055696, -4418288, 0], [0, 1646683, 2315174, 0], [36004296, 0, 0, 107479], [-57265926, 0, 0, -336136], [0, 1500012, 3947861, 0], [0, 429987, -1473882, 0], [0, 1300206, -7041364, 0], [-8281996, 0, 0, 86135], [-100155992, 0, 0, 178213], [0, -813573, -6618938, 0], [0, 157087, 163662, 0], [0, -139122, -682252, 0], [0, 1480356, 5959693, 0], [47026526, 0, 0, 293384], [0, 2242408, 5789632, 0], [-20012496, 0, 0, 47735], [2287266, 0, 0, -15390], [0, -2138843, -7856362, 0], [35393800, 0, 0, 171937], [0, 1533692, 2267952, 0], [-123801108, 0, 0, -36463], [0, 2890800, 5427736, 0], [0, 877520, 585036, 0], [68335616, 0, 0, -268599], [130953046, 0, 0, -54594], [85026798, 0, 0, -342661], [0, 726256, -5294649, 0], [0, 2084096, 3151012, 0], [121116072, 0, 0, -151922], [0, -330808, -1368974, 0], [0, -935637, -865886, 0], [0, -1945464, 3423715, 0], [-101923676, 0, 0, -18497], [-83156814, 0, 0, 391912], [-88789330, 0, 0, 177382], [0, 1490472, 6795010, 0], [0, 1964860, 3852336, 0], [38497094, 0, 0, 545870], [0, -1924168, -2265297, 0], [75651330, 0, 0, -370211], [0, 1979776, 7807911, 0], [-92923906, 0, 0, -472832], [0, -1109491, -7725542, 0], [0, 1049880, 6001640, 0], [0, 219049, -11245002, 0], [0, -278272, 11898409, 0], [0, -4207496, -2076395, 0], [0, -4059914, -4485116, 0], [5089594, 0, 0, -278966], [139141808, 0, 0, 295586], [28426392, 0, 0, -127363], [-45072016, 0, 0, 648013], [-70513762, 0, 0, 251168], [-109718248, 0, 0, -485065], [0, 3618207, -2547554, 0], [-94384820, 0, 0, -354849], [247059782, 0, 0, -30364], [0, 2004720, 1561212, 0], [154684882, 0, 0, -63646], [-59891714, 0, 0, 527896], [-1571016, 0, 0, -887467], [-123040656, 0, 0, -428328], [0, 5025168, 12149104, 0], [0, 5195420, 3713541, 0], [-183162688, 0, 0, -47554], [0, 3211160, -2029096, 0], [270528782, 0, 0, 260600], [0, 5084400, 3591917, 0], [305518854, 0, 0, 126256], [0, -443557, 5440554, 0], [-65941672, 0, 0, -119308], [-28522298, 0, 0, -210019], [0, -3752538, 8362644, 0], [220990448, 0, 0, -417249], [0, 1424400, -8630225, 0], [59808628, 0, 0, -499605], [77690682, 0, 0, -547564], [249298054, 0, 0, 220294], [126342530, 0, 0, 372868], [0, 4144408, -6384126, 0], [0, 3928364, -15416107, 0], [-146511680, 0, 0, 556295], [0, -1644220, -13940517, 0], [138784634, 0, 0, 548126], [0, 2397028, -4649216, 0], [0, -5436876, 2908880, 0], [0, 1359984, 14987570, 0], [-201078002, 0, 0, -194922], [171387050, 0, 0, -107837], [0, -2724667, -5167926, 0], [40099312, 0, 0, -483604], [-52348926, 0, 0, 87564], [105678232, 0, 0, 1046877], [0, -588183, -12311574, 0], [120528024, 0, 0, 675839], [0, -6313592, -4101076, 0], [0, -3428373, -4221626, 0], [0, -4389736, -9142175, 0], [-246788406, 0, 0, 240584], [298734726, 0, 0, -189378], [0, -892592, 10819250, 0], [15888606, 0, 0, 904714], [0, 5110996, -8385712, 0], [0, -3744152, -619562, 0], [0, 3004220, 4093135, 0], [-15190350, 0, 0, -720912], [-63467532, 0, 0, -823127], [-207574394, 0, 0, -208284], [0, -4399216, 2078344, 0], [44369228, 0, 0, -1022255], [-48594984, 0, 0, -76347], [0, -2240484, 8054323, 0], [257014882, 0, 0, 677561], [0, 1169213, 3714046, 0], [79881124, 0, 0, 67773], [-175350570, 0, 0, -526331], [-345432736, 0, 0, 588965], [0, -6213796, -1241063, 0], [135355240, 0, 0, -209344], [175672294, 0, 0, 847832], [0, 861544, -12227376, 0], [14796606, 0, 0, 82028], [0, 3274260, 9411355, 0], [-468730572, 0, 0, -457153], [0, -1257136, -4577184, 0], [0, -6754482, -10604996, 0], [0, 5493222, 10640884, 0], [0, -5744423, -3505486, 0], [-312671082, 0, 0, -727327], [-156221432, 0, 0, -914090], [278177986, 0, 0, -372104], [0, -48180, 8104841, 0], [0, -7635104, -9576688, 0], [194327016, 0, 0, 218040], [0, 2791735, -9733138, 0], [464088488, 0, 0, -307407], [0, 4851192, 562794, 0], [287038698, 0, 0, -367295], [0, -2760381, 10957758, 0], [-177348368, 0, 0, 1423579], [0, 1958192, -3910835, 0], [-29316420, 0, 0, -874409], [113952166, 0, 0, -1590824], [0, -3577272, 10988934, 0], [0, -7321118, 3937652, 0], [-379709440, 0, 0, -90301], [-342874870, 0, 0, -170092], [0, -10475781, -2085118, 0], [-321068414, 0, 0, -1100720], [-72134016, 0, 0, 1002974], [0, 6808726, -7731340, 0], [0, -1138947, -7358666, 0], [0, -5474176, -16748070, 0], [55879182, 0, 0, 877052], [348754494, 0, 0, 315345], [0, -3714360, -16777655, 0], [0, 10620396, 12327813, 0], [0, 7912872, -19165360, 0], [-274278150, 0, 0, -129088], [-347967944, 0, 0, 457991], [210910224, 0, 0, -141311], [-459989498, 0, 0, 323372], [0, -4452063, 28618786, 0], [-220515704, 0, 0, -114196], [0, 908272, -4671734, 0], [0, -4678954, 26171388, 0], [0, -10347072, -22602940, 0], [775670506, 0, 0, 39914], [0, 7182491, -7485802, 0], [-432072408, 0, 0, -85100], [0, 2566720, -7038315, 0], [0, -56698, 7479932, 0], [0, -5390465, -14490202, 0], [204387272, 0, 0, 222233], [-81444170, 0, 0, 293780], [0, 7369872, -219267, 0], [0, 11756104, 3432062, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_392_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_392_6_a_h();".
// 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_392_6_a_h(:prec:=4)
    chi := MakeCharacter_392_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_392_6_a_h();".
// 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_392_6_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_392_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![56448, 0, -904, 0, 1]>],Snew);
    return Vf;
end function;