
// Make newform 7728.2.a.bc 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_bc();".
// 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_bc();".
// 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 := [-10, -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], [4, 0], [2, 1], [4, 0], [-2, 2], [-1, 0], [4, -1], [2, 0], [8, -1], [-4, 1], [-2, 1], [0, 3], [-2, -2], [0, 2], [-2, 0], [0, -4], [0, 2], [-6, 2], [-8, 0], [-6, -2], [-4, -2], [10, -1], [4, -2], [-6, 1], [-4, -4], [-4, -1], [-4, 3], [2, 1], [0, 2], [-16, -1], [-14, -1], [2, -6], [2, -7], [6, -2], [-4, 4], [6, 2], [12, 2], [14, 3], [-2, -4], [-8, -4], [-12, -3], [4, 5], [6, -1], [4, -4], [22, 0], [12, 3], [-22, 2], [-26, 0], [4, -4], [10, -7], [-16, -1], [2, 0], [-6, -1], [12, -6], [6, -2], [-14, -2], [-4, 5], [10, -4], [-6, -4], [14, -7], [-6, -2], [16, -6], [-12, 1], [20, 0], [18, -6], [14, -1], [20, -2], [8, -1], [14, -3], [6, 3], [14, -4], [-10, -1], [0, -8], [-6, 0], [16, -2], [30, 0], [-2, 2], [-22, 6], [-12, -1], [-22, 7], [-2, 9], [22, 0], [10, 1], [6, -12], [6, 6], [20, -6], [26, -1], [0, 1], [-24, 2], [10, -1], [-20, 8], [16, 2], [-12, 2], [8, 8], [-28, 2], [-6, -4], [26, 2], [8, -10], [-30, -2], [-8, 3], [28, 1], [0, 4], [-10, 0], [0, -4], [40, 1], [16, -8], [-6, -2], [10, 8], [0, 1], [-34, 4], [22, -4], [0, 8], [20, -11], [14, -4], [14, -2], [-4, 3], [-8, 0], [-2, 12], [4, 1], [-6, -12], [-4, -8], [-18, 5], [10, 10], [38, -4], [-20, 7], [12, 0], [30, 6], [-8, 10], [-32, 0], [0, -8], [18, -12], [-6, -8], [-10, 7], [4, -3], [26, -2], [12, 1], [-6, 10], [-34, -5], [-2, 8], [10, 1], [40, 2], [48, 2], [-20, -6], [-2, 3], [-4, 1], [34, -5], [36, -8], [-10, -2], [-16, 6], [32, -2], [6, 6], [-2, -5], [-42, -3], [8, 12], [-20, -7], [14, 3], [-8, 9], [10, -7], [2, 16], [0, 4], [2, -14], [-24, 11], [-20, -6], [-28, 0], [-16, -2], [18, 0], [28, 0], [16, 2], [-18, 1], [2, 3], [30, -12], [2, 10], [-28, 10], [-16, -6], [10, 0], [-30, -9], [-46, -4], [4, 0], [36, -7], [-10, 6], [24, -1], [22, -7], [4, 1], [38, 4], [-14, -10], [20, -3], [24, -5], [-6, 12], [-6, -3], [-52, 0], [8, 2], [4, -10], [0, 0], [-18, -4], [-22, 12], [-16, 2], [0, -3], [-6, 0], [22, 10], [34, 5], [-16, 6], [8, -15], [-52, 4], [66, -1], [-12, 0], [-14, -4], [-56, 4], [64, 1], [-4, -6], [16, -8], [-34, 6], [-4, -15], [32, 2], [8, -4], [-40, 5], [26, -13], [-4, -1], [14, 10], [-24, 16], [10, -12], [0, 20], [44, 0], [10, 4], [8, -4], [4, 8], [10, -15], [4, -4], [18, 4], [-58, 0], [-8, -16], [34, 2], [14, -6], [12, -4], [-14, -11], [-6, 12], [-14, 13], [2, -18], [-12, -14], [-20, 16], [6, -18], [-42, 8], [-4, -13], [-20, -11], [-38, 12], [16, 11], [-10, -15], [-14, 11], [8, 5], [-44, -6], [18, -1], [-6, -11], [32, -8], [-10, 3], [-12, -9], [22, 4], [-8, -10], [-26, -6], [32, -4], [-12, 6], [50, -3], [-26, 4], [-10, 20], [14, 4], [6, -12], [0, 0], [-10, 9], [50, 0], [30, -15], [28, 0], [10, -1], [-68, -2], [-10, -4], [-6, 16], [30, 3], [14, 4], [-54, 4], [4, 7], [16, -5], [12, -6], [-4, 2], [-14, 6], [-14, -1], [24, 6], [14, 10], [30, -4], [46, 0], [-20, -15], [-14, 22], [-16, 9], [6, -2], [28, -7], [-42, 0], [18, 16], [50, 3], [12, 8], [-12, -18], [-50, 7], [22, -3], [14, 10], [-4, 14], [58, 1], [38, 9], [12, -13], [14, 3], [26, 10], [-34, 5], [38, 8], [48, -3], [-30, 20], [-2, 4], [52, -12], [-16, 12], [-4, 14], [16, -12], [36, -16], [66, -5], [-42, 6], [10, -20], [-50, 12], [-44, 2], [54, -3], [-28, -13], [56, -6], [16, 16], [26, -9], [30, -3], [-22, -10], [-46, -10], [-20, -1], [-6, 0], [-20, -12], [-18, 17], [-8, 0], [24, -13], [20, -22], [18, -4], [-2, -7], [6, -8], [52, 5], [8, -14], [72, -4], [-26, 14], [22, -1], [-22, 17], [80, -2], [-40, 8], [44, -13], [-28, -8], [-92, -1], [4, 5], [-40, 0], [-16, -1], [-56, -5], [4, 22], [30, -22], [26, 6], [4, 2], [34, 8], [-12, 17], [-8, 8], [80, 0], [-10, 7], [-60, -3], [-28, 12], [16, -4], [6, 18], [-28, 0], [6, -3], [-12, 26], [-38, 6], [-28, 12], [66, -2], [-12, 10], [-26, 9], [30, -9], [-68, 6], [82, -2], [54, -8], [-6, -20], [4, -12], [58, 4], [2, 10], [-28, 17], [54, 7], [42, 1], [66, -1], [20, -2], [-26, 0], [-16, 2], [38, 3], [-6, 7], [8, -28], [22, -16], [22, -3], [0, 8], [2, 1], [20, -25], [-10, -7], [-82, 4], [-60, 2], [24, 16], [-40, 14], [54, 0], [4, -7], [34, -14], [-66, 2], [16, -16], [2, 24], [-68, 11], [-56, 16], [-20, -16], [86, -4], [24, 8], [-20, 14], [-2, -12], [12, 18], [20, -14], [30, 8], [62, 6], [32, -16], [20, 0], [-26, -2], [72, -8], [-52, -4], [46, 6], [-26, 13], [8, 3], [-22, 15], [-20, -6], [20, 16], [28, -8], [30, 13], [52, -14], [-8, -13], [-18, -6], [-12, 16]];
    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_bc();".
// 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_bc(: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_bc();".
// 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_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7728_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-10, -1, 1]>,<11,R![-4, 1]>,<13,R![-4, -5, 1]>,<17,R![-4, 1]>],Snew);
    return Vf;
end function;