
// Make newform 5.10.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_5_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_5_10_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_5_10_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 := [304, 0, 45, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 37, 0, 1], [0, -7, 0, -1], [1350, 0, 60, 0]];
    Rf_basisdens := [1, 2, 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_5_b();"
function MakeCharacter_5_b()
    N := 5;
    order := 2;
    char_gens := [2];
    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_5_b_Hecke();"
function MakeCharacter_5_b_Hecke(Kf)
    N := 5;
    order := 2;
    char_gens := [2];
    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 := 10;
    raw_aps := [[0, 1, 0, 0], [0, -1, 1, 0], [285, 19, 7, 1], [0, 133, -49, 0], [27492, 0, 0, -20], [0, -1918, -110, 0], [0, -7448, -1632, 0], [-159220, 0, 0, 476], [0, 17005, 5199, 0], [-882930, 0, 0, -1976], [-2646928, 0, 0, -760], [0, -335370, -51378, 0], [-4197138, 0, 0, 24890], [0, 719131, -132643, 0], [0, -1012111, 214259, 0], [0, -1349666, -259794, 0], [-115207260, 0, 0, -52972], [90122642, 0, 0, -43150], [0, 6669647, 1448953, 0], [-11902968, 0, 0, -91200], [0, -1847940, 90564, 0], [-182010880, 0, 0, -267976], [0, -12737657, 1180353, 0], [-395675190, 0, 0, 185592], [0, 14786464, -1954216, 0], [567800502, 0, 0, -904040], [0, 22365509, -2238569, 0], [0, -40643317, 4617701, 0], [-534190510, 0, 0, -1403302], [0, 14543912, 8158280, 0], [0, -52485639, 12947955, 0], [868437372, 0, 0, 5517980], [0, 65182540, -32656548, 0], [3760961060, 0, 0, -2505588], [295441050, 0, 0, 6666890], [-2579341048, 0, 0, -3951240], [0, 65396138, 65546866, 0], [0, 63351567, 21906945, 0], [0, 350837317, 58941063, 0], [0, 5571010, -105145686, 0], [-7810592580, 0, 0, 15429444], [-4345285978, 0, 0, 3309800], [4123722912, 0, 0, -15711440], [0, 183619856, -174939368, 0], [0, -882570026, 107391414, 0], [-4925548600, 0, 0, -20616480], [15012114092, 0, 0, 24866060], [0, 1174355305, 233718899, 0], [0, -782129489, -123402495, 0], [-4145569930, 0, 0, -11031496], [0, -211219732, 198194228, 0], [-70133972640, 0, 0, -15102568], [-10747963738, 0, 0, -58281550], [75185487252, 0, 0, 34567500], [0, 1912970368, 63190656, 0], [0, 21208997, -266664865, 0], [53634804930, 0, 0, -54199134], [39842371232, 0, 0, 102971240], [0, 775253086, -102372970, 0], [-123537488178, 0, 0, 33407890], [0, -1098544717, -1031645027, 0], [0, -920587754, 720156702, 0], [0, -1966876617, -478455999, 0], [148798578792, 0, 0, -149310760], [0, 6302796052, -1051745500, 0], [0, 3225914602, -1952104182, 0], [230021907572, 0, 0, -68818380], [0, -11449570600, 752580232, 0], [0, -7086433021, 1675687829, 0], [-9582303250, 0, 0, 426458840], [0, -4829921296, -2697265984, 0], [69738875640, 0, 0, -419342712], [0, -310858943, -139794517, 0], [0, 9755797550, 3985241734, 0], [6794088020, 0, 0, -316311316], [0, -1813928327, -941730957, 0], [-102622727190, 0, 0, -74282438], [0, 9722079714, 2127492834, 0], [-292116701598, 0, 0, 249449480], [-347638455010, 0, 0, -396335782], [-137072876820, 0, 0, -228300124], [-313152328918, 0, 0, -372139510], [882689283072, 0, 0, -131006520], [0, 26012733048, 942022368, 0], [-212801146840, 0, 0, 1370252792], [0, 4845976771, 1674398877, 0], [-835558180650, 0, 0, 773032290], [0, 6651540748, 6519245996, 0], [991786317342, 0, 0, -647336840], [0, -28372639903, 2663499235, 0], [0, 3672450967, 3854618313, 0], [-188325202080, 0, 0, 64627264], [0, -33913559115, -8555972913, 0], [-202007035788, 0, 0, -1001861980], [286784207900, 0, 0, -544577260], [0, 39016122109, -7462943169, 0], [75222801390, 0, 0, 2181579848], [1656408145482, 0, 0, 1251373440], [0, 12083238555, -3394650651, 0], [803429749262, 0, 0, -709252920], [0, 11650217839, -502065391, 0], [0, -987291262, -21763902934, 0], [0, -26479120633, 21590591945, 0], [376799628030, 0, 0, -1761544454], [-3101021760268, 0, 0, 405774620], [0, 101254661376, -9826270800, 0], [0, 30920462155, 27878177997, 0], [0, 16386185656, 3626152632, 0], [-2303587797000, 0, 0, 1243659440], [-393754646098, 0, 0, 2818690850], [0, -64563647527, -18502025429, 0], [0, -40009353018, 4373133990, 0], [0, -29673444788, 928194948, 0], [3409283676980, 0, 0, 2787520836], [-1307195826328, 0, 0, 3879823160], [5132887401462, 0, 0, -2786988590], [0, -176700836209, -23759718263, 0], [0, -99222619451, -5609002161, 0], [0, 161796778594, -46557715614, 0], [2191153884540, 0, 0, -527027852], [3774024946442, 0, 0, -6061860510], [0, 171902693440, 34759014104, 0], [0, -29769894394, 35756735990, 0], [0, 37815069883, -12147432627, 0], [-1532927293588, 0, 0, 3571846460], [3199467371202, 0, 0, 5184896490], [-2203435665610, 0, 0, -9214126872], [-1457801997120, 0, 0, -8774111784], [0, 294489151741, 13248594695, 0], [0, -347130577942, -27723171902, 0], [4320493994060, 0, 0, 8014408052], [0, 226941606101, -4964070433, 0], [-4129885808848, 0, 0, -10232150560], [0, 345925609038, -18597765834, 0], [3352326900042, 0, 0, 15492843560], [-9691028355070, 0, 0, 8060978816], [0, 213206228950, -62447981466, 0], [0, -41730629785, -9087906623, 0], [0, -553339005926, 41340058314, 0], [2337513670890, 0, 0, 8923416768], [-4224834674908, 0, 0, -3267464580], [-1325100080118, 0, 0, -12626556590], [0, 287649795005, 65410744399, 0], [0, 324685537651, -45209270475, 0], [6924394295570, 0, 0, 13812732594], [-14868549756840, 0, 0, 3203985352], [0, 567250700494, -7768642114, 0], [0, -378206316572, -128732145564, 0], [16827431359940, 0, 0, -3997604332], [0, -508598057543, 173039733915, 0], [0, -82665808894, -36581830310, 0], [-9962935700778, 0, 0, -15682119510], [0, -220169786937, 107912506713, 0], [0, -715520406515, -79363054713, 0], [0, -524358798917, 64380735701, 0], [16047443942592, 0, 0, 21446373880], [-17324007739720, 0, 0, -3821368464], [-14175840998730, 0, 0, -4318217246], [0, 263149682700, -211020404268, 0], [4356304592862, 0, 0, -7919836120], [0, 509958266839, -29960006991, 0], [0, -44906334796, 168305176916, 0], [0, 479684002037, -140213955977, 0], [20687904094932, 0, 0, -27704465820], [0, 1306242952616, -714293680, 0], [0, -597899311427, -155877664857, 0], [696864118112, 0, 0, 41721488960], [0, -1397284908506, 55342550774, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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