
// Make newform 2790.2.a.u in Magma, downloaded from the LMFDB on 18 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2790_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_2790_2_a_u();".
// 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_2790_2_a_u();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2790_a();"
function MakeCharacter_2790_a()
    N := 2790;
    order := 1;
    char_gens := [2171, 1117, 1801];
    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_2790_a_Hecke( : Kf := Kf)
    return MakeCharacter_2790_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], [0], [-1], [3], [-3], [-2], [-8], [-7], [-7], [8], [-1], [-4], [0], [1], [-6], [-5], [-6], [2], [10], [-9], [1], [13], [16], [3], [6], [-5], [8], [3], [4], [-1], [-12], [-6], [-10], [-10], [9], [-8], [-7], [18], [-15], [6], [-4], [-21], [24], [-14], [-6], [-3], [17], [-10], [-25], [-13], [25], [-8], [-22], [-20], [23], [-24], [18], [7], [-8], [28], [-16], [-14], [-12], [16], [-10], [-24], [32], [-10], [12], [20], [18], [-1], [-18], [13], [19], [36], [22], [25], [35], [12], [-16], [34], [-32], [19], [-26], [-19], [-34], [-38], [20], [-40], [0], [27], [-20], [29], [-20], [-32], [24], [18], [29], [14], [-14], [-17], [36], [-37], [-22], [-8], [-16], [-30], [-35], [-30], [-13], [26], [3], [-18], [-5], [30], [19], [-49], [6], [32], [-46], [-46], [43], [15], [5], [-33], [-15], [30], [-29], [2], [-40], [-1], [6], [-2], [-49], [9], [1], [-27], [2], [-13], [-23], [24], [14], [44], [-21], [27], [45], [22], [-24], [31], [2], [-18], [-13], [-22], [-40], [0], [-10], [-3], [-16], [28], [-38], [-12], [-32], [54], [-46], [-48], [5], [-6], [-22], [-9], [-20], [-15], [-32], [28], [30], [33], [-12], [43], [29], [21], [-64], [-33], [46], [-18], [-30], [-26], [57], [-60], [-28], [-35], [53], [33], [64], [20], [32], [24], [14], [29], [25], [-30], [-9], [19], [65], [-43], [-34], [-38], [48], [-66], [-48], [-28], [-41], [-24], [24], [-63], [66], [7], [8], [54], [-40], [-42], [13], [-12], [24], [-21], [39], [67], [-26], [36], [38], [-54], [-2], [36], [14], [-25], [-44], [-57], [13], [-66], [63], [-16], [-24], [-10], [-6], [50], [36], [45], [-30], [19], [44], [-4], [29], [38], [51], [23], [24], [58], [-26], [-39], [-22], [-40], [-19], [18], [-61], [-71], [26], [-53], [27], [-28], [-46], [4], [52], [44], [49], [41], [18], [0], [-67], [46], [58], [-39], [-12], [50], [-26], [-42], [-38], [-50], [41], [78], [-8], [30], [-63], [39], [12], [-22], [-20], [68], [52], [-2], [-1], [-17], [-58], [37], [-56], [-33], [38], [36], [-18], [-10], [42], [26], [88], [-16], [6], [-47], [-2], [-28], [36], [-68], [-28], [65], [-40], [-49], [-35], [63], [39], [-44], [19], [-66], [-12], [-69], [-50], [-6], [26], [10], [89], [-15], [-38], [21], [-55], [-8], [68], [42], [0], [85], [-30], [6], [52], [-53], [-90], [-12], [0], [71], [43], [-50], [14], [-30], [-6], [-59], [-48], [-58], [83], [-17], [-63], [-62], [38], [-39], [-22], [46], [55], [-12], [-39], [42], [42], [-82], [-94], [-77], [3], [56], [100], [-11], [-28], [-66], [22], [92], [50], [-66], [68], [-100], [93], [-59], [64], [7], [28], [-86], [17], [66], [37], [38], [70], [4], [69], [-31], [45], [-98], [24], [-42], [58], [-30], [59], [-29], [34], [-60], [-52], [-12], [-56], [13], [42], [13], [-69], [-18], [22], [-36], [-45], [-60], [-56], [1], [47], [15], [-52], [-90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2790_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2790_2_a_u();".
// 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_2790_2_a_u(:prec:=1)
    chi := MakeCharacter_2790_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_2790_2_a_u();".
// 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_2790_2_a_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2790_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 1]>,<11,R![3, 1]>,<13,R![2, 1]>,<17,R![8, 1]>,<19,R![7, 1]>],Snew);
    return Vf;
end function;