
// Make newform 192.13.g.c in Magma, downloaded from the LMFDB on 18 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_192_g_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_192_13_g_c();".
// 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_192_13_g_c();".
// 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 := [18766224, 4332, 4333, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [9380946, -4333, 4333, -1], [311928, 0, 0, 48], [8664, 34660, -4, 4]];
    Rf_basisdens := [1, 9385278, 4333, 361];
    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_192_g();"
function MakeCharacter_192_g()
    N := 192;
    order := 2;
    char_gens := [127, 133, 65];
    v := [1, 2, 2];
    // 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_192_g_Hecke();"
function MakeCharacter_192_g_Hecke(Kf)
    N := 192;
    order := 2;
    char_gens := [127, 133, 65];
    char_values := [[-1, 0, 0, 0], [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], [0, -243, 0, 0], [5490, 0, 5, 0], [0, 5372, 0, 3], [0, 93060, 0, 374], [1452518, 0, 2250, 0], [-8470566, 0, 4826, 0], [0, 16087436, 0, 4974], [0, -55966464, 0, 21702], [-10645974, 0, 119443, 0], [0, 208303380, 0, -123861], [-2350716434, 0, -372708, 0], [4492220634, 0, 370134, 0], [0, 341094852, 0, 996882], [0, -6216878808, 0, 1486618], [-15136739190, 0, 4280187, 0], [0, 15536372220, 0, 7263544], [-42071800418, 0, 1069776, 0], [0, 28609418996, 0, -19551816], [0, -12886833744, 0, 3537406], [197256657250, 0, -30749832, 0], [0, -5869754828, 0, -38237649], [0, 77882293404, 0, -17505770], [-159667615134, 0, -99275060, 0], [-140885510750, 0, 338673564, 0], [1159870585194, 0, -230862597, 0], [0, 602605692980, 0, -36685971], [0, -419222822436, 0, -194912668], [1347507076790, 0, 623980278, 0], [-2261733109614, 0, -509247844, 0], [0, -439511808996, 0, 1365982593], [0, 1756057131252, 0, 851128144], [-3467607491574, 0, 961559554, 0], [0, -417324932468, 0, -443361360], [-4807950143022, 0, 3343130557, 0], [0, 304431350572, 0, -3073054581], [-19357983182162, 0, 2383968924, 0], [0, -10043951847380, 0, -29606934], [0, -19423812277368, 0, -204376456], [-308428222158, 0, -9238575251, 0], [0, 16668221427972, 0, 1304360872], [-1101986855434, 0, 743775894, 0], [0, -40016210360256, 0, -747604616], [-17933342705758, 0, 529245000, 0], [85155078410586, 0, 570547111, 0], [0, -2575570101436, 0, -2699009391], [0, -83398003051292, 0, -4223605848], [0, -2748546567252, 0, 26995880085], [0, -65959894136196, 0, 26805807602], [50361807601478, 0, -51079713894, 0], [-49856253606270, 0, -31284890084, 0], [0, -142162005159360, 0, 14502795604], [-23920459239662, 0, -38768327460, 0], [0, 23966470591956, 0, -75789362618], [88533974701314, 0, 120849604480, 0], [0, -132399828485208, 0, -67867989792], [-408342907373526, 0, 35877352427, 0], [0, -240725451773924, 0, 9836066277], [-354749641039978, 0, -19171195290, 0], [622005134116050, 0, 16250250848, 0], [0, -14253313012452, 0, -72221200608], [-303368090815926, 0, 14844388499, 0], [0, 28710492807492, 0, -141592615848], [0, 147063964791528, 0, 192196792684], [-385916785952302, 0, 179117513784, 0], [-417525985430118, 0, -386906962249, 0], [0, -120149220006980, 0, 345311017572], [-1081545425126990, 0, -89003105352, 0], [0, -1222125693311052, 0, 17234691390], [1152491632567678, 0, -103482418032, 0], [472291404122898, 0, 137548043772, 0], [0, 695362542798672, 0, 313920044798], [0, 664462562114276, 0, 88186775931], [823092840054910, 0, -289378872936, 0], [0, 1734079005848132, 0, -96420727770], [0, 370827458906976, 0, -324760242816], [-205013531186766, 0, -1480876113867, 0], [-1971009022775618, 0, 1774834308792, 0], [1349556084747306, 0, -340972576322, 0], [2563617018214450, 0, -345734488620, 0], [0, 4626233593455132, 0, 312749442362], [-3674847759868810, 0, 133478315046, 0], [0, -796662930846600, 0, 1631396981094], [790708868657426, 0, 2802267165240, 0], [0, 3514784485421700, 0, 412573922973], [0, 3643202651896980, 0, -123347948082], [-3879208470096774, 0, -842270226846, 0], [-1447491430335278, 0, -788016554820, 0], [9207020721640050, 0, -767264681739, 0], [0, 4004808581384828, 0, -960616943427], [0, 3323020117350636, 0, 1229064197450], [0, -4618492405874424, 0, -225361047226], [0, 8547412991961212, 0, 598195594923], [0, 4686219493053372, 0, -932823494572], [0, 2398558165640964, 0, -150300651456], [0, 154766875771584, 0, -1808414705674], [19617749005544442, 0, -1802470690641, 0], [7739333053074522, 0, 3105684297870, 0], [0, -890285702164876, 0, -3303269416890], [-1436998208391082, 0, 11240728692030, 0], [0, -3211917867250820, 0, 4504220562870], [-1898988448053726, 0, -5312194452239, 0], [0, 4784201806708764, 0, -1728536588586], [21878206518867354, 0, -13390749749338, 0], [0, 1197880284007340, 0, 1416041938596], [19166934113989010, 0, -685000834056, 0], [0, -12841883261707140, 0, -10058555953204], [53519946102203922, 0, 3788134975132, 0], [0, -2514660779388816, 0, 1874986156170], [-13445321514104158, 0, 15760642513248, 0], [0, -14813962989043492, 0, 2974205125209], [-11259333851059970, 0, 10015108735536, 0], [25363408601959794, 0, -19894770552728, 0], [0, -20066518959945940, 0, -2363406245352], [0, -15092188455199796, 0, 3534399423627], [19951713025105338, 0, 17645543566234, 0], [0, 3855872211852348, 0, -9282473845362], [0, 51295540125192624, 0, 7039550022374], [45065841393611394, 0, -14849003284599, 0], [0, -13697547332486796, 0, -20655952471828], [7281396403842286, 0, -5900950600884, 0], [-101986839130678606, 0, -12308406130512, 0], [62079578945268066, 0, 14010520626057, 0], [0, -46184396741096652, 0, -321080525230], [0, 12945041945988444, 0, -25735332859206], [91004125895499258, 0, 17722315572887, 0], [-58025890420737562, 0, 769834346490, 0], [0, -36490654309456152, 0, -9514534519910], [0, 9876338595502956, 0, 11090415360555], [-161912220732450106, 0, 18694780769682, 0], [0, 69174375232369284, 0, 16610424015684], [0, -10433713094686440, 0, 30407074982052], [0, -6402511474735436, 0, 17694632039991], [-118912365019003258, 0, -32084938728918, 0], [164165131650509802, 0, -15356623344926, 0], [35623360166965442, 0, -11573370273168, 0], [193259593901187450, 0, 6115774916239, 0], [0, 107966654222047964, 0, -36868985536662], [181161407132651106, 0, -50638198299839, 0], [128215800274961610, 0, 46408704976402, 0], [0, -6427299311119260, 0, -67226721151278], [313665727100077530, 0, -45412648969609, 0], [0, 237731984297387740, 0, -7541645383545], [0, 170122519740763116, 0, -20563159208916], [-255568652829594154, 0, -13866389775450, 0], [0, 230167678562337888, 0, -46743178503150], [-87274601616341906, 0, -3856566736188, 0], [82663307043697818, 0, 31159581474886, 0], [0, -249190193796223580, 0, -40303640510706], [0, 3711304510628832, 0, 67852227827240], [-228831019112435426, 0, 2776305584088, 0], [-355498402925530206, 0, -53287977272472, 0], [0, 318739233389903164, 0, 5954275082082], [0, 100299347912075544, 0, -85791583778288], [0, 237221339231852756, 0, -74929423674954], [0, -116625018881142720, 0, -22422947079044], [0, 92055767885559036, 0, 164013923567079], [680558155303450698, 0, 136695172355270, 0], [30285227061793970, 0, -132370324082064, 0], [-267542085666499758, 0, -15048810498659, 0], [0, 148006870400003652, 0, 53776755899592], [808070021802641754, 0, -47914811609858, 0], [0, -140661444659680844, 0, 69534453562101], [0, -681833511468984780, 0, -50432487677366], [717283169454647754, 0, -270618280095546, 0], [0, 635694079265958168, 0, 6932259080840], [0, -766166159899340668, 0, -72777610425825], [17702814724875934, 0, 295980661446408, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_13_g_c();".
// 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_192_13_g_c(:prec:=4)
    chi := MakeCharacter_192_g();
    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_192_13_g_c();".
// 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_192_13_g_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,13,sign)));
    Vf := Kernel([<5,R![-219397500, -10980, 1]>],Snew);
    return Vf;
end function;