
// Make newform 448.6.a.g in Magma, downloaded from the LMFDB on 25 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_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_448_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_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], [-6], [-4], [-49], [-240], [744], [-1042], [-986], [-184], [734], [-5140], [6054], [7598], [13016], [-14668], [14522], [-13362], [-9676], [-62124], [2112], [-28910], [101768], [-23922], [141674], [99982], [108684], [-87396], [71892], [118166], [252774], [3592], [364534], [-77246], [-122742], [469234], [411584], [574632], [-264704], [-343356], [303296], [-362756], [146560], [-552536], [305358], [-743838], [-286220], [-895372], [1188120], [808822], [344344], [-334022], [954272], [-272882], [43754], [-1732014], [-613248], [2013600], [1221376], [-2118214], [-1645158], [1663934], [1157316], [344998], [-3287976], [-2210626], [-1196310], [2128280], [1898414], [2175480], [-2129504], [-2541438], [479280], [-1893896], [-1566830], [-57360], [4412388], [872470], [-3631696], [-3584226], [2183094], [-4911374], [-693766], [1250352], [157750], [-263736], [-1504100], [2111282], [3999382], [2240904], [1473040], [8504718], [6569836], [-7710376], [8721468], [-7874300], [-8687264], [1341312], [6001854], [11910854], [7207034], [1651720], [7581706], [-12656806], [4574454], [-5778016], [5465202], [9893858], [6126858], [-299432], [-4981334], [11069408], [13782902], [11145030], [-3007218], [570304], [13735934], [2586922], [-6524460], [-3757930], [-6974360], [-11705948], [-18282518], [-2056608], [12491340], [176630], [-4031114], [-14183914], [24627180], [13048156], [20886980], [-14761472], [4445696], [-11909360], [25503542], [-14692506], [-19277930], [8565844], [18902686], [17125920], [28451142], [6556038], [3143562], [-16219112], [-4747068], [-34733276], [6105516], [-27561304], [-18209994], [33592042], [-32608360], [-13335170], [14319434], [4015564], [42904908], [-30470620], [27574840], [-33334600], [20862446], [-16661838], [33620196], [-42533512], [32061290], [56511528], [44157998], [-26905302], [-8686884], [15490896], [4475876], [24612222], [25872952], [-60295924], [-15080520], [41829888], [12277690], [-48611940], [33032386], [-2054284], [-16533930], [-14754880], [-59868412], [-42792352], [47058490], [-11895154], [35246426], [-47583720], [64084416], [16398466], [52009910], [9946530], [-47960508], [27976946], [33710556], [-13629268], [7324584], [42503372], [-61983390], [-68003186], [-2736098], [-15105286], [38649832], [59927618], [46871700], [42582580], [54590458], [71833686], [13329588], [66623620], [-39160512], [49735582], [33058738], [-6012498], [76877484], [82677440], [-67619202], [27484424], [-11187882], [29435664], [97753750], [-10019304], [65860006], [-49617858], [130045784], [59086930], [-135760992], [29068262], [49387246], [-61150950], [-143796256], [67785632], [-3263328], [3939446], [-30230638], [12511088], [-38858278], [-34415402], [68769648], [-99865810], [-14095230], [-121166788], [-133633584], [64736104], [-91472602], [34594816], [24429026], [-105766806], [26032852], [-63406672], [-3146138], [88226616], [46669376], [-7649510], [71908882], [-64871072], [-90701526], [7919908], [35002956], [-150558626], [-141624766], [-61928868], [-16541178], [31322608], [137268048], [-67037220], [-48869116], [47788782], [88168130], [-186549686], [-50078614], [8202564], [60451422], [-96759520], [-13660952], [151726610], [94577592], [208946418], [-107143712], [-106221752], [152939930], [-227391586], [-218386914], [179436120], [99570712], [48715548], [-184925388], [185929238], [93510168], [-32348670], [160675138], [21625980], [-231449022], [74229042], [250185278], [-28530026], [287477414], [-195755630], [295788784], [-200191824], [-88403104], [-72149766], [-62563702], [-9925738], [-89233242], [136719360], [-333838512], [44915160], [184928330], [217956456], [250672748], [-172070312], [336142762], [2554280], [117103046], [110592986], [189477856], [139859312], [-129530006], [-198401926], [328580032], [319280698], [111500610], [-345733438], [-86549566], [-10598796], [177906392], [195365302], [-310853770], [293802376], [-426398186], [70735992], [-60814338], [17275290], [-3135114], [317435396], [420810914], [249355268], [-12783722], [-40779658], [10125506], [239384906], [106096292], [-319858302], [38387814], [178522080], [40990864], [-378595066], [-206693208], [376960832], [326804656], [-363538856], [398559812], [-506462902], [113227834], [-163868190], [270170964], [307136610], [256061970], [-333070068], [315061438], [61835058], [280553784], [124370242], [-440289102], [-10459224], [348070452], [-328026906], [-381166282], [387501888], [-602191560], [-451776506], [278469820], [189768314], [512942976], [-266177342], [255156680], [45787674], [-11477482], [4285680], [263540954], [104707054], [361551766], [-364824512], [-338404346], [-401792872], [-679842414], [-92358934], [169421304], [450436840], [192054268], [-515181796], [-672027836], [705624830], [-581393588], [488476164], [-454766718], [153879472], [369662546], [399592796], [46407086], [381613252], [-491790090], [-671637420], [-542243054], [262230384], [35123382], [-317501704], [-272512964], [322884466], [-97624930], [-110515326], [407193882], [693412410], [374082270], [-757868576], [-852113996], [230192778], [-310693656], [73422472], [750711356], [-777700338], [242640640], [810554022], [683438260], [-239518656], [-686174862], [842198574], [237940236], [315952136], [-450891894], [-215895022], [435005620]];
    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_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_448_6_a_g(: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_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_448_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![6, 1]>,<5,R![4, 1]>],Snew);
    return Vf;
end function;