
// Make newform 3234.2.a.bf in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3234_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_3234_2_a_bf();".
// 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_3234_2_a_bf();".
// 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 := [-20, -15, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-10, -2, 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_3234_a();"
function MakeCharacter_3234_a()
    N := 3234;
    order := 1;
    char_gens := [1079, 199, 2059];
    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_3234_a_Hecke(Kf)
    return MakeCharacter_3234_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 := [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, 0, 0], [-1, 0, 0], [0, 0, 0], [1, 0, 2], [-3, 0, -1], [1, 1, -1], [3, -2, -1], [-2, 0, -2], [7, 0, 1], [4, 2, -1], [1, 0, 3], [1, -1, -1], [8, 0, 0], [-3, -2, -1], [-2, 1, 2], [2, 2, -1], [3, 0, -3], [0, -2, 2], [4, -1, 0], [6, -2, 1], [-4, -2, 0], [7, 0, 0], [3, -4, -1], [-4, 0, 2], [0, 2, 3], [-6, -1, -2], [4, 0, 2], [-3, 1, -1], [6, 0, 2], [0, -2, 0], [11, -2, -1], [9, -4, -1], [-1, -3, 1], [1, -4, -3], [12, 2, -3], [4, -6, -2], [10, 0, 2], [9, 4, -3], [10, 2, -2], [-8, -2, 0], [-2, 2, -2], [-9, 0, -1], [4, 4, -2], [-4, 6, 0], [0, -2, 2], [4, -2, 3], [-10, 2, -2], [-5, -4, -2], [-4, 2, 4], [0, 4, -2], [7, -4, 3], [-8, 2, 0], [2, 2, 0], [6, 3, -2], [0, -2, 0], [-16, 0, 0], [-1, -4, 4], [-12, -2, 4], [17, 2, -1], [-8, 0, 6], [-1, -3, 1], [-7, 2, 1], [-4, -3, -4], [-8, -2, 1], [-2, 6, -2], [2, 2, 7], [-4, -3, -4], [0, 2, -2], [-14, 0, 4], [-12, 2, -4], [-14, -3, 6], [0, -2, 3], [7, 4, 1], [12, 3, 0], [-23, 2, 1], [6, 6, 2], [6, -2, -2], [-23, 0, 1], [19, 0, -1], [-20, -2, 0], [9, 0, -2], [1, -7, -5], [-13, 2, -1], [0, 2, 8], [-2, -4, -8], [9, 2, -7], [-4, -2, -2], [3, -2, 5], [2, 2, 0], [-4, -6, -6], [30, 2, -1], [-2, 0, 2], [6, 6, -2], [-4, -8, -4], [-18, 0, 0], [4, -6, -4], [0, -1, 0], [7, -8, 1], [9, -4, 1], [8, -8, 0], [-5, -6, 3], [-5, -2, -1], [8, 2, -5], [-16, 2, -6], [9, -6, -3], [-20, 7, 0], [-10, -8, 6], [-12, -5, 4], [16, -1, 8], [6, -2, -6], [4, -2, 7], [-16, 2, 2], [14, 0, 2], [-14, -4, -6], [-4, 3, 0], [0, 5, 4], [-12, 2, -5], [1, -4, 5], [-4, 0, 6], [7, 4, 5], [5, 2, 3], [-20, 2, -7], [-3, 4, -1], [5, 2, -9], [-11, -3, 7], [-30, -4, 4], [22, 1, -2], [-8, 0, 2], [-6, -6, -10], [-6, -2, 6], [-5, -2, -5], [0, -6, -9], [2, 2, 2], [6, -1, -2], [29, 0, -5], [6, 7, -10], [16, -2, -7], [-16, 0, 6], [2, -8, -6], [6, -2, 6], [12, 6, 7], [19, 4, 5], [0, 13, -4], [-28, 1, 4], [-7, -8, 8], [10, 6, 3], [-4, -3, 0], [8, -3, 8], [0, 4, -2], [-4, -6, -5], [12, 2, -2], [-6, 2, -3], [5, -3, -1], [19, 7, 13], [-30, 2, -2], [-32, 4, 2], [23, 6, -1], [11, -10, 3], [4, 2, 5], [-23, 5, 7], [12, 4, 14], [12, -8, 0], [-11, 1, 3], [24, 10, -12], [-16, 0, -8], [-20, 2, 4], [18, 4, 6], [-20, -6, -1], [14, -2, -10], [30, 8, -8], [36, -2, 0], [28, -2, 6], [6, 6, 14], [33, -2, -3], [26, 4, 10], [4, 1, 0], [-24, 0, 4], [-8, -6, 0], [12, 2, -5], [-29, 4, -3], [29, -4, -6], [-3, 0, 3], [-4, -4, -8], [28, -7, 0], [10, -2, -9], [-4, 4, -8], [-14, 6, -6], [-19, 14, 1], [-16, 2, -9], [42, -2, 5], [10, -8, -6], [-18, 12, -2], [-6, -4, 8], [-8, 0, -14], [5, -2, -13], [34, -8, 0], [50, 0, 2], [-6, 12, -4], [27, 8, -3], [-26, -6, -6], [-16, 0, 8], [-7, -6, 5], [12, -12, -8], [-4, 12, 0], [16, 10, -1], [-12, -10, 13], [30, -4, 2], [-2, 0, 4], [-20, 5, 8], [4, -6, 6], [16, 2, -10], [-24, -10, 4], [5, -2, 5], [32, 6, 4], [-16, 6, 1], [-24, 11, 0], [14, 0, -2], [14, 0, -2], [11, 5, 5], [14, -14, -6], [-38, -4, -2], [-6, -2, 9], [-20, 1, -12], [2, -2, 0], [9, 11, -5], [11, 1, 9], [-12, -4, 4], [19, 2, -3], [13, -4, 13], [31, -8, 1], [1, -4, 4], [48, -6, 1], [48, -2, 2], [45, 2, 5], [22, 10, -12], [12, -10, -8], [-20, -3, 0], [-3, 6, -9], [-40, 4, -4], [-14, 12, 6], [25, -6, 5], [-3, 6, -11], [-40, -2, -4], [-12, -8, 14], [-1, 6, 7], [-7, -12, 9], [-64, 0, 0], [-12, -12, 8], [-35, 6, 1], [-27, 3, -1], [32, -6, -1], [10, -8, 4], [10, -4, 2], [14, -14, -4], [-19, 14, 5], [-22, 0, 2], [-56, -2, 6], [4, -15, 0], [42, 8, -2], [-36, -7, -8], [-14, 3, -2], [-30, -6, 0], [10, 4, 10], [-18, 3, -10], [26, 12, -10], [-11, -4, 11], [14, 10, -4], [9, -12, 1], [26, 2, -3], [-2, 0, -12], [-39, 5, 3], [-2, 18, 0], [34, -2, -2], [27, -8, 1], [-30, 3, -2], [34, -6, 0], [-12, 2, 5], [-26, 0, 4], [20, 0, -2], [2, -4, 6], [-22, 9, 6], [17, 8, 9], [43, 1, 9], [6, 16, -8], [11, 4, -17], [44, 0, -10], [5, 2, -7], [-18, 3, -14], [-13, -4, 9], [4, -14, 3], [-56, -2, 3], [-6, -5, -2], [10, 6, 2], [32, -12, -2], [18, 3, -2], [12, -2, -7], [17, 6, 9], [6, -14, -12], [13, -2, 17], [25, -12, -9], [17, 2, 21], [16, -2, -13], [-40, -10, 3], [4, 0, 4], [11, 8, 19], [-15, -8, -1], [-10, -11, -10], [-14, 4, 12], [-38, 0, -14], [11, 8, 0], [-34, 10, 7], [16, -18, 6], [-10, 2, 2], [27, 10, 3], [-30, 8, 2], [11, -4, 12], [-33, 6, -9], [-9, 2, -5], [45, -8, 4], [-15, 8, 9], [-40, 8, 8], [5, -2, 9], [-38, 8, 0], [6, 14, -11], [30, 6, -5], [14, 12, 2], [18, 4, 10], [-12, 3, -12], [28, 0, 16], [-5, 0, -19], [14, 10, -13], [28, 4, 0], [-28, -2, 4], [-19, -2, 7], [-7, 2, 13], [7, -18, -5], [19, 0, -3], [14, 8, -22], [36, 6, -12], [-15, 14, -9], [20, 4, 6], [24, 0, -12], [40, 12, 0], [41, -2, -3], [22, 16, -14], [-2, -4, -6], [-2, 3, -6], [51, -8, -3], [-15, -4, 14], [30, -11, 2], [13, 1, -9], [-26, 4, -6], [-33, 10, -5], [-28, 7, -4], [30, -6, -5], [27, 6, -9], [-28, -15, 16], [22, 12, -10], [-29, -4, 4], [32, -10, -4], [-10, 10, 5], [48, 4, 0], [41, 4, 8], [25, 14, 9], [-28, -10, 0], [32, 0, 18], [-7, 4, -17], [-38, -6, 1], [-26, 0, 4], [-46, -2, 10], [-4, 2, 12], [51, -2, 9], [19, 8, -9], [-8, 6, -12], [-56, -2, -2], [56, 6, 1], [-48, 6, -2], [48, 5, 8], [-60, 0, 0], [-52, 7, -4], [23, 6, 3], [27, 10, -3], [12, 1, 8], [38, 8, -16], [31, 4, 17], [-27, -6, 3], [-7, 11, 3], [-9, 8, -6], [30, 3, -18], [19, -26, -1], [-52, 6, -1], [41, -1, -5], [-24, 6, 10], [-1, -20, 13], [-4, -6, 4], [-2, -8, -6], [-17, -4, -7], [-14, 24, -6], [-16, -18, -10], [-56, 6, 0], [18, 10, 16], [21, -8, 7], [-44, -7, -12], [-29, 26, 3], [15, 12, 12], [-4, 14, -1], [-51, -8, -5], [-10, -4, 4], [-27, 4, 1], [-9, -18, -3], [5, -14, 7], [4, 8, 4], [22, 3, 2], [18, 4, 24], [18, -16, 0], [14, -2, -16], [26, -14, 10], [30, 13, 2], [-8, 11, 8], [-65, -4, 9], [-58, 0, 2], [-35, 10, 1], [-16, -11, -8], [-20, 2, 14], [21, -2, 9], [-2, 22, 5], [-14, 10, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3234_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3234_2_a_bf();".
// 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_3234_2_a_bf(:prec:=3)
    chi := MakeCharacter_3234_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_3234_2_a_bf();".
// 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_3234_2_a_bf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3234_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-20, -15, 0, 1]>,<13,R![0, 1]>,<17,R![139, -57, -3, 1]>],Snew);
    return Vf;
end function;