
// Make newform 3267.2.a.r in Magma, downloaded from the LMFDB on 04 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3267_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_3267_2_a_r();".
// 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_3267_2_a_r();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_3267_a();"
function MakeCharacter_3267_a()
    N := 3267;
    order := 1;
    char_gens := [3026, 244];
    v := [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_3267_a_Hecke(Kf)
    return MakeCharacter_3267_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, -1, 0], [0, 0, 0], [-1, 0, 1], [0, 1, 1], [0, 0, 0], [2, 2, -1], [1, 1, 2], [-3, 0, 0], [-4, -1, -2], [2, -2, -2], [2, -4, -1], [-2, 2, -1], [-4, -3, -2], [-1, -2, 1], [-1, 2, -2], [-4, -2, 1], [-7, 5, 1], [-5, -1, -1], [6, -4, -1], [-7, 1, 1], [-5, 0, -3], [-5, 1, -5], [6, -6, -3], [1, -1, -1], [-1, -6, 0], [5, -4, 4], [1, 4, -2], [1, 5, 5], [6, -2, 1], [-4, -5, 4], [4, -2, 4], [-11, 5, -1], [-13, 2, -2], [7, 3, -3], [-6, 7, -3], [8, -3, 0], [0, 5, 2], [1, 0, 3], [2, 4, -2], [3, 3, 3], [3, 6, 0], [0, -8, -2], [-7, -7, 4], [-5, 3, 6], [-10, -3, -2], [-12, 6, 3], [14, -5, -2], [-3, 1, -2], [2, -5, -2], [3, 0, 3], [10, 5, -4], [18, 3, 0], [1, -6, -6], [7, -2, -1], [-10, 9, 1], [0, 1, -6], [-10, 6, -5], [6, 5, 8], [5, -13, -1], [6, -3, 12], [-1, -13, 2], [-5, 8, 2], [10, -2, -2], [15, 0, 9], [16, -5, -2], [-23, 1, 2], [7, 6, 3], [5, 0, 9], [9, 5, 3], [4, -13, -1], [-7, 4, -8], [-6, 8, 6], [-1, -4, 8], [-15, 4, -5], [18, -8, 4], [-2, -3, -4], [-5, -7, 2], [-20, 3, 0], [0, -5, 0], [7, -7, -1], [-5, -3, -7], [15, 7, 4], [-10, 10, 7], [4, 9, 3], [14, 2, -1], [0, 5, 6], [-11, -6, -13], [10, -4, 11], [17, 1, 4], [-2, -6, -3], [1, 8, -4], [12, -2, 3], [-23, 1, 1], [-18, -4, -12], [-12, 8, 8], [-3, -1, 0], [-8, 2, -7], [6, 3, -9], [8, 0, -3], [-23, 3, 3], [-1, -3, -9], [-10, 18, 4], [-28, 0, 4], [20, -14, -5], [-21, 2, 8], [-6, 3, -15], [22, -5, -7], [28, -9, -4], [-19, 3, 1], [4, 7, 1], [11, -3, 6], [6, 11, 5], [-8, -16, 5], [4, -5, 16], [-2, 6, 6], [16, 2, 2], [-25, -3, -3], [3, -11, 3], [-3, -7, 9], [-24, -4, -15], [7, 3, 9], [-18, 17, 11], [-20, 2, -7], [5, 8, 7], [-1, 3, 12], [25, 3, 2], [11, 6, 15], [15, 9, 12], [2, -17, -2], [1, 5, 14], [-3, 14, -7], [31, -8, 2], [-15, 7, 7], [-3, 2, 14], [23, 7, 13], [-4, 9, -6], [-10, 7, 1], [-3, -11, -2], [-22, 11, -2], [-33, 3, 3], [-14, 12, 0], [-11, 1, -13], [22, 5, 14], [-16, 11, -14], [-20, 9, 0], [18, -25, -3], [-14, 7, -11], [2, 11, -2], [2, -5, -17], [10, 14, -7], [-12, 15, -9], [6, -20, 9], [11, 2, 2], [1, 9, 17], [2, 19, -2], [11, 7, -5], [-3, 7, -11], [4, -19, 5], [8, 0, -6], [17, -8, 1], [-25, 19, 1], [-40, 0, -5], [-17, -12, -9], [-1, -19, 10], [-31, 1, 1], [-10, 13, 7], [26, 11, -1], [-9, -7, 8], [1, -2, -2], [-22, -14, 1], [-12, -2, 0], [-24, -2, -11], [-4, 5, -11], [38, 6, 12], [1, 13, 16], [-3, -11, -3], [25, 1, 4], [-8, 6, 8], [-9, -4, -7], [-28, 2, -4], [-22, 18, 6], [-32, -3, 5], [-17, 8, -1], [-20, 5, -4], [-4, 22, -11], [-10, -11, -20], [14, -5, 10], [0, 3, -9], [9, 11, -16], [-2, -15, -16], [-21, 8, 8], [-12, -13, 12], [2, -8, 16], [-16, -2, -17], [-8, -13, -1], [-13, 10, -8], [41, -3, 3], [-16, -4, -4], [9, -12, -3], [-18, 10, 15], [5, -8, 1], [11, 22, -11], [-44, 8, 2], [-54, 1, 4], [-13, -13, 10], [-21, 2, -15], [11, -23, 10], [24, -6, 15], [25, -10, -10], [-16, -7, -4], [-37, 19, 4], [-8, 17, 5], [-12, -18, -6], [25, 13, 2], [-39, 21, 6], [-5, 13, -17], [37, -23, -11], [-37, -5, 1], [-26, -1, -13], [-39, 0, -3], [13, -9, -12], [10, 11, 17], [37, 5, 11], [-13, -21, -15], [-7, -2, -14], [-4, 12, 3], [-6, -6, 9], [33, -18, 0], [27, -17, 1], [8, 15, -8], [-40, 8, 2], [35, -1, 8], [-15, 1, -17], [-43, 14, -5], [-29, -9, -21], [3, -10, -12], [-20, -13, -19], [-16, 19, 4], [26, -21, -11], [6, 29, -3], [2, -24, -23], [4, -29, 13], [21, -12, 18], [-2, 23, 2], [23, -9, 1], [-9, -6, 9], [21, 5, 8], [62, -4, 4], [-26, 2, -7], [-50, 16, 2], [10, 3, 18], [-18, -8, -15], [5, 1, 1], [-12, -4, 11], [10, 8, 8], [0, -16, 3], [2, -10, 23], [17, -20, 1], [-6, -18, -6], [3, -23, -8], [10, 18, 12], [24, -6, 6], [-17, 7, 13], [-8, 2, 5], [-7, 13, 1], [9, -5, -11], [6, -18, -15], [18, 12, 18], [12, 11, 20], [-32, -4, -19], [-1, -9, -15], [4, 17, 2], [23, 2, -7], [-19, 24, -3], [-1, -27, 0], [45, 14, -4], [16, -10, 2], [1, -3, 3], [10, -3, 15], [4, -1, 14], [-5, 10, 17], [9, -10, -22], [-26, 18, -7], [-20, 4, 1], [-7, 11, 2], [4, 14, 29], [32, -17, -8], [2, -32, 4], [-12, 4, 4], [-6, -7, 6], [-65, 6, -4], [-20, -21, -7], [26, 22, -5], [13, 17, -7], [-32, 20, -4], [4, -3, -4], [39, 7, -8], [5, -9, 10], [-26, 17, 17], [-65, 1, 1], [-28, 1, -20], [-39, 0, -12], [-1, -4, 5], [-53, 4, -4], [-15, 11, -16], [34, -6, 9], [11, 4, 22], [-6, -24, -9], [4, 11, -22], [1, 23, 5], [-4, -29, 4], [23, -21, -20], [42, -15, -3], [-41, 16, 4], [-2, 17, -13], [-35, -2, -8], [45, 13, 9], [16, 1, -7], [25, 6, 36], [-7, 32, -2], [16, -21, 0], [-13, 38, 14], [33, -11, 6], [0, -28, -10], [-31, 33, 7], [-24, 2, -16], [48, -27, -12], [18, -1, 5], [34, 8, 2], [-20, -8, -7], [18, 7, -5], [-55, 4, -14], [13, -5, 7], [45, -7, -6], [36, 3, 0], [-44, 23, 8], [15, -17, -8], [-16, 6, 19], [-48, -2, -20], [37, -35, -17], [14, 27, 21], [24, -30, -6], [8, 4, 28], [-13, -6, 15], [1, -27, -13], [12, -4, -12], [-18, -2, 10], [15, -4, 8], [-31, 16, -8], [-77, -4, 2], [-41, 1, -23], [-32, -10, 11], [26, -5, -5], [-40, -8, -17], [-1, 26, 8], [16, -22, -13], [35, -17, -17], [-36, -8, -24], [-13, -28, -20], [-11, 18, 5], [-34, -24, 9], [56, -17, -11], [45, 0, 15], [-9, -1, 3], [-27, 6, 0], [23, -28, -25], [-21, 12, 3], [-55, 0, -12], [-27, 15, 6], [-25, -20, -14], [53, -20, 7], [-72, 2, 0], [8, -27, -17], [30, -17, 13], [-55, -13, 2], [-2, -21, 8], [-7, -25, 22], [45, -4, -1], [46, -1, 11], [20, 10, -5], [-16, -6, -17], [-41, -1, -10], [30, -37, -16], [-10, -10, 16], [-26, 18, 6], [5, -5, -14], [17, -5, 7], [21, 17, 17], [-33, 26, -4], [28, -27, 2], [52, -14, 4], [-21, 8, 0], [54, 10, 21], [22, 18, 3], [47, -5, -11], [30, 13, -8], [56, 12, -3], [55, -4, -7], [-8, -15, -21], [-22, -4, 13], [-1, 3, 18], [25, -2, 26], [-2, -25, 5], [38, -14, 19], [-66, 5, 12], [-30, -15, -12], [20, 1, 13], [-21, 14, -21], [-6, -7, 20], [13, 3, -28], [-41, 11, -19], [24, -31, 3], [12, -19, -3], [-16, -15, -9], [-7, -24, 21], [11, -14, 22], [23, 2, -8], [-19, -2, 4], [-24, -11, 18], [18, -27, -12], [-36, 22, 6], [-25, -1, 20], [12, -27, 18], [5, 12, 1], [18, 13, -11], [1, 26, 17], [12, 6, -9], [-3, 5, 15], [-53, -9, -15], [51, 8, -12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3267_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3267_2_a_r();".
// 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_3267_2_a_r(:prec:=3)
    chi := MakeCharacter_3267_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_3267_2_a_r();".
// 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_3267_2_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3267_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -4, 1, 1]>,<5,R![-1, -1, 4, 1]>,<7,R![-1, -9, 0, 1]>,<23,R![-89, 14, 11, 1]>],Snew);
    return Vf;
end function;