
// Make newform 2100.4.k.j in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2100_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2100_k_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_2100_4_k_j();".
// 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_2100_4_k_j();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_2100_k();"
function MakeCharacter_2100_k()
    N := 2100;
    order := 2;
    char_gens := [1051, 701, 1177, 1501];
    v := [2, 2, 1, 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_2100_k_Hecke();"
function MakeCharacter_2100_k_Hecke(Kf)
    N := 2100;
    order := 2;
    char_gens := [1051, 701, 1177, 1501];
    char_values := [[1, 0], [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+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 := 4;
    raw_aps := [[0, 0], [0, 3], [0, 0], [0, 7], [36, 0], [0, -62], [0, 114], [76, 0], [0, 24], [-54, 0], [-112, 0], [0, -178], [378, 0], [0, 172], [0, -192], [0, 402], [-396, 0], [254, 0], [0, -1012], [840, 0], [0, -890], [-80, 0], [0, 108], [1638, 0], [0, 1010], [6, 0], [0, 472], [0, -972], [1786, 0], [0, 2286], [0, 1328], [-1212, 0], [0, -1254], [340, 0], [-1038, 0], [2936, 0], [0, -1330], [0, 3364], [0, 3048], [0, 2706], [-4716, 0], [1910, 0], [4080, 0], [0, 2686], [0, 510], [-1352, 0], [-3364, 0], [0, 4768], [0, 420], [1882, 0], [0, -5082], [5424, 0], [-2590, 0], [-4932, 0], [0, -3438], [0, -6120], [18, 0], [6896, 0], [0, 6254], [1194, 0], [0, 7156], [0, 3738], [0, -844], [6312, 0], [0, -8282], [0, 9318], [1652, 0], [0, -1294], [0, 3636], [-10478, 0], [0, 7566], [8040, 0], [0, 7568], [0, 13522], [-2468, 0], [0, 12336], [3762, 0], [0, -8770], [6642, 0], [1510, 0], [1260, 0], [3998, 0], [-2736, 0], [0, -2690], [1240, 0], [0, 3900], [10878, 0], [0, 2330], [15150, 0], [0, 2992], [0, 8724], [-9744, 0], [0, 4136], [16212, 0], [-2396, 0], [0, -13128], [-12798, 0], [7386, 0], [0, -5180], [4070, 0], [0, 14780], [0, -6858], [0, -6660], [150, 0], [-8188, 0], [0, -5854], [0, 17580], [0, -17154], [18120, 0], [17546, 0], [0, -14560], [0, 4498], [0, -5478], [-6044, 0], [-15352, 0], [-22398, 0], [0, -3764], [0, -17688], [0, -19878], [20004, 0], [-1306, 0], [0, 13054], [0, 5046], [0, -12468], [-23212, 0], [35958, 0], [-6446, 0], [4704, 0], [0, -10600], [0, -12542], [-23324, 0], [0, 6312], [35840, 0], [0, -34594], [23946, 0], [-18770, 0], [0, -30342], [0, -26188], [0, -34818], [21702, 0], [-20356, 0], [-19890, 0], [0, -4232], [0, 9636], [-35294, 0], [3768, 0], [0, 39466], [0, -34038], [3364, 0], [0, -13104], [0, -40858], [-37374, 0], [0, -9788], [0, 50424], [0, -12412], [6576, 0], [-8264, 0], [-39426, 0], [0, -4678], [-17346, 0], [0, 19452], [0, -4458], [0, 52520], [-10404, 0], [0, -7566], [0, -44376], [-27328, 0], [0, 2774], [36526, 0], [0, -18438], [39324, 0], [2990, 0], [58632, 0], [0, -45146], [-16928, 0], [-5274, 0], [-36940, 0], [-16242, 0], [0, 6568], [-782, 0], [0, -25072], [25236, 0], [0, -56270], [0, 26346], [0, -2832], [-16326, 0], [0, -68506], [0, 51388], [43750, 0], [-23760, 0], [0, 29758], [0, -11316], [76124, 0], [-3810, 0], [0, -26244], [0, -30282], [-47470, 0], [0, 7306], [0, -48174], [0, 2952], [330, 0], [19232, 0], [0, 14150], [-36290, 0], [-30684, 0], [0, 36750], [-64496, 0], [0, 41748], [4710, 0], [-42100, 0], [0, -20590], [14454, 0], [0, -18488], [0, -49428], [-20184, 0], [27914, 0], [0, 61904], [24882, 0], [0, 45336], [0, -76566], [5966, 0], [49912, 0], [-68418, 0], [0, -45056], [0, -54636], [-48350, 0], [0, 16038], [45408, 0], [0, 632], [69924, 0], [0, -15590], [-33860, 0], [92672, 0], [-11238, 0], [0, 11140], [0, 85008], [-68450, 0], [0, -8910], [-3300, 0], [65592, 0], [0, -109692], [20492, 0], [0, 103816], [49354, 0], [0, -35778], [-48984, 0], [0, -40384], [-88188, 0], [-11540, 0], [0, 90912], [0, 15302], [49170, 0], [0, 114408], [-60026, 0], [0, 28482], [30420, 0], [4766, 0], [0, 68828], [0, -97914], [0, 118298], [0, 27472], [0, -30132], [78538, 0], [0, 133666], [0, 52866], [-89492, 0], [-22806, 0], [65562, 0], [0, -4628], [0, 37458], [-125314, 0], [0, 107660], [0, -33098], [110416, 0], [0, -8206], [0, -107336], [0, 2196], [-135014, 0], [99674, 0], [-122124, 0], [0, 39072], [83480, 0], [0, -46824], [149558, 0], [0, 102044], [79728, 0], [0, -44018], [0, -30546], [135400, 0], [41646, 0], [-93546, 0], [0, 27636], [0, -27786], [-57732, 0], [0, -97238], [73794, 0], [33920, 0], [0, -89286], [-116796, 0], [0, -55180], [0, 83446], [0, -108858], [132784, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2100_k_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2100_4_k_j();".
// 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_2100_4_k_j(:prec:=2)
    chi := MakeCharacter_2100_k();
    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_2100_4_k_j();".
// 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_2100_4_k_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2100_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![-36, 1]>,<13,R![3844, 0, 1]>,<17,R![12996, 0, 1]>],Snew);
    return Vf;
end function;