
// Make newform 7448.2.a.x 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_x();".
// 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_x();".
// 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 := [-2, 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_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, 1], [1, 0], [0, 0], [1, 3], [2, -1], [4, -2], [1, 0], [3, -1], [-8, 1], [-6, -1], [-8, -1], [0, -4], [1, 3], [-3, -3], [-4, 1], [-2, -2], [5, 0], [6, 2], [-12, -3], [7, 0], [-6, -7], [-5, 7], [2, 11], [0, -4], [7, 6], [-8, -4], [10, -5], [-8, 8], [4, -5], [-4, 11], [4, 4], [-5, -4], [3, -11], [-1, 4], [0, -4], [13, 8], [7, -5], [-20, -1], [4, -4], [-2, -6], [2, -9], [5, -3], [-2, -3], [-9, -6], [5, 5], [-2, -10], [12, -3], [0, 1], [-16, 0], [-12, -4], [-10, -4], [4, 9], [1, -15], [-14, 0], [-24, -2], [16, 0], [-15, -9], [-11, 12], [-8, 7], [1, 11], [-4, 4], [4, 16], [-8, 0], [13, 10], [-6, 3], [-10, 6], [-2, -5], [11, -1], [0, 4], [-24, 0], [7, -21], [6, 16], [-12, -4], [14, 1], [8, 3], [-4, 8], [10, 0], [14, 16], [18, -8], [1, -21], [-26, -1], [-4, 7], [-12, 0], [-18, 6], [-28, -8], [8, -16], [3, -2], [9, 14], [-15, 9], [-5, -9], [17, 5], [-26, -10], [11, 21], [-5, -3], [-9, 9], [2, 0], [12, -7], [4, 8], [-15, 10], [-6, 11], [27, -6], [-16, 19], [6, 8], [-13, 21], [-31, -2], [34, 0], [7, 8], [0, -15], [-16, -23], [-6, 7], [-24, 6], [-1, -20], [-19, -7], [1, 13], [22, 8], [-36, -6], [-35, -5], [-16, 10], [6, -13], [18, 19], [-18, 16], [0, 8], [-10, 10], [-6, -16], [-1, 14], [13, -28], [8, 8], [1, 3], [40, -8], [22, -16], [34, 9], [14, 6], [-43, -8], [-1, -10], [29, 18], [8, 5], [-16, -3], [-4, -35], [-11, 12], [10, 30], [25, 12], [-3, -9], [-12, -8], [-28, 8], [-22, 6], [27, -18], [-24, -12], [-11, -27], [2, 19], [10, -19], [4, 8], [-28, -2], [0, -20], [-34, 11], [-10, 11], [7, 1], [13, -16], [-39, -6], [-26, 1], [-26, 0], [-4, 39], [0, -12], [-22, 19], [6, -8], [16, -24], [-18, 18], [20, 28], [6, 36], [-3, -38], [-20, -11], [12, 17], [12, -22], [-3, 28], [-22, -9], [-21, 2], [45, 3], [9, -12], [20, -19], [-7, 16], [-19, -7], [6, 30], [-8, -13], [8, -3], [36, 6], [-10, 32], [10, 0], [-18, -6], [-8, -23], [13, -15], [38, 4], [4, -8], [0, 8], [8, -33], [-12, 24], [-8, 25], [9, 8], [11, 24], [23, -8], [39, -9], [54, -8], [40, -12], [-28, -4], [18, -28], [-20, -24], [41, 6], [3, 21], [32, -5], [20, 30], [-40, 17], [-19, 26], [-8, 30], [15, -15], [-14, -14], [28, 3], [20, -3], [-9, -1], [-16, -17], [44, -4], [25, 12], [16, 4], [24, 16], [24, 23], [28, 14], [-24, 1], [11, -12], [-6, 27], [2, 42], [-20, -9], [23, -11], [9, 16], [24, -33], [12, -43], [-12, 35], [24, -22], [-4, -6], [-33, 6], [-4, -16], [-17, 11], [-42, 5], [-32, -7], [1, -35], [3, -7], [-24, -3], [6, 32], [-29, 15], [-32, -8], [0, -1], [28, 21], [23, 19], [-65, 0], [-4, 30], [0, 16], [6, -9], [3, 10], [-11, -33], [17, -14], [26, 26], [6, 25], [0, 48], [2, 19], [0, 29], [-64, 12], [-4, 39], [9, 2], [-16, 12], [-10, 16], [-23, 8], [-6, -6], [-39, -12], [20, 12], [-36, -20], [-31, -26], [17, -11], [-32, -9], [16, 12], [49, 5], [-36, -28], [-20, 4], [-9, -1], [-18, -30], [40, -28], [-21, 43], [2, 20], [-52, -18], [-25, 5], [-8, -8], [-26, 12], [-15, 3], [24, 0], [-1, 4], [-11, -15], [8, -20], [56, -4], [-8, -24], [-8, -28], [-32, -15], [24, 12], [14, 6], [55, 21], [69, -2], [-2, -56], [-11, 9], [26, -2], [21, 23], [20, -48], [-34, -22], [18, -32], [-24, 40], [-69, 4], [-5, 1], [-23, -8], [24, 23], [12, 21], [-2, 8], [-50, -16], [-29, -39], [-8, 25], [-12, 36], [67, 16], [24, -23], [-12, 26], [34, -31], [-4, 12], [57, 2], [10, 12], [-22, 47], [-24, -43], [26, -27], [-42, -24], [13, 22], [-24, 4], [-76, 10], [-3, 27], [4, 24], [-11, -23], [-6, 8], [8, -52], [49, 24], [-15, 11], [-38, 36], [11, -32], [58, 0], [-22, 14], [-24, -16], [56, -12], [-8, 10], [-14, 26], [-54, 27], [-5, -12], [-30, 3], [-24, 23], [-27, -48], [-36, 12], [-14, 25], [-6, 11], [-9, -25], [51, -7], [33, -2], [12, 16], [32, -6], [-4, -6], [-50, 17], [12, 48], [-35, 5], [-46, 32], [6, 40], [-36, 1], [66, 12], [26, 12], [44, 36], [-33, 25], [34, 17], [-48, 4], [-84, 4], [30, 23], [19, -11], [29, -36], [-5, 22], [-34, 8], [80, -5], [89, -6], [-32, 8], [61, 14], [6, -2], [-64, 16], [-19, 17], [11, 12], [68, -2], [22, -13], [12, 4], [-10, 15], [-43, 1], [32, 6], [14, -23], [-24, 27], [22, -2], [18, -1], [56, -16], [11, -6], [24, -20], [45, -28], [4, -51], [0, 3], [46, 20], [-63, -19], [40, -2], [42, 12], [22, 46], [36, 18], [2, -51], [57, 32], [-42, 19], [-20, -8], [-91, 6], [-35, 26], [10, 15], [-70, -6], [7, -6], [18, -22], [-18, 45], [-18, 24], [79, -1], [32, -37], [38, -39], [10, 55], [-78, -2], [31, -50], [45, -9], [-17, 21]];
    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_x();".
// 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_x(: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_x();".
// 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_x( : 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, 4, 1]>,<5,R![-1, 1]>,<11,R![-17, -2, 1]>,<13,R![2, -4, 1]>,<17,R![8, -8, 1]>],Snew);
    return Vf;
end function;