
// Make newform 14.12.a.d in Magma, downloaded from the LMFDB on 19 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_12_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_12_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 := [-88242, -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 := 12;
    raw_aps := [[32, 0], [-175, -1], [1869, -3], [16807, 0], [476850, 714], [-112861, -1449], [2558136, -750], [8265971, 7893], [-7050864, -1848], [-35446752, 280014], [-2582146, 415386], [53644736, -790650], [86095044, -903714], [439424078, 2050398], [-649570278, 1150398], [3719878158, 2845248], [1109635779, 2904957], [-4869899419, 6782157], [1389543956, -19290600], [10598770044, -24722964], [-7007615314, 13241052], [-10854222052, -39612636], [5425851375, -50028951], [-62703588990, -66399000], [52346110208, -58568454], [-120432896619, 141349557], [167063905106, 3985902], [-65738035344, -34899900], [146618953148, -170548686], [29145815820, -200945346], [165763967420, -738926748], [-221897126829, 636206757], [-260857966506, -335069196], [591210120221, 589646043], [-847339665006, 492792972], [1162843277900, -298797156], [1494008881883, 201647151], [1260641901566, -367028298], [414423440550, -2935158198], [1171752767367, 3011757795], [-1529538166104, 4335182628], [136306908227, -2474782065], [-1175961691452, -5576450292], [-589397211064, -1186520958], [-1290603943998, -7205398452], [3724693378238, 2868909714], [-4689861149188, -624758400], [-3825162352228, -3666883500], [-2330091271725, 752404197], [-5971916179873, 9914952051], [-6019875827310, 8146463304], [-8088383816784, 18054262128], [6791919985256, 1880153442], [-2584891142379, -47167306893], [-13860000753942, -13460763144], [9698408579100, 9399753804], [-6219307290777, 9896078499], [-9580097210488, -25635259800], [18606771212270, -19866980448], [18141703289082, -19810887600], [-23366653953013, 9744618645], [-13369618410183, -1168796895], [-17499292201069, -74942920395], [-20069588173488, 90310498200], [-16490676989164, 131123673342], [-30351697271814, -10342204740], [42508983787646, -149357651058], [52010150815520, -27541273158], [-5898707694618, -24306613002], [13966974791231, 28890556443], [-142638095600574, 69694191552], [-10524169055892, -238277055156], [171455695845476, 53491124700], [74188049272370, -112693392756], [29597601919034, 82167393042], [-189631007165334, -172972652898], [115121541520632, 179375140686], [186419737485695, 97020691947], [13719154101000, -181403851566], [151783659470240, -245520427230], [-94610437974171, 197771321307], [119722373820086, -474692579928], [-26606142420792, -183585784872], [-312845412830020, 257318425854], [157405081856792, 274522332816], [-169120708841100, 356752003104], [143808179339610, 3917277000], [-33108201533920, 649847213442], [431762150335635, -615046666521], [-189322553108512, -507034935792], [296950384935519, 240516074649], [-344159421244674, -518763843942], [-362005911982096, -156004601256], [1070842015766700, -67782593256], [-23630617019116, 486513590472], [1074726529735572, 224471967300], [-266929781500641, -223700704293], [-908816418608532, 869387721558], [-1263558636465937, 477070790193], [-744609028611310, -1236784336956], [-728361464626822, -1727875657494], [1081384515243714, -1181545920156], [125549191428969, -3467305080009], [-734312217116424, 1840278888378], [1351322633490434, 1484671407786], [-983431736958454, -1018051757640], [698348207465937, 1391153036343], [-1602755707471842, -2822370173052], [-206375947472832, 1160277144264], [-781835233595710, -661182494616], [532614993630272, -3574436298912], [-57278209449976, -493951812354], [-764532833071320, 4503801195642], [2993093489083019, -2284367632443], [282897685886132, 5667048458820], [-1553416206397584, 1851750887322], [741889652442281, 871957704807], [906840828769134, -1476633329886], [-166773552297060, 4889498343954], [-3459918950498862, -2852417285886], [-360281764054639, -5146544210823], [1772128730963894, -7936954232004], [-3289740776760837, -3191789683449], [2800535877549588, 7317513370608], [83573389743179, 1640577427101], [-883704834588924, -9077482654758], [4099033861917944, 5779415502], [2364729199930230, 11370249119730], [-8420008934165206, 797140142694], [2020366159188461, 6862774323717], [-31135044007330, 14503635851670], [-284661613578060, 4859883499044], [8396886762887768, 478503853128], [5543064316215344, -3446282797146], [1378791250308024, 4828753465386], [-2163947241216124, -10536761751642], [-2078056447694367, 8296147456953], [-2978691885381961, 18830148321249], [842365149504543, 22410613457211], [136075319097672, 20213556081306], [-15409407029405137, -83496352527], [-13937616440521482, 7351129072728], [-10474262993310400, 7394357613384], [-2883095188961328, 2746042180308], [-18652380370226323, 5258187998181], [-1602737700978582, -4534132311786], [-12348971376290689, 3231834602787], [-2161158252281952, -3700988531934], [7723726491688613, 6139113858819], [20379763818142188, 6562730727588], [-2319168830457880, -14459231198538], [2665650183511518, -31208001995772], [2828788153467824, -11786068810404], [4899345342153234, -12568883120706], [-16991814574125976, -24833818931796], [-11706867608554116, 14717186535156], [-519663204233728, -36408020211864], [-18136665034301856, 5819894323002], [-17368257907382578, -12173013556452], [9777846626053653, 35199622179693], [-7762988092081350, -50629604418918], [-16751929303747566, 25733579179896], [4485005871742664, 22410548504064], [22451777738886363, -17779169730507], [10192527489895950, 12199053669012], [22028359241504154, -18592670737194], [8372261597009096, 29854534234392], [1607741592773225, 83780843862897]];
    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_12_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_12_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, 12));
    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_12_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_12_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<3,R![-322344, 350, 1]>],Snew);
    return Vf;
end function;