
// Make newform 7728.2.a.bv in Magma, downloaded from the LMFDB on 16 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_bv();".
// 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_bv();".
// 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 := [4, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-5, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0], [1, 0, 0], [0, -1, 0], [-1, 0, 0], [-1, 2, 0], [1, 0, -1], [1, -1, 1], [-1, 0, 0], [-1, 0, 0], [-3, -1, -1], [-1, -1, 1], [-3, 3, -1], [-1, 2, 2], [-5, 2, -1], [-4, 1, 1], [-4, 0, -1], [-4, 0, -1], [7, 1, 0], [0, 1, 0], [3, -2, 3], [1, 1, 1], [-1, -5, 1], [-3, -1, -1], [5, 0, -1], [3, 1, -3], [-6, 4, -3], [-10, -1, 1], [-7, -2, 1], [2, -1, 2], [4, -5, 2], [-1, -3, -2], [-7, 2, -2], [-5, 0, -2], [-8, 3, 0], [-4, 5, 1], [-8, 3, -1], [-2, -1, -1], [-10, 4, -3], [-9, 0, 0], [7, -1, 5], [4, -5, 0], [7, -3, -3], [-4, 3, 3], [2, 1, -3], [-5, -2, 1], [2, -8, 3], [13, -2, 0], [-8, 9, 2], [2, -1, 0], [2, 4, 3], [2, -3, 2], [2, -1, -6], [-1, 0, 2], [4, -4, 2], [-12, 3, -5], [1, -6, 2], [-3, -12, 3], [-3, 1, 5], [-11, -1, -2], [-24, 0, -2], [2, -3, 2], [-8, 4, -4], [-11, -1, -3], [3, -1, 2], [6, 1, 3], [-14, 5, 0], [-4, 1, -1], [11, -2, 1], [9, -11, -1], [0, -7, 6], [-11, -3, 3], [2, -5, -2], [19, -3, -4], [1, -1, 3], [12, -6, 2], [-25, -3, 1], [-25, -1, 1], [-6, 6, -4], [7, 0, 0], [-7, 1, 3], [2, -7, 0], [-1, 2, 3], [-3, -1, -2], [14, 9, -3], [-9, 5, 3], [-12, -8, 0], [-18, 1, -4], [14, -5, 0], [-24, -1, 2], [-1, 6, 6], [-5, 9, -7], [5, 15, -3], [3, 1, -1], [13, -2, -5], [14, -5, -2], [-18, 1, -2], [-8, -1, -9], [14, 0, -4], [-4, -1, -3], [20, -11, -3], [10, 7, -2], [-24, -8, 2], [-7, 2, -3], [-10, 1, -5], [-7, -9, 1], [2, -8, 4], [-7, -5, -2], [8, 0, 2], [-11, 6, 7], [14, 7, 2], [5, 4, 1], [5, 5, 3], [15, 0, 9], [21, 8, -3], [7, -3, -7], [-5, 9, 4], [-5, -9, 2], [-12, 3, -4], [14, 9, -6], [9, -3, 1], [-27, 4, -6], [17, 4, 0], [-7, 4, 9], [-1, -15, 3], [11, 12, -5], [8, 14, -5], [-1, 14, 1], [-21, 3, 3], [29, 0, 4], [12, 4, -6], [-25, 3, 3], [20, 4, 1], [-10, 1, -6], [-9, -1, -1], [22, 1, 3], [28, -8, 6], [15, 7, -5], [22, -10, -3], [30, -6, 0], [-21, -4, 5], [-1, -15, -3], [18, 4, 6], [-12, -6, 1], [-6, -2, 7], [3, -1, 9], [-9, 14, 5], [16, -6, -8], [-14, 17, 1], [22, -14, -2], [-20, -4, 2], [10, -11, 7], [20, -8, -2], [5, 12, 1], [-39, 0, -3], [6, -11, 6], [10, -4, -6], [51, 1, 1], [-2, -9, 8], [29, -8, -4], [0, 8, 4], [18, -2, 2], [9, -11, -8], [22, -14, 2], [-17, 8, -3], [15, 7, 2], [15, -7, 5], [-7, 13, 4], [-13, 1, -5], [26, -1, 4], [-17, 17, 6], [11, -11, 0], [6, 0, 8], [-15, -9, 6], [19, -5, 11], [44, 6, -2], [19, -11, 5], [9, 7, 2], [2, 9, 0], [6, -22, -1], [-4, -3, -6], [8, 4, -7], [7, 6, 1], [8, -2, -1], [-7, 21, -4], [-35, 4, -6], [-17, 4, -7], [-4, -3, -9], [1, 9, -3], [-8, -6, 3], [-13, -11, 3], [8, -7, 6], [-22, -5, -6], [16, 18, -8], [-7, -4, -8], [-35, 3, 2], [13, 2, -11], [-15, -10, -1], [16, 4, 10], [-18, 18, -2], [-22, 0, -1], [-12, 17, -1], [8, 0, 8], [-24, -13, 2], [-1, 17, 0], [-7, 1, -13], [36, -1, 5], [31, -13, -9], [6, 17, -8], [-14, -3, 6], [13, -17, 7], [4, -13, -1], [28, 4, -3], [-3, 17, -1], [-12, 2, 2], [-1, 0, 3], [16, -11, 6], [29, -12, -6], [-11, 6, 7], [-13, 5, -5], [-5, -13, 5], [-25, 9, -12], [-28, 11, -11], [-3, -4, -3], [-12, -24, 8], [15, 6, 4], [22, -8, -11], [-7, 7, -9], [-40, 8, 4], [37, 8, 1], [27, -7, 3], [-15, 16, 0], [35, 0, 3], [8, 25, -4], [-16, 8, -4], [-21, 5, -2], [-29, -14, 3], [4, -1, -9], [-15, -1, -5], [43, -11, -1], [7, 13, -9], [27, -12, 14], [-12, 7, 0], [12, 14, -4], [-39, 12, 2], [17, 0, 8], [23, -9, -6], [-12, -14, -6], [24, -14, -10], [-35, -5, 7], [-25, -6, 6], [-3, 9, -7], [10, 2, 6], [-11, 14, 4], [3, 16, -8], [-9, 9, 9], [-8, 8, 2], [-9, -25, 11], [53, 0, 0], [-3, -11, -2], [-31, 5, -1], [3, -4, -5], [-24, 15, 9], [-24, 13, -6], [-23, 22, 2], [9, -3, -6], [25, -4, -6], [-16, 1, 11], [-9, -3, -11], [5, -5, -3], [-10, -19, 6], [-5, -27, 3], [-3, 19, -9], [-1, -2, 9], [-2, 10, -12], [-5, -11, -9], [-10, 16, -12], [-11, -5, 13], [-27, 8, 6], [17, 1, 17], [19, 19, -9], [-8, 5, -3], [1, 4, -3], [47, 5, 5], [5, -9, 7], [-2, 1, -8], [45, 1, 7], [-3, -1, -9], [16, -11, -1], [23, 12, -5], [4, 22, 2], [-21, 3, 0], [27, -10, 5], [-31, 18, 11], [31, -15, 3], [36, -2, 2], [-21, -5, 7], [0, 8, 12], [-41, -13, 4], [5, 6, -4], [5, -19, -1], [29, -12, -9], [18, 0, 0], [21, -3, 19], [26, 17, -6], [4, 2, 2], [15, 2, 4], [-6, 3, -14], [-13, 18, -10], [18, 3, -9], [-27, -16, -1], [-1, -24, 10], [-9, 17, -11], [54, 4, 1], [-45, 5, -5], [-3, -14, 10], [-14, 7, 1], [55, -16, -6], [17, -17, 5], [49, -4, 4], [-10, 12, 2], [-40, 9, -9], [-17, -2, 9], [0, -10, -13], [-13, -28, 8], [43, 6, -2], [6, -16, -3], [-33, 13, 11], [-26, 13, -2], [4, 21, -11], [6, -9, 15], [-24, 14, 14], [-11, -1, 5], [-19, 14, -3], [10, -20, 3], [-14, -16, 6], [-40, -11, 3], [44, 12, -2], [2, 14, 0], [16, -5, -14], [18, 15, -2], [-29, 3, -15], [28, -9, -11], [17, 19, -14], [5, -25, 3], [-20, 9, -13], [-41, 6, -15], [16, 17, 0], [-22, -12, -9], [0, -13, -2], [27, -9, 9], [19, -10, 1], [33, -14, -2], [1, -9, -3], [-6, 18, -19], [27, -17, 9], [-30, -25, 9], [0, 8, -14], [-5, -21, 9], [-29, 5, -3], [25, 5, -1], [15, -19, -1], [-9, 12, -12], [-41, 13, -9], [54, 7, 1], [-2, 0, 2], [42, -27, -13], [-19, 9, -10], [-62, 6, -8], [63, -2, 1], [47, 18, -1], [17, -5, 13], [-20, -2, 2], [14, -5, 7], [-2, 23, -3], [23, -9, 17], [22, 11, -10], [-38, -8, 5], [4, -13, -1], [-42, 14, -6], [3, 17, -9], [19, 5, -9], [55, 8, -7], [16, -7, 1], [-3, 32, 1], [4, 13, 12], [-27, 11, 8], [-41, -5, 4], [-46, 6, 6], [-33, -17, 11], [-48, 6, 12], [25, -1, -7], [-12, -2, -9], [34, -12, 0], [38, -8, 6], [-25, -7, -2], [46, -3, 8], [-17, -24, 0], [-55, 9, -1], [-85, -2, 1], [-9, -1, -3], [65, -1, -7], [29, 4, -11], [20, 20, 6], [-57, 4, 5], [55, 5, 0], [-27, 0, -5], [0, 16, 0], [12, -24, -2], [-4, 8, 4], [-34, 3, 14], [5, 0, 15], [-54, 6, -12], [-42, 1, 11], [3, 16, -1], [11, -4, -3], [-18, -24, 12], [11, 1, 5], [-53, 1, 11], [9, 9, 13], [18, -16, 10], [13, -17, 3], [-1, -8, 14], [-18, -11, -4], [37, -12, -11], [11, -18, 3], [28, -21, -5], [-39, 11, -8], [-24, -12, -6], [-8, 21, -2], [31, 11, 2], [9, -18, 18], [22, 1, -13], [-52, -6, 5], [-27, 2, -13], [16, -26, 16], [18, -18, 6], [-2, 14, -7], [-2, -7, 5], [-13, 8, -10]];
    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_bv();".
// 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_bv(:prec:=3)
    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_bv();".
// 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_bv( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7728_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, -7, 1, 1]>,<11,R![3, -29, 1, 1]>,<13,R![-2, -15, -3, 1]>,<17,R![32, -19, -2, 1]>],Snew);
    return Vf;
end function;