
// Make newform 2672.2.a.b in Magma, downloaded from the LMFDB on 30 April 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_b();".
// 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_b();".
// 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+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, -2], [4, -1], [4, 0], [5, -1], [0, -5], [2, 4], [4, -3], [-5, 2], [-2, -2], [-3, 8], [-1, 2], [5, -4], [1, 2], [-8, 2], [-2, -6], [-11, 2], [-5, 2], [-7, 3], [-2, 5], [3, 0], [3, 8], [0, -2], [-5, 13], [7, -8], [-1, 7], [-9, 14], [14, -4], [-5, 2], [-7, 16], [11, -8], [-12, 8], [-1, -13], [10, 3], [4, 3], [19, -2], [18, 2], [1, 0], [-1, 4], [-12, 11], [-10, -8], [-7, -5], [7, -1], [6, -3], [-19, 5], [20, -3], [1, -17], [11, 0], [17, -1], [-10, 11], [-4, 9], [9, -13], [17, -6], [11, -21], [-5, 12], [-5, 17], [12, 0], [14, -21], [-21, 16], [8, -8], [2, 8], [-20, -5], [5, 12], [15, -23], [0, -13], [7, 0], [3, 14], [11, -1], [-31, 0], [10, -2], [23, -10], [-11, -6], [8, 11], [-1, 20], [5, -8], [-19, 16], [-7, 11], [-28, -1], [4, 1], [-7, -4], [8, 14], [30, 2], [-10, -11], [-29, 18], [-11, 15], [-13, 26], [-13, 1], [-18, 5], [11, 6], [-31, 9], [28, 0], [-15, 24], [13, -16], [-14, 11], [26, 5], [16, -9], [6, -2], [25, 2], [9, 8], [-6, 1], [9, 6], [-6, 5], [-25, -2], [-32, 7], [-23, -5], [-12, 11], [-1, 0], [1, 23], [24, -13], [-3, 5], [21, -7], [-13, -18], [30, -30], [-18, 3], [-33, -9], [35, -5], [-6, 13], [-15, -7], [22, -34], [42, -9], [18, 0], [-4, 14], [-7, 9], [-5, 16], [-15, 18], [31, -11], [25, -9], [20, -5], [-6, -8], [18, -27], [34, -1], [1, 12], [4, 17], [28, -27], [-37, 24], [10, 26], [2, -10], [-19, -2], [17, 17], [27, -10], [-14, 3], [45, -13], [-20, -9], [10, -2], [-51, 6], [14, 25], [-31, 23], [14, 6], [-18, 43], [34, -35], [-16, 24], [-28, 11], [29, -32], [7, -28], [-11, -22], [35, -1], [-23, 31], [-10, 6], [23, -16], [3, 5], [46, -17], [-51, -3], [-15, -22], [3, -21], [-44, 24], [4, 8], [-26, 48], [26, -48], [-15, 13], [12, -16], [21, -16], [33, -15], [-19, -6], [25, -30], [-18, 0], [48, -8], [-42, -2], [19, -2], [-8, -17], [-21, 13], [49, -23], [63, -2], [17, -43], [-30, 0], [-20, 1], [-8, -17], [-29, 6], [-17, -6], [-13, 46], [1, 8], [-21, 32], [-8, 27], [34, -51], [-9, -8], [-7, 42], [22, -7], [-22, -10], [-33, 22], [36, -50], [-27, 16], [-26, 12], [18, -52], [27, -26], [-8, 9], [-35, 25], [-22, -21], [39, 12], [17, 1], [56, -22], [-19, 19], [-6, 27], [0, -27], [-2, 8], [4, 12], [23, 1], [36, -36], [-25, 14], [-15, -13], [-7, 48], [35, -28], [57, -28], [-41, 17], [47, 9], [35, 21], [62, -14], [11, -15], [-27, 18], [-17, -4], [-10, -24], [-3, -26], [11, 22], [14, -28], [3, -14], [-32, -23], [-3, -3], [6, -3], [-4, 19], [-17, 41], [-32, 33], [-33, -22], [49, -3], [35, -53], [8, 12], [8, 6], [42, -20], [-20, -2], [15, -26], [-62, 4], [11, -28], [-45, 18], [-13, -4], [50, -16], [-5, -39], [-27, 8], [16, -45], [-6, 22], [-35, -6], [31, -56], [20, -24], [-11, 27], [-36, -12], [42, -9], [11, -11], [26, -4], [-13, 40], [-34, -24], [19, 12], [21, -26], [51, -27], [30, -21], [7, 20], [6, -28], [-19, 48], [-39, 56], [-30, -3], [26, -66], [24, 34], [-38, -11], [-8, -15], [-2, -49], [24, 12], [10, -37], [-2, 38], [-26, 56], [-21, -9], [24, -1], [9, 10], [-61, 18], [1, 1], [-45, -10], [-46, 19], [-6, 9], [11, 3], [-8, 13], [-63, 19], [59, -24], [-43, 53], [0, -10], [1, 23], [-20, 47], [21, -33], [-11, 32], [-2, -37], [39, -15], [22, -14], [1, -35], [16, 44], [5, 8], [55, -8], [49, -35], [28, 10], [9, -18], [-32, 6], [-13, 32], [-33, 62], [29, -4], [-48, -6], [-76, 4], [-21, 2], [-28, 61], [12, -24], [14, 29], [-31, 24], [54, -22], [30, -46], [-26, 21], [-24, 7], [-71, 3], [22, -15], [-65, 29], [17, -28], [-6, 9], [-9, 18], [-29, 63], [-13, 28], [-34, -14], [16, 14], [-42, -21], [34, -16], [50, -42], [-40, 2], [-77, -3], [-45, -10], [-36, 70], [-9, 13], [-32, -28], [-16, 7], [-23, 15], [-41, -3], [29, -36], [-44, 12], [-51, 28], [-52, -8], [22, -9], [16, 33], [-32, -2], [7, -49], [56, -19], [-53, -16], [46, 10], [-28, 73], [-35, 34], [45, 25], [-27, -16], [63, -26], [43, -48], [22, -42], [28, -14], [-18, -18], [4, 42], [10, -48], [19, 10], [-20, 23], [23, -44], [-78, 8], [79, -20], [-20, -33], [11, 37], [-33, 5], [-7, -53], [18, 33], [-49, 67], [74, -23], [33, -40], [-51, -20], [3, 26], [-45, -20], [-7, 14], [-28, -1], [14, -39], [19, 7], [-56, -26], [-71, -17], [31, -32], [43, -67], [19, -24], [66, -26], [-17, 32], [31, -64], [53, -17], [-28, 30], [54, -52], [-6, 48], [50, 15], [24, -4], [46, -31], [-47, -17], [-32, -30], [-3, 57], [-27, 26], [18, -44], [61, -63], [3, -26], [-70, -6], [34, 9], [13, 6], [55, -14], [51, 16], [10, -47], [53, -33], [-19, -39], [-54, 52], [-44, 48], [-31, 20], [34, -12], [31, -13], [-7, 3], [-54, 56], [61, 14]];
    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_b();".
// 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_b(: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_b();".
// 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_b( : 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, 3, 1]>,<7,R![11, -7, 1]>],Snew);
    return Vf;
end function;