
// Make newform 4410.2.a.bb 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_bb();".
// 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_bb();".
// 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], [2], [-2], [-2], [-6], [-4], [0], [2], [2], [-10], [-8], [8], [-2], [-4], [-8], [-4], [6], [2], [-8], [-4], [10], [-18], [2], [-16], [0], [10], [-2], [12], [12], [-14], [-14], [20], [0], [10], [8], [-12], [6], [10], [-20], [-6], [-6], [-6], [2], [-4], [-28], [12], [-16], [-26], [-26], [20], [20], [-6], [-24], [22], [-10], [2], [20], [8], [-18], [-4], [8], [14], [6], [-4], [34], [-4], [-16], [30], [34], [4], [-18], [-28], [28], [36], [-26], [-32], [8], [12], [26], [-18], [22], [26], [-20], [0], [30], [-18], [-20], [28], [8], [-20], [18], [4], [36], [-18], [18], [-20], [2], [28], [6], [24], [40], [36], [-34], [40], [-10], [26], [-4], [4], [-14], [-18], [18], [16], [-12], [12], [-28], [-46], [-34], [-16], [-26], [-2], [-36], [46], [-32], [-42], [48], [28], [30], [36], [24], [-8], [-2], [-6], [44], [-18], [-12], [-50], [44], [34], [0], [-52], [32], [-44], [0], [-2], [42], [22], [-36], [18], [-2], [-20], [8], [4], [-14], [8], [-30], [18], [-14], [-36], [14], [32], [44], [-42], [-56], [0], [54], [34], [-34], [42], [28], [-18], [-30], [-10], [-54], [20], [-52], [52], [44], [-56], [60], [-26], [-18], [-16], [-6], [26], [-4], [-18], [-48], [-18], [24], [-12], [-18], [52], [-18], [34], [46], [-46], [36], [48], [-14], [10], [20], [60], [-18], [-34], [-48], [-44], [-10], [22], [-42], [-56], [-20], [-56], [44], [-4], [-2], [0], [50], [6], [-14], [36], [16], [32], [-2], [-30], [18], [40], [-6], [-66], [-38], [56], [20], [-20], [-16], [-40], [-54], [-6], [-8], [-24], [-70], [-24], [2], [-22], [16], [-12], [-20], [-20], [-36], [-30], [-66], [-20], [8], [62], [34], [18], [24], [38], [-42], [36], [-20], [-32], [-54], [-58], [6], [16], [-30], [36], [-30], [4], [16], [46], [32], [-58], [-36], [32], [-50], [-38], [-52], [-72], [72], [32], [4], [-68], [-14], [-50], [22], [50], [34], [-32], [60], [46], [44], [-2], [30], [-42], [18], [-76], [-68], [-70], [-22], [-16], [-60], [20], [-70], [-72], [-72], [54], [-10], [-40], [-8], [-40], [-60], [12], [76], [84], [50], [-74], [-32], [62], [-10], [30], [-16], [34], [-28], [44], [56], [-20], [-26], [-34], [-22], [-50], [0], [68], [24], [66], [-30], [-28], [-52], [-26], [-42], [-82], [0], [-46], [54], [-56], [-76], [72], [-82], [18], [70], [24], [80], [10], [-42], [16], [36], [6], [64], [6], [30], [48], [-34], [52], [-10], [-30], [-32], [58], [66], [-90], [16], [-36], [38], [18], [-4], [-22], [14], [-70], [-62], [58], [-50], [-28], [-22], [-38], [-12], [-16], [62], [44], [-48], [22], [2], [14], [-28], [30], [-78], [-82], [-10], [20], [104], [-12], [30], [-16], [10], [-70], [6], [18], [32], [-56], [-36], [-14], [62], [36], [-68], [-94], [-10], [-82], [60], [-50], [-8], [-60], [-34], [32], [36], [6], [-50], [104], [56], [-10], [-48]];
    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_bb();".
// 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_bb(: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_bb();".
// 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_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4410_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-2, 1]>,<13,R![2, 1]>,<17,R![2, 1]>,<19,R![6, 1]>,<29,R![0, 1]>,<31,R![-2, 1]>],Snew);
    return Vf;
end function;