
// Make newform 1800.4.a.e in Magma, downloaded from the LMFDB on 13 May 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_e();".
// 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_e();".
// 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], [-20], [-16], [-58], [38], [4], [-80], [-82], [-8], [-426], [246], [524], [-464], [-702], [592], [574], [172], [-768], [558], [408], [164], [510], [-514], [-666], [1100], [1212], [2078], [-1458], [2436], [-2544], [694], [516], [-770], [-424], [-922], [3788], [-48], [3242], [2728], [-4090], [1480], [1622], [2530], [-2440], [-148], [676], [-6276], [6190], [5406], [600], [-1054], [2232], [3630], [6960], [2062], [-2544], [694], [1982], [-5228], [-7454], [1316], [832], [-6770], [-6582], [11292], [8006], [-316], [4926], [2438], [3336], [-44], [11966], [12676], [6672], [-354], [5054], [-10266], [-1526], [-2064], [4590], [5536], [-1850], [11704], [6948], [-12090], [-11626], [-16314], [15756], [5684], [3368], [5588], [-10584], [-12220], [16152], [-10642], [-22882], [10052], [-6530], [-16652], [-12886], [-11108], [9214], [-4052], [8446], [2172], [-1218], [-21240], [17626], [-2580], [14166], [-21426], [3668], [20032], [-7458], [-7092], [3384], [-29398], [6624], [8646], [-28698], [19426], [8604], [12980], [19630], [8030], [-22720], [-27116], [-30882], [-13836], [32712], [-8472], [-9866], [3774], [-28670], [-3246], [19372], [-11814], [30054], [2852], [-2170], [-19804], [5508], [33262], [4600], [4198], [-5826], [-3004], [-36936], [-5434], [4758], [-15476], [-27440], [48924], [3440], [-27184], [-42490], [-37354], [24470], [-34100], [1878], [-38484], [-45272], [-25354], [-18744], [59600], [17886], [-32926], [41234], [42880], [24118], [-53096], [9982], [-22744], [-16002], [17044], [61486], [-3532], [29974], [-4292], [-62400], [14182], [55606], [7952], [-45506], [9766], [26140], [22442], [40328], [3862], [-66588], [-25828], [-26138], [79732], [-47242], [-29550], [79830], [-3874], [-11704], [54486], [40120], [28078], [22674], [63312], [16538], [62728], [-43556], [61134], [-17188], [11702], [19726], [9148], [47316], [62384], [48426], [-2620], [-21914], [-28104], [-16070], [61550], [40744], [-6754], [3228], [77124], [-6434], [95510], [-54848], [4612], [32608], [-17146], [-42804], [36560], [-33058], [70932], [-94392], [45906], [77010], [11456], [66960], [-89684], [-19604], [46484], [98254], [38822], [-11984], [-38668], [-63608], [46588], [-9112], [798], [102590], [-43200], [-98710], [84506], [-72384], [470], [96372], [58962], [77070], [-62620], [118076], [-50562], [-12242], [-6802], [93652], [42758], [109926], [-732], [120418], [-11098], [-96028], [20670], [-59704], [107782], [13468], [-22796], [-34834], [61370], [115152], [72], [-8376], [141080], [-71762], [117164], [-12040], [21454], [-112974], [129720], [-54978], [-21178], [154644], [-15666], [-157392], [-83506], [-52746], [26504], [92658], [-26800], [37812], [103614], [53514], [-4336], [-153052], [136764], [25262], [-154692], [-85226], [70032], [5038], [-8696], [-17514], [-68874], [-140908], [-86056], [-99926], [142088], [-109320], [26054], [55742], [15860], [-6194], [92382], [156236], [-75026], [-136734], [119884], [-112196], [-100864], [-19230], [132422], [143290], [-122120], [15604], [-65324], [208140], [-112186], [-141738], [2266], [-4284], [127054], [-126882], [63686], [29192], [-9014], [15464], [157150], [106028], [-212520], [79410], [144172], [108534], [-23266], [-22220], [-52474], [-13298], [-199920], [23168], [163486], [71648], [-182402], [147398], [-76624], [-14448], [-215604], [-169018], [78906], [-185060], [98954], [-95208], [-222700], [106496], [96486], [-33144], [164254], [198696], [126352], [-7826], [-41418], [-232010], [127222], [48694], [126540], [-159786], [-86436], [6112], [183928], [128598], [96108], [-207992], [-194942], [-17310], [-77664], [142652], [-120680], [-136154], [-261184], [-134010], [67244], [3246], [-63498], [-198690], [212372], [-247866], [20886], [-127440], [74846], [-39258], [-109300], [33408], [-169378], [63762], [-7156], [-150668], [-35986], [45582], [-58720], [-90868], [140910], [263952], [92118], [135134], [-14816], [173096], [-28434], [74058], [118596], [112278], [312812], [-98744]];
    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_e();".
// 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_e(: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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![20, 1]>,<11,R![16, 1]>,<17,R![-38, 1]>],Snew);
    return Vf;
end function;