
// Make newform 810.4.e.u in Magma, downloaded from the LMFDB on 25 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_u();".
// 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_u();".
// 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], [-6, 6], [0, -68], [78, 0], [44, 0], [0, -120], [-126, 126], [0, 244], [-304, 0], [0, 480], [-104, 104], [-600, 600], [-258, 0], [0, -534], [-362, 362], [0, 268], [-972, 0], [470, 0], [-1244, 1244], [-396, 396], [-972, 0], [46, -46], [1506, -1506], [0, 1474], [924, 0], [698, 0], [0, 222], [-1906, 0], [0, -2874], [798, -798], [0, 700], [0, -114], [-1064, 1064], [0, 1948], [2060, 0], [0, 1248], [1146, -1146], [-1146, 0], [-118, 0], [-1692, 1692], [0, -3350], [-3606, 0], [2696, 0], [0, 4], [1162, -1162], [2400, -2400], [0, 2314], [-18, 0], [0, 5868], [4330, -4330], [498, 0], [0, -642], [7968, -7968], [-4218, 0], [848, 0], [1504, -1504], [1308, -1308], [0, 5932], [0, -5226], [4448, 0], [0, 9132], [2170, -2170], [-7674, 7674], [-9596, 9596], [0, -12158], [0, -10320], [2158, -2158], [330, -330], [-8664, 0], [-3782, 3782], [0, -11276], [980, 0], [0, 4200], [-13338, 13338], [-7192, 0], [0, 2316], [0, 12358], [0, -3306], [14506, -14506], [-6480, 0], [11894, 0], [12688, -12688], [-4968, 4968], [-11508, 0], [-1082, 1082], [11238, -11238], [0, 2302], [15876, 0], [-4644, 4644], [2426, 0], [0, -234], [0, -14204], [4920, 0], [0, 4458], [4212, 0], [-11212, 0], [14018, 0], [-18200, 18200], [-11826, 0], [0, 2952], [-3084, 3084], [0, 4756], [-11014, 0], [852, -852], [15546, 0], [0, 8616], [-17510, 17510], [0, 13894], [-6496, 0], [0, 570], [2140, -2140], [14660, 0], [456, -456], [0, 23452], [7224, 0], [0, -19146], [-27810, 27810], [0, 30598], [3778, -3778], [27198, -27198], [32316, 0], [-29324, 29324], [22782, 0], [-26054, 26054], [-5976, 0], [5110, -5110], [0, -17336], [-13660, 0], [0, -1320], [0, -15860], [22160, 0], [0, -13116], [0, -32846], [-11982, 0], [0, 21076], [0, -22086], [21384, 0], [5228, 0], [38010, -38010], [0, -38642], [-15432, 0], [-3886, 0], [-27552, 27552], [-15104, 15104], [12306, -12306], [0, 47500], [4272, 0], [0, 27796], [-39996, 0], [-3772, 0], [0, 5784], [8440, -8440], [31920, -31920], [34652, 0], [-1404, 1404], [-7654, 0], [0, -11298], [-28968, 28968], [46410, 0], [0, 41506], [-18246, 0], [0, -25998], [-14616, 14616], [-2968, 0], [9052, -9052]];
    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_u();".
// 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_u(: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_u();".
// 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_u( : 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![36, 6, 1]>],Snew);
    return Vf;
end function;