
// Make newform 6034.2.a.h in Magma, downloaded from the LMFDB on 25 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_h();".
// 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_h();".
// 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_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], [-1, 0], [0, -1], [-1, 0], [2, 1], [1, -1], [-3, 1], [3, 0], [-4, -1], [-1, 2], [-3, 3], [2, 4], [0, -2], [-2, 4], [2, -2], [3, 0], [-3, 0], [-8, -2], [3, -3], [-3, -3], [-5, 1], [-12, 0], [-11, -1], [-2, -2], [-2, 3], [0, 2], [0, -6], [6, 0], [14, 0], [-12, 0], [-6, 0], [3, -1], [-3, 3], [-9, -6], [-3, 2], [4, -1], [2, 3], [12, 3], [-2, 8], [6, -7], [0, 0], [2, 4], [-21, -1], [-17, -3], [-5, -2], [-8, 4], [1, -3], [-1, -4], [-1, -8], [20, -3], [-3, -9], [21, -1], [-10, -4], [-19, -5], [-21, 1], [14, 5], [-26, 2], [-15, 3], [9, 0], [-6, -2], [13, 0], [-19, -1], [-8, 8], [-9, -7], [4, 6], [26, -2], [20, -4], [-18, 0], [4, 4], [1, -1], [0, 7], [0, 6], [-7, -5], [10, 2], [16, -8], [-12, -6], [-15, 4], [-6, -3], [2, 2], [-20, -2], [6, -8], [13, -11], [1, 0], [-14, 9], [-25, -2], [6, 9], [9, 10], [-14, 8], [6, 11], [14, 9], [-4, -8], [-6, 6], [3, -15], [-12, 0], [35, 3], [17, -2], [3, -11], [30, 4], [8, 0], [-9, 0], [14, -13], [-5, 5], [34, 2], [9, -12], [-30, 0], [1, -1], [-17, 13], [2, -1], [-12, -6], [-2, 0], [28, 4], [14, 8], [-29, 1], [-12, 6], [-8, 11], [-20, -4], [4, -20], [-5, 10], [-21, -9], [-12, 1], [-18, 3], [8, -2], [12, -3], [39, -3], [-2, -14], [12, -14], [19, -10], [0, 4], [17, -3], [2, 17], [-13, -3], [-16, 8], [-4, 3], [10, 12], [12, -2], [-32, -7], [24, 7], [32, 6], [-26, 8], [18, -6], [27, 0], [0, -2], [22, 1], [28, -7], [-16, 16], [8, 8], [7, 15], [-18, 0], [6, 0], [-18, 2], [13, 4], [-12, -9], [2, -8], [9, -8], [46, 3], [-34, -1], [34, -3], [25, -5], [2, 9], [35, 1], [-9, -21], [3, -20], [3, -9], [4, 4], [9, -2], [5, 2], [8, 6], [-10, -19], [9, -18], [16, -2], [30, -5], [-28, 3], [20, 7], [-1, -4], [25, 0], [-9, 9], [2, 26], [33, 1], [21, 9], [20, -10], [26, 1], [-44, -4], [-4, -6], [-36, 2], [0, -8], [-37, 11], [-21, -15], [-7, -8], [-4, -16], [4, -8], [34, -15], [2, -19], [-18, 18], [-20, -1], [9, 13], [21, 13], [-17, -7], [-16, 12], [-9, 9], [-46, 2], [6, 2], [-9, 6], [28, -5], [41, -3], [3, -4], [-19, 5], [20, 4], [1, -19], [-25, -7], [7, -13], [13, 22], [-12, -15], [-34, -5], [-16, 2], [-39, 5], [36, 12], [27, 3], [-33, -9], [-10, 2], [2, -8], [3, 0], [7, 22], [36, 2], [30, 0], [-20, 4], [4, -26], [45, -5], [27, 11], [-10, -18], [45, -5], [-8, -14], [12, -6], [-30, 0], [-61, 5], [-16, 8], [-15, 12], [-14, -13], [-41, 14], [-35, -11], [-41, 4], [-42, -2], [41, 2], [59, 6], [35, -2], [27, -11], [-12, 18], [-11, -3], [-1, -16], [38, 16], [-24, -17], [-1, -30], [13, 23], [28, -16], [-34, 0], [8, -2], [-24, 12], [-35, 6], [46, -4], [18, -18], [-34, -1], [31, 9], [0, 14], [26, -6], [-24, 6], [1, -23], [-26, 2], [0, 12], [-22, 10], [-12, 0], [-46, -4], [-12, 12], [32, -3], [-42, 0], [-16, 26], [-24, 9], [-60, 0], [-48, -10], [42, 12], [11, 27], [20, 4], [-15, -12], [66, 0], [30, 6], [-7, -21], [-29, -15], [-30, 1], [-13, -4], [33, 1], [33, 21], [6, -35], [-30, -8], [-63, -10], [-1, -19], [-45, -12], [-19, 2], [4, 34], [-28, 0], [-39, 19], [19, -11], [-29, -6], [-15, 27], [12, 18], [-40, -20], [-15, 11], [-25, -9], [31, 5], [-71, -1], [-28, -5], [-17, -13], [9, 30], [12, 20], [-33, 16], [-32, 14], [1, -1], [18, -19], [16, -8], [-9, -4], [-57, -9], [44, -6], [-39, 22], [-41, 3], [-7, 33], [-56, 11], [-14, -10], [-21, -3], [-34, 9], [20, 23], [-65, 8], [12, -2], [27, -24], [-26, -8], [35, 2], [24, -6], [9, 26], [54, -6], [-7, 37], [-51, -12], [18, -3], [42, -18], [4, 24], [-56, 6], [32, -26], [-18, 16], [-13, -5], [30, -14], [8, 5], [22, -14], [10, -7], [-7, -8], [-64, -10], [12, 0], [26, 6], [-15, 15], [61, 6], [77, -3], [40, -7], [-5, -34], [-33, 24], [-36, 2], [-69, 11], [-15, -3], [-12, 12], [-51, 15], [-28, 16], [-8, 14], [-25, -12], [46, 22], [-50, 9], [-51, -18], [-2, 26], [40, 4], [-40, 7], [-21, 12], [5, -28], [45, 21], [79, -10], [18, 23], [-36, -12], [-12, -13], [60, 12], [-18, 20], [39, 5], [6, -9], [-13, -19], [43, -3], [24, 10], [-71, -7], [16, -6], [26, 11], [1, -25], [80, -2], [-2, 8], [18, 8], [-11, -28], [-58, -7], [8, -12], [54, 6], [18, 30], [-12, 24], [-19, -17], [90, 0], [12, 22], [49, -17], [-50, 8], [6, -6], [-13, 14], [-4, -30], [0, -10], [33, 30], [54, 0], [-56, -14], [-8, -26], [68, 16], [-44, 15], [-10, -26], [4, 11], [38, 28], [28, 0], [4, -8], [-21, -15], [-5, 7], [-34, -12], [-9, 21], [29, -10], [-33, 21], [18, 38], [12, -18], [-6, -28], [-23, 31], [13, -25]];
    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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6034_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<5,R![-5, 0, 1]>,<11,R![-1, -4, 1]>],Snew);
    return Vf;
end function;