
// Make newform 2672.2.a.e in Magma, downloaded from the LMFDB on 04 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2672_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_2672_2_a_e();".
// 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_2672_2_a_e();".
// 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_2672_a();"
function MakeCharacter_2672_a()
    N := 2672;
    order := 1;
    char_gens := [335, 2005, 673];
    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_2672_a_Hecke(Kf)
    return MakeCharacter_2672_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], [0, 1], [-1, 0], [1, -2], [3, -1], [-1, 2], [-1, -3], [-1, 2], [1, 2], [-7, 2], [-1, 6], [6, -9], [-5, 2], [-2, -5], [6, -6], [3, -1], [3, -4], [-2, -1], [-4, -3], [-8, 12], [0, 1], [-7, 2], [-13, 3], [-6, 10], [0, -6], [-9, -2], [-7, -3], [0, 1], [-6, 6], [-6, -1], [-3, -3], [9, -10], [-15, -1], [4, 2], [-2, 10], [5, 6], [-11, 11], [-5, 13], [1, 0], [11, -6], [12, 3], [-5, 12], [-14, 2], [-3, 11], [6, 1], [11, -13], [2, 7], [-13, 0], [-2, 10], [7, -12], [-9, 21], [20, -7], [-11, 7], [-12, -4], [7, -13], [11, -12], [8, -5], [-7, 20], [-13, 12], [-4, 14], [-11, -6], [28, -6], [6, -25], [3, -9], [-11, 24], [15, -20], [15, 1], [-22, 1], [16, -3], [14, -2], [1, -9], [13, -14], [3, 6], [7, -11], [-11, 15], [-1, -7], [-14, -5], [-32, -2], [7, -2], [-3, -7], [8, -12], [2, -23], [26, -12], [16, -18], [23, -2], [-4, 27], [11, 2], [-12, -15], [30, 4], [4, -6], [-6, 30], [-4, -16], [19, 7], [18, 1], [-29, -7], [1, 16], [16, -13], [29, 4], [-9, 18], [5, -7], [8, 4], [9, 21], [-15, -2], [-10, -15], [32, -22], [-1, 16], [-19, 7], [3, -13], [-10, 17], [-36, 11], [23, -22], [-29, -4], [20, -11], [9, 12], [-30, -10], [22, -20], [32, -30], [-5, 15], [11, 14], [3, 6], [23, -32], [13, -38], [-22, -9], [-36, 10], [3, -2], [12, 14], [28, 0], [-33, 6], [1, 14], [30, -19], [-31, -2], [27, 8], [-25, 27], [-1, 33], [0, 31], [-2, -11], [1, 30], [-17, 8], [21, -9], [-36, 7], [47, -4], [2, -28], [-50, 1], [-13, 17], [-12, 22], [25, -19], [21, -29], [41, -10], [-25, -20], [19, -24], [28, -13], [13, -1], [9, -9], [43, 7], [22, -2], [2, 15], [18, -2], [9, 24], [-34, -6], [-51, 6], [37, -29], [3, -19], [-47, -2], [-8, 29], [-26, -19], [29, -6], [10, -15], [10, -23], [-38, 19], [-43, 23], [-12, 11], [37, -14], [-21, 24], [-40, -12], [-28, 26], [-39, 18], [-19, 34], [-16, -21], [26, -3], [20, -3], [28, -32], [-5, 7], [-16, 32], [-4, 23], [32, -34], [1, -28], [-24, 4], [28, -24], [30, 5], [-39, -1], [-47, -2], [43, -20], [-18, 6], [-14, -13], [1, -10], [33, -21], [-12, 36], [-4, 28], [-11, -2], [-50, -5], [-24, 15], [-40, 23], [1, 16], [-14, -12], [9, 10], [-15, 34], [-7, -13], [-17, 40], [-35, 1], [-60, 13], [9, -9], [37, -28], [20, -2], [-38, 6], [-3, 37], [33, -62], [-45, 16], [10, -34], [37, -28], [-19, 35], [-15, 24], [37, -27], [-58, 8], [-13, -1], [-22, -15], [-1, -20], [-18, -30], [-10, -21], [4, -17], [35, -51], [-5, 40], [56, -24], [18, -33], [35, -62], [56, -7], [31, -30], [35, -14], [-53, 14], [46, -30], [-7, -22], [-58, -10], [-31, 27], [41, -49], [-31, 8], [9, -12], [17, 18], [-17, -20], [20, -33], [-25, -17], [27, 20], [31, 7], [51, 8], [8, -28], [-62, 15], [19, 15], [-28, 2], [-72, 10], [-1, 20], [5, 26], [-27, 60], [-6, -38], [37, 15], [39, -34], [-41, 48], [-13, -2], [-14, -16], [1, -23], [-9, 28], [-12, 12], [-52, -3], [-3, -14], [-52, 42], [44, 2], [0, 48], [-11, 6], [-17, 50], [-25, 14], [-22, 24], [-40, 47], [-33, 24], [78, -1], [-29, 23], [-30, -17], [27, 23], [-34, 17], [-7, -2], [19, -26], [5, -23], [-48, 2], [-70, 14], [-10, -10], [-27, 17], [11, 17], [41, 10], [-19, 17], [-3, -39], [56, -24], [-32, -8], [50, -9], [33, -18], [53, -18], [-34, 39], [-38, -24], [19, 11], [35, -24], [75, -12], [16, 28], [-13, 13], [1, 27], [-48, 18], [8, 2], [13, 46], [43, -6], [-71, 0], [3, -6], [7, -23], [-39, 28], [32, -17], [1, -26], [69, -24], [-59, -3], [-5, -13], [-8, -30], [-27, 59], [15, 1], [-32, -15], [45, -69], [12, -32], [-3, -25], [-53, -18], [-57, 40], [15, -58], [36, -28], [-38, 18], [50, -60], [-5, 2], [34, -45], [7, 32], [44, -66], [-78, 13], [26, 23], [32, 18], [0, 20], [15, 30], [-16, -15], [70, -27], [22, 22], [21, -46], [-46, 10], [2, 37], [33, -1], [-73, 24], [-50, 7], [-4, -51], [38, 12], [-3, 0], [-31, 49], [58, 20], [31, -6], [17, -13], [29, -44], [53, -4], [29, -51], [-2, 54], [72, -1], [41, -66], [51, 12], [34, -63], [-28, -34], [-78, 3], [-2, 21], [-51, 16], [-59, 61], [62, -21], [9, -24], [76, -39], [53, 22], [-79, -8], [24, 14], [2, 20], [-27, 50], [14, -23], [46, 13], [8, 38], [31, 8], [-73, 22], [34, -56], [-36, 33], [-37, 26], [-77, -13], [14, 36], [-46, 4], [19, -3], [-25, 42], [32, -57], [3, 12], [-60, 24], [1, 29], [77, 6], [10, -52], [33, 34], [-6, 36], [30, 6], [49, -68], [32, 26], [-16, 44], [72, -31], [43, -46], [57, -42], [-26, -18], [-29, -12], [22, -59], [-15, 22], [-44, 60], [66, 16], [28, -62], [-61, 58], [-51, -22], [47, -63], [-62, -17], [32, 11], [-61, 19], [-25, -15], [26, -14], [26, 15], [15, 48], [14, -60], [19, 27], [5, -66], [15, 46]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2672_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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