
// Make newform 2.14.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2_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_2_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_2_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2_a();"
function MakeCharacter_2_a()
    N := 2;
    order := 1;
    char_gens := [];
    v := [];
    // 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_2_a_Hecke(Kf)
    return MakeCharacter_2_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 := [[-64], [-1836], [3990], [-433432], [1619772], [-10878466], [60569298], [-243131740], [-606096456], [5258639310], [-1824312928], [-3005875402], [-49704880758], [58766693084], [-42095878032], [-181140755706], [206730587820], [-124479015058], [95665133588], [-371436487128], [-1800576064726], [1557932091920], [2492790917604], [2994235754490], [4382492665058], [-5661103299978], [-21610430889016], [10934823426588], [-4206822356770], [28765024146354], [47801294415488], [-103693704636588], [50538262349418], [21487752160700], [-87974080244250], [-20743522235848], [-227522725788082], [-141533307998476], [55799971905288], [126777035126814], [308976432380100], [-474335729440378], [-658450343765568], [210092454662594], [1565591114474838], [366803879539880], [1344847324997732], [-2040830210528416], [291994379357748], [-2814848786784010], [4393774620286794], [-4409529963591120], [1929397247427122], [346330697094252], [459506466032898], [-8089657193951256], [5060589068340990], [-491452915256368], [3929165996758118], [11441731284838842], [2122458566592524], [-19904981098076106], [-12661051360200892], [1086779606388312], [21338344665108314], [-30097120490396562], [10046812884491132], [4004874143133458], [60627264503628], [30757831702864910], [-20889663448536606], [-24636638117826360], [-52865058749411152], [-6445692106547386], [-65878722779659540], [88745679897654144], [62746427689257750], [-98626099602657922], [-3660882400499118], [141674536806418490], [144389625186388980], [132169256453691062], [-180535240406715408], [-133562817873339406], [234588273429423320], [-126521740137981396], [-191606761445794110], [-262243232425677142], [-69496129015518018], [-231197913974997616], [170771382851372388], [322879998550800480], [-24156170451130552], [-461063651229506148], [-585158129454996220], [-503072917124812776], [239180645026210350], [584938651103209962], [-138090764553408196], [28730763018322382], [177510090358098548], [670558256920318878], [310510773508535364], [-258365085562536870], [991258931637668012], [-999359466177127102], [779667709167908988], [886852492014836754], [-1566128865746044680], [1441861250492277242], [408279638223527648], [-1013864799275684746], [-2387636276891589942], [-805525467979639780], [2640345608223966872], [-1064290620407953278], [681097184977260884], [2044569594697118568], [2081955274082093694], [2119078637477401380], [-1464593699730624538], [725357520895214114], [422901813407040438], [1374691301994994524], [-3239180040514932028], [-4327295383699107858], [3722108478963896150], [-2697427753135732080], [-1303379099981623432], [1232141483066728334], [-2379984280955451340], [-1713421718031510456], [8155762506038273072], [-4088185976132339002], [4833395052014788122], [-5137684853959848190], [-2819476732432206186], [-5906004638161456732], [6004645534665006798], [-10328053161182757750], [2374885951617386972], [6177412576278913542], [-3842459230884091816], [13592581271691290028], [407966203464814190], [4609302694997853480], [-5134957188287044186], [8291277963445810938], [-679619354044679860], [-21187480015448495136], [5292431009453678558], [2318315269207038642], [13896076792985526404], [-16848370811275660392], [-25485385669930828612], [-17564079678607797168], [2762909748223398200], [-20225174145943400670], [9124093360956590858], [9470050245008047902], [-10706014711945900092], [-117295666306367526], [14819588502913514408], [30368691683219670012], [-34220350538321078382], [-21977824437178008456], [17234839188798296672], [53036552658967308278]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2_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_2_14_a_a(:prec:=1)
    chi := MakeCharacter_2_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_2_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_2_14_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![1836, 1]>],Snew);
    return Vf;
end function;