
// Make newform 3234.2.a.bc in Magma, downloaded from the LMFDB on 24 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_bc();".
// 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_bc();".
// 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 := [-2, 0, 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_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], [2, 0], [0, 0], [-1, 0], [4, 1], [2, 0], [2, -3], [-2, -2], [4, 4], [2, 3], [-2, 2], [6, 4], [-2, -2], [2, -7], [-2, -6], [4, 2], [4, -1], [-4, 2], [0, 4], [6, 4], [-8, -6], [-2, 5], [8, -3], [0, -7], [-8, -5], [2, 3], [10, 2], [10, -4], [0, 4], [0, 10], [2, 11], [6, -8], [10, -7], [4, 0], [4, 0], [10, 2], [-8, 4], [-8, 2], [4, -7], [-12, -6], [2, -8], [2, 14], [2, -12], [10, 4], [-6, 15], [-26, 2], [2, 3], [-2, -7], [14, 0], [-2, -4], [12, -8], [-2, -4], [0, 6], [-8, -15], [12, -2], [-6, 8], [8, 10], [-16, 0], [10, -8], [2, -3], [-12, 5], [-18, -5], [18, -7], [-4, -3], [10, 2], [-8, -14], [10, 2], [-6, 18], [-16, -1], [0, 15], [8, -2], [-34, 1], [2, 24], [4, 20], [-10, -9], [-6, -20], [-14, 2], [22, -8], [-10, 6], [16, 0], [-22, -4], [-12, 10], [-16, -13], [-32, 2], [4, 6], [0, 12], [-18, -8], [-32, 1], [8, -8], [12, 0], [-4, 8], [-14, 10], [-20, -16], [8, -10], [0, -6], [34, 0], [0, 15], [-2, -5], [-34, -8], [-20, -16], [14, 4], [-14, -5], [-22, 8], [-20, 0], [-20, 11], [-8, 14], [-26, -8], [8, 0], [18, -2], [-24, -8], [-36, 4], [-8, 0], [-16, -4], [22, 10], [-24, -8], [12, 18], [-6, 5], [-6, 20], [-18, -22], [-6, -24], [-26, 6], [-12, -17], [-8, 26], [0, -10], [-2, 8], [2, -26], [-6, -27], [10, 15], [4, 11], [-20, 16], [4, -16], [2, -10], [-34, -10], [-10, 6], [-30, 10], [14, -6], [-2, -1], [26, -6], [-10, 26], [18, 13], [36, 8], [-14, -10], [28, 8], [22, 20], [-10, -5], [20, 11], [-14, 10], [12, -30], [-2, -26], [-18, 8], [28, 7], [12, -16], [-24, 20], [-28, 14], [14, -18], [16, -12], [32, -15], [-6, -36], [12, 11], [4, -40], [18, -6], [24, -24], [16, -8], [4, 16], [-26, 19], [0, 36], [32, -1], [-30, -4], [14, 12], [-2, 26], [50, 6], [4, 8], [-30, 2], [-22, -21], [-52, -7], [28, 8], [30, -4], [-12, -22], [-8, 21], [8, 28], [30, 5], [-10, -38], [38, -2], [32, 4], [-2, -28], [-34, 16], [52, -4], [6, 26], [20, -6], [36, 11], [34, -18], [-4, -26], [14, 18], [4, 12], [40, -5], [2, -22], [-10, -2], [-14, 20], [20, 22], [-4, -40], [-32, 14], [38, 18], [14, -4], [28, 12], [14, -24], [-18, 1], [4, 28], [14, 2], [20, 8], [-42, 14], [50, 14], [-48, -16], [-12, 2], [24, -22], [28, -21], [24, -2], [42, -14], [8, 20], [-50, 0], [40, -16], [-16, -2], [-28, -8], [-8, 36], [14, -31], [-6, 8], [4, 5], [-8, -24], [12, 10], [10, 42], [-30, 2], [-30, 29], [16, 8], [-26, -14], [-40, 8], [8, 10], [0, 37], [4, 48], [-32, 16], [-6, -23], [-32, -10], [14, -9], [6, 21], [-34, -8], [-34, -26], [4, 30], [6, 5], [20, -38], [28, -24], [0, -54], [-2, 32], [14, -4], [-64, -8], [40, -15], [12, 11], [6, -22], [54, 14], [-54, 9], [-10, 36], [-22, -28], [0, -4], [12, 8], [20, -13], [-32, 3], [4, -13], [32, -10], [-2, 2], [76, -1], [36, 8], [-8, 4], [42, -6], [24, 12], [-20, -3], [44, 10], [38, 8], [10, -45], [-12, -12], [6, -8], [-22, 24], [42, 11], [20, 4], [24, -4], [-68, -4], [-24, 3], [34, -7], [-10, 14], [0, -12], [-16, -4], [-30, -5], [-6, 26], [-42, -18], [40, 8], [-34, 12], [-2, -27], [0, -8], [8, 5], [-18, 41], [-2, -8], [10, 11], [10, -47], [-2, 10], [-50, -16], [-12, -38], [-12, -10], [68, -8], [6, -32], [24, 8], [-22, -40], [-64, 12], [-32, 24], [-44, 24], [2, -4], [62, 0], [48, 26], [-20, 8], [-18, 44], [48, 6], [0, 26], [20, 43], [-58, 12], [-30, -31], [0, -48], [28, 17], [38, -10], [14, -18], [28, -5], [-8, -24], [-4, 4], [-24, -42], [18, -40], [14, -32], [-34, 0], [-24, -26], [10, 7], [-12, 44], [-4, -32], [34, 30], [-10, 22], [0, -49], [-28, -28], [22, 20], [80, -8], [20, -5], [-6, -18], [-18, 12], [-68, 16], [26, 16], [48, -12], [-16, -48], [-6, -14], [54, 27], [-44, 28], [54, 6], [-8, 40], [60, 8], [-18, -54], [14, 39], [-18, -39], [14, 50], [-32, -20], [-60, 8], [-34, 2], [-40, 12], [-20, -44], [0, 56], [12, -12], [20, -5], [68, 22], [-14, -12], [44, 12], [-16, 4], [40, 30], [10, 12], [8, -24], [-46, 8], [-12, 20], [-68, 22], [50, -2], [-62, -16], [22, -8], [6, 14], [-42, -20], [36, -2], [-46, 38], [-6, 9], [-26, 3], [46, 14], [6, -20], [-6, -14], [38, 15], [36, -20], [42, -26], [-60, 24], [-40, 22], [-24, -16], [30, -38], [-32, 12], [4, -13], [40, 10], [34, -8], [-44, 11], [-10, -32], [-12, -20], [-20, -27], [20, -19], [40, -30], [10, 20], [-10, 30], [12, -16], [-44, 16], [-66, 12], [52, -20], [36, 4], [-28, -24], [-26, 2], [22, 14], [-4, 14], [54, 17], [-4, 65], [-64, 20], [10, 4], [20, -17], [-16, 0], [-38, 31], [4, -19], [18, 22], [-40, -34], [86, -4], [12, 12], [-52, -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_bc();".
// 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_bc(: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_bc();".
// 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_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3234_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 1]>,<13,R![14, -8, 1]>,<17,R![-2, 1]>],Snew);
    return Vf;
end function;