
// Make newform 2100.4.k.g in Magma, downloaded from the LMFDB on 20 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_g();".
// 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_g();".
// 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], [4, 0], [0, 54], [0, 14], [-92, 0], [0, -152], [106, 0], [-144, 0], [0, -158], [-390, 0], [0, -508], [0, 528], [0, 606], [364, 0], [678, 0], [0, -844], [-8, 0], [0, -422], [-384, 0], [0, -548], [-1194, 0], [0, 1502], [398, 0], [0, 1160], [0, -324], [938, 0], [0, -622], [0, -1200], [-1396, 0], [0, -2810], [-4, 0], [-1374, 0], [2104, 0], [0, -3206], [0, 332], [0, -1496], [0, -3322], [900, 0], [1902, 0], [4128, 0], [0, -1342], [0, 3506], [-680, 0], [5372, 0], [0, -1072], [0, 2868], [-4798, 0], [0, -5126], [528, 0], [-814, 0], [-1932, 0], [0, 3294], [0, -7080], [-7814, 0], [3168, 0], [0, 7858], [6730, 0], [0, -3020], [0, -6834], [0, -2332], [8840, 0], [0, -1046], [0, -7542], [2756, 0], [0, -3954], [0, -6900], [2426, 0], [0, -1470], [-6872, 0], [0, 7072], [0, -818], [5132, 0], [0, -8576], [3730, 0], [0, -6678], [-3054, 0], [-266, 0], [-8844, 0], [-4482, 0], [9936, 0], [0, -11758], [4104, 0], [0, 9748], [478, 0], [0, 11174], [-11674, 0], [0, 10528], [0, -16604], [8576, 0], [0, -9704], [-4092, 0], [-17884, 0], [0, -7704], [-14358, 0], [5082, 0], [0, -1756], [16230, 0], [0, -17676], [0, 12250], [0, -10052], [-25674, 0], [3732, 0], [0, 1214], [0, -7108], [0, 6162], [-2472, 0], [-13750, 0], [0, 11376], [0, 20382], [0, -21178], [4700, 0], [-21736, 0], [-13022, 0], [0, 3308], [0, 13800], [0, -2682], [-23836, 0], [-11282, 0], [0, -13726], [0, -4974], [0, -8988], [10172, 0], [27446, 0], [-3998, 0], [-25872, 0], [0, -12088], [0, 7974], [31764, 0], [0, 888], [-34656, 0], [0, 22866], [22570, 0], [1790, 0], [0, 2990], [0, 30756], [0, -15126], [6502, 0], [-8252, 0], [-21986, 0], [0, 3736], [0, 23820], [-7942, 0], [-21016, 0], [0, 24878], [0, 6390], [46444, 0], [0, -25408], [0, -1078], [-45006, 0], [0, 4028], [0, 29304], [0, -50916], [-24432, 0], [20360, 0], [-23202, 0], [0, 1990], [-51130, 0], [0, 47044], [0, 46858], [0, -30632], [-3804, 0], [0, 49326], [0, 11112], [13616, 0], [0, 56674], [-42770, 0], [0, 19038], [-8756, 0], [-14042, 0], [-37416, 0], [0, 41946], [22848, 0], [-11882, 0], [12276, 0], [-19634, 0], [0, -36664], [-13622, 0], [0, -17808], [-19604, 0], [0, 16414], [0, 39046], [0, 45392], [29826, 0], [0, 11034], [0, -7252], [24774, 0], [15360, 0], [0, -33470], [0, -44316], [-28100, 0], [33814, 0], [0, -32844], [0, 6298], [65810, 0], [0, 23302], [0, 58014], [0, -33288], [-65862, 0], [-37536, 0], [0, 7474], [45726, 0], [-30084, 0], [0, 22314], [-69104, 0], [0, -3060], [-51354, 0], [-86812, 0], [0, -66098], [24062, 0], [0, 17688], [0, 66316], [-54840, 0], [57914, 0], [0, -22240], [27442, 0], [0, -93832], [0, -59978], [-66242, 0], [2312, 0], [-3234, 0], [0, -9440], [0, -27420], [74386, 0], [0, -75542], [71776, 0], [0, -37896], [-76092, 0], [0, -9450], [16964, 0], [75376, 0], [-41958, 0], [0, -14044], [0, -48720], [50702, 0], [0, 22686], [-2484, 0], [20984, 0], [0, 38620], [3668, 0], [0, -84664], [-84438, 0], [0, -65582], [77496, 0], [0, -60528], [74860, 0], [-73508, 0], [0, -65232], [0, 23354], [-113694, 0], [0, 36360], [10790, 0], [0, 123910], [-81244, 0], [36494, 0], [0, -88884], [0, -30158], [0, -32042], [0, -39632], [0, -47660], [-32734, 0], [0, -86138], [0, 24606], [97364, 0], [-69414, 0], [-7798, 0], [0, 80308], [0, -63954], [97878, 0], [0, 141124], [0, -95478], [59344, 0], [0, 15470], [0, -112392], [0, -94804], [108954, 0], [-145190, 0], [89340, 0], [0, 8832], [51912, 0], [0, 6936], [-34114, 0], [0, -10788], [40528, 0], [0, 29874], [0, 1058], [126280, 0], [-19842, 0], [-72090, 0], [0, 105444], [0, -1494], [-110140, 0], [0, -146602], [-26070, 0], [13520, 0], [0, 46398], [98700, 0], [0, -102444], [0, 37018], [0, -63558], [67904, 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_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2100_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![-4, 1]>,<13,R![2916, 0, 1]>,<17,R![196, 0, 1]>],Snew);
    return Vf;
end function;