
// Make newform 7728.2.a.bf in Magma, downloaded from the LMFDB on 25 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_bf();".
// 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_bf();".
// 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 := [-3, -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], [-2, -1], [1, 0], [-3, 2], [1, -1], [-3, -2], [3, 2], [1, 0], [-3, 2], [1, -2], [3, -2], [1, -2], [-3, 1], [2, -2], [2, -3], [0, 3], [1, -3], [-12, 1], [-9, 3], [11, 0], [-3, 8], [-11, 4], [-9, 5], [9, 4], [-6, 5], [-8, -4], [1, 1], [2, 5], [4, -1], [-9, 7], [-1, -6], [-3, 2], [6, -7], [-18, -2], [-6, 2], [4, -6], [0, -7], [1, -10], [-9, -2], [-8, 13], [-19, 0], [6, -2], [8, -10], [-9, 13], [-2, -3], [-23, 2], [-6, 9], [-8, 3], [-6, -7], [-2, -7], [-2, 3], [3, -4], [-12, -6], [18, -6], [-1, -8], [3, -7], [11, 8], [5, -15], [4, -2], [-24, 1], [-24, -4], [23, -2], [-1, 7], [-20, 8], [-14, -1], [2, 0], [5, -9], [5, 4], [2, 1], [13, -2], [-6, 3], [-19, 5], [19, 6], [0, -8], [11, -12], [3, 12], [-6, 2], [-11, 12], [11, 2], [8, -3], [-11, -3], [3, -1], [16, -6], [25, -2], [12, 4], [2, 7], [-22, -1], [-30, -3], [-17, 0], [3, -16], [9, -14], [1, 4], [-31, 3], [-22, -7], [-12, 7], [-22, -2], [10, 4], [-26, 4], [14, -10], [14, -11], [24, 6], [19, -15], [-20, -4], [35, 4], [14, 0], [29, -5], [24, 2], [-7, 15], [-8, 15], [1, -15], [-13, 12], [19, -1], [-39, 1], [-19, -2], [-11, 15], [-23, -3], [10, -5], [14, -3], [21, 6], [5, 8], [5, 0], [-21, 7], [15, -12], [7, 3], [2, -13], [-11, 7], [-21, 16], [9, 2], [-24, 10], [29, -6], [-34, -5], [26, -13], [13, -6], [0, 12], [4, -6], [3, 4], [22, -7], [-42, 6], [19, -5], [5, 12], [6, 18], [42, -5], [-24, -1], [9, 6], [9, -15], [0, 2], [-4, -10], [-2, 20], [4, -6], [-32, 0], [16, 14], [3, -3], [-5, -5], [38, -9], [-22, 2], [5, 10], [-36, -1], [-19, -10], [0, 4], [-2, -16], [15, -9], [-10, -20], [-23, -13], [-15, -1], [-13, -8], [1, -23], [-11, -6], [-10, -17], [43, 5], [21, -5], [34, -12], [-13, 19], [29, 6], [-4, 12], [-9, 0], [-35, 13], [30, 3], [10, -5], [-14, 25], [18, 9], [-3, 5], [-18, 25], [5, 15], [-17, 2], [-23, 3], [-10, -20], [23, -4], [-34, -3], [15, 18], [14, -27], [30, -5], [12, 2], [23, -30], [-21, 11], [11, 13], [19, -15], [32, -6], [34, -16], [-30, 15], [10, 24], [32, -16], [26, -9], [13, -23], [-39, 10], [2, -4], [-23, 4], [-46, -5], [26, 1], [-5, -16], [46, -10], [-24, 21], [35, 0], [12, -32], [21, -23], [-10, 29], [61, -2], [35, -17], [-5, -20], [15, 24], [3, 25], [2, 16], [21, 3], [16, -12], [29, 0], [-24, 5], [1, -16], [12, 16], [29, -11], [-21, -8], [-35, 0], [-21, 39], [-8, -7], [-24, -16], [-23, 15], [5, 3], [2, 18], [5, 18], [-21, 0], [-25, 22], [-3, 26], [-34, -7], [0, 6], [-51, -10], [39, 2], [35, -25], [-8, 8], [8, 24], [51, -14], [9, -28], [-9, 2], [-6, -8], [47, -10], [7, -10], [-53, -4], [12, 6], [25, 2], [9, 2], [17, -19], [27, -6], [29, 11], [-2, -4], [-30, -11], [-19, 30], [61, 5], [5, 0], [-18, 16], [-37, 0], [-49, -4], [10, -3], [45, -18], [19, -34], [47, -13], [-34, 26], [-23, 46], [50, -4], [-3, 24], [45, -10], [19, 2], [27, -36], [6, 18], [-13, 29], [-53, 20], [15, 28], [-40, -5], [9, -12], [-37, 6], [-18, -12], [15, -37], [24, 0], [1, -31], [5, 17], [45, -21], [-9, -22], [16, 4], [-65, 0], [52, -16], [39, -7], [27, -24], [3, 14], [69, -1], [-30, 24], [-21, 0], [-6, -3], [-32, -4], [19, -22], [-2, -13], [27, 10], [48, -2], [23, -25], [69, -4], [-5, 14], [-24, 39], [13, 8], [-57, 4], [-32, -4], [81, 0], [-47, -4], [25, -18], [-22, 22], [-2, 12], [25, -45], [12, -15], [35, 16], [-15, -16], [14, -17], [-19, -12], [-76, 1], [6, -26], [-8, 6], [20, -16], [53, 4], [-7, -13], [-30, -17], [2, -18], [54, 12], [-36, 2], [18, 18], [38, -21], [-40, 23], [-7, 20], [-6, 32], [41, 7], [7, -6], [42, -32], [39, -31], [58, -13], [-52, -13], [-50, 21], [19, -30], [-37, -21], [5, -12], [1, 8], [-46, 5], [57, -28], [0, -4], [-60, 10], [-9, 42], [-5, 26], [-23, -4], [-71, 4], [33, -42], [-57, -4], [44, 16], [-74, 18], [16, 0], [-23, -7], [30, -2], [17, 11], [-33, -13], [-49, -2], [12, 0], [8, -10], [-4, 12], [1, 40], [4, -31], [52, -21], [-58, 14], [2, -20], [-23, 22], [-9, 30], [3, -17], [-2, -10], [-3, 7], [22, -9], [-35, 33], [19, 23], [-6, -32], [41, -18], [0, 30], [-77, -8], [0, 33], [-14, 24], [-26, 46], [1, 5], [6, 29], [3, 10], [-35, 6], [-35, -13], [15, 16], [-29, 46], [81, -5], [-44, 6], [41, -37], [-49, 19], [-19, -17], [0, -28], [-92, 2], [-56, 8], [8, -23], [21, 3], [18, 30], [24, -24], [61, -17], [-23, -31], [-38, 12], [-53, -10], [-35, -18], [-43, -8], [42, -30], [-67, 14], [-53, 8], [6, 7], [11, 3], [-5, -3], [-78, 6], [71, 9], [-12, 2], [42, 21], [39, -17], [-39, 30], [0, -36], [-38, -5], [-25, -33], [68, -18], [42, 8], [40, 19], [16, -42], [11, -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_bf();".
// 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_bf(: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_bf();".
// 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_bf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7728_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 5, 1]>,<11,R![-9, 4, 1]>,<13,R![-3, -1, 1]>,<17,R![3, 8, 1]>],Snew);
    return Vf;
end function;