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