
// Make newform 1800.4.a.l in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_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_1800_4_a_l();".
// 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_1800_4_a_l();".
// 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_1800_a();"
function MakeCharacter_1800_a()
    N := 1800;
    order := 1;
    char_gens := [1351, 901, 1001, 577];
    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_1800_a_Hecke(Kf)
    return MakeCharacter_1800_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+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], [-6], [19], [12], [75], [-91], [-174], [272], [-230], [-182], [-117], [372], [52], [402], [-312], [170], [763], [52], [-981], [1054], [-351], [-799], [962], [-486], [-1188], [-1325], [126], [-183], [-902], [-2068], [1339], [-2939], [208], [-2678], [1482], [-1469], [4004], [-3224], [4191], [-3718], [-870], [2197], [2314], [-252], [-741], [-5092], [-5876], [-604], [-278], [-2496], [-2567], [-5395], [1490], [3330], [-6096], [-6006], [6976], [-3998], [-13], [4466], [9041], [346], [-10646], [8116], [-3007], [83], [-6189], [-5362], [1690], [-1638], [-7580], [-5630], [-4385], [-12558], [6570], [1268], [6299], [-13459], [9567], [2708], [-5126], [11445], [-5096], [-13247], [-7449], [3497], [13108], [-5428], [1516], [14762], [-3926], [-996], [7804], [16732], [-10426], [2235], [-10855], [10608], [-11583], [-17244], [18416], [-11913], [3900], [24899], [-1751], [-10887], [14650], [-4237], [11440], [-19370], [21346], [7436], [22490], [16086], [-2396], [-23244], [-13598], [-9751], [19104], [25402], [2224], [-8281], [481], [16788], [-23452], [20886], [22576], [35308], [188], [-29870], [22784], [-28496], [-7397], [-8883], [33960], [-32084], [4766], [31278], [-29956], [-14642], [20844], [-23751], [11380], [29744], [-37726], [-5429], [32149], [29176], [20068], [36850], [30025], [-156], [-356], [-8748], [36974], [-44382], [-2445], [7076], [-1560], [35087], [-9360], [-22269], [-37249], [17602], [-26402], [16836], [29101], [28488], [4745], [-51350], [-37926], [-8485], [3336], [60529], [61867], [-38422], [-18088], [35386], [-45676], [48487], [39286], [-11583], [37772], [49980], [-5078], [-43507], [-1183], [-10640], [30511], [-23643], [47019], [43706], [-9789], [-36634], [-76765], [71378], [-10907], [43890], [15158], [-40924], [-67856], [-17133], [-43836], [-56642], [-48278], [-82380], [-750], [-38792], [13666], [59358], [-19552], [-22009], [5430], [-17127], [-16054], [-52325], [56442], [-49530], [25286], [54340], [34775], [38662], [-64121], [93150], [35673], [-78624], [39988], [-49575], [-77758], [20255], [-31750], [-33007], [-56392], [39546], [16445], [87880], [-29435], [89348], [-38441], [34039], [21698], [-59644], [-1811], [-74976], [76654], [77292], [-59345], [52408], [-14736], [-28635], [121050], [-66893], [-60776], [-99255], [-64000], [-19825], [-105178], [-115427], [-11162], [-25299], [-43832], [-80484], [42939], [-92807], [32010], [91650], [47417], [-77202], [-3804], [-13529], [75991], [21016], [-39326], [13628], [101799], [-9880], [-2834], [7743], [69900], [-40930], [38664], [-67756], [50395], [-123352], [4926], [116688], [-128160], [-155810], [75166], [52364], [-146523], [86541], [-62596], [6042], [165802], [-44616], [-138996], [33631], [12433], [-73638], [131136], [-48645], [60763], [-63479], [111004], [68654], [102726], [65174], [-47022], [-164554], [-63049], [-165944], [-175532], [64806], [-25701], [103528], [37615], [29021], [70764], [93141], [28964], [137234], [-45786], [39298], [195995], [7540], [17230], [-31812], [100964], [144846], [-68914], [-2373], [-76271], [-199368], [-128440], [90942], [-105105], [177450], [68744], [122135], [197178], [49980], [214530], [-11588], [161108], [-183573], [-29568], [197114], [9711], [-45454], [71210], [49244], [103306], [64429], [157164], [97119], [39538], [-37852], [69082], [72813], [-70758], [-83092], [-137977], [168507], [32792], [120328], [75405], [110252], [-15595], [65572], [-228476], [-71552], [-76258], [-11709], [-151554], [-238021], [-248313], [-8494], [-68530], [-121225], [62264], [55961], [155552], [197366], [27248], [-210400], [-214192], [-20242], [109115], [-6292], [-127211], [63103], [35230], [149941], [195412], [-233337], [117909], [196950], [42904], [66955], [-96596], [102063], [-69264], [160952], [266266], [143286], [-57148], [213421], [37375], [-51856], [201553], [182380], [1287], [-56990], [-135126], [-169430], [149903], [-53854], [-59056], [98934], [-16666], [147993], [44317], [77328], [-119272], [-196027], [54353], [283258]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_4_a_l();".
// 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_1800_4_a_l(:prec:=1)
    chi := MakeCharacter_1800_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_1800_4_a_l();".
// 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_1800_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![6, 1]>,<11,R![-19, 1]>,<17,R![-75, 1]>],Snew);
    return Vf;
end function;