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