
// Make newform 5.14.a.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_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_5_14_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_5_14_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
        poly := [-499, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5_a();"
function MakeCharacter_5_a()
    N := 5;
    order := 1;
    char_gens := [2];
    v := [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_5_a_Hecke(Kf)
    return MakeCharacter_5_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 := 14;
    raw_aps := [[-40, 1], [390, -12], [-15625, 0], [-308150, 1636], [-1233568, 79000], [3258930, 133328], [316730, -1020944], [-187031700, 440480], [310991070, -9519732], [-3897567050, -18112480], [-2478909908, -59933000], [10916535890, 199286496], [2782906822, 9362000], [-26255438850, -44127052], [46427943170, -310471484], [133124438090, 823152688], [126750803900, 2843365840], [-188729619918, -2095600000], [-1187891156870, -36295844], [-278095051388, 10496675000], [-278232691230, 7446633968], [-1204115283800, -28106767280], [-1949147801490, 12892649508], [53423837850, -3668003040], [9372204725570, 28322321616], [-3912891838698, 79598268000], [3806258398790, -75646404612], [-14320837990350, -59759800164], [15416109009650, -30520956960], [18820866062330, 57925229728], [-57215847704790, -47308254124], [-62593870960608, -172906551000], [-9427966319310, 681671925696], [-66319537738900, 1042244642160], [61184538762250, -1714401690400], [-139698952435548, 294787763000], [221584785050, -460955156064], [102778792352030, -3563344084572], [97734303459930, 492070144356], [-2023482967830, 6780704326368], [167591013757700, -1062777292880], [-174734864918458, -5675749560000], [137254689504772, -6095330947000], [-282276013675750, -780766487952], [-349715859441630, -4412283047184], [291059741553000, 12767354412800], [863614949406032, 1335957033000], [-265727963922130, -7758649264932], [1694198145789010, 2196480808076], [-901525402254050, -2824067655680], [914500009667610, -23393298505392], [-623622926337400, 24239198828560], [1592733119197422, -8349259990000], [-1745477438329248, 10116696435000], [-2219993725758150, -19493745312864], [2844636138435430, -35490788283172], [7927872813522050, -2181349555520], [-3336209424349788, 96183862277000], [-4389265882581590, -21254421585824], [7978830780078342, -91633889658000], [-9818761362719690, -2070798573692], [9441938483017650, 93638456096448], [1377380440040250, 211864835706236], [-4198881842641668, 20026551057000], [-1828688307274870, -123253710677472], [-2582424359630870, 128171652384656], [-16792148422302008, 70258119421000], [582237770212290, -68366237295904], [-26938998314775430, -290018386752884], [28487592478227750, 228995442718400], [63576496915846290, -5451998246112], [7334920050473400, 182892105287040], [20234525171708530, 210395873194756], [15762858970556970, -570806628228832], [-29847760227204300, 700857004005920], [64450296603907710, 300692501379708], [-6716699301780150, 56000837588160], [18840318225329970, -1180517090964784], [-40233988938024798, -593818781616000], [-78634315757610850, 1072690367376240], [-102748392240370700, -900272462435920], [13623831815085162, -1076561643988000], [-47038987866717708, 60109623249000], [499416971617410, 720260435891408], [-35116755825509400, 1936523794655360], [-81935033560739250, 1037720166250548], [143640641860571750, -705921887217200], [-87555365090348550, 391186956033536], [119179369258336782, 1402972694988000], [140924964822440230, -2237510811800372], [-41061717348517670, -4114457939975044], [119409775977112200, -509665254397680], [198582587935735490, 3505216214325396], [-50098863940279328, 378285360971000], [-307893350291572500, 1923220949960000], [-443963348389315610, -997180655983012], [-183380665927851850, 3977976838848640], [-279880547257584038, 3763534593152000], [-149899964329761930, -7448876891392732], [342394928791045822, -8057230720316000], [200984567646157170, -754307992530484], [-460217015834088750, 1439791181576736], [-415314098031983370, -6418466838648972], [617943117854771550, 6575539154725680], [-611890729516024888, -3097143863379000], [-1423972627650783190, 176115253555776], [508125569068498290, 10755282129469596], [14459778565200850, -5051953205940352], [1486045035222904000, -6199550204455600], [-934789728337634698, -9740789581890000], [520612397403985650, -5049428147879164], [1097727397068333330, 2770764365091728], [-1693918716947050470, -426125609589744], [-1698639142723332700, -5528646624117120], [-1589160090504444108, 14085653880743000], [573616873459508622, 28773935217018000], [67077129210870550, -1982811285580652], [2049402806729629970, -5930721023094284], [122243477194038490, -12511261114264912], [-59160901920057100, -21926457747691760], [1213068543281733882, -19432942173448000], [-835932099467214830, 22762166608568368], [160047752149784610, 3874458763712976], [-1702069853481837090, 21549921162409908], [2881068674135611272, -28921620662017000], [685798225231331602, -12976429276468000], [1302167110179591150, 57246495403377440], [-2486126843218126200, -15755202262572720], [-5114303037317317990, 12819718973879076], [645113602511107610, -65096855199643392], [-3519879371186199900, 39878930417604560], [-4459542524183702050, 20091135350988748], [-2907534889606097748, -62329627640053000], [167508919294121850, 55254260476723136], [1239760282142948682, 28777111792848000], [93936241374642050, -102223824604823520], [-1265287032992924430, 48847111831470768], [6099362441342539890, -49010593169562004], [-1660336082489817830, 107542328636500016], [-8257240056757197350, -32439873129948160], [11762249449214274832, 30957666171211000], [-9557580851025241638, -19906537506732000], [-997123263150201730, 106097696132259468], [2901747300272978810, 21756443172451276], [4929601552670662450, 22999672712254720], [7362652280458171600, -22175490438873040], [-995826042648483710, 155878601525035888], [-7789232148118478350, -103790148277813664], [8441172847005585900, -26536964030914960], [1347992961854816830, 31314338142635228], [-2250890320722652790, 69076428315837376], [-10651496578379095858, -39746163490058000], [6490733942448402710, 79852124018286708], [-11660050201447382310, 50989536460292196], [-1704097972689972950, -54869417363504564], [7154455718917547132, 188957416127779000], [-26073545367525133200, 62948276861868080], [-33519076402840911050, -19925046470232880], [18954084729053518090, -96241199108250704], [5396724689467437022, -192441502757296000], [-3501698650150368630, -127279460108475684], [11721700823094689690, -11478980758483712], [-34193924687335122670, -114602337064044], [17900830413994278312, -255273374837331000], [22972962202842229010, 71756321914534576], [7972946128003699110, -211115616139229892], [-28483505576685967828, -12011629168137000], [1141026476995577770, 84270126728582416]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5_14_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_5_14_a_a(:prec:=2)
    chi := MakeCharacter_5_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 14));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_5_14_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_5_14_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<2,R![-6384, 80, 1]>],Snew);
    return Vf;
end function;