
// Make newform 448.6.a.a 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_a();".
// 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_a();".
// 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], [-30], [-32], [49], [624], [708], [934], [-1858], [-1120], [1174], [2908], [12462], [2662], [7144], [-7468], [27274], [-2490], [11096], [-39756], [-69888], [16450], [78376], [-109818], [-56966], [-115946], [-8352], [179484], [53892], [-105970], [2502], [287792], [47662], [223154], [-250542], [487394], [-54680], [-211068], [20192], [-4524], [104332], [201724], [-655700], [-151496], [229326], [-421086], [197300], [-679052], [-184440], [868078], [593860], [48218], [241688], [565270], [1437746], [494802], [1556544], [-1362036], [558320], [-586342], [606234], [865174], [353352], [1959038], [3062568], [-582634], [3095850], [-625496], [2324942], [781128], [-1485860], [1444626], [404040], [-2716984], [1793986], [18624], [-1330044], [-2265058], [4489004], [-95442], [-2990034], [-3390374], [-3383974], [-1983528], [-7175810], [-2443896], [-231716], [-4736366], [-7874858], [8232180], [2360384], [6316998], [1458556], [9287824], [234972], [7007924], [4947520], [-5506404], [1630758], [10076542], [12522506], [-6674296], [4616426], [8842178], [11577126], [-4480688], [13278786], [11118794], [-3927366], [-17409944], [7462426], [701152], [-10957522], [1906662], [2223462], [752624], [-2454290], [-15823726], [-2654892], [-9268994], [16824232], [6772168], [7613146], [-6116724], [11258844], [-9509522], [-15386818], [1213790], [-10000212], [13374476], [-16137976], [-8610592], [-28502728], [-7287208], [27716462], [30762510], [-18366482], [10139720], [18944150], [11983500], [-6318234], [-1470786], [21013770], [-13585576], [26207028], [11770984], [14489772], [-17786476], [37912398], [-33237550], [2331656], [33818854], [26570698], [-17491300], [-17745156], [28233508], [17175664], [24227320], [24591910], [-13119870], [-640776], [-20150152], [-33321686], [45185664], [-26293498], [20254842], [9437820], [15326544], [2165144], [-9067938], [-26993884], [-25524820], [-61973436], [9349824], [-30563462], [-31033380], [13198562], [29170276], [12817614], [25831216], [17981912], [-49438136], [-20468222], [28601606], [37907194], [21397680], [-11883876], [-80497262], [80937838], [11623122], [27892500], [-27318910], [-57151284], [-78671780], [70923972], [74709116], [-19426686], [55239502], [17542774], [-57020678], [-15301784], [67110802], [-6340092], [-65615096], [-77717030], [30310638], [27934152], [-106447756], [-94470192], [11897534], [-27161254], [-75119970], [43284432], [25628776], [99920982], [55428776], [86460894], [47033088], [111618254], [1127016], [-116316562], [-41188602], [-80512808], [23089298], [67317432], [-68632354], [-147744362], [62398314], [122781656], [-15748928], [132738912], [-5675938], [-27224390], [102007936], [110459290], [54220334], [-15277824], [-135250714], [144687282], [-53397220], [46660608], [-89183912], [-160640834], [-55786144], [-54234286], [-104392662], [119624212], [-9985808], [-135753794], [-106165416], [-63052000], [-38556950], [-138803902], [4590640], [182485338], [-137392216], [47065836], [205213030], [31808170], [169406688], [-41624322], [-151973368], [129415584], [96679296], [122249000], [-22621002], [133294186], [-60911686], [47789050], [165402324], [-147380874], [160226444], [131014040], [178190354], [17807712], [91523058], [27992816], [213298984], [-81904198], [-227079682], [72823638], [213896040], [136880600], [81025836], [-36030504], [-136756658], [-150050640], [-38788926], [-188004862], [-78522036], [-154109358], [-88135230], [-175740586], [260448470], [37957022], [-27942926], [-143286484], [139539456], [278535484], [-628350], [274730674], [-154868434], [-273039906], [-39311856], [38786112], [-284221416], [-291835654], [-27028872], [246201152], [-163736672], [84908842], [-106438312], [-94988786], [218537194], [-247306384], [-387802624], [-59248070], [-232607614], [359795920], [294508954], [-160455390], [134429098], [132285074], [-322515288], [-108737576], [-52728298], [192447614], [-151177432], [222432878], [-247945008], [-60491226], [-402505734], [126601758], [-163419260], [73394858], [205239988], [-364485650], [-23901490], [148879762], [-67128598], [262675828], [411232290], [-467038986], [233702796], [-50094976], [113979118], [373388184], [-293054932], [-122534752], [216816424], [245740792], [210251986], [-39135398], [-257303694], [456297156], [-30798270], [-326289006], [-118416900], [358634902], [130461138], [-88991472], [77921746], [-251280222], [-444403440], [-70496364], [-394628418], [101132630], [263684652], [189118416], [-233706938], [-359322164], [-481410110], [364398048], [-512202958], [-12867752], [368281866], [74295758], [350080584], [-298534534], [260721782], [588070606], [500189084], [-500683546], [257541304], [190138770], [-433525358], [-229651944], [-322137304], [-700266752], [-41539844], [434531668], [-504200386], [-178859632], [-288813228], [264218538], [-509217992], [390345986], [69464812], [-157162634], [302925524], [444885294], [241323912], [-687935950], [324209472], [-129123378], [-695523068], [90121916], [-718073102], [-324874850], [553269642], [-239841822], [-165970086], [-189312378], [-418588304], [128314628], [-201541686], [67988532], [306933448], [-682969652], [-266289258], [-151382528], [662583870], [728883688], [457932096], [801772890], [-719066490], [210014784], [260639288], [115902570], [-541011206], [470343364]];
    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_a();".
// 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_a(: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_a();".
// 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_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![30, 1]>,<5,R![32, 1]>],Snew);
    return Vf;
end function;