
// Make newform 7448.2.a.be in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7448_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_7448_2_a_be();".
// 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_7448_2_a_be();".
// 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 := [-14, -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_7448_a();"
function MakeCharacter_7448_a()
    N := 7448;
    order := 1;
    char_gens := [1863, 3725, 3041, 3137];
    v := [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_7448_a_Hecke(Kf)
    return MakeCharacter_7448_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 := [[0, 0], [2, 0], [1, 0], [0, 0], [-2, 1], [-2, 0], [-3, -1], [1, 0], [1, -2], [-4, 0], [4, 0], [2, 0], [-4, 2], [-1, 0], [-2, 1], [2, -2], [4, 0], [-8, -1], [0, 0], [2, 2], [-8, 1], [-8, 2], [-3, -2], [-8, -2], [0, -2], [3, 0], [-10, 0], [-12, 2], [-2, -2], [10, 2], [2, -4], [3, 3], [8, -1], [-2, 3], [-3, 4], [0, -2], [-1, 4], [-15, 2], [0, 4], [-14, 2], [-2, 4], [6, 2], [-21, 0], [10, 4], [-1, -4], [-3, 0], [-6, 6], [4, -4], [16, 2], [13, -1], [1, -1], [7, -5], [-4, 2], [15, -4], [16, -2], [13, -3], [18, -2], [-11, 2], [-4, -1], [-6, -2], [17, 0], [-8, 6], [26, 0], [7, -1], [5, -8], [-4, -4], [-14, 0], [-4, -4], [1, -8], [-7, -5], [-6, -4], [-22, 1], [-8, 8], [2, -2], [-14, 4], [-22, 0], [25, 3], [25, -1], [4, 4], [14, 0], [-11, -2], [10, 2], [-8, 4], [-8, -4], [0, -8], [13, -3], [0, 0], [8, 1], [-20, 1], [-10, 3], [14, 1], [21, 2], [-6, -4], [-1, -2], [5, -8], [-9, -6], [2, 0], [26, 0], [16, 6], [-17, 0], [-32, 0], [-15, 4], [20, -2], [18, -8], [-29, 2], [8, -5], [7, -1], [-3, 0], [-10, 6], [20, -2], [0, -6], [-25, -3], [-7, -4], [-3, -2], [-17, 0], [38, 2], [13, -3], [-3, 4], [-5, 1], [-34, 2], [36, 2], [2, 2], [-20, -4], [8, -6], [7, 7], [-15, 0], [-15, 0], [-31, 1], [31, -4], [-34, 0], [-17, 3], [-4, -10], [-4, 0], [4, 5], [43, 0], [9, 8], [14, 0], [-14, 0], [8, 2], [-1, -4], [-20, 10], [-4, 7], [-18, -7], [-22, 6], [28, 4], [-18, 6], [29, -4], [-22, 6], [-3, -4], [-16, -4], [0, -10], [-27, 7], [-5, 11], [26, -8], [20, 4], [18, 2], [-33, 2], [33, 0], [7, 0], [-8, 0], [44, 0], [30, -4], [16, -8], [-28, -2], [4, 12], [26, -8], [-16, 0], [17, 3], [28, -4], [20, -7], [46, 2], [14, 10], [-4, 12], [-49, 4], [-46, 2], [21, 8], [13, 2], [25, -8], [-8, 8], [-44, 3], [-19, 0], [-24, 10], [0, -4], [24, 0], [-33, -5], [-3, -5], [-14, -4], [-36, 8], [6, -8], [-3, -2], [-22, 6], [-37, -5], [-44, 6], [-38, -2], [-20, -8], [-16, -4], [25, -12], [-5, 0], [-3, 8], [-9, 12], [10, -2], [20, -14], [32, -6], [-22, -2], [-12, 8], [4, 5], [-30, 5], [38, 2], [55, 1], [-18, -10], [-41, 0], [6, 8], [42, -3], [8, 6], [-10, -6], [26, -4], [31, -2], [-8, 8], [22, -8], [-20, 9], [-8, -2], [-14, -10], [-4, 8], [-43, 1], [0, -6], [-41, 4], [8, -4], [20, 10], [-36, 8], [-45, -4], [-17, -8], [0, 4], [0, -6], [18, 12], [-1, 7], [-39, -3], [43, 4], [25, -9], [13, 14], [-42, 6], [40, -2], [-41, 0], [3, 14], [-8, -14], [10, -2], [-6, 9], [27, 7], [-24, -8], [14, 0], [22, 7], [3, 16], [-13, -11], [24, 12], [-2, 0], [44, -1], [-7, 18], [-56, 3], [28, -10], [26, -4], [30, 8], [-22, -12], [14, -10], [-1, -15], [0, 12], [5, -16], [0, -10], [28, -2], [56, -5], [22, -10], [7, 4], [-40, -4], [-48, 2], [31, -12], [-38, -3], [-8, -4], [-48, 0], [6, -7], [-10, 16], [12, -2], [37, -8], [-38, -2], [32, 8], [14, -3], [0, 12], [61, -3], [55, -4], [17, -1], [32, 4], [-19, -12], [-32, 0], [33, -4], [-3, 16], [-14, -2], [-12, 10], [6, 2], [-2, 8], [18, 2], [39, 5], [-62, 2], [-2, 1], [35, 12], [32, -6], [67, 0], [-36, -2], [34, -5], [20, 4], [-24, 0], [-6, 8], [-13, -5], [-29, 4], [29, -16], [19, -4], [38, 8], [68, 0], [8, 8], [-30, 0], [23, -12], [-42, 8], [-69, 5], [-24, -13], [-14, 2], [-5, 13], [-8, -12], [-62, 8], [-3, -16], [14, -12], [2, 10], [-30, 16], [-30, 4], [-73, 5], [-12, 1], [38, 10], [-40, 4], [26, -5], [59, -1], [31, -8], [-86, 0], [12, 12], [24, -5], [39, -10], [-52, 4], [-20, 15], [-42, 2], [22, 12], [18, 6], [-68, 6], [2, -12], [-46, -4], [38, 2], [-4, -7], [-20, -12], [-34, -10], [-48, -3], [18, -6], [-30, -10], [10, -14], [15, 2], [45, 6], [53, 0], [-46, -4], [-73, -3], [22, -8], [-30, 6], [-12, 20], [-58, 1], [-20, 18], [-14, -16], [46, -8], [-30, 4], [60, 0], [-26, 4], [-35, 4], [-22, -2], [41, -3], [-5, 21], [-28, -4], [-21, 10], [0, -17], [0, -1], [86, -4], [14, -10], [31, -8], [41, 1], [23, -4], [-52, -6], [64, -8], [29, 6], [47, 12], [-27, -11], [6, 6], [-42, 14], [-48, 0], [-35, 10], [15, -1], [34, -14], [-30, 2], [22, 6], [12, 2], [-20, 12], [3, -16], [46, -4], [56, -11], [40, -2], [-24, -6], [-22, -6], [98, 1], [-49, -3], [10, 10], [52, 0], [-17, -1], [-22, -12], [-68, 1], [0, -22], [-59, -7], [-27, 16], [-89, 4], [-12, 12], [-2, 6], [27, -16], [-2, 16], [-36, 2], [-12, 20], [-39, -12], [16, -20], [40, -4], [28, -8], [60, -6], [11, 16], [37, 0], [2, -19]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7448_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7448_2_a_be();".
// 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_7448_2_a_be(:prec:=2)
    chi := MakeCharacter_7448_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_7448_2_a_be();".
// 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_7448_2_a_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<5,R![-1, 1]>,<11,R![-12, 3, 1]>,<13,R![2, 1]>,<17,R![-2, 7, 1]>],Snew);
    return Vf;
end function;