
// Make newform 441.6.a.m in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_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_441_6_a_m();".
// 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_441_6_a_m();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 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_441_a();"
function MakeCharacter_441_a()
    N := 441;
    order := 1;
    char_gens := [344, 199];
    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_441_a_Hecke(Kf)
    return MakeCharacter_441_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 := [[-1, -1], [0, 0], [-19, -10], [0, 0], [-212, -23], [462, -28], [-1173, 132], [180, -277], [6, 69], [3526, 700], [-1774, 715], [5545, -790], [1750, 868], [-6340, 1344], [-11478, 1635], [-1521, 1818], [-32904, 531], [21243, 4154], [21156, 919], [1104, 2184], [25253, 7372], [4502, -5193], [-52164, -4536], [-13333, 9356], [-104566, 196], [32581, -638], [-46874, 2901], [-76952, -1793], [91345, 21254], [-81734, 6916], [90232, -6328], [-157288, -1543], [31449, -9816], [-868, -55160], [108555, 40578], [-123814, -38631], [-210381, -40858], [144768, 58801], [-398524, -45724], [231877, -79082], [305240, -73075], [-464982, 26096], [-322610, 15637], [49163, -118620], [240238, -39284], [29894, -65561], [-43188, 89656], [768264, 66584], [-876600, -5517], [23371, -89646], [1049649, -1128], [340380, 196308], [698233, 50856], [-415408, 69692], [-117773, -67364], [320290, 5227], [110085, 60738], [1586562, -100111], [547857, 69190], [1272962, -156940], [-1480524, -47935], [1736854, -15680], [592284, -20608], [-1647426, -129963], [-2018963, -66084], [194739, -340446], [-186724, -147363], [-995538, -262892], [56600, 298205], [612486, 165116], [-42949, -88012], [2869250, -148135], [11582, -359393], [-135799, 249978], [275704, 509012], [3264522, 2643], [-852693, 624846], [616439, -89954], [1512741, 301692], [-2149535, -125376], [142548, -783552], [-95590, -416724], [-1156878, -1049589], [-1602678, -695884], [-1361110, 196129], [-498744, 549135], [-39006, 239148], [-302469, 305740], [-5286470, 136948], [4429392, 81088], [-189768, 868137], [-7481870, -134639], [9085470, -74219], [4048952, -681268], [-1086168, 530713], [-2576784, 1286376], [-6841511, -616094], [-6073197, 251292], [257640, 824351], [8469833, -416814], [-6641640, -358148], [3817231, -433190], [2912444, 191519], [-4344467, -629924], [4264892, -157617], [255105, 1133504], [5233004, 733040], [-3867981, 1727436], [-4420782, 1259739], [-52654, 937636], [-2218442, 325965], [-928275, 282298], [-11604630, -849828], [-11170344, 484541], [-5326816, -101640], [10546737, 21264], [-4798388, 1303680], [-10534682, 920653], [4653627, -1705782], [-8577564, 1350552], [4133511, 2463938], [5898174, -1063916], [5342661, 1043550], [-10118796, -1356063], [-21473888, -343137], [-12523422, -127344], [4970617, -1943878], [5029950, 3541647], [-456176, -281736], [9724307, 1272610], [-18763400, 841283], [2092704, -2793000], [-14552166, -1774541], [-4841086, -3589068], [11489823, -1793592], [1771378, -2797284], [-5092091, -2367422], [-15485172, 305369], [17336522, -2253580], [-2587083, -4486596], [-3696812, 776496], [18694451, -1181734], [-3960290, -3478795], [13089060, -1799280], [15827767, -2736558], [-16784152, -714112], [9949702, 1471428], [5391011, 5234060], [12825496, -2605089], [11551266, 2570049], [-5426847, 3750538], [4001634, -1996848], [-34815940, 622440], [-3705938, -1807865], [-12119728, 4145115], [-13433520, -2208864], [-1604602, 473103], [5984407, -2515544], [-9306682, -412496], [11867677, -6119030], [-25521280, -159937], [9673298, 1505924], [993120, -5341112], [-1048164, -954915], [-28440435, 48228], [-13107798, 6016905], [-2527390, 63009], [-19711233, -883798], [-14904426, 5404588], [1895665, 4775026], [30790296, 1896669], [-26528194, -588476], [5866734, -2588307], [-21672061, -1370388], [41627338, 3137331], [-12527690, 193396], [47935344, 1723708], [6395527, 908290], [40393472, -2447816], [-13878657, 7391702], [-67122418, -1165905], [-26002116, -1293768], [-3271546, -739536], [41799907, -4714748], [4625262, -8039313], [19910425, 591646], [40909353, 117070], [-37948704, 3836645], [13518639, 7105288], [-12382906, -3890083], [3981633, -4998592], [21537612, 3461976], [3985724, -11808411], [7042065, -2264790], [40874608, 5810005], [21893007, -5380656], [-10109293, 62652], [9360289, 1629818], [47938254, 5012196], [-33306390, 1263483], [20817431, 87218], [24842104, -6075720], [-8479081, 2965126], [763389, 752564], [-11031692, -12194168], [26284429, -7638758], [47704802, 8088097], [-208860, 11586315], [-20227482, 1666224], [-1570992, -14305339], [-21145277, 8556668], [-7544670, 9715188], [32439528, -8822576], [20744348, 3986861], [-91042718, 42097], [-2178087, -13726192], [58861406, -7310427], [-2367397, 4433876], [-25666334, 5655817], [-35899950, -11637696], [63813149, -2587290], [18995676, -3777172], [-82190263, 5190296], [-53930134, -644349], [117687724, 4514776], [86942186, 1913100], [62707871, -7872280], [-101182426, -720169], [-36123446, 10849233], [-99096012, -7033293], [-78331083, 7594834], [-21708900, 11282825], [-32249488, 10699920], [9956329, -10154216], [-68527900, 11359936], [25262394, -2844759], [103196973, 7416020], [49439795, -12971974], [57077508, -8535408], [39842572, -16203236], [-35488812, 20318289], [47070896, -11091161], [-9215902, 3818347], [60071229, -1650914], [-106541022, -5471760], [8619242, 11859467], [-73515288, 5271224], [-29720072, 4679107], [-5303940, 24966895], [-7494636, -2712612], [-58898446, -13142388], [-867249, -10928592], [-105883850, -886601], [74210514, -10056844], [18341501, -1685398], [78268700, 3512963], [-12736855, -13027698], [7420340, 30253441], [141446970, -6996276], [52519969, 22366200], [-148608262, -8401335], [90651356, 4805360], [-23952029, 20283894], [27670342, -3465924], [112400179, 2286556], [-51898940, 5781387], [-164423394, 8959860], [87627302, 9015524], [117163356, 3981040], [65334043, -5633378], [66894399, -21605770], [62910416, 20907147], [-91574031, 12303152], [101353610, -24125709], [68510106, 423332], [-34757186, 8750829], [150787132, 7580635], [-30328163, 14932682], [98267499, 15077980], [-137470100, -6377675], [3012838, -26491907], [-20821694, -16654447], [-55884920, -6122480], [-10744818, -16395988], [-57655880, 20930703], [34483518, 5584725], [144769431, 10506568], [-22359906, -3419892], [-118335542, -14766429], [-63649866, -19681284], [-166576265, 8451154], [-160780792, -17949037], [38048373, 4990068], [-177710904, 18437076], [-221930238, -7888244], [-202229479, -7239394], [32959806, -21586555], [-103107830, -13658036], [-271362572, -5056523], [5266072, 23145780], [703589, -13362668], [-273348657, -742554], [125527278, -12615083], [-86073836, -3970904], [-121809512, 23989169], [-64449362, 18716516], [-112340328, -17897091], [-39039322, 19089868], [-180761582, 27839545], [-34898835, -17775050], [-288504522, 2551959], [130684391, -1117342], [-1066227, -28071996], [-111877652, 38480591], [95850200, -25750816], [-63999743, 41015136], [-309764196, -2738232], [58345866, -41571693], [-25543518, -22552852], [-193199526, -13749372], [191706736, 5651829], [-56165913, -21538880], [-56442246, 49098756], [-159095788, -6069588], [-69405555, -18400188], [-121600047, -35528224], [-116419680, -33678287], [47774620, -45732453], [-41069974, -41276551], [-183145818, -3486252], [-40835451, -52714346], [32763183, 6252090], [-3223976, 34995240], [-289070268, 21115191], [-96119868, 31214311], [-92792644, 50735216], [-127748878, 83244], [-78620925, -30976788], [-24774554, 25797072], [-145147998, 36683825], [254129493, 6127858], [-310899934, -12621196], [-20595078, -68490324], [228080400, 25200280], [121684331, 6260330], [100021108, 59503864], [-336860289, 3868586], [-19962144, -16730951], [189070812, -3632076], [362414761, -189542], [-110766672, -30816769], [-136223897, 26562776], [63315670, -4258436], [-143693098, 24125767], [106608153, 23311114], [-68630198, 47464816], [-58099410, -23423697], [-255945204, 31094559], [230564501, 30648428], [155877048, -6764688], [133063282, 6532820], [381586319, 7708040], [104325786, 15076899], [344303588, -18583405], [253714108, -13270263], [172944759, -35713376], [-4563902, -35358932], [-209968134, -1292135], [178337770, -47519920], [-268367052, -7853295], [-237092032, -3127961], [-197836122, -56504883], [-96292086, 39263952], [-286178714, 2132775], [-132729939, 78733054], [-441898552, -25612525], [-54799712, 10440640], [290959141, -58959060], [-308458113, 11952336], [321861554, -44064860], [207611953, -3697562], [-48835446, -64310820], [-271236264, -18554144], [-70717159, 66000968], [-41375236, -76310864], [220864906, 58390345], [-35899582, -12930783], [64409559, 1889714], [-53586196, -25145091], [298267200, -72596160], [-634092366, 7908880], [45576309, 16504590], [-389328, -64424859], [126557128, -62977065], [13061138, 847769], [-111128925, -46414772], [-536624658, -25849585], [-7035546, 103474644], [-209105300, -40232752], [269873931, 41079918], [529590451, -16230750], [484363613, 9197012], [195795090, -18778661], [11152059, -116222340], [116872269, 24606042], [-609063618, 25345085], [-378496067, -27613654], [62570450, 55813772], [-155425280, 66548133], [307324824, 35844729], [522792961, 29658576], [-424481065, -7284922], [234789476, 22653680], [-253122372, 21292405], [579969910, 43868804], [-264605619, -38081298], [298784646, 11249181], [404477686, 36604023], [-105401730, 100544388], [-58122258, -63286233], [-373959021, -24089466], [-433760553, -59496490], [500330192, -38327296], [196730884, 55372744], [-20799254, 121113468], [233094669, 112898778], [74892964, -85001477], [-527691054, 26700324], [-103135504, 61458181], [-433037574, 14122233]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_6_a_m();".
// 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_441_6_a_m(:prec:=2)
    chi := MakeCharacter_441_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_441_6_a_m();".
// 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_441_6_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-36, 2, 1]>,<5,R![-3339, 38, 1]>,<13,R![184436, -924, 1]>],Snew);
    return Vf;
end function;