
// Make newform 1800.4.f.w in Magma, downloaded from the LMFDB on 24 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_w();".
// 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_w();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, 26], [59, 0], [0, -28], [0, -5], [-109, 0], [0, -194], [-32, 0], [10, 0], [0, -198], [-117, 0], [0, -388], [0, 68], [0, -18], [392, 0], [-710, 0], [0, -253], [612, 0], [0, 549], [-414, 0], [0, -121], [-81, 0], [0, -1502], [234, 0], [0, 1172], [0, -1125], [1234, 0], [0, 567], [0, -2358], [1692, 0], [0, -229], [-2781, 0], [1472, 0], [1322, 0], [0, 298], [0, 341], [0, -684], [0, -2344], [-1111, 0], [2042, 0], [-5270, 0], [0, -613], [0, -1174], [-3428, 0], [2339, 0], [0, -3932], [0, -6084], [-4996, 0], [0, 3222], [2736, 0], [1673, 0], [-5355, 0], [0, 5490], [0, 3150], [176, 0], [2394, 0], [0, -6256], [4802, 0], [0, -2123], [0, -8834], [0, 1369], [10426, 0], [0, 3574], [0, -9036], [10233, 0], [0, 4627], [0, -4901], [4482, 0], [0, -1210], [-9882, 0], [0, -11260], [0, 3230], [-11575, 0], [0, -18], [10710, 0], [0, -3788], [10539, 0], [-5581, 0], [5193, 0], [4788, 0], [-8006, 0], [0, 2395], [-1864, 0], [0, 5463], [12969, 0], [0, 18313], [-12492, 0], [0, -4428], [0, 1084], [-13082, 0], [0, -3014], [3564, 0], [15796, 0], [0, -10908], [21946, 0], [6395, 0], [0, 5615], [-4112, 0], [0, -2167], [0, 19444], [0, 20416], [-3127, 0], [-22580, 0], [0, -829], [0, -7119], [0, -8217], [-90, 0], [-17117, 0], [0, -15120], [0, 6570], [0, -18846], [-16316, 0], [20170, 0], [12726, 0], [0, -2196], [0, 16884], [0, -4018], [19071, 0], [17424, 0], [0, 5382], [0, 4496], [0, 3249], [-13399, 0], [18148, 0], [-4868, 0], [-17366, 0], [0, 21824], [0, 31428], [14292, 0], [0, 13950], [-38736, 0], [0, -3664], [-19557, 0], [13283, 0], [0, 24840], [0, 18044], [0, 6174], [-1998, 0], [-7156, 0], [-27922, 0], [0, -22636], [0, -26559], [-12580, 0], [-11344, 0], [0, -14786], [0, 29259], [13651, 0], [0, 29016], [0, 21412], [1170, 0], [0, 12655], [0, -32764], [0, -29844], [-15628, 0], [-42974, 0], [13342, 0], [0, -3005], [-16204, 0], [0, 30200], [0, -29583], [0, -6480], [40171, 0], [0, -50801], [0, -58338], [-51202, 0], [0, 1764], [52579, 0], [0, 41288], [13775, 0], [-49670, 0], [2074, 0], [0, 14005], [-47096, 0], [42111, 0], [-7613, 0], [-22982, 0], [0, -49528], [-30106, 0], [0, -12844], [-513, 0], [0, 25786], [0, 30353], [0, -62428], [-43420, 0], [0, -18982], [0, 30763], [-74177, 0], [-2560, 0], [0, 55441], [0, -50733], [23219, 0], [-9734, 0], [0, 73499], [0, 41306], [43875, 0], [0, -15282], [0, 35077], [0, 590], [59562, 0], [52036, 0], [0, -27664], [4653, 0], [62316, 0], [0, 39262], [-36442, 0], [0, -5540], [16110, 0], [40328, 0], [0, -81566], [26158, 0], [0, -58832], [0, -31761], [-47750, 0], [-44487, 0], [0, 23194], [87115, 0], [0, 63738], [0, -67190], [-4474, 0], [-84340, 0], [-75335, 0], [0, 12762], [0, 26271], [-81550, 0], [0, -41737], [-62896, 0], [0, -76348], [74785, 0], [0, 19502], [38745, 0], [35450, 0], [-53887, 0], [0, -69192], [0, 85914], [-36045, 0], [0, -91800], [98995, 0], [106308, 0], [0, 82129], [32239, 0], [0, -51922], [-38116, 0], [0, 42899], [-82624, 0], [0, -8594], [-49028, 0], [-23815, 0], [0, -50152], [0, 32976], [4325, 0], [0, -8550], [-67427, 0], [0, 48344], [-77985, 0], [105200, 0], [0, 67815], [0, -114282], [0, 59517], [0, -39142], [0, -50171], [86472, 0], [0, 89236], [0, -73589], [49727, 0], [-67370, 0], [-104670, 0], [0, 76527], [0, -67262], [15956, 0], [0, -86321], [0, 52281], [24184, 0], [0, -81694], [0, -114812], [0, 76271], [52120, 0], [-30034, 0], [50103, 0], [0, 8820], [85230, 0], [0, -107384], [1684, 0], [0, 23635], [52808, 0], [0, 76546], [0, -43488], [-43200, 0], [-70110, 0], [-8914, 0], [0, 11196], [0, -26613], [94581, 0], [0, -52156], [89478, 0], [117962, 0], [0, 94104], [-67964, 0], [0, -117081], [0, -125937], [0, -114102], [-25856, 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_w();".
// 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_w(: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_w();".
// 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_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![676, 0, 1]>,<11,R![-59, 1]>],Snew);
    return Vf;
end function;