
// Make newform 2828.2.a.c in Magma, downloaded from the LMFDB on 12 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2828_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_2828_2_a_c();".
// 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_2828_2_a_c();".
// 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_2828_a();"
function MakeCharacter_2828_a()
    N := 2828;
    order := 1;
    char_gens := [1415, 2425, 2325];
    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_2828_a_Hecke(Kf)
    return MakeCharacter_2828_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 := [[0, 0], [3, 0], [2, -3], [-1, 0], [1, -4], [2, 1], [2, 2], [5, 0], [-6, 3], [-7, 4], [3, 4], [-6, 7], [-2, 3], [-5, 1], [-8, 5], [-7, -3], [-1, 10], [-8, 7], [-6, 7], [4, -1], [4, 4], [3, -6], [15, 1], [-5, -8], [13, -2], [-1, 0], [11, -5], [2, -13], [-6, -5], [3, 5], [9, 2], [18, -7], [0, 8], [3, 0], [-2, 0], [16, -4], [-7, -7], [-5, 13], [15, -11], [10, -1], [-4, 14], [8, -10], [-4, -10], [8, -14], [-2, -3], [-4, -6], [-24, 4], [9, -12], [-11, 3], [-9, 6], [-7, -8], [-17, 8], [7, 8], [-1, -13], [14, -12], [12, -16], [-7, 3], [-6, -5], [3, -6], [7, 6], [9, 4], [4, -20], [13, -15], [23, -10], [17, -14], [-28, -1], [-11, 1], [8, -10], [1, 8], [-12, 10], [28, -1], [-1, 6], [7, 14], [6, -26], [16, -27], [5, 5], [23, -12], [3, -18], [-17, 18], [5, 3], [-19, 30], [-6, 25], [-20, 21], [-9, -13], [13, 16], [-2, -7], [-21, 17], [-21, 4], [3, -26], [19, 11], [24, -2], [21, -12], [14, 8], [-16, 2], [9, -10], [15, 4], [-5, 27], [10, 8], [-4, 4], [21, 12], [28, -14], [5, -19], [23, -9], [-10, 0], [-5, 13], [18, -22], [-31, -4], [-11, 10], [-4, 10], [-35, 12], [-3, 5], [22, -28], [-28, 10], [21, -7], [-29, 7], [-2, 29], [30, -30], [12, -19], [6, 2], [-1, -13], [-18, 22], [5, -12], [-3, 28], [-49, 0], [-6, -4], [-11, 21], [11, -10], [24, -26], [-35, 6], [-9, 26], [16, -20], [23, -32], [-14, 21], [20, 1], [-6, -21], [3, 13], [7, 9], [34, -12], [-19, -12], [-11, 19], [4, -6], [-22, -12], [3, 10], [-15, 35], [-27, -2], [-37, 19], [22, -1], [-16, 33], [39, -7], [31, -36], [-46, 12], [36, 11], [-52, 2], [25, -6], [3, 17], [-4, -13], [-27, -6], [-4, -33], [-17, 8], [-15, 16], [4, 9], [-26, 17], [10, -38], [21, -8], [16, -45], [9, 2], [13, 15], [-18, 33], [40, -27], [-8, 41], [-7, 31], [-38, 16], [8, -24], [-25, 12], [-28, -4], [7, 18], [-33, 28], [-30, 27], [17, 4], [13, 9], [-40, 33], [4, -22], [18, -11], [-57, -2], [27, -6], [12, -34], [27, -18], [-25, 18], [-14, -19], [-35, 5], [-5, 12], [-11, -16], [-24, 32], [11, -35], [-30, -17], [-2, -25], [31, -33], [-28, -5], [-33, -4], [-5, 26], [19, -8], [-12, 15], [-23, -9], [-17, 9], [5, 13], [6, -23], [39, -18], [11, -34], [-6, 9], [26, -34], [26, 14], [29, -4], [6, 1], [3, 20], [41, -9], [-5, -11], [37, 12], [2, -25], [-31, 23], [-42, 36], [-25, 25], [22, 28], [40, -28], [10, -12], [-39, 16], [46, -25], [1, 31], [-40, 13], [20, -52], [29, -13], [-7, -19], [23, 12], [54, -4], [43, 9], [29, -49], [-50, 9], [-11, -30], [-24, 10], [8, -16], [-12, 30], [-25, 34], [3, 18], [6, 36], [13, -34], [-33, 48], [31, -50], [58, -4], [26, 3], [25, -60], [-45, 30], [-4, -9], [25, -10], [67, 1], [-27, -12], [9, 34], [-65, 16], [38, -34], [15, 18], [-40, -18], [30, -6], [-1, 11], [1, 32], [-36, 19], [-30, -8], [6, -15], [8, -17], [-22, 20], [-19, 36], [28, -4], [36, -48], [-22, -7], [-17, 48], [-37, 9], [-27, 46], [1, 18], [-3, -1], [-58, -15], [3, 37], [42, -44], [-62, 37], [23, -27], [-21, 16], [-76, 6], [-41, 38], [-34, 4], [-32, 5], [-15, -15], [-23, 5], [-29, 5], [-19, -4], [-44, -12], [10, -18], [22, -18], [4, -6], [-47, -14], [-27, 6], [-41, -1], [0, 32], [33, -18], [1, 31], [26, -21], [3, -42], [37, -32], [-8, 11], [-21, -25], [61, 4], [-66, -3], [52, -34], [25, 30], [-21, 28], [1, 40], [-25, 19], [1, -20], [-52, 5], [-10, -6], [1, 3], [-17, 13], [-1, 48], [1, 16], [-51, 34], [-7, 14], [-46, 35], [-28, 18], [54, 7], [65, -14], [-65, -14], [-21, 10], [62, 4], [18, -31], [-24, 16], [-14, 7], [2, 3], [-38, 40], [-65, 18], [-17, 64], [-1, -46], [-52, 12], [-5, -38], [-23, -4], [-30, 37], [-21, 54], [0, -23], [-39, 79], [-1, -25], [23, -22], [35, 16], [-8, -35], [15, -27], [11, -46], [48, 0], [13, -66], [31, 5], [-8, -5], [84, 4], [23, -51], [69, 4], [-41, 39], [-40, -12], [8, 11], [-30, 16], [-30, 11], [-58, -24], [-35, -29], [23, 11], [-6, 29], [-11, 55], [-49, 67], [56, 15], [-38, -10], [-51, 12], [-16, 66], [-11, 42], [25, -14], [7, 14], [22, -37], [-45, 6], [-17, 27], [32, 26], [-1, -6], [-44, 72], [-12, -21], [-30, -22], [4, -32], [-4, 26], [-57, 15], [69, 10], [51, -10], [39, 16], [36, -22], [22, -1], [-23, 18], [-25, -17], [47, -26], [-85, -4], [-11, -38], [24, -59], [-2, -46], [-42, 32], [-15, 48], [31, -57], [42, 11], [45, -11], [-30, 60], [-35, -35], [-28, 38], [-4, -16], [-39, 7], [32, 33], [17, -69], [21, -12], [-33, 63], [66, 5], [-39, -30], [0, 19], [-20, 31], [8, -16], [-22, 19], [-45, -2], [49, -17], [12, -42], [44, -44], [-5, -29], [-11, -9], [40, -54], [29, -12], [93, -21], [-1, 27], [2, 57], [18, -57], [-1, -41]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2828_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2828_2_a_c();".
// 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_2828_2_a_c(:prec:=2)
    chi := MakeCharacter_2828_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_2828_2_a_c();".
// 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_2828_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2828_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>],Snew);
    return Vf;
end function;