
// Make newform 1800.4.f.s in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1800_f_Hecke();"
// 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_f_s();".
// 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_f_s();".
// 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
        poly := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1800_f();"
function MakeCharacter_1800_f()
    N := 1800;
    order := 2;
    char_gens := [1351, 901, 1001, 577];
    v := [2, 2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1800_f_Hecke();"
function MakeCharacter_1800_f_Hecke(Kf)
    N := 1800;
    order := 2;
    char_gens := [1351, 901, 1001, 577];
    char_values := [[1, 0], [1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, 0], [0, 0], [0, 9], [34, 0], [0, 6], [0, 51], [-164, 0], [0, 24], [-146, 0], [100, 0], [0, -164], [-288, 0], [0, 60], [0, -8], [0, -63], [-642, 0], [602, 0], [0, -218], [652, 0], [0, 531], [-388, 0], [0, -222], [820, 0], [0, 383], [-798, 0], [0, -201], [0, -722], [198, 0], [0, -1005], [0, 433], [-2098, 0], [0, -443], [500, 0], [-2302, 0], [-2384, 0], [0, -726], [0, 302], [0, 332], [0, -2059], [-1746, 0], [-1270, 0], [2676, 0], [0, -1573], [0, 1837], [1392, 0], [-540, 0], [0, 2083], [0, 2512], [-4454, 0], [0, -763], [-6828, 0], [5782, 0], [-6394, 0], [0, -931], [0, -3252], [-8298, 0], [1848, 0], [0, -1412], [-1940, 0], [0, 3274], [0, 3283], [0, -4216], [-4916, 0], [0, -5053], [0, -1691], [-6460, 0], [0, -2647], [0, 6048], [862, 0], [0, -3439], [-6216, 0], [0, 6637], [0, 650], [-13324, 0], [0, 3096], [-2022, 0], [0, -3928], [1148, 0], [6310, 0], [13362, 0], [-5146, 0], [-6368, 0], [0, -3069], [4424, 0], [0, -244], [-16884, 0], [0, 2699], [-6122, 0], [0, 4081], [0, 1330], [-9788, 0], [0, -2357], [-6690, 0], [20636, 0], [0, 7976], [2230, 0], [1260, 0], [0, 1450], [19554, 0], [0, -1332], [0, 5679], [0, -1220], [24156, 0], [-2220, 0], [0, 2891], [0, -842], [0, 7623], [-9016, 0], [-18682, 0], [0, 11011], [0, -11404], [0, 4711], [-4172, 0], [-11572, 0], [-936, 0], [0, 7946], [0, -12528], [0, 2027], [-6758, 0], [25098, 0], [0, 1415], [0, -5327], [0, 8578], [-812, 0], [-30270, 0], [394, 0], [37224, 0], [0, 6307], [0, -12832], [18772, 0], [0, -9688], [30092, 0], [0, -9068], [10948, 0], [-1422, 0], [0, 13071], [0, -11702], [0, -709], [17304, 0], [-28012, 0], [32266, 0], [0, 2481], [0, -2532], [8174, 0], [28240, 0], [0, 5236], [0, 16051], [11060, 0], [0, 18044], [0, 17254], [-6596, 0], [0, 8810], [0, 25392], [0, -8036], [-41760, 0], [-34100, 0], [22812, 0], [0, 19491], [52766, 0], [0, -6804], [0, 3223], [0, 21321], [-19938, 0], [0, -24877], [0, 3968], [-33248, 0], [0, 10098], [-1510, 0], [0, 26145], [-5954, 0], [-34610, 0], [-36888, 0], [0, -12473], [2748, 0], [-3676, 0], [15796, 0], [-8794, 0], [0, -23975], [56162, 0], [0, 12011], [63190, 0], [0, 21116], [0, -12507], [0, -23444], [-23406, 0], [0, -242], [0, 3430], [61594, 0], [-54596, 0], [0, -8569], [0, 20244], [25380, 0], [-58906, 0], [0, -6738], [0, -23081], [-5662, 0], [0, 23878], [0, -19439], [0, -13452], [30634, 0], [58916, 0], [0, 24238], [-41166, 0], [-74850, 0], [0, -12575], [38204, 0], [0, -2076], [5604, 0], [-1148, 0], [0, 35905], [-2898, 0], [0, 25435], [0, -19252], [40452, 0], [28674, 0], [0, -28171], [-20708, 0], [0, -25368], [0, -12759], [-46162, 0], [-65320, 0], [-22472, 0], [0, -51535], [0, 9646], [-78030, 0], [0, -37449], [-76104, 0], [0, 22483], [75546, 0], [0, -7586], [71308, 0], [33896, 0], [11108, 0], [0, -4586], [0, 38460], [35422, 0], [0, -25441], [-79618, 0], [-46132, 0], [0, 13304], [5068, 0], [0, -4535], [20830, 0], [0, 14969], [-70044, 0], [0, 41893], [-36102, 0], [33500, 0], [0, 24128], [0, -7344], [-31488, 0], [0, 37344], [53534, 0], [0, -43723], [-106758, 0], [-96262, 0], [0, -13078], [0, -45577], [0, 50629], [0, 63887], [0, -32952], [-286, 0], [0, -7584], [0, 29541], [23204, 0], [95730, 0], [-82296, 0], [0, -69686], [0, 18255], [-57954, 0], [0, -6224], [0, 9791], [3524, 0], [0, 44425], [0, -10541], [0, -12936], [78166, 0], [-110054, 0], [33366, 0], [0, -11232], [-7672, 0], [0, 71616], [-77866, 0], [0, -52304], [13724, 0], [0, 38517], [0, 28905], [-142176, 0], [-83728, 0], [28534, 0], [0, -28174], [0, -49839], [32418, 0], [0, 43300], [116994, 0], [-126956, 0], [0, -17943], [50166, 0], [0, -67136], [0, 16199], [0, 13365], [-111336, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_4_f_s();".
// 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_f_s(:prec:=2)
    chi := MakeCharacter_1800_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_f_s();".
// 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_f_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![324, 0, 1]>,<11,R![-34, 1]>],Snew);
    return Vf;
end function;