
// Make newform 1800.4.a.o in Magma, downloaded from the LMFDB on 26 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_o();".
// 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_o();".
// 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], [-4], [28], [16], [108], [32], [-28], [238], [-180], [40], [-422], [-276], [60], [220], [804], [-358], [884], [64], [152], [-932], [-1292], [1146], [-824], [1290], [1604], [892], [966], [1124], [1884], [588], [1060], [-2864], [-342], [1636], [2072], [-772], [-1044], [4404], [-3452], [526], [-72], [-208], [372], [4348], [-416], [5748], [1148], [3234], [-228], [-4760], [3230], [-1708], [6372], [-3036], [114], [-5236], [5712], [-3222], [4620], [-5404], [9700], [-9672], [-4048], [-84], [5416], [8216], [3836], [-2038], [5292], [3896], [-7652], [1576], [-5416], [8292], [9642], [13032], [13358], [6410], [-7644], [14674], [9704], [-1296], [-15684], [-5772], [4782], [-15000], [3762], [-5036], [2268], [-16208], [-11572], [-5636], [-5560], [15172], [17342], [4886], [-18548], [-15770], [7700], [-19236], [8388], [16758], [8056], [-5728], [12172], [10708], [9416], [9270], [7996], [232], [3740], [-26000], [11660], [7602], [-29268], [17836], [-19188], [-13860], [-16558], [4640], [-34260], [-19420], [4608], [2318], [16834], [7400], [-20340], [-4896], [26040], [-6780], [-20692], [10816], [-13978], [2926], [13916], [-29996], [-8940], [10698], [-6408], [-23130], [-11852], [-32628], [36694], [1704], [-31880], [-7972], [-6008], [1716], [9032], [-27838], [4316], [-43524], [-10556], [47472], [11964], [15214], [-39712], [36034], [-2532], [55284], [-4372], [-24300], [46204], [-25468], [11668], [7224], [-40450], [-30924], [-15980], [-618], [8160], [-3032], [-27892], [-57190], [-61008], [49450], [-8428], [2262], [-6836], [-24108], [-24432], [372], [-41388], [-32650], [-25888], [13996], [4474], [21672], [-50440], [-8604], [37840], [-30546], [11484], [9076], [-57074], [-31664], [-1964], [59252], [43326], [30100], [65984], [41710], [63068], [29812], [-15404], [30004], [28906], [-1472], [24448], [-45450], [-81452], [4940], [57616], [-59978], [64604], [25390], [89516], [-78452], [54386], [81772], [-16734], [9828], [54476], [10574], [-1356], [44056], [101756], [7860], [109888], [-107976], [59004], [-75014], [1532], [96204], [-31486], [-924], [-62036], [56016], [35860], [-6760], [-63388], [33146], [-79620], [14000], [76444], [-32604], [44040], [115892], [-106944], [41214], [-7764], [97546], [97484], [31692], [29294], [75044], [28220], [60576], [-2300], [-60500], [-13022], [-39160], [-84684], [17112], [-94946], [-75290], [-57300], [-33732], [-85082], [-105292], [76696], [-55364], [54024], [5428], [-33236], [-10614], [-64554], [-104564], [-62492], [10060], [11612], [-37298], [-5228], [-43800], [20840], [87804], [71956], [48494], [92270], [118172], [-112148], [-135612], [132072], [-94254], [-148492], [-127308], [-48308], [-32684], [22976], [48988], [107876], [-101436], [-129952], [114744], [-99732], [-25814], [109824], [-166904], [-131292], [24246], [-48226], [-170740], [-129172], [-117738], [112212], [156256], [-91512], [25630], [118216], [41536], [-114962], [148692], [-24676], [-71122], [82888], [170748], [-120724], [87508], [47194], [-123892], [-111548], [119492], [-119952], [146060], [6310], [-145796], [-29946], [-127764], [-173128], [7228], [132314], [-118196], [-33636], [-148980], [-163982], [-107436], [129264], [170084], [-148280], [-187048], [-4482], [19092], [-12574], [108476], [95504], [-20588], [-161564], [36100], [-157880], [143670], [-206084], [75900], [82868], [17392], [154620], [-114892], [-5962], [2604], [-179288], [-242412], [-218630], [170308], [7024], [-207380], [103776], [-143600], [-2434], [48280], [40866], [211588], [-25972], [-60020], [130760], [64020], [84828], [-266320], [-47044], [-6660], [-35118], [-182772], [-229468], [3428], [13744], [-97768], [256252], [-82326], [275328], [20774], [245862], [152164], [21948], [-88396], [102858], [-85444], [-236864], [64078], [172], [-120988], [253856], [-136284], [-66828], [-196816], [-210232], [-117886], [-127056], [-176500], [224308], [-166316], [212818], [-112376], [26508], [-130380], [44448], [-32892], [194900], [-220202], [132896], [-202376]];
    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_o();".
// 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_o(: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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![4, 1]>,<11,R![-28, 1]>,<17,R![-108, 1]>],Snew);
    return Vf;
end function;