
// Make newform 14.9.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_14_b_Hecke();"
// 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_9_b_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_14_9_b_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 := [3438, 0, 120, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 156, 0, 2], [0, 108, 0, 2], [240, 0, 4, 0]];
    Rf_basisdens := [1, 9, 3, 9];
    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_b();"
function MakeCharacter_14_b()
    N := 14;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_14_b_Hecke();"
function MakeCharacter_14_b_Hecke(Kf)
    N := 14;
    order := 2;
    char_gens := [3];
    char_values := [[-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 9;
    raw_aps := [[0, 0, 0, 2], [0, 2, -1, 0], [0, 7, 2, 0], [-1519, 49, 0, 147], [-3390, 0, 0, 1308], [0, -229, 360, 0], [0, -1658, -622, 0], [0, -2888, -2391, 0], [-223518, 0, 0, 11952], [79266, 0, 0, 135396], [0, 24378, -8790, 0], [-623774, 0, 0, -89676], [0, -12442, -39488, 0], [2296642, 0, 0, 291720], [0, -5030, 73286, 0], [-9681822, 0, 0, -300696], [0, 219680, -32825, 0], [0, -315443, -127506, 0], [-3080062, 0, 0, -6305424], [15542178, 0, 0, 5125614], [0, -959492, -58842, 0], [6222434, 0, 0, -1672830], [0, 1668614, -261617, 0], [0, 1588536, 474774, 0], [0, -2464114, -369330, 0], [0, -857955, -298344, 0], [0, -2999912, 1336230, 0], [-127663422, 0, 0, -9938784], [34048546, 0, 0, -3225840], [60271362, 0, 0, -19456494], [29410850, 0, 0, -29971416], [0, -5762730, 1607715, 0], [15246786, 0, 0, 26906352], [0, 4216324, -1208361, 0], [330451938, 0, 0, -53047344], [-434279966, 0, 0, 637632], [0, 8188023, -4220088, 0], [-695455486, 0, 0, 123148548], [0, 6727468, -12436198, 0], [0, 38214207, -1379004, 0], [944103426, 0, 0, -109845108], [0, -8838217, 4455534, 0], [-83309214, 0, 0, -106059702], [-413597438, 0, 0, -73410534], [356466018, 0, 0, 112607724], [0, -18014968, -11847618, 0], [740056834, 0, 0, 87975816], [0, 76904712, -6963984, 0], [0, 33452436, -10278831, 0], [0, 10979109, 8914080, 0], [-193871166, 0, 0, 546374880], [-4501721694, 0, 0, 119872128], [0, -108053474, -11566782, 0], [0, -39745298, -36220531, 0], [0, -119855604, 60588252, 0], [1900817826, 0, 0, 625877958], [0, 63596867, -31359440, 0], [0, -75273796, -35857464, 0], [1947971426, 0, 0, 357203508], [-5174940990, 0, 0, -967888416], [0, 80590014, -635403, 0], [0, 299164133, -21697232, 0], [0, -10971234, -36329361, 0], [0, -288983846, 93219116, 0], [0, -68414242, 7514364, 0], [4028305698, 0, 0, -257309748], [-8954284478, 0, 0, -1134069228], [10628702722, 0, 0, 2035160082], [-533653566, 0, 0, -339554568], [0, 586453105, -101868438, 0], [0, -265314872, 104394560, 0], [-12556828830, 0, 0, 1959749616], [0, 297161276, 208249200, 0], [11463522146, 0, 0, -1934020260], [-1586422334, 0, 0, 5375077380], [0, -216121978, -296958866, 0], [-2115046302, 0, 0, -3911268420], [0, 41891145, -247098210, 0], [-19667428734, 0, 0, 2965923282], [0, 367910410, -217640112, 0], [0, 292185478, 385291115, 0], [17805281378, 0, 0, 6438187416], [9526153890, 0, 0, 6664410936], [0, -746442246, 334987038, 0], [0, 269593518, 79498320, 0], [-6686875710, 0, 0, -2802904740], [45642241410, 0, 0, -2106999192], [-19950300734, 0, 0, -8633609874], [0, 205840181, -471796502, 0], [-24338491678, 0, 0, -7347763854], [0, 638429160, 246847593, 0], [0, -687099118, -69217742, 0], [33405399394, 0, 0, -696081792], [-32444801982, 0, 0, -7027424208], [29099666818, 0, 0, -11858431452], [0, 1008784406, 583842952, 0], [0, 2718995417, -870015686, 0], [0, 3239428214, -848643704, 0], [0, -955458004, -78121089, 0], [-3757222366, 0, 0, -17522141112], [-89543675902, 0, 0, 8558540244], [-37804979166, 0, 0, -1098510144], [0, -1018293768, -856164351, 0], [128892129090, 0, 0, 1237962702], [17107113410, 0, 0, -3924458352], [0, 3368649436, -324622788, 0], [0, -1752107784, -1943235189, 0], [0, 2994748580, 2377988584, 0], [35216011938, 0, 0, -5661979914], [0, -1345920036, 1514730474, 0], [0, 957828584, 1412156400, 0], [-7140311710, 0, 0, -2596879896], [246990753090, 0, 0, -840287106], [0, 2330424602, -1388627619, 0], [-19098002014, 0, 0, 26647273710], [85655452674, 0, 0, -33805139430], [0, 4501839048, -146591571, 0], [0, -1786741560, 1907629710, 0], [100141142178, 0, 0, 10903204248], [77460624258, 0, 0, -31839687408], [0, -5868728371, -799715868, 0], [-96663394814, 0, 0, 36102681672], [0, -2668211277, -2697769722, 0], [-98545438782, 0, 0, 32978210424], [0, 3695567982, -1580904801, 0], [52735476258, 0, 0, 1584451032], [-162470524190, 0, 0, -17612360136], [0, 6584737058, -2404514426, 0], [0, -7941301320, -886780662, 0], [0, -5680119183, 3042737610, 0], [98114029058, 0, 0, -15828926148], [-328449069726, 0, 0, -4660350816], [-10384602974, 0, 0, -83101502784], [166157892322, 0, 0, -56805944328], [0, -4977508486, 3022883416, 0], [0, -4768894718, 1463555226, 0], [0, 8094979015, 4816135298, 0], [0, 7220529128, -3183671847, 0], [0, 13378328571, 1690964508, 0], [360303766722, 0, 0, 52625155614], [0, -3153943290, 6886902633, 0], [-237930228126, 0, 0, -63037526604], [-246018733534, 0, 0, -34702735482], [-149080235454, 0, 0, 48539889516], [0, 228350885, -3052227546, 0], [0, -20425572320, 791598806, 0], [0, 13096595021, -6838807596, 0], [0, 1180148302, -6696039628, 0], [0, -8851769458, -8833345995, 0], [313043895906, 0, 0, 37716429162], [35864048546, 0, 0, 115770124404], [0, -1727597292, 391762464, 0], [-73113911678, 0, 0, 77643002016], [0, -9871117520, 8311539962, 0], [-808385765054, 0, 0, -26653789332], [508848202146, 0, 0, 71127267840], [393745556770, 0, 0, 163785390366], [0, 6818516266, -4163307766, 0], [0, -13792276688, 5308031010, 0], [0, 15757746875, 9678010192, 0], [90998891394, 0, 0, -135852245928], [-793083529278, 0, 0, -76255426800], [395957035106, 0, 0, -54377395440], [0, -6389039008, -8794548365, 0], [1042549401858, 0, 0, -85361427072], [0, -21760539856, -1895560862, 0], [-79092295454, 0, 0, 177100491834], [0, -8427798765, -10750858890, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_14_9_b_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_14_9_b_a(:prec:=4)
    chi := MakeCharacter_14_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 9));
    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_9_b_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_14_9_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;