
// Make newform 2100.4.k.c in Magma, downloaded from the LMFDB on 14 January 2025.
// 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_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_2100_4_k_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 := [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]];
    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, 34], [0, -6], [28, 0], [0, -192], [186, 0], [176, 0], [0, -418], [-30, 0], [0, 412], [0, -432], [0, 306], [564, 0], [-322, 0], [0, 716], [-48, 0], [0, 1078], [496, 0], [0, -468], [-1314, 0], [0, -1438], [1038, 0], [0, 520], [0, -324], [538, 0], [0, 1278], [0, 800], [2484, 0], [0, 2010], [-1004, 0], [1746, 0], [-376, 0], [0, -2626], [0, 3652], [0, 1944], [0, -822], [-2580, 0], [2822, 0], [-72, 0], [0, -2402], [0, -3234], [-920, 0], [-2068, 0], [0, 1888], [0, 6228], [1162, 0], [0, 1254], [-3432, 0], [5906, 0], [7548, 0], [0, 2634], [0, 5280], [-1254, 0], [848, 0], [0, 4958], [3450, 0], [0, 100], [0, -1614], [0, 6308], [600, 0], [0, 9094], [0, -6042], [356, 0], [0, -2254], [0, 3180], [-3854, 0], [0, 6150], [1728, 0], [0, -11728], [0, -638], [3052, 0], [0, 144], [6690, 0], [0, 1742], [1986, 0], [-5066, 0], [6156, 0], [2078, 0], [7416, 0], [0, -6338], [-4376, 0], [0, 5988], [16638, 0], [0, -8806], [14166, 0], [0, 14368], [0, -11484], [-10464, 0], [0, 13736], [-15492, 0], [-6764, 0], [0, -7944], [1482, 0], [-5838, 0], [0, 15364], [14150, 0], [0, 5564], [0, -10410], [0, -16692], [10566, 0], [24932, 0], [0, 9314], [0, -708], [0, 3222], [22848, 0], [19370, 0], [0, 12896], [0, -27038], [0, 10842], [2980, 0], [5384, 0], [21618, 0], [0, 22588], [0, 9720], [0, 6858], [29004, 0], [-31642, 0], [0, -11426], [0, -8514], [0, 9012], [-11308, 0], [-6714, 0], [-30638, 0], [24288, 0], [0, -6808], [0, -23966], [38404, 0], [0, -4512], [-33616, 0], [0, -12274], [-16110, 0], [26350, 0], [0, -21390], [0, 17876], [0, -2106], [1542, 0], [-38212, 0], [39054, 0], [0, -21944], [0, -23700], [-24782, 0], [5544, 0], [0, -422], [0, -30750], [-10316, 0], [0, 9432], [0, -5578], [-20646, 0], [0, 37108], [0, -6936], [0, 4724], [26808, 0], [51400, 0], [2838, 0], [0, -33190], [-4650, 0], [0, -13116], [0, -38202], [0, -47752], [-33204, 0], [0, 12786], [0, -56568], [7856, 0], [0, -56986], [5230, 0], [0, 2898], [-7836, 0], [-12562, 0], [19824, 0], [0, 13606], [-34832, 0], [37038, 0], [-47884, 0], [-30114, 0], [0, 68056], [-47342, 0], [0, 64832], [-35964, 0], [0, -38366], [0, 20466], [0, -15528], [-12174, 0], [0, 66134], [0, 3388], [-51386, 0], [45360, 0], [0, -14930], [0, -62076], [64460, 0], [20934, 0], [0, 24036], [0, -27762], [-70510, 0], [0, 5722], [0, -54486], [0, -54408], [68298, 0], [68624, 0], [0, -2266], [34126, 0], [36756, 0], [0, -39786], [-59744, 0], [0, -61140], [-48474, 0], [-45412, 0], [0, -71758], [75822, 0], [0, 33928], [0, 72876], [19320, 0], [-21526, 0], [0, -16720], [-21558, 0], [0, 50928], [0, 74682], [77198, 0], [37912, 0], [-26754, 0], [0, 16000], [0, -31500], [-20414, 0], [0, 70638], [95016, 0], [0, 57704], [86028, 0], [0, 29770], [72844, 0], [-14704, 0], [3642, 0], [0, 11956], [0, 83760], [73102, 0], [0, 54546], [39156, 0], [-27336, 0], [0, 53580], [21068, 0], [0, -28184], [2122, 0], [0, -30522], [-35304, 0], [0, -10768], [-110940, 0], [-83828, 0], [0, 69768], [0, 54614], [-115734, 0], [0, -102480], [31990, 0], [0, 15930], [-804, 0], [103454, 0], [0, 28556], [0, -74418], [0, -21382], [0, 48448], [0, -12540], [42586, 0], [0, 51442], [0, -7734], [63244, 0], [25386, 0], [70482, 0], [0, 6028], [0, -116574], [-4642, 0], [0, 117884], [0, 99622], [53824, 0], [0, 132770], [0, -632], [0, -89124], [79834, 0], [97370, 0], [15540, 0], [0, 15552], [37592, 0], [0, 134616], [132566, 0], [0, 125372], [119448, 0], [0, -62066], [0, -39762], [-144920, 0], [-114042, 0], [-91050, 0], [0, 104724], [0, 160566], [42780, 0], [0, -129542], [4410, 0], [-32080, 0], [0, 116418], [51780, 0], [0, -138124], [0, -39242], [0, -145578], [-15536, 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_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_2100_4_k_c(: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_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_2100_4_k_c( : 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![1156, 0, 1]>,<17,R![36, 0, 1]>],Snew);
    return Vf;
end function;