
// Make newform 405.4.a.d in Magma, downloaded from the LMFDB on 14 November 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_405_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_405_4_a_d();".
// 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_405_4_a_d();".
// 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 := [-8, -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_405_a();"
function MakeCharacter_405_a()
    N := 405;
    order := 1;
    char_gens := [326, 82];
    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_405_a_Hecke(Kf)
    return MakeCharacter_405_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]];
    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], [0, 0], [5, 0], [5, -1], [-16, -5], [-60, 8], [26, 25], [30, -25], [-145, 23], [143, 39], [-6, 0], [-314, -10], [89, 60], [-92, 87], [-445, -11], [162, -100], [-18, -49], [-221, 195], [-211, -184], [252, -110], [-508, 205], [-382, -76], [33, -453], [-375, -315], [-450, -131], [1094, -370], [1120, -292], [-449, -80], [-375, -485], [-220, -2], [1891, -225], [474, 90], [20, 179], [-508, 531], [1757, -69], [-176, 990], [154, -754], [-1668, -260], [-2221, 251], [128, 662], [1440, -40], [-863, 1175], [954, -170], [-420, 583], [-1924, -700], [-290, -330], [-1476, -200], [-727, -543], [-3980, -31], [627, -999], [4562, 155], [512, 286], [1089, 200], [-2898, 1365], [3294, -909], [-992, -88], [485, 145], [2082, -1810], [2610, -1776], [649, 25], [-655, 2243], [2810, -2212], [-5709, -490], [-3586, 260], [-6672, 127], [-3460, 1644], [-4106, 1150], [-2656, 1801], [-2936, 1941], [-4717, -1211], [-652, 2717], [6310, -590], [-360, 2064], [-2970, -1672], [-4550, -765], [-2800, 2588], [-6107, 2119], [-14, 3990], [10934, 635], [-1938, -989], [10892, 876], [-926, 600], [9202, 1990], [3482, 25], [-5012, 1314], [-3077, -2288], [3990, -325], [2630, 169], [6389, 275], [780, 1848], [-5524, -735], [-9802, 1964], [7496, 1650], [-5936, 455], [9212, 2821], [-4503, 205], [4627, -39], [-1293, 3970], [-3153, 3125], [-6323, 115], [-7945, -656], [11746, -1790], [1615, 3358], [3118, -2741], [-10936, -2475], [4606, -2845], [-12205, -916], [-5358, -1700], [-1918, -7794], [18834, 685], [-1181, -2259], [16842, 800], [10684, -4139], [5478, 1159], [1992, 2270], [5069, -3580], [5015, -3352], [12731, -5525], [-19850, 3548], [2508, 7784], [17534, -2750], [1068, -78], [1080, 84], [-20388, 2655], [-8166, -3370], [-12913, 555], [-2937, 2039], [-22590, -210], [-25, -2811], [1190, 1818], [10950, -3625], [6315, -1297], [-3896, 6060], [9916, 3330], [-18701, -425], [-4823, 2081], [-9508, 350], [-5056, -4124], [30704, 1056], [-990, 11095], [8062, 11005], [-10241, 985], [-25235, 4103], [10381, 7215], [-555, 975], [12398, -6516], [10148, -328], [25560, -8266], [-17108, -4239], [-12843, -8315], [10244, -11434], [-11343, 5285], [-26773, 2670], [-4056, -6474], [-16335, -8556], [-14546, 8220], [-42950, -3300], [-4522, -12216], [22496, -8170], [6209, 6495], [24745, 1594], [-8408, 8235], [-11371, -5739], [13102, -18650], [1784, -7169], [-30477, 1737], [-16298, 12110], [11950, 10084], [-4355, -775], [1430, -18072], [-29852, 6439], [-48391, 3835], [8784, 14490], [-6432, 13617], [12952, -11334], [-27178, 9536], [46904, -415], [47602, -5390], [6887, -495], [50813, 139], [31880, 6384], [36234, 3835], [38030, 898], [20716, 2285], [205, 5143], [-22677, -12901], [-7664, -15290], [-3907, -13253], [-5433, -854], [-44218, 1900], [-10108, -10235], [-16917, 16562], [-10598, -7505], [9059, 11725], [-29059, 6980], [-22260, 12553], [16429, 1530], [-47172, 12582], [-7050, -2781], [37047, -1355], [10522, 20746], [-5516, -15980], [35924, -15904], [-41667, 4994], [-33080, -3905], [9296, 6500], [-10380, -7160], [-33975, -4672], [17453, 21794], [5364, -23645], [-49514, 8585], [43514, 5040], [17053, -11243], [-60380, -9696], [68532, -2334], [60189, -13100], [-17691, 16721], [40494, -7605], [-65449, 2235], [-63340, 13298], [-23221, -12965], [26872, 9386], [25677, -25164], [-18073, 35095], [-7831, -14274], [33298, -10246], [24238, 9292], [72720, 70], [-5625, 16619], [-2966, -16790], [-14290, -18232], [-14200, -9560], [-25476, -9470], [1389, -22450], [-60857, 9557], [29765, 3209], [-19333, 28271], [-23188, 4800], [-23898, -9609], [3492, -17040], [40173, -21318], [-52388, -1760], [73065, 2453], [-33365, 20515], [53370, -25137], [-25682, -6426], [44421, -21125], [27294, 13325], [-51418, 17766], [-12953, 18435], [-90086, -624], [57967, 5100], [-70656, 3606], [25323, -11541], [-49092, 172], [-21280, 31655], [6162, -16180], [-55475, 14039], [-43774, 3710], [67786, 6905], [26833, 9657], [-66955, 16524], [-32558, -16624], [-25758, 3240], [-36796, 13346], [40078, 18249], [55050, -26140], [-12801, -4520], [-93565, -2982], [71830, 918], [79574, 10380], [-28149, 40145], [-27922, -30393], [90762, 4416], [-6896, -21479], [49857, -4175], [-3791, 10771], [17778, -7686], [14177, 1970], [-38596, 5195], [-40720, 20358], [138944, -4730], [-5960, -17596], [-25511, -3635], [113459, -12304], [-16228, 14690], [116072, -50], [89384, -24604], [22448, 25584], [-3985, 6020], [-41566, 33600], [-91064, 4595], [-28470, -35217], [58534, 30055], [47598, 11212], [-93163, 12761], [44864, 1590], [-17112, 16122], [60930, -27630], [-33400, -26796], [-57650, 7993], [88376, -19070], [172590, -1510], [-34340, 31648], [112634, 610], [11256, -33650], [-96725, -14591], [-54873, -23489], [33782, 12296], [-42068, -16130], [45108, -1578], [-76425, -375], [72334, -17780], [-18695, 2363], [75336, -41780], [18945, -4390], [79478, 1949], [-41496, -6180], [-46862, -14093], [-91018, 33776], [51284, 29145], [-29256, 24811], [35522, 1750], [46672, 810], [113738, -19708], [-11283, 34760], [1690, -43945], [96413, -44618], [-32665, -8251], [20062, 25140], [22579, 4075], [-27446, 46506], [25028, 3114], [-34052, 8897], [-113718, -125], [-141899, 21275], [20385, 23605], [-40620, 913], [-67651, -18270], [112316, -17350], [-75252, 47582], [-660, 49474], [67077, 25731], [20314, 44410], [-45002, 2562], [39700, -5495], [66922, -43120], [-7585, -3746], [13014, 19410], [51796, -3970], [7174, 10870], [35576, -21325], [-12521, 5435], [37423, -22983], [-122453, 7921], [31222, 9700], [109332, -44894], [-114408, 42660], [114164, -28174], [-117967, 21967], [-53800, -24296], [-40161, 560], [55576, -49910], [-32032, 12919], [12356, 25065], [74578, -5193], [131620, -22706], [72757, -14765], [-179278, 12675], [-107966, -3530], [5040, -2835], [-35105, -8307], [-110547, 2619], [127344, -34140], [-99364, -6680], [52372, -69039], [-122568, 25500], [-137288, 36290], [-195385, 15050], [-28070, 59844], [105589, -42715], [-60720, -6357], [74351, 51355], [162520, -7291], [-38418, -4059], [113552, 37960], [57174, -3770], [-158856, 35536], [87477, 38775], [-56371, -28639], [-56737, -25876], [41468, -17288], [41270, -29915], [62860, -81241], [-120406, -29150], [-171130, 18168], [171430, 21350], [38418, 20919], [-46846, -63575], [26554, -2990], [-8023, 19381], [120562, -13715], [29404, 57546], [193994, -30084], [-148655, 30665], [149872, 8100], [141980, 24864], [90739, -36850], [59605, 42298], [28798, 41374], [-161632, 53177], [18180, -46836], [51267, -26020], [-22096, -40465], [63404, 20826], [-212023, -10385], [-16000, -3030], [162340, -3906], [-50244, -37845], [134565, 8593], [-28047, -79631], [-105884, 43050], [-148080, 60054], [-8998, 68911], [-55338, -12140], [111804, 32276], [75963, 31762], [38750, -104080], [174332, -17700], [90658, 31914]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_405_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_405_4_a_d();".
// 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_405_4_a_d(:prec:=2)
    chi := MakeCharacter_405_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_405_4_a_d();".
// 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_405_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_405_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-8, 1, 1]>],Snew);
    return Vf;
end function;