
// Make newform 7728.2.a.bl in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7728_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_7728_2_a_bl();".
// 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_7728_2_a_bl();".
// 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 := [-7, -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_7728_a();"
function MakeCharacter_7728_a()
    N := 7728;
    order := 1;
    char_gens := [4831, 5797, 5153, 6625, 6721];
    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_7728_a_Hecke(Kf)
    return MakeCharacter_7728_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], [1, 0], [0, 1], [1, 0], [-5, 0], [1, -1], [1, 0], [-1, -2], [-1, 0], [-5, 0], [-1, -2], [1, -2], [-1, 0], [-3, 1], [-6, 2], [-4, 3], [6, -3], [7, -1], [0, 1], [-7, 3], [-9, 0], [1, -4], [7, -2], [-3, -3], [-9, 4], [8, -3], [-8, 0], [-11, 3], [10, 3], [-2, -3], [-7, 1], [-1, 4], [9, 0], [6, 3], [6, -2], [-2, -2], [-12, -2], [-4, 7], [-23, 0], [-7, 4], [-14, 3], [7, 0], [-6, 2], [-4, 2], [7, -1], [-2, -7], [-9, 2], [-6, 3], [6, 3], [2, -1], [8, 5], [-20, 1], [-11, 4], [-16, -2], [10, 6], [-11, 6], [19, -5], [5, 0], [-11, 1], [-12, 2], [16, 5], [24, 0], [5, 2], [-7, -5], [4, 0], [20, -1], [-22, -4], [-1, 5], [9, -6], [-2, 1], [-21, 4], [8, 3], [-7, 5], [5, 6], [-12, 8], [33, -2], [7, -10], [2, 10], [-11, -2], [-1, -10], [-18, 1], [15, 3], [-17, 5], [-16, -2], [-13, 10], [4, -12], [4, -1], [14, -7], [-12, 5], [13, 0], [-3, 10], [11, 0], [19, -4], [-17, -5], [-2, -1], [14, 3], [6, -2], [-10, -4], [-6, -4], [-14, 2], [-14, 3], [-4, -6], [-1, -5], [20, -8], [-1, -4], [-26, -4], [-5, 7], [-40, -2], [11, -9], [16, -5], [15, 7], [9, 8], [-23, 3], [-3, 9], [17, 6], [3, -9], [-11, 13], [4, -15], [-20, 5], [-29, 0], [11, -8], [-7, 4], [-3, 11], [15, -2], [-15, -3], [-4, -3], [-9, -11], [-1, 10], [13, -18], [-32, -2], [7, -10], [24, -5], [6, 11], [7, -18], [8, -4], [-16, -6], [27, -6], [-2, 17], [2, -10], [19, -11], [-9, 12], [-10, -2], [2, -7], [6, -17], [-11, -10], [-3, -13], [8, -10], [24, -6], [42, -4], [-20, 10], [48, 0], [16, -14], [1, 15], [-7, 15], [50, -1], [18, -6], [-27, -2], [-54, -1], [-29, 6], [0, 4], [-46, -4], [-35, -1], [2, -16], [-23, -3], [-5, -5], [-11, -2], [23, -13], [5, 14], [38, 5], [31, 7], [-11, 17], [-42, 0], [3, -7], [19, -2], [44, 4], [3, 2], [35, -9], [-16, 11], [2, 11], [2, -5], [-10, 11], [-19, -9], [10, 5], [25, -11], [-23, 8], [3, 7], [-6, 0], [15, -12], [-10, 1], [-9, 8], [6, 5], [12, 1], [-8, 14], [-7, -16], [31, 5], [-23, -3], [29, -1], [40, -6], [-26, -8], [8, 5], [22, -4], [-12, 0], [22, 7], [7, -9], [-33, 8], [-30, 0], [9, -12], [16, 9], [-36, 13], [29, -8], [6, 14], [-34, -7], [-57, 0], [4, -20], [15, 5], [34, -1], [55, 2], [27, -3], [-27, 14], [-27, -6], [11, 13], [18, 8], [-23, -3], [-44, 4], [-47, 2], [-28, 17], [45, -6], [-28, 12], [29, -3], [15, -18], [13, 8], [15, 11], [-44, 9], [40, 0], [25, 7], [-55, 1], [-38, -6], [-59, 4], [-21, -14], [7, 16], [39, 8], [10, -13], [8, -18], [37, -2], [-19, 20], [33, -13], [-28, 0], [12, -16], [7, -18], [19, -18], [13, 10], [-34, 0], [21, -8], [37, -14], [-19, -14], [40, -14], [31, -10], [-27, 10], [-27, 11], [-1, -2], [-23, 11], [2, -12], [-10, -15], [11, -6], [-43, 11], [13, 16], [34, -4], [19, 2], [3, -16], [4, 13], [-15, 6], [19, -14], [-35, -3], [46, 10], [-11, 18], [-14, 16], [17, 10], [-11, -6], [53, 6], [-7, -6], [-2, 2], [-5, 25], [-23, -10], [21, -4], [48, -3], [17, 14], [-31, -6], [2, 12], [1, 5], [36, 0], [19, 13], [69, 3], [5, 9], [-19, -4], [4, -20], [-1, -2], [32, -4], [63, -5], [7, 10], [-27, 10], [-17, -3], [22, 0], [43, 8], [44, 3], [56, -4], [-5, -18], [-20, 1], [-15, 10], [24, -6], [55, -13], [13, -2], [-29, 20], [38, 5], [43, -12], [-43, -6], [-32, 8], [-43, -10], [25, -30], [-25, 6], [34, 6], [-18, -8], [31, -7], [14, 9], [-43, 0], [-27, -2], [34, -15], [17, -24], [-12, -5], [14, 18], [-16, 6], [-8, -8], [7, -14], [23, -31], [-4, -11], [22, 18], [-54, -8], [20, 2], [2, 18], [58, -9], [-4, -17], [-59, -8], [34, 4], [-39, 1], [55, 10], [22, 0], [-11, -7], [34, -17], [-48, -7], [-32, -3], [-21, -8], [-23, 1], [-39, 16], [3, 2], [6, -15], [-45, 0], [12, -8], [64, -14], [-15, -24], [-19, -12], [37, -14], [35, -16], [47, -20], [35, -14], [-28, 32], [-2, 2], [44, -8], [1, -17], [-58, 14], [-29, -3], [-3, -17], [13, 22], [40, 0], [-44, -10], [-16, 20], [13, -4], [-2, 19], [-10, 31], [-18, 26], [-18, -8], [13, 2], [59, 0], [-7, 11], [18, -18], [-11, 17], [18, 11], [-61, 5], [9, -3], [10, 16], [17, 10], [44, -10], [25, 24], [-2, -27], [-22, -24], [-50, 14], [25, -5], [-26, 11], [-25, -14], [-7, 12], [-91, 3], [37, 6], [31, -26], [-11, 5], [-24, 18], [-13, -5], [-85, 5], [19, 13], [-4, -4], [-28, 14], [36, 0], [34, -21], [21, 15], [-50, 18], [20, 16], [-15, -17], [-57, -5], [26, -12], [-21, 8], [55, -18], [21, 10], [34, -2], [-11, 28], [49, 0], [-24, 33], [1, 23], [-29, -15], [-70, 2], [31, -13], [-56, 2], [34, 11], [-39, 19], [-37, 2], [-8, -4], [-30, 13], [-33, 13], [-68, -2], [-38, 32], [28, 11], [36, 2], [17, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7728_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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