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