
// Make newform 2100.4.a.a in Magma, downloaded from the LMFDB on 27 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2100_a();"
// 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_a_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_2100_4_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2100_a();"
function MakeCharacter_2100_a()
    N := 2100;
    order := 1;
    char_gens := [1051, 701, 1177, 1501];
    v := [1, 1, 1, 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;

function MakeCharacter_2100_a_Hecke(Kf)
    return MakeCharacter_2100_a();
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], [-3], [0], [-7], [-36], [34], [30], [-16], [48], [-126], [8], [-74], [-138], [352], [396], [78], [-60], [-70], [664], [156], [-410], [344], [-444], [-1002], [-290], [-942], [16], [1812], [-634], [-1302], [-992], [132], [1098], [2864], [66], [2288], [-38], [-3272], [-2676], [-234], [204], [962], [36], [-3530], [-978], [4136], [-364], [-6104], [1692], [-2182], [-318], [-3348], [-2830], [-3300], [3654], [-3912], [-534], [-2296], [1534], [-9078], [-6620], [-5754], [-4580], [-1632], [4582], [3270], [-11380], [1414], [-3204], [2690], [-3690], [-4476], [2656], [4390], [-5380], [-11268], [-8910], [8002], [-11694], [-214], [-1476], [-994], [1476], [-818], [8192], [540], [-4710], [14614], [18282], [5944], [2340], [-4488], [1576], [-15948], [2804], [-14388], [-15894], [14550], [21292], [-18178], [13384], [-23274], [-12900], [-5766], [-21580], [8494], [14148], [-16434], [16380], [5882], [8536], [11206], [-23694], [29720], [6440], [23082], [-7868], [11172], [1974], [-13884], [11858], [18742], [16206], [3396], [13376], [28386], [-6730], [2520], [-13136], [15298], [-22732], [6432], [-6448], [-22826], [19374], [-2566], [5334], [31228], [-25002], [-5766], [26480], [-1542], [26032], [9612], [-24718], [-37512], [37738], [29406], [-23896], [-29712], [2662], [-27066], [16792], [8748], [31408], [-21516], [37736], [-40362], [-48314], [-11574], [-9540], [2514], [-44984], [6732], [-18342], [1044], [17120], [-19910], [58466], [16782], [-39540], [-28006], [14772], [27790], [49304], [-5826], [40724], [64770], [-4352], [-8254], [-31544], [-54660], [-23354], [-49770], [-14352], [-54702], [40414], [-24956], [66602], [46824], [62494], [3588], [10820], [71322], [41436], [13542], [-19678], [56998], [-3834], [-60636], [-38550], [-30400], [24274], [36170], [-40788], [24750], [47864], [-28188], [-41166], [86936], [-52634], [-23214], [-47768], [14172], [12360], [40322], [79360], [-31026], [-94392], [-5082], [-82762], [38120], [-52062], [-43832], [38172], [-2794], [558], [5172], [70984], [-76044], [71638], [-35440], [-59824], [28242], [7108], [32820], [-54670], [-28818], [20004], [-66648], [31740], [-74008], [-61832], [-56002], [18318], [33840], [97864], [75684], [-47860], [-105792], [21526], [270], [-23304], [-50398], [63582], [103836], [-6802], [-17516], [37446], [79126], [58696], [48612], [-73294], [5146], [134886], [-58768], [90234], [-133530], [-66296], [-110466], [-16918], [83440], [56806], [59672], [-91298], [-58808], [-98700], [-50482], [-74902], [-24084], [-153108], [-40768], [-18276], [-11302], [33628], [-112884], [-63362], [-48594], [-15136], [102390], [-76278], [-73428], [-101550], [-77508], [-62186], [-41190], [-81160], [-139674], [77100], [-69428], [-119114], [-174282], [-46240], [-1812], [-166300], [-60386], [26724], [12890], [68124], [-55274], [45324], [143754], [-29550], [34792], [74136], [27890], [104316], [-64932], [-147362], [13098], [147776], [-115730], [85242], [-32144], [-67398], [32546], [764], [86764], [20064], [39198], [-149722], [141030], [15920], [36132], [148724], [-155076], [112574], [210558], [74546], [135952], [40102], [11634], [60258], [-178504], [45462], [-60420], [131594], [-116408], [-159264], [24534], [-46312], [-85706], [74418], [25936], [-29770], [-169218], [-55032], [69684], [-3462], [161544], [-13610], [2766], [-47376], [127404], [45772], [-215210], [12894], [10384], [65786], [106500], [-157048], [170928], [70410], [103568], [225574], [170004], [-240180], [-86882], [-82146], [-219242], [-63078], [147810], [64072], [160098], [144872], [118068], [55400], [-166886], [158944], [2484], [-30334], [146478], [84684], [-4484], [-233700], [-122330], [-134176], [-23442], [12380], [143394], [142418], [250554], [-174152], [156102], [6114], [279128], [-41258], [-98550], [13084], [114156], [-722], [-147474], [141708], [185612], [83518], [176298], [20316], [111832], [132966], [59052], [-170694], [-53270], [-226536], [85644], [10870], [137454], [156228], [283506], [155072], [18744]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2100_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2100_4_a_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_2100_4_a_a(:prec:=1)
    chi := MakeCharacter_2100_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_a_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_2100_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2100_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![36, 1]>,<13,R![-34, 1]>,<17,R![-30, 1]>],Snew);
    return Vf;
end function;