
// Make newform 6034.2.a.i in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6034_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_6034_2_a_i();".
// 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_6034_2_a_i();".
// 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;
    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_6034_a();"
function MakeCharacter_6034_a()
    N := 6034;
    order := 1;
    char_gens := [1725, 869];
    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_6034_a_Hecke(Kf)
    return MakeCharacter_6034_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], [2, 0], [0, 0], [1, 0], [2, -2], [-3, 1], [0, -2], [4, 2], [6, 0], [4, -2], [2, 2], [7, 1], [0, 4], [3, -5], [2, 6], [2, 0], [0, 2], [2, 2], [-1, -1], [4, 4], [2, 0], [12, 0], [-3, -5], [-2, 0], [-8, 0], [-3, 1], [6, 2], [3, 3], [-2, -4], [-8, -2], [0, -4], [3, 1], [0, -6], [8, -6], [-6, 8], [2, 4], [-14, -6], [10, 2], [-2, -10], [-8, 8], [-6, 2], [-9, 7], [-2, 2], [-10, 0], [0, -10], [6, -2], [5, 9], [0, -14], [12, 2], [-18, 6], [-14, 0], [14, -2], [-14, -4], [-5, 5], [4, 2], [6, 8], [-3, 9], [-12, -12], [-20, -6], [-2, -8], [14, -4], [-3, 5], [4, -2], [4, 0], [-4, -2], [-21, 1], [-7, -15], [6, -6], [12, 4], [-15, 5], [-24, -4], [-12, 4], [4, 0], [-17, 5], [-4, 12], [2, -2], [-8, 14], [12, -4], [10, -4], [12, 2], [3, -3], [-13, 1], [1, 0], [18, 0], [-24, 0], [-2, 6], [14, 8], [26, 4], [10, -6], [-20, 4], [18, -4], [32, 2], [4, 4], [10, 2], [5, 5], [-24, 0], [15, -1], [28, 4], [-12, 2], [-22, 4], [-2, 18], [-27, -5], [-6, -8], [-6, 2], [13, -15], [-4, 14], [23, 1], [-18, -16], [-22, 2], [12, 2], [-20, 6], [-40, 2], [-8, -2], [7, 5], [20, 12], [-6, 0], [-16, 2], [4, 10], [-23, 3], [14, 2], [-14, -6], [-34, 8], [-18, -6], [-1, -13], [-1, -11], [16, -2], [-16, 18], [0, 28], [-38, -2], [4, -12], [-11, 1], [-4, 16], [26, 0], [18, 20], [-8, -12], [-2, -12], [-12, 4], [-5, 9], [-2, -26], [22, 0], [34, -12], [-3, 27], [-16, 16], [-12, 20], [25, -11], [-26, -6], [25, 9], [12, -22], [-21, 5], [12, -20], [-4, -10], [-6, -4], [25, -7], [-4, -16], [16, -20], [52, 4], [10, 0], [-6, -8], [-8, 4], [27, -9], [-11, 17], [14, 22], [-2, -18], [4, -22], [-6, -6], [32, 4], [24, 12], [-12, 16], [10, 8], [10, -10], [-12, 4], [4, -16], [0, -16], [-38, 14], [-4, 2], [16, 22], [23, -13], [1, 11], [-8, 24], [-40, 4], [52, -4], [-4, 2], [-17, 1], [-10, 0], [-18, 14], [-35, 1], [21, 3], [-4, -34], [20, -6], [4, 0], [-10, 8], [-28, -20], [33, 13], [0, 12], [-25, -5], [12, 14], [0, -18], [-11, 15], [24, -2], [-32, 8], [21, -21], [-4, 0], [20, -24], [-34, -12], [12, 10], [11, 19], [-44, 6], [5, -27], [-8, 6], [-31, 3], [2, -18], [-18, -2], [0, 0], [9, 15], [32, -12], [-30, -12], [12, 16], [16, -30], [-10, -18], [-8, 10], [-6, 20], [28, 12], [14, -18], [50, -2], [21, 11], [33, -13], [24, 2], [-38, -10], [-20, -8], [37, 13], [-12, -2], [-9, -31], [10, -34], [-30, 24], [-66, 0], [-36, 4], [-6, -8], [-12, 26], [-3, 9], [-12, -30], [-38, -10], [-8, -14], [12, 14], [16, -26], [10, 32], [14, -18], [-8, 24], [-26, -24], [-7, 21], [-48, 16], [-4, 6], [-12, 14], [22, -28], [6, -32], [-54, -6], [6, -18], [-46, -8], [5, 7], [-21, -1], [-16, 8], [-40, -8], [33, -19], [-23, 13], [-6, 2], [42, 12], [-37, 21], [-9, 21], [-42, -4], [9, -7], [18, 16], [39, -17], [52, -8], [8, 20], [-58, -10], [4, -20], [0, -24], [13, -15], [-7, -17], [-36, 2], [6, -12], [-12, -4], [-40, -8], [28, -2], [-17, -5], [-11, -13], [30, 28], [54, -10], [33, 7], [14, -6], [-30, -12], [-4, -18], [-48, 14], [12, -34], [-14, 8], [14, 20], [-14, -22], [32, -8], [3, -1], [39, 25], [-6, 8], [-50, -8], [38, 12], [12, 4], [13, 1], [29, 9], [-8, -6], [25, -31], [-4, -40], [-6, 14], [-22, 8], [12, -12], [18, -8], [18, 18], [9, -19], [-24, 8], [-34, -20], [-6, -16], [24, -32], [-22, -12], [-30, 6], [33, -21], [-4, 34], [4, 28], [-14, 30], [34, 32], [0, 20], [2, -18], [52, -18], [36, 16], [74, -8], [50, -12], [20, 30], [-42, 14], [-70, 0], [4, 32], [-31, -1], [-60, 2], [-16, -28], [12, 22], [-32, 26], [2, -8], [-18, -4], [-3, -23], [12, -24], [15, -7], [12, 12], [-17, -21], [12, 32], [12, 14], [-33, 19], [-16, 26], [16, -26], [27, -7], [32, -20], [19, 41], [-44, -12], [68, 2], [18, -12], [-20, -6], [-36, -20], [39, -11], [-56, 14], [-40, 4], [-12, 36], [-7, -17], [90, 2], [35, 35], [6, 28], [-10, -30], [5, 45], [-14, -48], [0, -16], [-2, -28], [16, -34], [-59, -5], [2, -28], [42, 8], [50, -8], [-10, 12], [40, 14], [57, -3], [42, 16], [-14, 24], [30, -24], [-27, 7], [0, -36], [32, -24], [32, -28], [18, -14], [58, -2], [72, 10], [35, -1], [11, -5], [-10, 16], [-60, -12], [16, -30], [22, -26], [-30, -20], [26, 14], [1, 27], [24, 32], [-36, 18], [6, -54], [-28, 30], [-11, 29], [80, 10], [55, -19], [22, -12], [-50, -4], [43, -11], [14, 28], [9, 19], [-3, 37], [-14, 26], [18, -8], [24, -8], [-12, 20], [64, -4], [-64, -14], [24, 16], [75, 5], [11, -21], [48, 8], [8, 10], [-34, -24], [27, -29], [7, -33], [30, -28], [21, -9], [90, -10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6034_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6034_2_a_i();".
// 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_6034_2_a_i(:prec:=2)
    chi := MakeCharacter_6034_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_6034_2_a_i();".
// 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_6034_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6034_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<5,R![0, 1]>,<11,R![-8, -4, 1]>],Snew);
    return Vf;
end function;