
// Make newform 462.6.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_462_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_462_6_a_c();".
// 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_462_6_a_c();".
// 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_462_a();"
function MakeCharacter_462_a()
    N := 462;
    order := 1;
    char_gens := [155, 199, 211];
    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_462_a_Hecke(Kf)
    return MakeCharacter_462_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 := [[-4], [-9], [106], [-49], [121], [-166], [-842], [1200], [1724], [1010], [-1328], [15718], [-7498], [-2456], [-2252], [15714], [-5340], [-25718], [-4572], [-67708], [-7406], [25560], [22404], [61530], [-72782], [99402], [105384], [52228], [144010], [56794], [100808], [-52068], [296298], [-307960], [359770], [-418848], [331558], [509284], [507128], [-102046], [-541180], [539102], [111172], [-166], [-420342], [-718160], [-369368], [-470216], [1271948], [526430], [1016454], [456560], [898482], [952092], [1784418], [1003344], [1745370], [-1982648], [-426102], [-274538], [-14616], [-1649766], [1153088], [-3167588], [556714], [1248858], [3284332], [2549658], [-1362692], [2608850], [-1779726], [-4461200], [-2883272], [2893754], [4947340], [3057124], [5201850], [-4682442], [-2502798], [-446630], [2351540], [-57818], [4656632], [4262834], [-5297480], [-4495356], [-5745270], [-7609702], [5313282], [1397344], [-6514092], [8479960], [-385552], [1933812], [4494140], [2910744], [8880250], [-1752118], [-8880136], [-1611958], [10209288], [3333058], [114004], [-14374530], [127072], [-14734222], [5619588], [-10042626], [4621740], [-8283478], [-6701032], [-7118366], [869298], [-14325100], [-5583048], [-3443718], [-1061396], [-7370052], [1896914], [426020], [-1040098], [-1487606], [12103018], [-15388116], [10717692], [11518722], [-12781170], [9034220], [-27246592], [-21546406], [-9489120], [21622704], [5952832], [11022038], [-19978818], [20100490], [-12353406], [5802848], [-18003182], [-7349250], [-21277648], [-1139238], [543104], [-21243572], [-1502210], [-30562860], [25522514], [-21182162], [-15027140], [4323164], [14242978], [-19804998], [17807764], [16459088], [-25872172], [33194412], [-15609600], [-12265950], [20070378], [-4835998], [25722028], [-39162626], [-23836672], [999412], [2369938], [25168044], [2246752], [-32901462], [-8487470], [23224714], [-38174940], [-6776938], [-50598928], [7199314], [-22933240], [-42458830], [-13227088], [-7076438], [-63028056], [66736690], [17598528], [-59665988], [20601814], [-39203362], [18913724], [9537450], [32987698], [-66739716], [-20676070], [-66645448], [-34650206], [-57111316], [19723052], [58853522], [70085108], [-18320646], [73409042], [-86499466], [-51595002], [15450744], [49018370], [-29178848], [1253278], [-46701190], [94051260], [40588218], [36165200], [50318844], [78836190], [103476332], [23218538], [6456602], [70949624], [39652588], [-87721200], [-125604758], [114744128], [-7146978], [68192388], [-44261966], [-78934998], [89072320], [135807810], [25162024], [-103872732], [-89386070], [131170754], [55732140], [-74696072], [86236372], [147483614], [-36282520], [-149770448], [58284702], [11959764], [29279808], [-138642270], [-49480806], [-97099380], [-13191068], [6743124], [25634392], [79130424], [85139990], [70989294], [-139615920], [26317528], [161973692], [-73815840], [123624744], [-149260062], [152830702], [-2304292], [84679690], [-138973646], [-172603020], [-185881498], [163048288], [142990498], [-195334702], [-53673656], [119356508], [-154705230], [-5008366], [127833258], [-178575420], [-166457070], [154250642], [-72536696], [117915754], [-81328298], [-201005252], [12332634], [2103440], [73385098], [-86869456], [-14373372], [-250187350], [202847242], [-136211628], [242769864], [96081632], [-245100912], [-141983078], [227505328], [143049252], [-166730846], [252034298], [67384320], [121703550], [181463922], [-208273652], [55868454], [-116056628], [215733874], [-27407150], [-35918328], [105054434], [86742220], [211544568], [296522114], [45997058], [47178080], [-254957916], [-162706948], [-172407262], [-131227372], [-330039890], [-227665260], [200682474], [59609424], [66257170], [244738942], [-112497396], [-3210912], [-357580110], [-47734780], [137249232], [50723634], [-10310250], [255049232], [-348984742], [190206722], [-171644696], [-361071066], [-56668398], [151591700], [-45067836], [373584528], [240874314], [113781282], [-241259102], [182030000], [364945564], [260649352], [-285638052], [-10094330], [-314960226], [138642282], [-299550312], [-173782786], [-46296702], [-251420870], [-218506208], [-223526406], [59335620], [135719342], [246168508], [195868872], [29816658], [401774232], [221419418], [-400142758], [-140971576], [-514282590], [-120237906], [-354587140], [-30074188], [199792598], [-169729476], [-416914702], [215251142], [458250068], [103771140], [68761028], [531295914], [342339218], [102830704], [520420802], [87243372], [-488254900], [123425264], [-356286950], [-333441688], [175117758], [41513340], [415287472], [-558964846], [-33339530], [237716538], [-355729598], [-334303726], [-692505232], [-633220202], [-186244640], [7104764], [728992112], [-122299002], [157524904], [105152068], [-370658990], [-414228646], [-307312900], [-361057732], [496578372], [102451434], [-237992320], [184499170], [325066412], [-149124038], [-455317830], [51227634], [-46912752], [-115796142], [-631358790], [-390492488], [-328200002], [-613323858], [-362713276], [265211900], [83733474], [177955578], [-484084236], [467012152], [-65514062], [-689628918], [19009120], [359598488], [-194987542], [49327384], [-492801070], [300719058], [-444411652], [506792180], [-257328166], [748840458], [-165230916], [-788863050], [258585692], [113004080]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_462_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_462_6_a_c();".
// 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_462_6_a_c(:prec:=1)
    chi := MakeCharacter_462_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_462_6_a_c();".
// 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_462_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_462_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-106, 1]>],Snew);
    return Vf;
end function;