
// Make newform 14.14.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_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_14_14_a_d();".
// 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_14_14_a_d();".
// 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 := [-19746, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_14_a();"
function MakeCharacter_14_a()
    N := 14;
    order := 1;
    char_gens := [3];
    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_14_a_Hecke(Kf)
    return MakeCharacter_14_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, 0], [553, -5], [37765, -39], [-117649, 0], [1667930, 34650], [3999051, 62475], [19512416, 358290], [62046467, -543855], [950408000, 448560], [-122567576, -10680810], [-5505280074, 9271530], [-19815245608, 36470910], [-1215513684, -8828610], [8911569158, -177554370], [32244155538, 349815630], [-63252088314, -317904720], [170629980619, -896167935], [223620350373, -616179855], [-1035661145444, 846793920], [325217232860, 1552163340], [-724904665058, 2850319740], [762576198828, -5153135820], [2128758819719, 10286107965], [6296825611314, -2018475960], [-8270785003880, -22566578790], [1108090913125, -14335059975], [967869663866, -46188504450], [2683418227752, -11732871780], [-12590629477148, 7571687130], [-18265807033724, -47401222890], [33667231880844, -135457326900], [6506525468443, 280031879865], [-67258465018922, -77969624460], [52512322929829, -52786895385], [-70895547386598, -348395492340], [-23976267732692, -6702475500], [107912110261571, 556026303555], [220789125668534, -267410946810], [-147260216051522, -1318336387830], [32993275073983, -699246973065], [-62875624604592, 489488515740], [214575402036555, 298123441875], [-67892036374236, 1014416685660], [-288496975771216, -1280291702550], [-311016000340918, -2113626396420], [639560151926150, -2663172107790], [1186485742469876, 1922654532120], [1106007994719068, 2708050378740], [-482404065458637, 3554304290385], [-255449828275649, -6886976686545], [3049941928029314, 500383837800], [-536738607903216, 2736318514440], [-2063701204907440, -13563633341550], [-5243468841775563, 54037428375], [-2591583017516262, 9548900783880], [2044611857256540, -22752111001620], [-9641540302978577, 7521126046695], [2551643769242904, -11371601330520], [-1906208929160650, 8399396219760], [4419928921290794, 15661857642480], [-4287066151242917, -20295530840415], [-3176667518777991, -13187606188155], [-2102423792912933, -22732236213015], [3080011974590656, -89599701375000], [6878968579601020, 29824492119390], [16351029728335746, -20979874705860], [11873304553852598, -25093721456370], [-26083549623081816, 8686932772770], [-18721207164045234, -91947608250330], [-17084796311055473, 1496635771575], [32736981616697778, 129326843236320], [27635368846818316, 171324507559380], [51382515902353748, 40005285784620], [-37337780283740486, 146330421939660], [-511208982174686, -219286596009390], [-63965584410607054, -64206781093410], [-42156727514756192, 258613902473430], [55845744484728975, -116237191962105], [-57823608011875248, 339479952368970], [-30138588268933816, 130131243766050], [72975852214867581, 367349481933735], [13166137628458110, 711867951233880], [10243875846083304, 34638925181280], [-15207928269987964, -319065944873970], [215148786896660568, -210001957986720], [-208213800853700212, 284233824278040], [-67286386261123622, 289064166354600], [-162081395593385720, 556476202095450], [131645076454430707, -302890556810205], [-64955621208080048, -327751269521760], [-101988732138975521, -203366396139435], [-116245070572616986, -347305412734950], [136058405398636544, 1115739190127520], [-67693741262962092, 1191465396408000], [75220816135080556, -802276006316400], [-19580562672316380, 634050859040340], [-86719477411364049, 735526595135895], [599958771824627796, 668622613835430], [-351528289605565513, 581495830990245], [676044151506490938, 1141768221748980], [-998957522459761422, 837017924604330], [327843283704470266, 2490143383720020], [296004965269882505, 666779456339355], [147959051243258496, 1425000385410210], [51437604750643242, -2973127349795190], [-573062416245840038, -498377642591400], [-438255696720473527, 811737274986435], [795268374892292574, -2079846964448460], [146057577802862976, -1771633715449080], [264899331556474706, 1029019713288840], [162758913091570992, -1429634231839440], [-1271092752892671648, -4290426951606810], [-911000752733509744, 3836627559330930], [-864167591333786789, -826336666045455], [-216150182430622396, 5886405024867780], [-470509067464131208, -7108925324504430], [943024396321002569, -1565156260568565], [1931940644892121878, 3657522210854850], [1417333326020513268, 6091339679921370], [-785502680096219734, -3487675953019230], [1236057050974892545, 1556627258453325], [-1722093034026830554, -9102981415994340], [415632864761587683, 14397154954396875], [670741134367241628, 3662843729500200], [1427563551127306019, 2254574770095105], [891056512336788268, -5045678677834830], [1306826152241431664, 10355836149945510], [-1090529908317789618, 3141618586790610], [2083584214011692434, -4967343366549690], [2417076554651601885, -11554480123847175], [2335610458235124054, -13643398921307610], [1638904342641090324, 8297159616417420], [832670776615905720, -9907689154075440], [26893931183609352, -28941502340123730], [-1163107249618161568, -599654414250630], [1266891456957694204, -6732463620677130], [4481394047280339049, 12363254129640885], [-7718035798965927897, 14490532780512525], [3386406289462762503, -21130761643843425], [-3528388137624837104, -26696959343338830], [8559488650893930127, 16549875900666045], [2860023826226145806, 4505456767670040], [5137207060215687280, -38099056465837080], [-4085873857833090216, -19730265554066340], [5945044308451932061, 37829196327300345], [-5831643405179708158, 14575630443380790], [6343075013295401759, -4622058884008545], [-1902569858094911208, 13147269945081330], [-5006730667324661611, 37539646954830135], [2931325422434670796, 4524457098606900], [1468895945725277968, 38975544225642990], [-7273685389420977954, -19759769898573180], [-18579343523661254920, -1412654843476380], [-18542647746467034246, -6282695418497250], [4261968175382142384, 52005326736024900], [-3767043072407550612, -41861163427102740], [-29118577944212768624, 3559434990882120], [1698379457151018936, -67510264848507030], [7275314007373173902, -73782558662059380], [8895549341932440061, 45223270389862665], [-8013589684966408526, 14344290776105850], [-14297688445324904254, 109052011568921400], [5055870223689345272, 11461395076300680], [7749834690644954019, 92259620635208505], [-33475387589901740226, -16467645455349900], [-21200372592559996206, -11442193753086570], [7790724549036854024, -81811202610106200], [-4886488889756749807, -195930610353919635]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_14_14_a_d();".
// 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_14_14_a_d(:prec:=2)
    chi := MakeCharacter_14_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_14_14_a_d();".
// 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_14_14_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![-1668816, -1106, 1]>],Snew);
    return Vf;
end function;