
// Make newform 2028.4.b.d in Magma, downloaded from the LMFDB on 15 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2028_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2028_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_2028_4_b_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_2028_4_b_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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_2028_b();"
function MakeCharacter_2028_b()
    N := 2028;
    order := 2;
    char_gens := [1015, 677, 1861];
    v := [2, 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_2028_b_Hecke();"
function MakeCharacter_2028_b_Hecke(Kf)
    N := 2028;
    order := 2;
    char_gens := [1015, 677, 1861];
    char_values := [[1, 0], [1, 0], [-1, 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]];
    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 := 4;
    raw_aps := [[0, 0], [3, 0], [0, 1], [0, -16], [0, -34], [0, 0], [14, 0], [0, -2], [-72, 0], [102, 0], [0, 68], [0, -193], [0, -125], [140, 0], [0, -148], [526, 0], [0, 166], [-410, 0], [0, -298], [0, 440], [0, 253], [-640, 0], [0, -690], [0, 725], [0, 223], [610, 0], [1352, 0], [-732, 0], [0, 757], [-1518, 0], [96, 0], [-2548, 0], [0, -115], [516, 0], [0, 921], [0, -264], [-1306, 0], [0, -1886], [0, 192], [-1462, 0], [1332, 0], [-2030, 0], [-16, 0], [0, -1039], [0, -1743], [-568, 0], [3804, 0], [0, -2956], [0, 1654], [0, -3025], [-4794, 0], [0, 2220], [0, 665], [5116, 0], [-642, 0], [4264, 0], [-3850, 0], [0, 1468], [2066, 0], [0, -107], [2620, 0], [0, -577], [0, -2038], [6456, 0], [-5526, 0], [0, 5229], [0, -1174], [-5298, 0], [9876, 0], [0, -2685], [0, -3665], [0, 3744], [1504, 0], [6702, 0], [0, 2850], [0, -1164], [11554, 0], [0, 3243], [0, 3849], [0, -1669], [-52, 0], [0, 2929], [0, -4420], [-11346, 0], [-16456, 0], [-3788, 0], [0, 273], [0, -1773], [0, -6459], [0, 9164], [-11980, 0], [0, -6172], [0, 40], [15660, 0], [0, 30], [12248, 0], [0, 45], [9818, 0], [-20252, 0], [0, -6317], [11756, 0], [0, 8811], [23092, 0], [1302, 0], [-24868, 0], [0, -1281], [0, -6742], [0, -8487], [3864, 0], [17546, 0], [9296, 0], [0, 3457], [0, 12723], [0, -5618], [0, -14712], [5054, 0], [0, 566], [-1464, 0], [5494, 0], [11580, 0], [0, -649], [-16162, 0], [-9890, 0], [0, 13550], [0, 5566], [-1862, 0], [0, -3969], [24240, 0], [13720, 0], [0, -10979], [0, 6674], [0, -10152], [3952, 0], [-22386, 0], [0, 6229], [0, 14063], [0, 17889], [0, 3626], [-4454, 0], [-34118, 0], [0, -8214], [0, 9369], [-13928, 0], [0, 20902], [43226, 0], [0, 5120], [0, -12841], [21558, 0], [-14060, 0], [0, -21004], [0, -11867], [37550, 0], [-12556, 0], [37368, 0], [-33364, 0], [50432, 0], [11864, 0], [0, 2975], [-20806, 0], [0, 11173], [0, 15818], [23190, 0], [0, -152], [-53372, 0], [0, -6825], [0, 17496], [18096, 0], [-18914, 0], [0, 22841], [60338, 0], [0, 6690], [0, 675], [28072, 0], [0, 291], [25328, 0], [46986, 0], [0, -18890], [0, 15887], [8616, 0], [8662, 0], [0, -23596], [52772, 0], [51518, 0], [0, -21021], [0, -8004], [-55502, 0], [29018, 0], [0, 8566], [0, 3869], [0, -38268], [-12350, 0], [0, -5958], [-60772, 0], [0, -16333], [-4604, 0], [51846, 0], [0, 15543], [75642, 0], [0, -23487], [37000, 0], [0, 3243], [-19872, 0], [0, -7847], [44642, 0], [0, 11038], [-52634, 0], [0, -19180], [-3188, 0], [0, -5277], [-19604, 0], [13070, 0], [-53778, 0], [-61640, 0], [0, -32250], [0, 31288], [0, -23907], [-21312, 0], [-80526, 0], [0, 25616], [0, 37235], [55710, 0], [0, 13208], [0, -21649], [0, 18332], [4884, 0], [-76078, 0], [-20854, 0], [13968, 0], [54152, 0], [0, 18846], [51114, 0], [-42084, 0], [0, 12116], [-45210, 0], [39172, 0], [0, 30492], [0, -50167], [0, -7017], [-64868, 0], [19560, 0], [0, -35570], [25148, 0], [110184, 0], [0, -11915], [0, -50393], [-70536, 0], [0, -38268], [0, -18798], [0, -23910], [-18384, 0], [0, -14669], [0, -36833], [0, 64], [-32282, 0], [-30858, 0], [0, -21318], [-9714, 0], [0, -57022], [36930, 0], [0, -52501], [-49984, 0], [-46068, 0], [0, 38833], [73286, 0], [0, -6975], [17484, 0], [0, 405], [0, -35013], [0, -57770], [73602, 0], [-5398, 0], [0, 46686], [0, -51883], [126048, 0], [-113774, 0], [0, -44736], [0, -5550], [0, -53245], [0, 48349], [115380, 0], [-54768, 0], [0, 19696], [80504, 0], [0, -1295], [0, -43442], [-150864, 0], [-20622, 0], [0, 33881], [0, -14456], [5598, 0], [-151306, 0], [-31204, 0], [0, -36325], [0, -22578], [55670, 0], [-64422, 0], [-147440, 0], [62802, 0], [94164, 0], [0, 22978], [-106778, 0], [0, 66891], [-10160, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2028_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2028_4_b_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_2028_4_b_d(:prec:=2)
    chi := MakeCharacter_2028_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_2028_4_b_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_2028_4_b_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2028_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![4, 0, 1]>],Snew);
    return Vf;
end function;