
// Make newform 1800.4.a.bc in Magma, downloaded from the LMFDB on 25 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_bc();".
// 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_bc();".
// 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], [18], [-34], [-12], [-102], [164], [48], [-146], [100], [-328], [288], [-120], [16], [-126], [-642], [602], [-436], [-652], [-1062], [388], [-444], [820], [766], [798], [402], [1444], [-198], [-2010], [866], [2098], [886], [-500], [-2302], [-2384], [-1452], [-604], [-664], [-4118], [-1746], [-1270], [-2676], [3146], [-3674], [-1392], [-540], [-4166], [-5024], [4454], [-1526], [-6828], [5782], [6394], [1862], [-6504], [-8298], [1848], [-2824], [1940], [-6548], [6566], [-8432], [4916], [10106], [3382], [-6460], [-5294], [-12096], [-862], [-6878], [-6216], [13274], [-1300], [13324], [6192], [-2022], [-7856], [-1148], [-6310], [13362], [-5146], [6368], [6138], [-4424], [-488], [-16884], [5398], [6122], [-8162], [-2660], [-9788], [-4714], [6690], [-20636], [15952], [2230], [-1260], [-2900], [19554], [-2664], [-11358], [-2440], [24156], [-2220], [5782], [1684], [15246], [-9016], [-18682], [22022], [22808], [-9422], [4172], [-11572], [936], [-15892], [25056], [4054], [-6758], [25098], [-2830], [10654], [17156], [-812], [30270], [-394], [37224], [12614], [25664], [-18772], [-19376], [30092], [-18136], [-10948], [1422], [26142], [-23404], [1418], [17304], [-28012], [-32266], [-4962], [5064], [-8174], [28240], [-10472], [-32102], [-11060], [36088], [34508], [6596], [-17620], [-50784], [-16072], [41760], [34100], [22812], [38982], [-52766], [13608], [6446], [42642], [19938], [49754], [7936], [-33248], [20196], [1510], [52290], [-5954], [-34610], [36888], [24946], [-2748], [-3676], [15796], [8794], [47950], [-56162], [24022], [-63190], [-42232], [25014], [-46888], [-23406], [-484], [-6860], [-61594], [54596], [17138], [40488], [25380], [58906], [13476], [-46162], [-5662], [-47756], [38878], [-26904], [30634], [58916], [48476], [41166], [-74850], [25150], [-38204], [-4152], [5604], [-1148], [71810], [2898], [-50870], [38504], [40452], [28674], [-56342], [20708], [50736], [-25518], [-46162], [65320], [-22472], [103070], [-19292], [78030], [-74898], [-76104], [44966], [-75546], [15172], [-71308], [33896], [-11108], [9172], [-76920], [-35422], [-50882], [-79618], [46132], [26608], [5068], [9070], [-20830], [29938], [-70044], [83786], [36102], [-33500], [48256], [-14688], [31488], [-74688], [-53534], [-87446], [-106758], [-96262], [-26156], [91154], [101258], [-127774], [65904], [286], [15168], [-59082], [-23204], [95730], [82296], [139372], [36510], [-57954], [-12448], [-19582], [-3524], [88850], [21082], [25872], [-78166], [-110054], [-33366], [-22464], [-7672], [-143232], [-77866], [-104608], [-13724], [-77034], [-57810], [142176], [-83728], [-28534], [56348], [-99678], [-32418], [-86600], [116994], [-126956], [-35886], [50166], [-134272], [-32398], [-26730], [111336], [57564], [42676], [-67714], [31828], [126494], [-40956], [-169556], [-174216], [-79106], [-54380], [-93592], [162208], [98838], [-7482], [-60100], [121730], [41224], [79236], [59946], [161446], [-186434], [191946], [99862], [-79732], [-8416], [-49736], [107058], [-84730], [-105630], [178388], [55308], [-49196], [-90396], [152822], [-3654], [11514], [129090], [-181148], [-141526], [132534], [141864], [41754], [193094], [21110], [-18480], [-32196], [97682], [-168012], [-140330], [-135866], [-23846], [-31238], [-146702], [117936], [80526], [9838], [192536], [62900], [-77040], [171912], [178366], [-232004], [81006], [-122614], [-44566], [87990], [-23018], [-94228], [212080], [128462], [-176840], [141664], [101190], [-20088], [81718], [-47604], [138574], [90874], [85934], [-173366], [159146], [-207604], [57752], [-88900], [63832], [-41336], [-1816], [67118], [44042], [250790], [148604], [19472], [-162370], [55480], [205512], [-12900], [-29046], [-133490], [94318], [140138], [-117834], [144870], [-21748], [-99784], [-117900], [-51452], [-62398], [126662], [-282754], [-178100], [-222212], [-186222], [-36706], [-192552], [-35182], [104678], [94376], [-73934], [-27660], [-29224], [-288174], [-125518], [-163410], [101588], [18160], [169292], [119648]];
    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_bc();".
// 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_bc(: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_bc();".
// 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_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-18, 1]>,<11,R![34, 1]>,<17,R![102, 1]>],Snew);
    return Vf;
end function;