
// Make newform 3234.2.a.x 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_x();".
// 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_x();".
// 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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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], [0, 1], [0, 0], [1, 0], [-2, 0], [0, -1], [-2, -1], [0, 2], [-6, 0], [-2, -1], [2, -2], [0, -1], [-4, -2], [-6, -1], [6, -2], [0, -2], [-2, 0], [8, 2], [-12, 0], [4, -1], [-4, -2], [6, -3], [-6, 2], [-2, 0], [6, 4], [10, 1], [0, -2], [2, 4], [-6, 4], [-4, -2], [-6, 3], [-6, 4], [10, 1], [-6, 0], [-16, 0], [-8, 3], [-4, 0], [-12, -2], [-6, 2], [0, -6], [4, -3], [0, 6], [26, 0], [18, 0], [10, -3], [-4, 6], [-2, 3], [-6, 3], [4, 5], [6, -4], [-24, 0], [-20, 3], [-24, -2], [-6, -2], [-12, 2], [0, -7], [4, 6], [2, -4], [6, -4], [10, 1], [18, 2], [-14, 1], [-18, -3], [10, 2], [6, 2], [-16, 2], [14, 2], [0, -6], [10, -6], [-6, -2], [-12, 2], [-2, -5], [2, 8], [-4, -4], [-18, 1], [-30, 0], [-8, 3], [18, -4], [-8, 5], [36, 0], [-10, -8], [-12, -2], [-2, 0], [4, 6], [0, -6], [-6, -4], [2, 4], [6, 0], [8, 0], [-12, 8], [0, 4], [20, 6], [12, -4], [-16, 2], [-12, -2], [24, 5], [-30, -2], [-14, -3], [2, -8], [-16, 0], [-6, 8], [-6, 7], [-18, -4], [8, 0], [10, 6], [0, 6], [24, -1], [-12, 4], [-8, -3], [-8, 8], [-22, 0], [-6, -4], [4, 8], [20, -6], [18, 4], [-8, -2], [-18, 5], [-6, -8], [-24, 2], [-20, -7], [14, 2], [18, -6], [24, -6], [40, -2], [18, 8], [26, 6], [6, 9], [-2, -9], [-26, 4], [8, 0], [0, -12], [-4, -6], [2, 6], [36, -3], [-32, 1], [36, -1], [-2, -9], [36, -1], [18, -2], [-14, 9], [-6, 0], [20, 6], [12, 0], [-20, -7], [30, 1], [22, 8], [-12, 5], [-32, -6], [24, 6], [-46, 0], [6, 0], [-28, -4], [-24, 4], [8, 2], [0, -14], [8, 4], [-6, -10], [4, 3], [18, -2], [36, 4], [-6, -6], [32, 0], [-12, 8], [-6, -12], [-6, -5], [-16, 4], [10, -10], [2, -8], [0, -7], [0, -2], [-8, 3], [0, 4], [-34, -2], [34, -3], [6, -4], [-16, 12], [18, -8], [4, 6], [-38, -6], [-16, -4], [-54, 3], [2, 6], [-12, 5], [12, 8], [24, -3], [-22, 0], [52, 4], [14, -6], [12, 10], [10, -2], [0, 10], [8, 6], [-12, -1], [-36, -4], [42, 2], [-34, 6], [2, 6], [-24, 3], [-12, 14], [18, 8], [-20, -2], [-8, -9], [-44, 3], [-12, 4], [-24, 5], [-38, -3], [-12, 4], [18, -10], [4, 12], [14, 10], [-36, 7], [-16, 0], [-48, -6], [-36, 6], [-14, -10], [-28, 6], [-12, -11], [12, -4], [-6, 0], [-22, 4], [-20, 6], [42, 8], [32, 0], [-30, -5], [26, 0], [-18, 16], [-12, -4], [28, 2], [-24, 2], [26, -2], [-2, 3], [8, 12], [-6, -6], [4, 0], [-12, 2], [22, -4], [42, 8], [-36, 0], [-54, -1], [24, -2], [-2, 19], [10, -15], [38, 0], [-36, 1], [60, -2], [-14, -3], [0, 10], [32, 12], [-60, -2], [-22, -8], [-24, -9], [-36, -8], [-2, 4], [42, 2], [0, -2], [-46, -2], [-14, 1], [-24, 1], [28, 3], [-16, 12], [12, 8], [-2, 4], [34, -10], [30, -12], [-8, 18], [30, 10], [-18, -16], [-64, 0], [-30, 8], [64, -1], [-4, -12], [-38, -6], [-4, 10], [28, 15], [-2, -9], [12, -4], [2, 8], [26, 0], [30, -7], [48, -4], [32, 12], [-48, 0], [34, 2], [-50, -9], [-24, -6], [2, -4], [-30, -4], [34, 1], [12, -15], [6, -2], [36, -4], [-42, -4], [6, 1], [26, -12], [-42, -8], [58, -7], [24, -7], [42, -5], [-14, 5], [64, -3], [18, 0], [-52, -6], [0, -6], [20, 8], [-22, 16], [60, -4], [-44, -3], [-12, 0], [50, 4], [24, 4], [66, -4], [-66, 4], [8, 6], [24, -16], [-68, -5], [72, 2], [-36, 6], [34, 10], [-42, -4], [-50, -1], [26, -16], [-30, 6], [-4, 6], [18, 2], [-38, 6], [-4, 0], [-44, 8], [-36, -2], [-6, 24], [26, -16], [-30, 4], [-20, -18], [42, -5], [8, 12], [12, -16], [50, 6], [-36, 1], [46, 4], [-32, -4], [62, 0], [-6, 4], [-54, -2], [20, 6], [-6, 4], [-36, -4], [-20, 1], [-4, -12], [0, -12], [-36, -5], [82, -3], [-22, 12], [6, 18], [-8, 0], [-70, -4], [60, 1], [-6, 11], [-6, -17], [-6, -2], [-12, 4], [-22, 12], [12, 5], [-12, 8], [-12, 0], [28, 4], [50, -12], [18, -18], [20, -18], [2, 0], [36, -4], [4, -4], [-12, -6], [-30, 16], [-56, 0], [-10, 4], [-60, -4], [84, 2], [40, 9], [24, -21], [-20, 15], [-12, -1], [-6, -4], [20, 6], [18, 2], [-38, -3], [30, 5], [-28, -18], [-20, 21], [-52, 6], [-30, -5], [-22, 12], [-36, -9], [-12, 4], [16, 2], [-60, 0], [38, 6], [-8, -12], [-42, -12], [32, 10], [42, -8], [22, 12], [-30, 8], [-64, 0], [-18, -16], [-6, -2], [-20, -22], [-10, 12], [18, 6], [-20, -4], [12, -8], [52, -9], [18, 8], [-36, -12], [-40, -12], [-58, 2], [12, 23], [-36, 6], [-50, 11], [6, 0], [24, -8], [18, -4], [-2, -20], [12, -8], [-42, 13], [58, -6], [36, 3], [-24, -6], [78, 0], [4, -12], [0, -8]];
    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_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3234_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-12, 0, 1]>,<13,R![2, 1]>,<17,R![-12, 0, 1]>],Snew);
    return Vf;
end function;