
// Make newform 6034.2.a.g 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_g();".
// 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_g();".
// 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;
    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], [-2, -1], [-1, 0], [2, -5], [-2, 4], [1, -1], [0, 4], [6, 2], [-2, 2], [2, 2], [-3, -3], [2, -8], [0, 0], [2, 0], [-8, -2], [-4, 10], [-3, -3], [-2, 4], [8, 1], [-2, 4], [-12, 3], [4, -4], [-12, -1], [2, -10], [2, -4], [4, 4], [6, 2], [-12, 6], [-8, 8], [9, -3], [-2, 5], [-16, -4], [12, -4], [-18, 0], [-8, 2], [-14, 8], [7, -11], [-2, 12], [6, -4], [7, -19], [-14, 18], [-7, -11], [-2, -12], [8, 8], [-10, -6], [4, 4], [-13, -5], [-14, 10], [-21, -1], [-14, -2], [11, -9], [4, 1], [19, 1], [-15, 11], [-14, -10], [-12, -4], [-28, 2], [12, -8], [-24, 10], [10, 2], [-22, 2], [16, -14], [10, 6], [-4, -5], [15, -9], [22, -20], [-5, -3], [-10, -9], [-18, 24], [-22, 12], [0, -9], [-6, 4], [10, -17], [2, 19], [8, -8], [-2, 10], [9, -3], [6, -12], [4, -3], [-9, 21], [-18, 1], [-1, 0], [-2, 10], [-17, 27], [23, -19], [0, 9], [18, -20], [7, -5], [2, -22], [12, 0], [0, -16], [-16, 0], [1, 3], [26, 8], [1, 13], [-8, 6], [-26, 12], [6, -24], [38, -2], [13, -1], [-2, -16], [-14, 0], [40, -7], [30, 10], [20, -21], [-1, 29], [-4, 12], [-3, 17], [9, -33], [16, -5], [-10, 6], [-10, 14], [15, -11], [-28, 6], [-2, 22], [28, -22], [-21, 7], [17, -23], [2, 21], [-22, 13], [32, 3], [-33, 23], [4, -6], [26, -3], [-26, 24], [12, -4], [4, -15], [24, -38], [-34, 11], [-10, -18], [9, -35], [-38, 14], [32, -16], [-16, 12], [-14, -16], [-49, 7], [6, -19], [22, -13], [0, 16], [-26, -2], [-21, 15], [-34, 24], [43, -7], [14, 0], [20, 0], [-20, -4], [19, -15], [-42, 15], [-22, 46], [8, -28], [-14, 6], [4, 24], [-36, 0], [9, 3], [-20, -10], [26, -34], [-14, 20], [-14, 26], [-2, -6], [28, -10], [25, 11], [-20, 7], [2, 30], [7, 17], [-36, 24], [16, -1], [-45, -5], [21, -33], [14, -5], [14, -19], [30, 0], [28, 6], [-8, 29], [-4, 21], [-2, 4], [30, -36], [-22, -15], [24, 4], [34, 8], [4, -14], [-2, -10], [-34, -7], [4, -39], [24, 7], [-12, -30], [2, 28], [-40, -4], [-30, 24], [20, -9], [10, -32], [33, -21], [34, 2], [34, -11], [44, 10], [40, -23], [28, 18], [10, -23], [21, -21], [0, -9], [26, -7], [40, -19], [-21, 15], [12, -21], [-20, -10], [28, -8], [8, 21], [4, -28], [-10, 32], [28, -20], [36, -17], [37, -15], [14, -18], [-26, -15], [6, -24], [-8, -15], [52, -32], [-66, 4], [40, 9], [-30, 36], [-26, -2], [-24, -9], [-24, 17], [-28, 39], [47, -39], [22, -44], [9, -9], [16, 15], [24, 10], [2, -22], [8, -8], [-47, 3], [23, -9], [2, -26], [34, 14], [60, -17], [34, -10], [-6, -16], [-20, -34], [16, -33], [-23, -1], [38, -32], [-16, -25], [10, -28], [16, -39], [-30, -20], [2, -6], [28, -2], [12, 8], [4, -48], [0, 30], [-33, -23], [-32, 12], [5, 23], [9, 13], [-38, 51], [-14, -32], [-29, 37], [-28, 2], [-34, -2], [-17, -21], [-10, 26], [30, 10], [-7, 29], [-36, 21], [18, -7], [-18, -4], [44, -15], [-26, 40], [74, 2], [-44, -12], [2, -5], [-8, 34], [1, -35], [24, -26], [-24, 20], [-42, 28], [-10, 9], [36, 14], [-50, 54], [15, 15], [-48, 32], [40, -32], [-26, 2], [-30, 33], [6, 2], [9, 35], [-26, 39], [-40, 0], [-32, -22], [4, 18], [20, 28], [28, -18], [-56, 24], [54, 16], [-38, -13], [48, -55], [8, -26], [-14, -7], [20, 34], [11, 29], [32, -18], [-32, 20], [40, 22], [60, -42], [-2, 36], [38, -22], [19, 31], [-7, -15], [28, -2], [28, -22], [12, -30], [23, -19], [-14, 12], [-32, 28], [-8, 9], [4, -36], [16, 27], [16, 4], [8, -35], [-34, -27], [20, 14], [-14, 23], [-24, 31], [36, -4], [-34, -18], [-41, -31], [-22, -28], [13, 33], [-16, 54], [-16, 8], [-14, -42], [-16, -20], [46, -16], [-42, 25], [28, 28], [48, -70], [-66, -10], [-27, -21], [-17, -37], [14, -42], [-30, 22], [24, -10], [35, -69], [53, -23], [5, -45], [62, -36], [-14, 51], [48, 24], [-36, 52], [40, 10], [-38, -30], [18, -23], [-51, 45], [42, 21], [-50, -16], [-4, -11], [28, 14], [60, 4], [32, 5], [-6, 0], [20, 19], [-56, 8], [21, -9], [-48, 52], [-4, -31], [-50, 32], [-20, -20], [-60, -23], [18, -16], [14, 14], [-20, -48], [22, -36], [-29, -29], [27, -5], [-28, -22], [52, -28], [-5, -15], [38, -46], [-7, 39], [-62, 32], [-40, 62], [30, -64], [-74, 40], [-17, 9], [48, -34], [19, 3], [-22, -45], [-49, 9], [-42, 46], [24, 0], [-48, 68], [44, -66], [-60, 14], [-56, 18], [78, -34], [-22, 36], [-32, 67], [-6, 9], [51, -37], [-54, 36], [-32, 4], [12, 41], [-60, -17], [52, -32], [16, 23], [-18, 0], [-18, -44], [20, -6], [22, -67], [41, 31], [-26, -9], [30, -12], [-50, 41], [38, -16], [50, 32], [-17, 67], [17, -39], [-12, 5], [8, -10], [-66, 27], [-34, 52], [-28, 13], [-38, 4], [-30, 36], [10, -54], [12, -46], [-74, -14], [46, -19], [26, -6]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : 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![5, 5, 1]>,<11,R![-31, 1, 1]>],Snew);
    return Vf;
end function;