
// Make newform 2793.2.a.v in Magma, downloaded from the LMFDB on 03 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2793_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_2793_2_a_v();".
// 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_2793_2_a_v();".
// 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 := [-2, 0, 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_2793_a();"
function MakeCharacter_2793_a()
    N := 2793;
    order := 1;
    char_gens := [932, 2110, 2206];
    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_2793_a_Hecke( : Kf := Kf)
    return MakeCharacter_2793_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]];
    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 := [[1, 1], [1, 0], [0, 2], [0, 0], [0, 1], [2, -2], [-4, 0], [-1, 0], [0, 1], [2, 4], [-6, 2], [2, -2], [2, 1], [0, -2], [-4, 0], [0, 2], [-4, -6], [0, -7], [10, 3], [6, -2], [-4, -7], [10, 1], [6, -4], [2, 9], [-10, 2], [0, -10], [6, 2], [2, -8], [-2, -12], [10, -4], [-10, -5], [4, 8], [2, 2], [8, 2], [-6, 0], [10, -1], [4, 9], [8, -6], [-4, 2], [-2, 11], [18, 0], [18, -4], [12, -9], [14, -6], [10, 4], [-8, 6], [-14, -7], [-8, -4], [8, 6], [-4, 13], [10, 14], [0, -9], [14, -4], [-24, 4], [-14, 9], [4, 13], [-6, -13], [0, 10], [-18, -8], [-16, -6], [0, -4], [-18, -5], [10, -2], [-18, 8], [-8, -5], [2, 0], [10, -3], [26, 2], [-24, 5], [28, 1], [16, -4], [16, -3], [24, -4], [-2, -14], [-18, 11], [4, -8], [10, -8], [4, -1], [-2, 4], [10, -14], [24, -8], [-6, 16], [-2, -18], [-22, 6], [-2, -18], [20, 3], [6, 4], [20, 8], [-8, 6], [4, 0], [6, 24], [-2, -20], [18, -13], [16, 15], [20, 2], [-22, 8], [30, -3], [-26, -11], [22, -2], [8, 0], [6, 5], [-22, -6], [8, 2], [-6, -12], [-16, 12], [0, -1], [-18, 4], [44, -2], [34, 2], [-6, -18], [24, -12], [-20, 16], [-14, 18], [-8, 0], [-12, 10], [-4, -2], [0, 26], [10, -4], [10, 6], [-2, -32], [34, 12], [-6, -20], [-26, 15], [-30, 6], [24, -14], [14, -14], [-2, -16], [-42, 0], [0, 14], [16, 15], [-32, -12], [-6, 4], [2, 15], [4, -4], [4, -6], [0, 29], [-22, -7], [-26, -2], [2, -35], [-30, 14], [10, 26], [2, -14], [36, 8], [-10, 0], [10, 6], [-16, -6], [-8, 7], [22, 3], [0, 14], [-34, -12], [2, 8], [16, -4], [4, 6], [-8, 10], [6, 19], [18, 10], [8, 16], [-16, 16], [-20, 13], [-10, 17], [-4, 15], [-30, 0], [16, 30], [-8, -16], [-6, -16], [32, 0], [10, 27], [44, 3], [-18, -26], [-12, -10], [-30, -22], [14, -12], [-8, 35], [16, -28], [8, -8], [20, -18], [36, 4], [-6, -2], [0, 12], [32, 21], [28, -6], [-4, -20], [-26, 2], [10, -1], [28, 11], [-40, 2], [26, -2], [12, 8], [-54, 4], [16, 4], [-18, 20], [44, 9], [-34, 7], [2, -27], [4, -25], [-34, -19], [0, 40], [-24, 32], [36, -8], [18, 12], [8, -34], [16, -24], [-30, 16], [34, 24], [38, 16], [20, -14], [-4, -20], [22, -2], [6, 22], [18, 14], [26, -28], [36, 18], [-4, -16], [12, 36], [-4, -30], [34, -4], [48, 4], [18, -13], [50, 6], [-14, -18], [-42, 12], [-16, -28], [-24, -26], [-24, -4], [0, 20], [28, 0], [18, -3], [-6, -24], [10, -18], [0, 23], [-46, 16], [6, 34], [50, 7], [-16, -14], [-16, -12], [48, 8], [-28, 17], [22, -30], [-4, -33], [16, -8], [-30, 6], [12, -2], [-8, 38], [54, 8], [-38, 13], [-10, -24], [0, -22], [4, 6], [2, 27], [4, -41], [-4, 48], [-8, 22], [28, 7], [-10, 20], [-4, 12], [8, -29], [-14, 4], [-4, -32], [-66, 3], [-12, 25], [-30, 21], [30, 26], [-8, 15], [-18, -26], [-12, 26], [-4, 32], [0, -6], [-12, -6], [50, 7], [14, -36], [-18, 8], [-6, -31], [-20, -3], [8, -50], [-30, -14], [16, -16], [48, -3], [22, 36], [-22, -2], [-30, -24], [56, -16], [-60, -8], [46, -8], [46, -18], [-4, -42], [0, 43], [-52, -16], [-20, -42], [-8, -20], [30, 15], [38, 2], [-22, 32], [8, 10], [-52, 2], [6, -30], [-8, -8], [-34, -10], [20, 2], [64, -6], [0, -28], [12, -23], [26, 20], [-52, -18], [22, 6], [-16, 6], [-10, -6], [-30, -14], [-10, -2], [-44, -11], [-44, -12], [16, -32], [38, 16], [-36, 10], [26, -3], [48, -21], [22, -2], [14, 36], [46, -14], [32, -37], [-74, 0], [20, -4], [42, -16], [14, 31], [30, 41], [26, -16], [42, -4], [-2, 53], [34, -18], [14, -18], [14, -10], [-52, 0], [20, 18], [28, -10], [0, -32], [-32, -42], [10, 4], [-50, 4], [-54, -27], [40, -31], [28, 2], [-38, 6], [-18, -32], [-46, -25], [30, -31], [-44, -30], [30, -44], [8, 31], [50, 9], [-20, -4], [4, 22], [-20, -20], [38, 2], [-74, 10], [24, -4], [6, -30], [-66, 1], [-8, -40], [68, -4], [6, 36], [-6, 42], [44, -12], [-44, 18], [70, -10], [-26, 46], [-60, 6], [18, 0], [-20, 24], [14, -21], [30, -6], [-52, 15], [52, 8], [40, -7], [-46, 36], [-56, -18], [-36, -8], [36, -24], [24, -29], [8, -7], [44, 22], [-62, 0], [-18, 27], [-78, -2], [12, 22], [-58, 0], [-4, -12], [-60, -20], [-32, 6], [-36, -35], [36, -34], [-92, 2], [-42, -24], [14, -39], [44, -31], [-20, -10], [-74, 0], [-38, -42], [14, 6], [-26, 1], [-42, 33], [26, -26], [-42, -14], [-6, -44], [-18, -29], [38, -13], [14, -15], [-44, -32], [-34, 8], [28, 18], [-50, -30], [38, 20], [-34, -6], [-50, -32], [-34, -36], [-84, -14], [18, 8], [24, 8], [-74, -20], [32, 0], [-88, -4], [-24, 14], [36, -2], [66, 12], [48, -25], [-84, 4], [-14, 62], [34, -31], [22, -44], [-26, 28], [20, 16], [60, -20]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2793_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2793_2_a_v();".
// 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_2793_2_a_v(:prec:=2)
    chi := MakeCharacter_2793_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_2793_2_a_v();".
// 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_2793_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2793_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -2, 1]>,<5,R![-8, 0, 1]>,<11,R![-2, 0, 1]>,<13,R![-4, -4, 1]>,<17,R![4, 1]>],Snew);
    return Vf;
end function;