
// Make newform 4410.2.a.bg in Magma, downloaded from the LMFDB on 25 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_bg();".
// 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_bg();".
// 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], [-3], [1], [-6], [1], [-9], [-6], [-8], [-7], [3], [2], [9], [-9], [0], [-8], [8], [0], [4], [-10], [0], [6], [10], [12], [4], [12], [-16], [0], [-1], [3], [-12], [4], [6], [-10], [-23], [20], [3], [9], [3], [-2], [-12], [-16], [-15], [16], [23], [-8], [-12], [4], [6], [6], [1], [-15], [0], [0], [0], [16], [-10], [27], [-14], [-9], [-14], [-24], [28], [-6], [-7], [-22], [0], [-26], [12], [-18], [19], [2], [23], [21], [12], [-14], [27], [-26], [-9], [2], [-12], [40], [-26], [-12], [-21], [14], [-30], [-1], [-6], [0], [-16], [-36], [-4], [24], [-42], [-15], [28], [8], [8], [9], [42], [-21], [20], [-44], [-24], [24], [42], [-26], [1], [29], [18], [-23], [20], [-27], [-2], [33], [9], [24], [28], [-34], [-9], [-12], [-32], [30], [-46], [0], [1], [43], [35], [45], [-10], [38], [-27], [-23], [-51], [22], [6], [9], [25], [-30], [-4], [-6], [-14], [-30], [19], [-18], [-32], [3], [-13], [33], [8], [-48], [-10], [30], [-22], [57], [10], [48], [-6], [-36], [32], [-45], [42], [3], [44], [22], [-1], [45], [36], [4], [24], [-58], [-8], [-6], [-25], [-54], [61], [16], [-55], [27], [17], [-6], [51], [6], [-25], [46], [-7], [-60], [-8], [-30], [-7], [0], [-42], [54], [-55], [-46], [24], [-24], [-24], [-26], [22], [55], [-48], [-57], [-20], [0], [-21], [67], [-4], [12], [44], [-42], [-6], [-35], [-13], [45], [-15], [21], [56], [-68], [-63], [47], [24], [-28], [-42], [-54], [-53], [-60], [11], [-11], [-10], [15], [46], [12], [-26], [51], [-9], [-6], [30], [7], [16], [2], [-78], [-78], [73], [-21], [-4], [-21], [2], [-21], [-45], [-47], [-18], [15], [-10], [4], [-63], [34], [-13], [24], [22], [10], [42], [-77], [12], [-45], [-58], [-15], [52], [38], [-14], [-46], [-50], [79], [-48], [-70], [-43], [57], [-21], [-16], [57], [52], [58], [-18], [-76], [-27], [10], [-9], [-18], [78], [54], [39], [-55], [-12], [22], [-30], [69], [-80], [40], [-3], [20], [-48], [68], [-52], [6], [-2], [-24], [-13], [-3], [24], [-18], [86], [33], [-5], [-21], [-18], [28], [30], [52], [14], [0], [29], [-24], [-47], [23], [28], [-48], [-78], [-88], [-18], [46], [-36], [77], [36], [-16], [-24], [19], [-71], [-58], [-18], [-42], [-58], [-66], [-36], [52], [-64], [18], [51], [31], [-52], [-36], [19], [80], [30], [-36], [-36], [-24], [-24], [-73], [-90], [-48], [-15], [70], [98], [9], [-43], [11], [-27], [-17], [-48], [-66], [-62], [62], [45], [-6], [16], [18], [-50], [-84], [54], [101], [-96], [67], [3], [44], [-5], [-22], [24], [62], [90], [12], [16], [18], [14], [-38], [51], [-13], [18], [4], [-12], [-49], [-18], [24], [-8], [-19], [54], [10], [63], [46], [-78], [30], [-55], [92], [-36], [-42], [13], [-30], [-9], [-90], [13], [-72], [-12], [16], [39], [0], [33], [-65], [-96]];
    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_bg();".
// 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_bg(: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_bg();".
// 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_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4410_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![3, 1]>,<13,R![-1, 1]>,<17,R![6, 1]>,<19,R![-1, 1]>,<29,R![6, 1]>,<31,R![8, 1]>],Snew);
    return Vf;
end function;