
// Make newform 425.4.a.g in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_425_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_425_4_a_g();".
// 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_425_4_a_g();".
// 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 := [-4, -14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-10, 0, 1]];
    Rf_basisdens := [1, 1, 2];
    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_425_a();"
function MakeCharacter_425_a()
    N := 425;
    order := 1;
    char_gens := [52, 326];
    v := [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_425_a_Hecke(Kf)
    return MakeCharacter_425_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 := 4;
    raw_aps := [[0, -1, 1], [-2, 1, -2], [0, 0, 0], [-6, 1, 4], [-10, 11, -2], [-12, -8, -6], [17, 0, 0], [24, 22, -8], [-46, 39, 4], [-142, -16, 30], [82, 39, 16], [-102, 28, 50], [-118, -52, -60], [-204, -2, -56], [-228, 48, -44], [-98, -116, 8], [212, -130, 0], [-2, -64, 78], [-292, -24, 132], [-110, 185, 72], [-274, -16, 16], [-138, -267, 180], [756, -82, -128], [-20, -276, 110], [50, -140, -120], [388, 32, -98], [-792, -76, 224], [534, 53, 98], [342, 420, -62], [498, -68, 188], [-1804, -62, -240], [-814, -185, -178], [-812, -392, -322], [666, -163, 570], [-34, 288, -544], [884, -354, -72], [550, -76, -388], [202, -167, 446], [566, 235, 540], [110, -420, 674], [648, -426, -8], [-2874, -220, 110], [-796, 372, -452], [510, 776, 12], [-258, -372, 134], [130, 1203, -420], [-3194, -271, -406], [-1776, 606, -508], [666, 21, 558], [168, -528, -810], [2698, 916, -420], [3412, -568, -348], [-3486, 708, -468], [-564, 1536, 916], [-2880, -240, -606], [-2964, 326, -888], [2422, -480, 1138], [2044, -736, 540], [942, -652, -1438], [-190, -4, -708], [858, 533, -1462], [202, 2008, -312], [1248, -1272, 500], [-4614, 257, -2356], [-242, -528, 676], [-4842, -376, -538], [3196, 138, -1184], [-2258, 1412, -496], [1218, -1579, 366], [-918, 228, 608], [-850, -604, -1308], [-4952, 10, -12], [3810, -1607, 968], [3356, -496, -1334], [-294, -2353, -70], [4612, 790, 560], [528, 816, -1922], [-2726, -2132, 154], [6170, 316, 2540], [-1450, -3168, 1680], [1070, 2025, 302], [-5988, -1336, -474], [414, 309, 540], [5024, -2876, -2], [1026, -703, -336], [-28, -1152, -1604], [8454, 1064, -1480], [1784, 3380, -3074], [-4966, 1972, -3952], [-4488, 2816, -2696], [-5640, 714, 552], [-12030, 1323, -1228], [-5366, 1473, 312], [8112, 2662, 136], [11278, 2525, -1486], [10098, 3045, -424], [6974, -776, 3128], [9546, -1100, 956], [-4948, -2896, 1868], [3774, -324, -1218], [-8410, -1083, 1674], [-4716, 216, 3482], [-11252, 978, 104], [-11090, -5172, 2860], [-6330, 1505, 830], [-11580, 352, -1082], [3360, -374, 4368], [586, -68, -1860], [13072, -968, 1752], [-2942, 4812, -5240], [-14154, 2165, 2216], [10514, -1680, 5448], [3970, -2972, 5460], [-3370, 515, 50], [1216, 3126, 4260], [-122, -5324, -208], [-3402, 4481, -4842], [372, 2936, -2932], [-9354, 3672, 1106], [-2968, -1376, 1428], [-7146, -4760, -2252], [-7014, 104, -2032], [13518, -2388, -1578], [-170, 837, -1906], [-11754, -2857, 2406], [4380, 4896, 246], [-9446, 3320, -4426], [-1094, -4167, 2096], [4988, 2568, 1452], [-302, 3128, 4668], [-16528, 5422, 2248], [-18650, -1991, -552], [21914, -3651, -3408], [-16808, 6752, 1538], [5524, -4120, -230], [-5724, 1568, -7662], [-2832, -5216, -6230], [23286, -77, -954], [9986, -504, 3116], [29262, 3016, -512], [-9774, 605, 6134], [5370, -3036, -2734], [-3198, -9013, 3660], [-7878, 3999, 2406], [5018, -1860, 7436], [-5370, -1973, 5140], [-6686, 3384, -5802], [18462, -7040, -3932], [-39732, -1762, 56], [-2704, -10248, 5296], [-398, -12380, 3670], [-14478, -6044, 1128], [4404, 7668, 5820], [-9378, -1335, 500], [10210, 1773, -2150], [6966, -461, 5316], [3780, 4692, 4764], [-8190, 2508, -10028], [-4502, 4904, -8944], [-8430, 9636, -1806], [20214, -2101, -4330], [-11620, 8596, 4706], [-7752, -3654, -1132], [32628, 3534, -1592], [7370, 5948, -7596], [9086, -2089, 4104], [5754, -8103, -1488], [-218, 8540, 8750], [-11706, -4672, -88], [-6430, 13004, -3486], [-16256, -2972, 5196], [-10748, 6200, -898], [-14066, -6611, 4784], [6292, 788, -6654], [21092, -3278, 3064], [-4422, 4576, 2832], [-8686, 6057, -3618], [-23490, -9252, 2750], [-25576, 5774, -1852], [15080, -1448, 4030], [-30216, -8832, 5184], [30050, 12185, -5750], [-19102, -3464, -12830], [-23786, 496, 1904], [-6036, 9614, -12976], [19772, -4960, 13686], [22154, -2808, 9290], [27464, 1124, 13196], [24342, 2624, -7984], [5322, 3315, 9008], [-38786, 708, 6240], [5210, 19663, -3094], [-12840, 6890, -1784], [-14720, -1408, 3022], [34966, -5045, 4698], [53454, 908, 6360], [-27938, 9192, -708], [5622, 14228, -6394], [-9946, -8836, -3696], [27216, -1820, 8664], [36654, -3956, 11166], [15542, 2441, 7580], [1386, -2416, -448], [16272, 14552, -12802], [-5416, -2264, 13284], [-15120, 3224, 14402], [-32384, 468, -6672], [-30232, 8342, -10992], [-36230, 7816, 6720], [-3328, 13800, -1444], [6138, 14084, -5896], [-5256, -4416, -3218], [-18966, 363, 3840], [4536, -7374, -984], [-1794, 11513, -12424], [18930, 5744, -4628], [-35528, 956, 7368], [-11158, 2192, 888], [-2270, -11561, 6128], [7764, 7168, -15374], [41594, -9036, 8940], [-11086, 2057, -16012], [-26642, -11432, 8880], [-19882, -7901, -19604], [7996, 2508, 18292], [29524, -2928, 14950], [16542, -13392, 7752], [13958, -16981, -1464], [32716, 17610, -2648], [56694, -1443, 8654], [-6030, 17624, -5524], [-20718, -12233, 8874], [6576, -5594, 5172], [-27576, -8484, 4594], [5604, -2912, 9356], [7488, 5474, 17012], [-18062, -1432, -5476], [39090, 3668, -14678], [26154, -4449, 13230], [-680, 13998, -7124], [-65598, -5957, 2290], [-22920, -2468, -12516], [-13596, -22140, 5868], [-33160, 12488, -6154], [-2022, -4716, 22788], [-51798, 15377, 7268], [-7266, 9281, -18768], [-5434, 11965, 10662], [-26412, -22762, 13456], [51096, 9582, -8292], [21990, 9436, 7732], [-37962, -11152, -2988], [-42452, -14014, -8256], [-25894, 7608, -14880], [-43864, -6448, 15426], [42348, -5692, -3540], [41562, -4756, -11262], [2406, 26641, -15074], [-38202, 15772, 9510], [36432, 800, -13182], [-64818, -10329, -1860], [-56888, -20840, 5004], [-25782, -10372, -270], [84206, -6176, -3582], [-51758, 16364, 5656], [-29804, 11548, -3412], [25358, 520, -148], [52686, -2464, 13520], [-55342, -14463, -234], [92798, -3076, -7004], [-28758, -23472, 8934], [20680, -12484, 32868], [3922, -18316, 8636], [4776, -6886, -19084], [92338, 968, -11056], [-53200, 9610, 15796], [-916, -4642, -15416], [-31300, 12832, -16970], [26820, -7396, -3530], [4980, -17914, -7840], [-17036, -12500, -8796], [-14102, -7775, -6196], [-18278, -16981, 7432], [35362, -19948, -6888], [63590, -5335, 20618], [-15456, -6420, -15360], [-49318, 1616, -3928], [58002, -26928, -8174], [105204, 742, 12944], [-17168, 12468, -12430], [-10190, -3392, 78], [76078, 20593, -8778], [25056, -13072, 12554], [95486, 1695, -2450], [-4302, -19428, -4182], [-8746, -14092, -8550], [13672, -7316, -23464], [-89700, 4872, 8850], [-10954, 32755, 9098], [107196, -598, 7784], [-7068, -9276, 3114], [-30832, -26632, -1230], [-1634, 24653, 4952], [78494, -22621, -14222], [24650, 759, 28874], [5658, 9512, -200], [17408, 28332, 716], [29694, 23084, 9174], [104712, 6024, -2936], [-24218, 6732, 7924], [87106, 4859, 1164], [49734, -12920, 11906], [-34802, 18208, 12288], [15912, 30998, 15680], [113144, -10472, 19928], [11414, -26336, -16160], [-21960, 16070, 19184], [-52278, 13265, -18724], [69946, 5696, 22364], [-53706, -4080, 18864], [19798, 1763, 19034], [-1250, 5764, -460], [-67426, 2064, -14504], [-40712, -2320, -12360], [-23866, 4172, -21812], [-14394, 28380, -34068], [29378, -12751, -19582], [-51310, 14721, -21982], [-51834, -20133, 5080], [-20930, 6052, -20850], [-99430, -3432, -7650], [13346, 22532, -19710], [77658, -15255, 49320], [35288, -35476, 21244], [12078, -3575, -7570], [31762, -22793, 29478], [-13062, -22156, 12800], [29858, 11996, 30052], [126390, 1988, 21228], [-35072, -56418, 25444], [-30294, -11736, -32124], [28326, 15792, 30520], [-77338, 10220, -4994], [70048, 41516, -22728], [56436, 5928, 36762], [-6282, 15669, -9698], [100994, 19096, -8702], [-43588, 29188, -8724], [72498, 1707, 4792], [17746, -22148, -19830], [25932, 1110, 15872], [16930, -37684, -34056], [-23702, 32932, 25764], [-11818, 41983, -2780], [15656, 1416, -16522], [-96068, -1664, 9014], [39552, -4238, 12236], [-102198, -19399, 10190], [39846, 840, -33292], [-108156, -12438, -14400], [101586, 39672, -18014], [-17450, 22388, -5036], [-66284, 19324, 4836], [68966, -13531, 35502], [-55968, -30066, -13920], [-25026, -20196, -20636], [9238, 26888, -35142], [-55516, -34432, 16940], [59214, 32224, -21096], [41740, -22594, -12480], [11334, -2629, 11118], [-34030, -11569, 2772], [40724, -49240, -17082], [-23740, -46372, 30644], [174070, 13668, 8002], [-72254, 12169, -55714], [-60602, 31571, -15020], [-35736, -62024, 25786], [124890, -23324, 6668], [-60010, 44272, -25616], [-66770, 28480, -24750], [100186, -35336, -24336], [-90210, 21589, 28924], [-162966, 6712, -39548], [-7050, -50827, 5166], [113698, 16675, 33648], [-202308, -242, -7616], [60912, -27464, -28430], [106062, -11577, 50138], [-46160, 21396, -28496], [-79274, -43756, 18644], [-76274, -14988, 30062], [54880, 7112, -5180], [63424, 9292, 11780], [63908, 5918, 62248], [-76714, 15156, -20340], [99276, -3112, 8780], [-112218, -8528, -5280], [152278, -20527, 9714], [-23892, 1736, -22338], [-84394, -25760, 30430], [-39628, -36720, -34970], [26472, 192, -14784], [70758, 100, -7172], [-60578, 28296, 11336], [-137366, -14061, -23352], [-33168, -37720, 31418], [82036, -16088, -1102], [196836, -21522, -10256], [11450, -3523, -6018], [-78186, 36516, -7368], [-134736, 12288, -23246], [37200, -988, -29260], [11450, 51711, -14170], [-95342, -47760, 35712], [185854, -29864, -3786], [-47050, 17011, 1872], [-10026, -3419, -12920], [29962, -34856, -3264], [83628, 8328, 40212], [-33206, 15612, -26008], [-77586, -29228, -36038], [-124058, 17275, -25584], [88744, -41754, 17672], [55950, 44632, 16276], [132574, 2100, -18868], [104342, -18397, 52830], [37954, 45384, -23680], [137500, -7092, 14716], [156190, 21391, -8316]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_425_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_425_4_a_g();".
// 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_425_4_a_g(:prec:=3)
    chi := MakeCharacter_425_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_425_4_a_g();".
// 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_425_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_425_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-32, -24, 1, 1]>,<3,R![-204, -62, 4, 1]>],Snew);
    return Vf;
end function;