
// Make newform 3234.2.a.bb 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_bb();".
// 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_bb();".
// 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;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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], [-1, 0], [-1, -1], [0, 0], [-1, 0], [0, 0], [-3, 1], [-1, 3], [2, 2], [0, -2], [-5, -1], [-2, 4], [-3, 1], [2, -2], [-3, -3], [-6, 0], [-6, -2], [0, 0], [2, -6], [2, 2], [-9, 3], [-2, -6], [-1, -1], [-2, 2], [0, 0], [-12, 0], [13, 1], [-8, -4], [6, 0], [0, -6], [-2, 2], [9, 1], [-12, 2], [1, 5], [-6, 0], [0, 0], [-17, -1], [-12, 0], [14, -2], [6, -6], [-10, -2], [5, -3], [-6, 2], [14, 4], [0, 10], [-3, 9], [-10, -6], [-9, 3], [-7, -7], [13, -3], [-18, -4], [0, 0], [7, -5], [-2, 2], [18, -2], [-14, -2], [-21, 3], [2, 2], [26, 0], [2, -8], [17, -3], [-18, -6], [1, -11], [7, 7], [10, 2], [-14, 8], [6, 6], [-18, 0], [0, 12], [-14, -6], [2, -10], [6, 2], [15, 3], [12, 6], [-4, 0], [15, 7], [2, 4], [-13, -5], [-4, 2], [5, 1], [24, 4], [-14, -4], [-18, 2], [-8, -8], [18, -6], [-6, -6], [24, 2], [18, 0], [0, 12], [16, 8], [-12, 8], [0, -16], [28, -4], [-12, 8], [-6, -6], [-10, 14], [-9, -1], [10, 14], [-31, -3], [8, -6], [34, -2], [-24, -6], [9, 1], [-26, 4], [-22, -2], [-26, 6], [22, 2], [21, 1], [-6, -14], [-7, -3], [-8, 0], [8, -2], [6, -8], [-8, -12], [-8, -8], [-18, 8], [30, -6], [7, -17], [-6, 4], [-4, -8], [-19, -11], [26, -4], [-42, 2], [18, 10], [-22, -2], [-26, -8], [14, 4], [27, 3], [43, -1], [4, 12], [30, -6], [-8, 8], [12, 12], [14, -4], [3, -9], [17, 13], [-3, 21], [11, 15], [33, 9], [18, -12], [-7, -11], [-6, -16], [-4, 12], [-8, -20], [5, -19], [23, -1], [-16, 8], [27, -9], [-30, 6], [-22, 10], [30, 0], [0, -12], [12, 0], [-28, 4], [-2, 14], [-18, 6], [0, 24], [-14, -10], [23, 11], [-30, -10], [-20, 8], [-22, 4], [28, -12], [-48, -4], [6, 8], [45, -3], [-4, 12], [14, -18], [26, 0], [-33, -1], [-12, 16], [-13, 11], [24, 16], [10, -12], [-31, 5], [-28, 8], [6, 18], [-26, 8], [-18, 6], [10, 2], [-16, -8], [13, 13], [-34, 12], [3, 15], [-2, -2], [-33, 7], [28, 14], [16, -20], [-34, -8], [6, -2], [14, -10], [-56, 4], [-22, -6], [9, -23], [-12, 8], [-18, -6], [6, 0], [26, -8], [-35, 1], [18, -6], [18, 0], [-38, -6], [-29, 3], [-25, 11], [24, 12], [-9, 15], [5, 9], [36, 0], [-14, 20], [16, 12], [-38, -12], [-27, 13], [12, -12], [6, -14], [62, -2], [-10, 22], [18, -18], [-45, -9], [42, 10], [-10, -8], [4, -22], [10, -6], [12, -10], [-44, -4], [-15, 17], [38, 0], [-24, -12], [-6, 18], [-22, -14], [12, -8], [-54, 0], [-9, -21], [44, 12], [-10, -8], [-32, -4], [18, 10], [68, 4], [-6, -16], [24, 20], [-3, -11], [30, 14], [-29, 15], [25, 5], [-14, 12], [-29, -1], [26, -14], [-11, 1], [-42, -6], [-62, 6], [-22, 14], [12, 30], [-15, 5], [42, -14], [12, -12], [38, 10], [24, 12], [22, 12], [41, 13], [-33, 15], [11, -9], [-16, 8], [24, 12], [-20, -4], [-34, -18], [-52, -8], [-42, -6], [34, -8], [-8, 4], [-22, 6], [68, 2], [-37, -5], [44, 0], [50, -6], [-22, 14], [-13, -25], [19, 15], [12, -16], [-8, 10], [26, -8], [-45, 11], [8, 16], [-32, -8], [-20, 28], [-22, -6], [-9, -21], [10, -14], [48, -6], [-22, -16], [-27, 9], [-25, 19], [-42, 4], [36, -16], [54, 12], [31, 7], [10, -24], [0, -12], [-15, -3], [-9, 31], [21, -19], [21, 9], [9, -27], [30, 0], [-22, -10], [-34, -2], [-40, 20], [-36, -6], [24, -12], [-7, -23], [30, -10], [-14, -8], [0, 16], [18, 28], [-18, 20], [-58, -10], [-20, 28], [19, -1], [18, -26], [14, -14], [26, 10], [42, 0], [-85, -1], [-18, 24], [-6, 14], [-8, 24], [66, -4], [-74, 6], [-28, -16], [20, 16], [-2, 10], [-34, 8], [44, -2], [10, -20], [26, -6], [65, 1], [38, 10], [36, -24], [-66, -12], [63, -13], [-28, 12], [32, 16], [-6, -12], [-2, 16], [66, 6], [4, 20], [-50, 8], [28, 16], [-35, -3], [-64, 12], [-28, -20], [-63, 1], [-47, -11], [-4, -10], [30, 12], [16, -16], [66, 0], [23, 19], [1, -23], [-31, -7], [18, -28], [-38, 2], [2, 32], [-33, 27], [-6, -6], [-16, -4], [-12, 24], [-42, 0], [42, 22], [10, -18], [38, -12], [44, -16], [-20, 24], [-6, -26], [-8, -14], [40, -24], [14, 24], [-48, 12], [38, 2], [13, 1], [-15, 5], [-1, -21], [-43, 13], [66, 0], [82, -2], [18, 20], [65, 13], [51, 3], [-36, 12], [21, -27], [-34, 18], [25, 1], [-26, 24], [21, -19], [-16, -20], [-42, 18], [-46, 2], [34, 20], [28, -12], [36, 8], [-10, -2], [22, 32], [-12, 36], [-6, -8], [-20, -20], [-24, 12], [50, 22], [22, 22], [30, 0], [14, 8], [-16, -4], [44, 16], [7, 27], [-40, 14], [36, -8], [-2, -14], [2, -20], [-27, 5], [-6, 22], [27, -33], [48, -20], [48, -16], [6, -40], [-28, -28], [-2, -2], [15, 15], [2, -6], [-3, 21], [6, -2], [26, -32], [-48, 12], [4, 4]];
    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_bb();".
// 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_bb(:prec:=2)
    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_bb();".
// 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_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3234_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 2, 1]>,<13,R![0, 1]>,<17,R![4, 6, 1]>],Snew);
    return Vf;
end function;