
// Make newform 441.6.a.g in Magma, downloaded from the LMFDB on 19 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_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_441_6_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := [[2], [0], [-11], [0], [-269], [-308], [-1896], [-164], [3264], [-2417], [2841], [-11328], [16856], [-7894], [-21102], [29691], [8163], [15166], [-32078], [38274], [34866], [13529], [68103], [114922], [154959], [107570], [8936], [-193667], [205110], [-46664], [-304365], [13303], [398262], [230286], [97134], [-29047], [-576500], [-265232], [363790], [164846], [-30628], [-651392], [757360], [-160339], [61738], [370908], [217450], [589771], [387045], [-232732], [-42096], [313416], [857807], [-454517], [-878182], [-1960934], [1053795], [-105059], [-427592], [-638878], [-2451422], [-1716169], [1808968], [-1521456], [-1348399], [49695], [1587836], [214825], [-2588596], [-24878], [1736008], [-862426], [3115419], [-1796944], [3454656], [-2155038], [462774], [-4066212], [5068632], [2877335], [3413424], [-1307374], [-1935468], [516670], [2915301], [1783791], [-4001580], [-1167665], [-3613582], [-1801112], [2369748], [-518146], [2826127], [-9347473], [8171854], [7377132], [326315], [2167026], [-723404], [5999642], [7015696], [8918725], [13348231], [-1102148], [1893482], [2829511], [10679893], [14699688], [-8491626], [8629467], [10580735], [3847840], [15100062], [9931018], [-9252241], [-5004282], [12613706], [12538310], [8660661], [-7941768], [-2114162], [-442307], [-10756071], [11488593], [10138832], [19683879], [-20171706], [-4157346], [-15443323], [-6204138], [21898446], [2754834], [12912079], [-26431522], [-12221388], [6106541], [3022202], [-20828522], [-23232839], [-10866768], [-22263178], [12388091], [1694808], [378495], [-10428748], [-30408224], [28031486], [-18802958], [7863230], [11285766], [13415008], [-31854690], [-30592168], [4637720], [604376], [24405918], [36709496], [22908854], [-5996109], [11651585], [1109264], [-10574314], [6326665], [-39239463], [1550742], [48748428], [-1925515], [54256390], [14158111], [-20562679], [-29542635], [-38633658], [-723588], [-25319179], [29030399], [19142900], [-2709698], [57314905], [61190640], [29055058], [-12368407], [59704029], [-64133242], [40891322], [40077594], [-45715627], [20193358], [46258414], [26327299], [-21666140], [-27706703], [19695933], [-37070140], [-79869066], [-49755233], [28097574], [76917830], [-903114], [-36276702], [12323538], [75100925], [88677848], [-42960522], [62435050], [-14714560], [65456903], [-87932736], [-95558811], [-64177920], [-45908822], [91875138], [34302849], [42256825], [73493605], [-111094444], [104166514], [14525843], [-73624592], [-23221910], [-6817134], [-132439624], [-22565816], [101539286], [-36923539], [-37433263], [27876704], [-27564674], [-56866036], [144928277], [117032652], [20782114], [76539112], [-55404823], [-8724614], [-104565510], [-93192756], [-144842477], [157090985], [69177036], [-71350552], [78326700], [-125684688], [5673891], [-11897342], [-172272156], [13868956], [-152265071], [112206956], [-149454848], [187069776], [149254730], [-131567202], [15000934], [125379058], [60650227], [-30483661], [153471482], [-3892596], [-103371093], [83743853], [-59547184], [166401191], [-18463306], [-130740316], [-16093426], [198146750], [65540025], [-148068452], [-57161732], [-92440127], [-38031920], [-75012718], [-191908571], [15189767], [-7228907], [-131676352], [-119471315], [-103273776], [98890678], [77824736], [98980610], [155525709], [56403116], [-187066628], [-209035690], [9405216], [192503671], [65240145], [190176335], [296787036], [106940950], [-143025875], [-182030364], [-134432172], [126514684], [-153781823], [168461248], [330541190], [172795556], [-52310146], [106973094], [81092097], [-289248593], [-179510417], [32804406], [141970866], [282247095], [6301638], [227093638], [160587334], [307897614], [-19710862], [105914244], [-66493872], [170537288], [-201042682], [182356587], [85083912], [61215301], [-94482936], [2837120], [172106002], [299825799], [323874896], [-57088776], [66083371], [88083154], [46366646], [-426227590], [-314224563], [135453106], [114675369], [143968496], [-458184], [205908538], [68296900], [-211782100], [140317698], [-27327223], [63432331], [75675190], [-111948748], [79815519], [-313919093], [401900207], [180893305], [229989430], [427613926], [262689714], [219322967], [-3929684], [-16559253], [-348243254], [-144256113], [-83156138], [-218369242], [-235998270], [6913971], [-302289244], [-403849602], [-40949550], [-532772552], [52366122], [293562572], [461548856], [285065779], [-39120214], [113164936], [-233329143], [-121130355], [595124688], [291054318], [297630975], [-447768784], [-355988096], [499800904], [123125308], [651505259], [-248777778], [457016910], [117103190], [-68711190], [221214688], [421424084], [-144373362], [200089226], [85876640], [-673547876], [-378207916], [-302811012], [-570049415], [-103881306], [-649291065], [-498209134], [-121110778], [-6405977], [-193675049], [-307643658], [650350080], [-336123735], [368220332], [-184821376], [-16311500], [-143233458], [-160497357], [542023675], [134848374], [-63635098], [-198987538], [547112415], [-691248673], [495450797], [-809194087], [718239310], [-185829222], [-91289517], [172441908], [-235006360], [-875314608], [617150922], [314557989], [382507318], [93634658], [26093711], [255188234], [-873249054], [-259983323], [202090488], [522132666], [963729684]];
    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_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_441_6_a_g(:prec:=1)
    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_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_441_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-2, 1]>,<5,R![11, 1]>,<13,R![308, 1]>],Snew);
    return Vf;
end function;