
// Make newform 1792.2.a.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1792_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_1792_2_a_t();".
// 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_1792_2_a_t();".
// 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;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_1792_a();"
function MakeCharacter_1792_a()
    N := 1792;
    order := 1;
    char_gens := [1023, 1541, 1025];
    v := [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_1792_a_Hecke(Kf)
    return MakeCharacter_1792_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, 1], [1, 1], [-1, 0], [4, 0], [-1, -1], [-2, 0], [-1, -1], [-2, 2], [-6, -2], [0, 0], [-2, 2], [-2, 0], [0, -4], [4, -4], [0, -4], [7, -1], [1, 1], [6, 2], [-4, -4], [6, -4], [4, 4], [7, -1], [2, 0], [2, -4], [-3, 5], [8, 0], [14, 2], [-6, -2], [0, -6], [-6, 6], [3, -5], [-10, 0], [-15, 1], [-8, 4], [2, -2], [11, -5], [12, 0], [4, 4], [3, 3], [2, -2], [23, -1], [0, 8], [8, -2], [4, 0], [24, 0], [-2, -6], [-20, 4], [3, 3], [-9, 7], [2, -8], [14, 2], [-6, 4], [1, -7], [10, 8], [12, -4], [7, -9], [-12, -4], [20, 0], [-6, 0], [-9, 7], [21, -3], [3, 11], [-8, 0], [-10, -8], [-4, 8], [-16, -4], [4, 6], [24, 4], [11, 3], [-26, -4], [-10, -6], [20, -4], [-24, 4], [-20, 8], [12, 4], [6, -6], [-17, -9], [4, 2], [-6, 4], [5, 5], [-12, 0], [10, -10], [14, 0], [12, -4], [2, -10], [6, -8], [16, -2], [11, -13], [-16, -8], [-9, 7], [-16, 0], [-18, 2], [10, -2], [-2, 10], [-20, -4], [15, 7], [18, -4], [-13, -5], [8, 4], [-8, 12], [12, 8], [9, -15], [-28, -6], [4, 16], [6, 12], [17, 1], [2, 0], [-24, 0], [-22, -8], [-8, -8], [10, -2], [-28, -2], [-21, -5], [0, -8], [12, 10], [-7, -15], [0, 8], [-26, -6], [16, -12], [25, 1], [6, 8], [-1, -9], [26, -2], [27, 3], [6, 10], [-2, 2], [-28, -4], [-12, -12], [-3, 13], [4, -8], [30, 2], [-6, -10], [-30, 6], [-10, 8], [26, 4], [9, 9], [-25, -9], [31, -1], [8, 6], [7, -9], [4, 0], [4, -12], [22, -6], [-7, 9], [40, 0], [31, -1], [-30, 12], [-19, 5], [16, -8], [22, 10], [6, 12], [34, -2], [12, 12], [22, -6], [-50, 2], [20, -12], [-10, 8], [-18, 4], [-15, -7], [48, 4], [14, -8], [-26, -6], [31, 7], [-18, 0], [8, 16], [4, -12], [33, 1], [0, 22], [51, 3], [-22, 14], [-33, -9], [12, -4], [-6, 16], [-4, 20], [26, -8], [22, -6], [-30, 6], [-24, 16], [13, 5], [26, -10], [37, -3], [-6, 14], [6, -4], [-10, 10], [-9, -25], [32, 12], [31, -1], [6, -16], [32, 0], [-10, -20], [10, -2], [-46, -2], [15, -1], [-14, -18], [34, 0], [-28, 6], [10, -2], [-18, 4], [4, -12], [-8, 4], [32, 16], [-27, -11], [14, -12], [19, 11], [-27, -3], [16, 0], [4, 8], [8, -6], [1, -7], [12, -6], [-11, 5], [26, 6], [31, -1], [20, 20], [-10, 8], [32, -8], [18, -20], [-48, -8], [22, -6], [22, 10], [12, -4], [38, 8], [-26, 10], [-9, 7], [-42, -6], [-6, 24], [-2, -14], [-52, -4], [-28, 0], [-2, -30], [-47, 1], [48, -8], [-14, 8], [39, 7], [-20, 4], [-42, 8], [0, -4], [-14, 6], [16, -8], [24, 12], [27, 19], [4, 20], [0, -20], [-18, 4], [0, -24], [32, 0], [-1, 7], [-40, 4], [-4, -4], [-16, -20], [14, -12], [8, 0], [-38, -8], [-39, 9], [-14, -2], [6, -6], [-7, 9], [-35, -3], [2, -4], [-34, 2], [36, -8], [21, -11], [-51, -3], [2, 12], [-19, 5], [40, -12], [58, 8], [-10, 10], [-46, 6], [-5, -5], [-24, -4], [-22, 24], [10, 22], [26, -8], [16, -24], [-24, 4], [4, 32], [24, 10], [35, 11], [-12, -4], [-20, -4], [52, 4], [13, 21], [23, -9], [-42, 10], [22, 8], [4, -32], [-44, 4], [-34, 20], [-40, -12], [3, -5], [4, 14], [-45, 3], [12, -8], [15, 23], [12, 4], [-17, -1], [-11, 29], [-3, 13], [-6, -28], [10, 14], [24, -16], [-20, -16], [0, -20], [14, 16], [-32, 12], [-55, 9], [26, 6], [-20, 8], [-36, 20], [-2, 2], [6, -24], [28, 0], [-16, 24], [42, -8], [33, 9], [-8, -32], [54, -4], [-38, 8], [33, 1], [30, -8], [5, 29], [52, 4], [8, 6], [6, -24], [16, 4], [19, -29], [-50, 2], [62, -14], [60, -8], [-18, -14], [-20, -12], [-3, -27], [6, 10], [43, 3], [66, 6], [38, -4], [-66, 4], [-48, -16], [-12, -16], [12, -14], [-33, 7], [8, -16], [-18, -14], [-24, -4], [-5, -13], [60, 8], [36, 12], [49, 1], [-47, 1], [-58, -16], [-32, -4], [24, 8], [28, -24], [-14, -32], [40, 8], [-5, -29], [-50, 0], [-34, 18], [-8, -12], [62, 4], [-38, -10], [-42, 10], [7, 23], [28, -26], [11, 27], [-10, -22], [0, -34], [-14, -34], [49, -15], [36, 4], [24, -12], [-32, -24], [48, -4], [-17, 15], [6, -6], [6, 28], [-46, -20], [-30, -4], [11, -13], [-56, 6], [-12, 4], [34, -16], [-19, 37], [28, -4], [28, -20], [17, 17], [2, -10], [-40, -8], [-28, -10], [45, -3], [38, -22], [33, -31], [18, 30], [6, 0], [-64, -16], [-22, -28], [22, -6], [-46, 22], [69, 13], [14, 32], [-24, -32], [-46, -4], [-57, -9], [-32, -8], [-44, 16], [8, -18], [5, 37], [41, 1], [-26, -4], [-2, -14], [12, 8], [70, -14], [-30, 24], [31, -9], [52, -12], [-36, 12], [42, 4], [-20, 12], [-70, 14], [-63, -15], [4, 20], [5, -3], [-2, 32], [17, 1], [40, 12], [-6, 0], [37, -19], [4, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1792_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1792_2_a_t();".
// 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_1792_2_a_t(:prec:=2)
    chi := MakeCharacter_1792_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(2999) - 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_1792_2_a_t();".
// 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_1792_2_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1792_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, -2, 1]>,<5,R![-4, -2, 1]>,<23,R![-16, 4, 1]>],Snew);
    return Vf;
end function;