
// Make newform 810.4.e.n in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_810_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_810_e_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_810_4_e_n();".
// 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_810_4_e_n();".
// 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, -1, 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_810_e();"
function MakeCharacter_810_e()
    N := 810;
    order := 3;
    char_gens := [731, 487];
    v := [1, 3];
    // 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_810_e_Hecke();"
function MakeCharacter_810_e_Hecke(Kf)
    N := 810;
    order := 3;
    char_gens := [731, 487];
    char_values := [[0, -1], [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 := [[2, -2], [0, 0], [0, -5], [-14, 14], [-3, 3], [0, -47], [-39, 0], [32, 0], [0, 99], [-51, 51], [0, -83], [314, 0], [0, 108], [-299, 299], [-531, 531], [564, 0], [0, -12], [-230, 230], [0, 268], [120, 0], [1106, 0], [739, -739], [-1086, 1086], [-120, 0], [1642, -1642], [-33, 33], [0, 1198], [-1542, 0], [-556, 0], [0, -1605], [1334, 0], [0, 2883], [-282, 282], [0, 2494], [0, -2595], [-1229, 1229], [0, 1591], [-457, 0], [0, 1164], [-3942, 3942], [-1212, 0], [2288, 0], [1938, -1938], [0, 1498], [-2124, 0], [-385, 0], [0, -3170], [-1388, 1388], [4644, -4644], [0, -4736], [2814, 0], [0, 2202], [-3485, 3485], [-6345, 0], [0, -525], [-5196, 5196], [-7479, 0], [-856, 0], [7054, -7054], [-1014, 1014], [0, -992], [0, 4950], [-4777, 0], [0, 7692], [2932, -2932], [-8352, 8352], [3070, -3070], [0, 1672], [0, 5076], [-8594, 8594], [-12711, 12711], [-1464, 0], [7630, -7630], [0, 3883], [-13768, 0], [0, 14139], [-567, 567], [-6685, 0], [0, -4572], [0, 25], [0, -12453], [-5048, 5048], [5400, 0], [-6298, 0], [6208, -6208], [3360, -3360], [14394, 0], [916, -916], [-8550, 8550], [0, -3734], [9840, 0], [17280, -17280], [-4588, 0], [0, -636], [0, 11716], [4653, 0], [0, -16479], [3120, 0], [17645, 0], [-2182, 0], [4033, -4033], [-960, 0], [0, 23754], [22536, -22536], [0, -17726], [17168, 0], [-7542, 7542], [-15543, 0], [0, -16026], [-10469, 10469], [0, 8074], [26855, 0], [0, -24447], [-1850, 1850], [21728, 0], [-23862, 23862], [0, -10523], [5484, 0], [0, 26784], [12120, -12120], [0, 18226], [11062, -11062], [9348, -9348], [19248, 0], [17710, -17710], [-19437, 0], [19516, -19516], [17358, 0], [-24428, 24428], [0, 21418], [-664, 0], [0, 34209], [0, -6857], [-23719, 0], [0, 14418], [0, 4849], [-36258, 0], [0, 18877], [0, 16200], [-26760, 0], [-10510, 0], [28230, -28230], [0, 39868], [32394, 0], [34820, 0], [1146, -1146], [19393, -19393], [8430, -8430], [0, -15470], [5871, 0], [0, 11299], [29682, 0], [40316, 0], [0, 21945], [-24911, 24911], [-33264, 33264], [-23191, 0], [-2160, 2160], [2066, 0], [0, 22233], [17754, -17754], [33891, 0], [0, -51074], [20967, 0], [0, -31749], [-47325, 47325], [2363, 0], [-45569, 45569]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_810_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_810_4_e_n();".
// 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_810_4_e_n(:prec:=2)
    chi := MakeCharacter_810_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_810_4_e_n();".
// 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_810_4_e_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_810_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![196, 14, 1]>,<11,R![9, 3, 1]>],Snew);
    return Vf;
end function;