
// Make newform 7728.2.a.bs in Magma, downloaded from the LMFDB on 18 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_bs();".
// 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_bs();".
// 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, 2], [-1, 1, 1], [1, -3, 1], [1, 0, 0], [-1, 1, -1], [-1, 3, -1], [-5, 1, -1], [-5, -3, 1], [3, 1, 0], [-2, -6, 4], [2, 2, 5], [6, 0, 1], [-1, -1, 0], [-4, 6, 1], [-1, -3, -4], [-13, 1, -1], [3, -1, -1], [-3, 5, -1], [-1, -5, -2], [-3, 3, 1], [-4, -4, 5], [-4, 4, 0], [5, -1, 4], [2, 6, -5], [-4, -8, 1], [13, -1, 4], [7, -1, 7], [3, 1, 7], [4, -2, 3], [2, 4, -2], [-2, -6, -4], [0, -6, -4], [4, 2, 5], [-7, -3, 5], [1, 7, -1], [4, -10, -1], [-11, 3, -3], [2, 6, 4], [-16, 2, -4], [-7, 1, -12], [-4, 2, 3], [-1, -5, -7], [-8, 6, -9], [-2, 4, -11], [-4, -4, 3], [-2, -10, -3], [2, 12, -5], [-9, 5, 3], [-8, 4, -10], [6, 16, -6], [-9, 3, 7], [-1, -1, 6], [-7, 9, -9], [-3, -7, 2], [12, 6, -4], [-6, -8, -3], [16, -2, -2], [-3, -11, -3], [-3, 11, 2], [-8, -2, -10], [10, 2, 3], [2, -10, 10], [5, -7, 4], [-11, -3, 1], [-8, -4, 3], [-1, 9, -11], [14, 0, 3], [-7, -9, 2], [-17, -11, 3], [-16, 0, 4], [-21, 3, -11], [5, -9, 11], [-6, -8, -6], [-13, 5, -3], [-17, 9, 1], [-2, -16, -1], [9, -7, 6], [-17, 5, -12], [-12, 14, 0], [-5, -1, -13], [-4, -8, 8], [-18, 2, 7], [-14, 10, 5], [-8, 0, -3], [-3, -7, 1], [-5, 3, 1], [-11, -15, 5], [-13, -1, 7], [-7, 19, 6], [6, 20, -13], [-10, 4, 9], [10, 0, 2], [30, -4, 0], [14, -2, -2], [-14, 0, -2], [2, 0, 11], [20, -2, 8], [-27, 7, -16], [-16, -2, -10], [29, 1, -3], [-6, -16, -4], [-21, 5, -8], [-12, -10, 8], [-11, 11, -2], [-26, 2, -9], [13, 11, -10], [19, 5, 9], [-27, -3, -2], [-3, -13, 2], [-5, 11, 1], [11, 11, -4], [-15, -1, -10], [-8, -2, 7], [-6, 14, -11], [9, -7, -1], [-7, 7, 1], [17, -5, 11], [3, -13, 0], [15, 7, -5], [-25, 5, 2], [14, -6, 7], [-19, -7, -8], [-5, 11, 9], [-9, -5, 3], [24, 10, 0], [-21, 7, -7], [2, -20, -9], [10, -16, -3], [-11, 19, -11], [8, -10, 14], [0, 2, 0], [-3, 3, -11], [-12, 18, -17], [14, 0, -14], [5, -11, -2], [-5, 15, 5], [-2, 20, -2], [38, -4, 9], [-8, -6, -7], [25, 7, 11], [-13, -11, 14], [0, -2, 8], [-24, -6, 0], [-10, -6, 2], [32, -4, -2], [-4, 14, -10], [8, 10, 16], [9, 3, -10], [-11, 11, -6], [-14, -8, -7], [18, -2, 0], [15, -1, 9], [2, 2, 9], [-7, -5, 3], [16, -2, -6], [-6, 22, -10], [17, 17, -14], [-26, -18, 10], [7, -11, 8], [-29, -21, 8], [-29, 11, -3], [7, -11, 20], [-19, -21, 11], [-10, -26, 17], [11, 19, -2], [-7, -9, 2], [6, -16, -16], [27, 1, -8], [13, 11, -3], [8, 8, 12], [-47, 7, 1], [-1, -15, 4], [50, 2, -1], [16, 10, -3], [24, 16, -13], [2, -12, 7], [-25, 9, 2], [2, 2, 11], [21, 5, 6], [3, 3, -3], [1, -15, 6], [-2, -16, 16], [-23, 17, 11], [-14, 14, 11], [-37, 7, -29], [16, -16, 19], [2, 0, -1], [-24, 4, -22], [13, -29, -1], [3, 17, -12], [19, 15, -14], [-25, 23, 8], [28, 14, -12], [-6, 0, 8], [24, -10, -13], [22, 20, -16], [32, -8, 16], [0, 0, -11], [19, 27, -16], [1, -11, 9], [-6, 20, -20], [11, -21, 9], [34, 0, 3], [-34, -2, -7], [17, -11, -5], [-34, -16, -2], [-18, -10, 7], [-7, 21, 1], [8, -8, 4], [11, -27, -2], [20, -12, 7], [23, -9, 13], [27, -5, 4], [-1, 11, -1], [-15, -17, -1], [-5, -25, 16], [30, -2, 10], [-1, -1, 24], [12, 4, -20], [-27, 17, -17], [12, -20, -11], [11, -15, 7], [16, 0, 12], [-7, 15, 6], [27, -5, -1], [21, -13, 15], [11, -19, 14], [28, -2, 17], [40, -2, 10], [-15, -5, -16], [19, -7, 16], [14, -16, -6], [19, 9, -9], [43, -13, -1], [47, -5, 3], [1, 9, 7], [32, 10, 11], [-28, 0, -18], [25, -13, 13], [25, -13, -5], [17, 15, -2], [24, -8, -12], [-4, 4, 4], [5, 37, -9], [41, -3, 5], [15, 21, -5], [-34, 20, -12], [23, -17, 5], [-9, -23, -3], [9, -5, -15], [28, -12, 10], [21, -5, -7], [-21, 7, -21], [-7, -7, 0], [7, 1, 9], [-25, 1, -18], [10, 2, -2], [-32, 12, -13], [21, 23, -21], [1, -3, 28], [-5, -13, 1], [-6, -16, -8], [-27, 11, -35], [9, -27, 1], [10, 14, -3], [37, -13, 23], [21, 13, -9], [1, -11, 12], [2, -2, 0], [-47, -5, 11], [18, -30, -2], [21, -19, 21], [-3, 7, 9], [-25, 21, -13], [-1, -33, 21], [-54, -2, 8], [29, 27, -2], [11, 27, -7], [-41, 5, -13], [-2, 4, -5], [45, 17, 1], [-25, -3, 15], [-22, -24, -8], [-17, 9, 10], [-16, -26, 6], [-9, -13, -2], [19, 13, -6], [15, 15, -20], [19, -1, -13], [8, 10, -6], [1, 7, 9], [48, 8, -4], [23, -1, 2], [7, 35, -23], [-15, 1, -7], [51, -1, 26], [-62, -8, 8], [-7, 5, 9], [18, -28, 13], [40, -8, 20], [23, 37, -9], [10, -32, -1], [-25, 1, -3], [-20, -16, 10], [-13, 3, 18], [45, -11, 43], [21, -13, 5], [-24, -12, -7], [-25, -33, 15], [35, 7, -5], [16, 6, 10], [-15, -3, 3], [53, -23, -11], [-27, -9, -21], [-62, 4, 2], [-26, -18, 10], [-23, -19, 0], [-18, 30, 15], [5, -7, 1], [-5, 13, -31], [-4, 40, 1], [-29, 15, -37], [42, 12, 17], [22, -6, 20], [-16, 34, 4], [-4, 6, 10], [-21, -7, 13], [-3, 15, -20], [-40, 18, -13], [10, 14, 0], [-2, -6, 22], [40, -14, 28], [-38, 4, -22], [-8, -28, 21], [-6, -44, 31], [53, 19, -1], [-46, 8, -16], [5, 25, 10], [-31, 9, 11], [6, -36, 28], [3, 41, -2], [12, 12, 13], [-44, -18, -1], [4, 22, 17], [-3, 15, -1], [-5, 1, 6], [-59, -17, 11], [-9, -19, 9], [8, 14, -13], [-11, -17, 11], [72, -2, 10], [-12, 24, -10], [35, -25, -5], [-27, -5, -19], [-7, -11, -31], [-3, 15, -25], [-41, 1, -15], [43, -9, -5], [20, 4, 24], [-42, -18, -12], [-4, 18, -2], [1, 9, -20], [22, 34, -12], [9, -3, 24], [-17, -7, -4], [33, 25, -11], [8, 0, 16], [-24, 18, 24], [-20, -36, 28], [17, 15, -25], [2, 16, 27], [20, 6, -7], [22, -24, -10], [-14, 16, 0], [-15, 11, -1], [33, 11, -17], [-19, 13, 6], [-22, 30, -24], [-17, -1, 24], [-12, 14, -15], [-1, 25, -34], [9, -13, 12], [-10, 32, -12], [-29, 19, -3], [-8, 36, -30], [-25, 1, -3], [-14, -6, 7], [22, 26, 6], [-18, 14, -32], [29, -25, 12], [-38, -2, -21], [5, -39, 37], [43, -11, 13], [-33, 25, 18], [-3, -5, 15], [-1, 13, -7], [23, -9, -8], [0, 20, -22], [-3, 5, -22], [-41, 3, 4], [25, 27, -24], [8, -18, 22], [-16, 10, -8], [4, 20, 8], [50, 24, -5], [39, 11, 2], [-46, 8, -38], [16, -16, 32], [-37, 5, -18], [-51, 5, -38], [-18, 16, 12], [19, -45, 5], [7, 27, -21], [47, -11, 27], [-46, 14, -20], [-9, 37, -13], [3, 1, -21], [-46, 12, 3], [-3, 23, -10], [-11, 5, -10], [-50, -4, -26], [-5, 45, -38], [-20, -18, -28], [-8, 18, 23], [17, 15, -22], [-55, -5, -1], [8, 16, 0], [-66, 0, -11], [-7, -41, 6], [56, 22, -12], [14, 4, 8], [44, 12, 3], [4, 2, 4], [-27, -31, 23]];
    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_bs();".
// 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_bs(: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_bs();".
// 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_bs( : 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![8, -1, -4, 1]>,<13,R![-2, -11, 5, 1]>,<17,R![-26, -7, 4, 1]>],Snew);
    return Vf;
end function;