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