
// Make newform 12.13.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_12_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_12_c_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_12_13_c_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_12_13_c_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 := [385000, 0, 4105, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-41050, 4505, -20, 1], [-41050, 35155, -20, 11], [1067300, 126140, 520, 28]];
    Rf_basisdens := [1, 75, 25, 75];
    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_12_c();"
function MakeCharacter_12_c()
    N := 12;
    order := 2;
    char_gens := [7, 5];
    v := [2, 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_12_c_Hecke();"
function MakeCharacter_12_c_Hecke(Kf)
    N := 12;
    order := 2;
    char_gens := [7, 5];
    char_values := [[1, 0, 0, 0], [-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 := 13;
    raw_aps := [[0, 0, 0, 0], [75, 1, 0, 0], [0, -3, 1, 0], [3950, 28, 0, -1], [0, -1794, 52, -63], [858050, 6608, 0, -236], [0, -26016, -1000, -1116], [-512506, 32900, 0, -1175], [0, 68988, 6800, 3438], [0, 460743, -20669, 15336], [-629752066, -573300, 0, 20475], [-1866677950, 2947504, 0, -105268], [0, -5597562, 30046, -211824], [-6529982650, 251748, 0, -8991], [0, 8463888, 121800, 339588], [0, 4976817, -887675, 88992], [0, 31893834, 817328, 1320993], [-2326808926, 48476400, 0, -1731300], [22263896150, 13071828, 0, -466851], [0, 19570764, -10716712, -483822], [116035618850, 122090304, 0, -4360368], [141755506622, -178563700, 0, 6377275], [0, 206986626, 19092900, 10164051], [0, 293742462, -26619346, 8226324], [215739631250, 143975888, 0, -5141996], [0, -103347123, -6449791, -4719096], [-301534332850, 1401453564, 0, -50051913], [0, -1220897046, -35171000, -51015771], [-650476549726, -735109200, 0, 26253900], [0, 1107872892, 66361500, 50267592], [-3467777510050, -857153556, 0, 30612627], [0, 503796246, -315183368, -16990533], [0, -5698728282, -69787250, -227234232], [-1294870411018, 3161958100, 0, -112927075], [0, -4430497191, -43703347, -175446432], [-42940085266, -4616801700, 0, 164885775], [16840672414850, -4922375472, 0, 175799124], [-3649943417050, -21137718812, 0, 754918529], [0, 17499088980, 449992800, 724964130], [0, 12769801371, 89539575, 501477696], [0, -13332383274, 502140592, -454844673], [10967225968034, -5168702000, 0, 184596500], [0, -30229927656, 581439848, -1095600312], [16500835405250, 31458775488, 0, -1123527696], [0, 48305936613, -1497459175, 1685136888], [-65998837471186, 38496187100, 0, -1374863825], [-52827735741706, -23529249100, 0, 840330325], [-63749217213250, -18190179252, 0, 649649259], [0, -54400787190, 6946774500, -1290787065], [101951311789154, -41142452400, 0, 1469373300], [0, -88972597542, -8464514150, -4398697692], [0, -164311130880, -3575412360, -6732206460], [111734160844994, 219195760000, 0, -7828420000], [0, 52650851982, 16044645244, 3876337989], [0, -210560806008, 8134541400, -7159891608], [0, 395576903964, 1786773800, 15420662514], [0, 39440322915, 9538957855, 2617584480], [-90419572301698, -436105086900, 0, 15575181675], [-240322197226750, -221038129872, 0, 7894218924], [0, -235128678186, -11540544362, -10375011972], [322477148739350, -424439805132, 0, 15158564469], [0, 239821841469, 21301687025, 11681803944], [-610826253915850, 183352563828, 0, -6548305851], [0, 152651461524, -17933951192, 3801907998], [-1130681547751150, -589204789712, 0, 21043028204], [0, 840106413831, -27886370125, 29094127056], [-191128425271498, -594692709100, 0, 21239025325], [998401681164050, -1192551472112, 0, 42591124004], [0, -776082980034, -4327152900, -30348632259], [-296574124797118, 1630058726800, 0, -58216383100], [0, 1370747813784, 69756237400, 60769866384], [0, -3361490298036, 3790768488, -128850692022], [914771476303550, 442858745868, 0, -15816383781], [3690492612438050, -403720833712, 0, 14418601204], [-1170536578028506, 1737592404100, 0, -62056871575], [0, 3709850117496, -134011487000, 127223679096], [0, -4732033289811, 24455330513, -179179511472], [-3341070684526750, 1315570557168, 0, -46984662756], [0, 2745988226520, 185696506240, 127041451740], [4812269033517794, 1936010036800, 0, -69143215600], [0, -2849309196462, -311231866404, -145500184449], [-3111269876271838, 4021670237200, 0, -143631079900], [0, -2061784317408, 156524375864, -61238891916], [-6354082264778350, -5040225760752, 0, 180008062884], [-3783584937485266, 9021886883100, 0, -322210245825], [0, 3002030239302, -288389946300, 82186938477], [0, -75296673612, 410496498396, 44468954676], [-1920140609725150, -8578499622336, 0, 306374986512], [0, 6728604219483, -415148952089, 210890667816], [9107229030609950, -8783304185236, 0, 313689435187], [0, -1633555004646, 446795109100, -11275756821], [0, -1551875095584, -109949868528, -72374026968], [-659284244844850, 12542713721468, 0, -447954061481], [0, -1016034101790, 307478502320, -3599945955], [11659060662225014, 18404855550900, 0, -657316269675], [0, -1948331979324, -1070070685800, -198405539874], [0, -13438216681257, -152133764669, -534408383664], [0, 2598489083910, 523760396270, 160375779720], [-14850491404627450, 3704388753828, 0, -132299598351], [-10832709625248286, -2993785701200, 0, 106920917900], [-27752327183215450, -19636951096476, 0, 701319682017], [0, -8768194685997, -1994745366625, -567401184072], [0, 7433365942026, 2217086025900, 541716308451], [0, -18003881394870, 115338859010, -679148646840], [-20036173290412906, 15918703899700, 0, -568525139275], [-18971102083869550, 21008955029328, 0, -750319822476], [0, 9520094636058, 1749876533000, 568066316733], [0, -71284833909780, 924480213500, -2635053587280], [0, -35575612060164, 1700802193712, -1172046364578], [-2872291251617566, 23547027873600, 0, -840965281200], [18965017373241950, 12925861617004, 0, -461637914893], [20424592251282050, 34753932440304, 0, -1241211872868], [0, 8807208057186, -1050157513550, 217566750636], [15430057582817654, -82178629728300, 0, 2934951061725], [96092395972357454, -1230709938500, 0, 43953926375], [0, -73291383181668, 2692359792244, -2508242454036], [-23059687606394650, 22922130371364, 0, -818647513263], [0, -11979056172348, 3635623034400, -41237964198], [0, -1975805160117, -2386836589225, -351396727992], [0, 28900283349846, -5149679927968, 517355521767], [-62979290773648318, -49051338848400, 0, 1751833530300], [22327523942440850, 65821077220304, 0, -2350752757868], [0, -33733042469619, 104337646625, -1285385751144], [0, -163586006299098, 958335109500, -6181192345023], [-7521913115973178, 133250427720900, 0, -4758943847175], [0, 35012690264607, -3557120453381, 936204957864], [-5194019187807166, -94593408994000, 0, 3378336035500], [0, 132538264360056, 57151233552, 5104219925412], [8189000707321550, -92714932827972, 0, 3311247600999], [-124890653030199550, 122914239238224, 0, -4389794258508], [586679215932182, 58704998606100, 0, -2096607093075], [0, -14506642764540, -7670838697200, -1443044571390], [-111605250943415458, -47584336774100, 0, 1699440599075], [74384872820526050, 64202749663248, 0, -2292955345116], [0, -181183296225006, -2389057480902, -7244248794912], [-19080346160742526, -113546354320000, 0, 4055226940000], [0, -86966164818171, -15548484443175, -5138908390296], [-362497183517165050, 57470872313988, 0, -2052531154071], [0, 55615685869431, 8529471112275, 3123234584856], [0, 31222735503222, -10601128105426, -22332646656], [-55866432115210426, -381673195551900, 0, 13631185555425], [0, -14636552076951, -11260165026067, -1862194121352], [65922259382420750, 334615542590588, 0, -11950555092521], [0, 292085248882386, -13665270091000, 9657286100361], [362817314809123202, -146089250196400, 0, 5217473221300], [0, -100445013646596, -3837254769432, -4306029921342], [67016077749850850, -69483651319152, 0, 2481558975684], [0, 392449211716338, -15237374846550, 13336041814488], [-229067457643684378, 308763320296900, 0, -11027261439175], [0, -105467489797848, 31360404948200, -437933652048], [-279353706848127550, 236972226330448, 0, -8463293797516], [0, 238338511441260, -8152578821780, 8226183652920], [-270222283458609850, 194384061408068, 0, -6942287907431], [0, -539086272408444, 13425430235800, -19184999296194], [-532280819548963450, -85485456385756, 0, 3053052013777], [0, 870444216686016, -163925572728, 33459709229532], [311105721105225614, 498598469163900, 0, -17807088184425], [0, -205344093032892, -20076298129764, -10214345670084], [-691955686474029550, -516273890718992, 0, 18438353239964], [0, -100695311909421, 27864945176543, -657710629992], [0, -344750832464850, 1620044369400, -13072719206025], [0, 172331300255130, 24548676611250, 9460666541880], [374782897272351950, 392990224822524, 0, -14035365172233], [0, 577750413369510, -2281257532980, 21957947721945], [0, -585751004714832, 24412222341800, -19712089911132], [0, -215919736555020, -5316777322600, -8918079558570], [193905359753964254, -548661710471700, 0, 19595061088275], [-1092735762007133950, -491461113272976, 0, 17552182616892]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_12_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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