
// Make newform 4410.2.a.g in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4410_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_4410_2_a_g();".
// 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_4410_2_a_g();".
// 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_4410_a();"
function MakeCharacter_4410_a()
    N := 4410;
    order := 1;
    char_gens := [3431, 2647, 1081];
    v := [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_4410_a_Hecke(Kf)
    return MakeCharacter_4410_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 := 2;
    raw_aps := [[-1], [0], [-1], [0], [1], [7], [4], [1], [-1], [8], [6], [-3], [-9], [-4], [3], [1], [-12], [-4], [12], [14], [-14], [4], [-12], [2], [-16], [0], [16], [18], [-10], [6], [5], [13], [2], [-4], [4], [-2], [15], [8], [5], [21], [-13], [-12], [10], [26], [3], [-12], [-15], [-4], [20], [-22], [-26], [6], [7], [3], [8], [16], [0], [16], [-2], [-3], [-2], [-9], [8], [-16], [-24], [-10], [-9], [0], [34], [-28], [8], [-36], [19], [26], [1], [-13], [14], [18], [17], [10], [-11], [-14], [12], [40], [16], [36], [25], [10], [28], [33], [-12], [-26], [-8], [12], [24], [-28], [-30], [21], [-14], [2], [36], [-45], [-14], [37], [-8], [-14], [-42], [-12], [-6], [22], [25], [-15], [-8], [-7], [14], [23], [26], [15], [-29], [12], [8], [-12], [-1], [-12], [12], [-6], [4], [-26], [17], [37], [41], [9], [-26], [-2], [17], [-29], [-43], [-22], [6], [-53], [37], [-34], [48], [-10], [12], [-44], [1], [22], [-20], [-29], [23], [25], [-58], [-20], [46], [58], [-44], [-31], [16], [30], [-46], [-44], [-20], [-43], [-18], [33], [10], [10], [-29], [-39], [20], [22], [2], [-44], [-16], [-30], [37], [-30], [-15], [-22], [3], [9], [-47], [2], [39], [-12], [23], [24], [-31], [-30], [2], [-2], [15], [54], [32], [-36], [5], [26], [38], [-12], [0], [-2], [-22], [-35], [0], [-17], [-56], [24], [5], [-37], [-52], [-66], [40], [-10], [16], [-41], [13], [33], [-35], [51], [-4], [-6], [51], [-59], [-8], [-6], [6], [-36], [-53], [-68], [19], [-23], [22], [-19], [-30], [64], [18], [45], [11], [-2], [60], [67], [-24], [38], [54], [6], [-51], [41], [-28], [-29], [-50], [-17], [19], [-57], [2], [-1], [-38], [-26], [-23], [-52], [-59], [66], [14], [14], [24], [-5], [20], [3], [-22], [3], [40], [22], [14], [32], [58], [43], [20], [44], [-47], [11], [-55], [44], [-9], [72], [50], [-4], [56], [-25], [20], [31], [-40], [-10], [36], [53], [9], [-48], [18], [-70], [71], [-46], [4], [-73], [-18], [-2], [36], [-14], [60], [78], [18], [39], [-21], [38], [-66], [38], [73], [-67], [-63], [12], [56], [-66], [-20], [22], [-86], [-49], [-56], [51], [-11], [46], [0], [62], [46], [74], [26], [-84], [23], [-50], [10], [-72], [-83], [-19], [-30], [2], [14], [-38], [-18], [20], [0], [66], [24], [67], [-69], [22], [6], [-13], [-18], [-22], [60], [-24], [36], [-92], [35], [-42], [-48], [-63], [-34], [-6], [1], [-49], [27], [-15], [43], [-12], [30], [6], [34], [39], [-72], [-36], [62], [-10], [10], [-20], [-37], [64], [-77], [-39], [60], [49], [-16], [8], [-50], [54], [60], [-4], [62], [38], [-44], [-33], [85], [30], [-28], [-6], [5], [-68], [-22], [60], [-71], [2], [32], [25], [-68], [-18], [-72], [-85], [28], [-82], [-52], [-35], [-28], [-63], [-26], [-37], [48], [56], [-56], [31], [-28], [63], [31], [94]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4410_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4410_2_a_g();".
// 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_4410_2_a_g(:prec:=1)
    chi := MakeCharacter_4410_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_4410_2_a_g();".
// 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_4410_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4410_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-1, 1]>,<13,R![-7, 1]>,<17,R![-4, 1]>,<19,R![-1, 1]>,<29,R![-8, 1]>,<31,R![-6, 1]>],Snew);
    return Vf;
end function;