
// Make newform 414.4.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_414_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_414_4_a_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_414_4_a_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 := [-10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_414_a();"
function MakeCharacter_414_a()
    N := 414;
    order := 1;
    char_gens := [47, 235];
    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_414_a_Hecke(Kf)
    return MakeCharacter_414_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 := [[2, 0], [0, 0], [-4, -2], [2, 2], [-40, 8], [-59, 7], [-50, -24], [2, 18], [23, 0], [25, -65], [25, 17], [44, -70], [-253, 21], [-248, 56], [-61, -93], [-182, 124], [-412, 32], [334, -212], [96, 48], [307, 91], [-1, 29], [334, -74], [-286, 178], [196, 94], [1158, -164], [-670, -112], [-30, 378], [1142, 14], [-1108, 58], [438, -616], [455, 39], [475, 23], [-472, 698], [-349, -161], [1370, 300], [613, 149], [-896, -170], [127, 491], [308, 628], [-2078, 240], [-39, 429], [-524, -374], [1128, -400], [-41, -371], [3205, -749], [2068, -588], [-2104, 276], [-2952, 360], [-1290, -1474], [-784, 534], [1287, 425], [-1001, 431], [4056, -34], [-1478, -174], [1651, -755], [-1266, 598], [-2755, -125], [-1480, -1568], [-737, 881], [962, 1436], [-3932, 1060], [-832, -606], [-3172, 576], [-5869, -13], [5728, -850], [-422, -1832], [-5185, -1573], [-348, 482], [-6636, 632], [5447, -527], [-3355, 127], [5014, 1286], [-4246, -270], [-5088, -1954], [-6236, 1356], [-5324, 2516], [-4928, -2742], [-2503, -2773], [148, 2350], [-8761, 1301], [-10132, -1028], [-2590, 32], [-2588, -1284], [-3308, -1494], [-9097, -353], [-6893, 3055], [4210, -2140], [12262, 932], [-9007, 1575], [-8112, -1800], [10174, -2098], [-938, 3638], [-3349, 5443], [9061, 2417], [4661, -1071], [15842, 1250], [-6919, -1761], [3740, 318], [-3074, 5142], [-4661, -907], [13007, 67], [12076, -450], [-4100, -4028], [388, -3258], [-17562, -1026], [6439, 1885], [8259, 887], [210, -908], [9592, -2512], [-1445, -4823], [-22056, -680], [10618, 960], [-3606, 1972], [6340, 6180], [6840, -4608], [2684, -3786], [-25724, 1932], [-3309, 4675], [-10601, -2667], [20482, 2018], [14, 5588], [30757, -629], [22726, -4200], [9937, -4075], [-7188, 9960], [-19622, 2700], [-4034, 4204], [-6080, 3760], [8204, -2020], [6906, -1968], [14263, 1267], [1306, 4866], [3324, -7812], [-2640, -9226], [2025, -1157], [14640, -2090], [16156, 3766], [-3496, -880], [-28650, 536], [6510, 2680], [-29839, 1741], [-27610, -812], [-21707, 5605], [-20732, -4532], [-21522, -1488], [-12946, -7034], [10594, -7356], [-18113, 9009], [26917, 1353], [-13251, 8853], [-20414, 10068], [226, -2988], [-23980, 128], [-1769, -8785], [17778, 8146], [19062, -7794], [32726, -2026], [-23945, -3855], [11328, -8394], [-6502, 12500], [3987, -9961], [18038, -6136], [-3901, -6285], [-12754, -498], [-33172, -42], [-6038, 7530], [-7696, 14288], [-12570, 8464], [35966, -6156], [-6141, -407], [15412, 8588], [-40589, 6941], [3766, -13778], [13572, 1866], [-15597, 3027], [-13330, 360], [30059, -5937], [1139, -14631], [23030, -7522], [-34686, -7864], [-16437, -2589], [-8844, 7252], [-11865, -1847], [-474, 17120], [44572, 5060], [-8342, 1252], [28482, -10548], [6234, 5394], [22651, 7369], [-10112, -3640], [47313, 2135], [-15768, -1100], [22532, 7820], [-29242, -11220], [33656, -14040], [63036, 2966], [-32348, 4530], [17128, -1650], [-40216, -1798], [-20147, 13789], [-39608, 3978], [-21640, -2368], [-22853, -12723], [-47788, -2782], [38552, -9192], [25049, 10447], [57636, 6604], [34355, -3553], [-57741, 6021], [-18597, 5999], [-15695, -8601], [-9157, 17185], [46076, -7948], [-19754, 1430], [59648, -12048], [1716, -8894], [81077, -2483], [-19859, -7833], [-7628, 17564], [48427, -15575], [13829, -17937], [-80184, -4176], [9633, -7733], [47950, -14162], [-25105, 10291], [-54539, 16719], [-42872, 2114], [76897, 4353], [-1930, -16786], [-7132, -19880], [17826, -4188], [13098, 402], [-50624, 12096], [-35738, -14224], [-19228, -19404], [41362, 10314], [14904, 23726], [15460, -658], [-20065, 3715], [19893, -675], [40192, -520], [43597, -4655], [42161, 8657], [52641, -14221], [24962, -18540], [-79585, 3135], [73177, 6617], [-37466, -13466], [78110, -2290], [7252, -17420], [-12310, 3704], [16940, 3278], [-40846, -21078], [154, 2176], [-36082, -9196], [13489, 13301], [-91472, 4374], [26056, -18672], [-6767, -21617], [-23677, 8241], [4072, -17704], [-3620, 6956], [26458, -19788], [-30646, 15864], [-12590, 14196], [-46090, 11470], [-78060, 14550], [-73888, 5466], [115258, 4490], [24461, 4491], [33627, -37195], [12774, -21650], [81708, -8030], [29594, 16266], [-2889, 8173], [-72847, -17015], [12104, 27972], [-59614, -2516], [6552, -3730], [-48356, 14404], [-15783, -8495], [64368, 23064], [-32364, -20460], [-63566, -14552], [-20996, -19480], [29100, -6292], [42114, 3784], [-32926, 3532], [15852, 33148], [-17090, 33520], [60182, -4624], [29326, 20830], [52286, 12856], [-54038, 3226], [-54181, -22811], [95666, -8436], [-94554, -16754], [1115, -9503], [-4715, -38735], [53995, -17681], [114006, -11148], [63462, -14136], [84926, -10186], [110969, -12107], [136768, -3336], [-75779, -9997], [77964, 10032], [-84964, -5846], [-49284, 13764], [-70742, 30380], [144919, 1343], [-55670, -14580], [-25030, 5908], [22715, -26257], [32090, -37094], [67634, -4584], [-13903, -23227], [40675, -35197], [18588, 6250], [54063, -40103], [6908, -3276], [112106, -11592], [-19865, 22773], [-2252, 2660], [12032, 25330], [-28456, 11678], [-12080, 36520], [19447, 39011], [96604, -1988], [-177554, 3096], [-86225, -26983], [-106741, 2457], [19023, 7247], [-23823, -4275], [-121602, 27774], [11385, -1899], [-56360, 6590], [66202, 7660], [-53923, -7845], [58728, -7384], [116029, -16841], [-42540, 8246], [-35106, 18476], [-98038, 40250], [-192456, 9738], [-104800, -17140], [-45723, 12415], [-12820, 41464], [-162602, 9470], [-147812, 12078], [80653, -9831], [16831, -25587], [97418, -9720], [-55222, -38670], [-80278, 7648], [-42202, 31824], [-170830, 8450], [-56440, 26688], [89273, 29683], [54936, 34216], [-16432, 22246], [21877, 13751], [-65899, -27195], [-86384, 5184], [41551, 26243], [39699, 46929], [23539, -36143], [28380, -61892], [50018, -37456], [-40039, 9037], [-159236, 8056], [16823, 8359], [-85230, 24620], [-101620, 51332], [8613, 16471], [-139671, 14821], [-116076, 20764], [93690, 248], [-131936, -11734], [113905, -12801], [39520, -61342], [56790, -14888], [436, 25428], [126207, 10329], [-76370, 26830], [-16379, -35099], [-62841, 20183], [-114306, -8840], [127044, -26116], [-44934, -11950], [72034, -12144], [45010, -36728], [-58061, 62071], [-62052, 58056], [38782, -50914], [135780, -19902], [-4304, 33264], [102874, -9684], [-146754, 13246], [50606, 23132], [122457, 29563], [97081, 531], [-14318, 19242], [-63570, -11584], [102899, -25319], [21205, -29483], [-30726, -35320], [22233, -15485], [159954, 714], [75292, -9752], [46377, 29631], [215531, 21025], [-24380, 45212], [-65006, -49902], [190806, -2452], [-84363, 50571], [51080, 53680], [237984, 6440], [86904, -37758], [-74584, -15464], [61486, -5616], [213644, 17850], [231768, -4072], [103484, 16536], [6547, 15761], [220263, -10267], [212802, 10250], [-85034, 85344], [124445, 457], [27503, 77367]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_414_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_414_4_a_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_414_4_a_j(:prec:=2)
    chi := MakeCharacter_414_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_414_4_a_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_414_4_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_414_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-16, 10, 1]>,<7,R![-32, -6, 1]>],Snew);
    return Vf;
end function;