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