
// Make newform 7440.2.a.bf in Magma, downloaded from the LMFDB on 06 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7440_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_7440_2_a_bf();".
// 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_7440_2_a_bf();".
// 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 := [-3, 0, 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_7440_a();"
function MakeCharacter_7440_a()
    N := 7440;
    order := 1;
    char_gens := [6511, 1861, 4961, 2977, 5521];
    v := [1, 1, 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_7440_a_Hecke(Kf)
    return MakeCharacter_7440_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]];
    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 := [[0, 0], [-1, 0], [1, 0], [-3, 1], [-2, -2], [3, 1], [0, 0], [-2, 2], [0, -2], [1, 1], [1, 0], [1, -5], [0, 2], [0, 0], [4, 2], [0, 0], [9, 3], [-4, 2], [-1, -5], [-5, 5], [3, 1], [-10, -4], [0, -2], [-5, -1], [-10, -4], [-12, -2], [9, 5], [4, 6], [6, -6], [6, 4], [2, -6], [5, -1], [2, 2], [-4, -8], [8, 2], [-10, 4], [-6, 4], [-1, -1], [-4, -12], [-10, 0], [-12, 4], [-4, -6], [-9, 1], [-2, 4], [-10, -2], [6, 4], [-18, 6], [-2, -14], [-14, 4], [2, 0], [-4, 8], [0, 4], [-2, 4], [8, 4], [4, -12], [0, 12], [-3, -15], [0, 0], [-5, 9], [-16, 2], [-23, 5], [4, -8], [-17, -1], [-11, -1], [1, -5], [-4, 4], [-2, -12], [17, -1], [24, -4], [-10, 6], [8, -8], [15, 9], [8, -4], [4, -14], [-22, 6], [0, 2], [-9, 15], [-22, -4], [-11, 9], [-4, 6], [9, -9], [-10, 14], [1, -1], [27, 5], [-4, -12], [-38, 0], [-15, 5], [-1, 13], [-13, -13], [-8, 12], [4, 18], [11, -3], [14, 6], [-6, -14], [-4, -8], [-8, -18], [1, 9], [-12, 2], [-14, -14], [-6, -6], [-9, 3], [0, 0], [-16, 14], [3, -13], [-24, 4], [8, 6], [16, -8], [-30, 4], [13, -1], [-28, -6], [17, 5], [25, 3], [2, 0], [22, 8], [-8, -24], [-33, -5], [-34, -6], [24, -4], [-16, 0], [17, 3], [-18, -12], [-17, 1], [-16, 8], [-10, 4], [-40, 0], [-30, -12], [-10, -8], [18, -18], [11, 11], [34, 8], [-14, -4], [16, 4], [16, 8], [-5, 17], [23, 7], [-18, -10], [-24, 4], [2, 10], [-2, 10], [9, -15], [-2, 18], [-37, -1], [0, -28], [-24, -10], [-20, -14], [-13, -11], [8, -10], [26, 0], [8, 20], [28, 4], [-8, 18], [11, -1], [-46, 2], [30, 12], [23, -1], [18, 6], [-14, -2], [-3, -15], [-30, 4], [-29, -13], [24, 2], [10, 14], [6, 10], [21, -9], [10, -16], [4, 0], [20, -4], [12, 10], [-14, 12], [-6, 26], [8, -12], [-38, 4], [27, 1], [2, 12], [0, 12], [23, -5], [32, 0], [-20, -2], [7, 3], [-26, 0], [7, -1], [40, 12], [10, -16], [18, 2], [2, 16], [57, 1], [16, 2], [7, -13], [-16, 14], [13, 11], [7, -3], [-24, 6], [-6, -20], [-5, 15], [-36, -2], [22, -6], [-28, 14], [26, 16], [2, 24], [18, 12], [10, -8], [4, -20], [40, 6], [-6, 0], [-9, -15], [26, 2], [14, -2], [-12, -14], [42, -12], [38, -6], [49, 11], [15, -5], [-11, -7], [-10, 8], [30, 18], [18, -2], [7, 15], [-4, 2], [12, -10], [6, -36], [38, 12], [38, -10], [46, -4], [17, 21], [-2, -28], [18, -16], [24, 16], [6, 22], [26, 22], [27, 25], [35, 9], [-26, 14], [10, -18], [43, -9], [-26, 14], [-12, -20], [2, -12], [-46, 8], [-56, 4], [-40, -8], [-56, 2], [-16, -4], [16, 0], [20, 22], [-4, 36], [-15, -9], [14, -6], [12, -20], [56, 4], [10, 4], [24, -10], [12, -22], [0, -16], [-26, 10], [62, 4], [-21, 17], [-10, -16], [4, 8], [-8, -16], [40, -10], [29, 9], [-48, 10], [-14, 0], [36, 10], [-6, -6], [44, -4], [6, -8], [66, -4], [31, 11], [-42, 8], [18, 26], [-16, 16], [7, -27], [-4, 20], [-8, -30], [1, -15], [-24, -18], [-52, -14], [40, 10], [-18, -26], [42, -16], [-26, 6], [-6, 4], [26, 32], [-25, -17], [-4, 0], [-3, -37], [12, -36], [30, -22], [-31, 29], [2, 24], [-46, -20], [0, 16], [-39, 11], [-7, -21], [15, -33], [-22, 16], [36, 0], [-18, 26], [-34, 2], [40, 6], [-12, -12], [-12, 4], [-30, -20], [14, 16], [4, 42], [28, 6], [2, 8], [-30, 22], [26, -8], [-12, 30], [37, 29], [4, -10], [-22, -18], [4, 14], [-18, 28], [0, -24], [-32, 24], [-32, -22], [13, -31], [-42, 28], [-15, -13], [-32, 14], [-23, 5], [-24, 4], [-26, 20], [52, 8], [5, -47], [76, -8], [30, 2], [-10, 24], [0, -48], [-38, 18], [36, -30], [-46, -2], [-12, 26], [26, 4], [-36, 0], [-54, -10], [-48, 8], [17, 11], [52, 4], [9, 21], [-36, -20], [30, -20], [-35, -5], [14, 22], [-6, -6], [78, -6], [16, 12], [-66, -8], [-7, 7], [4, 6], [-80, -8], [10, -32], [-28, -16], [-6, 46], [-48, -20], [-46, 14], [-16, -10], [40, -18], [3, -29], [24, 10], [-49, -3], [-5, -49], [-45, -11], [4, 44], [-28, 12], [42, 6], [35, 25], [34, -30], [-8, -14], [56, -6], [-40, 12], [-7, -1], [6, 30], [-39, 11], [-4, -18], [24, -22], [-43, -29], [1, 37], [-14, -6], [-56, 12], [4, -44], [64, -4], [44, 18], [70, -14], [-19, 3], [-14, 46], [-4, 54], [-28, 14], [-8, -8], [19, -7], [-43, -7], [-5, -23], [10, 28], [32, -40], [18, -4], [-66, -4], [-3, 13], [-62, -20], [-28, 4], [41, 17], [-12, 20], [-81, -9], [-26, -26], [-8, -6], [-33, 15], [34, 10], [28, 16], [-17, 25], [34, 4], [-44, 32], [-22, 4], [-54, 0], [44, -14], [-6, -38], [-37, 27], [52, -12], [-4, 38], [31, 7], [69, -9], [8, -18], [-9, 41], [4, -14], [-18, 2], [26, 20], [73, -11], [-68, 0], [-8, -48], [-34, -22], [49, -1], [44, -16], [32, -22], [-37, -11], [21, -3], [42, 8], [-28, -30], [8, 24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7440_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7440_2_a_bf();".
// 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_7440_2_a_bf(:prec:=2)
    chi := MakeCharacter_7440_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(3067) - 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_7440_2_a_bf();".
// 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_7440_2_a_bf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7440_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![6, 6, 1]>,<11,R![-8, 4, 1]>,<13,R![6, -6, 1]>,<17,R![0, 1]>,<19,R![-8, 4, 1]>],Snew);
    return Vf;
end function;