
// Make newform 448.6.a.n in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_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_448_6_a_n();".
// 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_448_6_a_n();".
// 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_448_a();"
function MakeCharacter_448_a()
    N := 448;
    order := 1;
    char_gens := [127, 197, 129];
    v := [1, 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_448_a_Hecke(Kf)
    return MakeCharacter_448_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 := [[0], [14], [64], [49], [-420], [-860], [830], [490], [-4872], [-8754], [-5628], [-1434], [-9258], [14756], [10108], [23058], [-13734], [25352], [19768], [-1792], [37914], [-95984], [88242], [43762], [65790], [17728], [-121660], [-48272], [177606], [128198], [-302960], [-295638], [-78318], [-234010], [397642], [236432], [-31852], [403172], [-569044], [-500116], [-112896], [20780], [215040], [408590], [721674], [-378308], [-265272], [-419608], [-776678], [71924], [-356966], [-1063832], [-834866], [1590694], [74754], [9744], [1245548], [-1626352], [-99070], [-1791654], [1071322], [396024], [-1262086], [-1710184], [-640634], [518738], [699412], [2510638], [4166036], [-4127540], [3540626], [3270288], [-3343368], [127946], [1403388], [1551340], [-5238410], [5665788], [-2220098], [-3898466], [-5785514], [563554], [5610360], [7274966], [-4463256], [-3780056], [-6954654], [2257654], [-3566972], [1064168], [-5836222], [3711988], [-1641752], [3181640], [-274120], [5342736], [2821068], [1672326], [9859906], [9362066], [-539252], [-5744430], [-11472258], [-7711194], [2865884], [5123570], [2639518], [15957562], [-11686808], [-5103438], [9919952], [-17088122], [6809590], [5562746], [-1110256], [-10088482], [3870958], [-15150772], [-18628618], [-4233684], [7916904], [-15014150], [-4524036], [-17904600], [-7157542], [19505174], [-9181866], [4645284], [16715300], [3553656], [-13481244], [10486896], [-11509400], [14592806], [-3336898], [-14995322], [18908440], [-12858622], [-23850548], [-29589946], [27382642], [-16242670], [21345912], [-18859008], [-25012760], [2344692], [39686916], [4615566], [5957014], [-5362224], [41964574], [-10358886], [34632304], [-24373468], [-28412384], [17215856], [42339752], [20524782], [18657930], [-4423128], [-4461156], [-19559094], [17028872], [-11009222], [-18499878], [-31975580], [-52312792], [-26075656], [10104638], [-16302876], [-16605736], [9057348], [47714352], [-51138022], [1696100], [-65406086], [34974576], [-38285658], [-7861728], [-36297976], [-34730360], [-22088066], [-45474370], [45385922], [59065216], [24177372], [16771930], [35867818], [22965650], [-75952884], [-9336574], [-74004952], [-45276448], [34904756], [-46696160], [-59947878], [29589422], [-29535666], [26191866], [-9875320], [-16334598], [-89613412], [97638200], [-55102870], [-60411246], [25301848], [27833596], [-28257964], [30986494], [-103877074], [117320078], [26658080], [62870416], [49229978], [-25070248], [62739038], [86332120], [15627894], [-43598744], [5502214], [-25501442], [120864856], [-85243294], [47148136], [-2734326], [47783214], [42078738], [-74142376], [91390208], [116911452], [-24134570], [59609830], [-22897672], [-33117686], [-124534830], [-40793312], [-150039458], [28692986], [44465848], [-143813600], [101118332], [166539170], [19479600], [21786170], [-125817766], [43189468], [-115618832], [102818730], [-73067932], [-93476376], [17086258], [-21277150], [-147835632], [71902930], [-59196232], [-85297856], [42507134], [55649454], [32381952], [116898574], [121995160], [77179844], [198029744], [-87217224], [131882446], [-184842042], [48919906], [-105252750], [39393872], [99826158], [-55170884], [-43043476], [87981114], [236245184], [198015922], [-118285552], [10995684], [-68396574], [61599454], [95809378], [17577672], [-50545320], [1630804], [-76994168], [-168646702], [-5303424], [-86039150], [119507498], [-77091980], [83173474], [83427050], [-8704318], [137040294], [-81782750], [11045914], [32536332], [232493744], [-181912532], [-94720682], [48835262], [-79891442], [-115527978], [-132788936], [-199632972], [-234956204], [-236557254], [-21062748], [-193381280], [170332120], [377661490], [-12642840], [12879078], [-122834678], [-194425308], [146329568], [-29735134], [84916174], [57994776], [387922874], [214362466], [199531878], [-184249582], [213542360], [-122002720], [-365722986], [-308563242], [-335258308], [112305074], [-410295872], [-374529186], [419046050], [-245518058], [137376316], [-225746682], [-185583328], [237594882], [181201094], [-42308558], [151744018], [34587868], [361830314], [-159638538], [-35010244], [-386834224], [166310598], [310722636], [141842284], [-92602132], [347570104], [-386627256], [199512670], [194801082], [-20033286], [337270668], [-153273718], [275299210], [220520020], [203004858], [-3585918], [-471648072], [-371131782], [-293483238], [-132955984], [365779120], [-566031046], [514333126], [-578711220], [232630328], [-89059194], [475246128], [68715654], [459693528], [-399191814], [-39102056], [-114953678], [76788138], [122002776], [-593608822], [-551005810], [-502499106], [374990796], [57870342], [397736024], [267318226], [219522030], [168952728], [467311376], [203492560], [346334744], [318307164], [280957022], [-64455760], [22861664], [319557798], [337989456], [-150251134], [-246405628], [-166420202], [299789616], [-653953466], [-575347144], [-205449790], [336322280], [-248672850], [84195732], [-79013900], [188600250], [252879102], [94725302], [-612962], [-266374502], [-320132450], [-75873476], [606764648], [697014762], [-511670668], [172246368], [-462913612], [-51047170], [789703936], [377676406], [-747092408], [816648168], [-740785906], [-50252138], [347511168], [236504940], [60921354], [-17020962], [-648716852]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_6_a_n();".
// 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_448_6_a_n(:prec:=1)
    chi := MakeCharacter_448_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_448_6_a_n();".
// 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_448_6_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-14, 1]>,<5,R![-64, 1]>],Snew);
    return Vf;
end function;