
// Make newform 6046.2.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6046_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_6046_2_a_c();".
// 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_6046_2_a_c();".
// 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_6046_a();"
function MakeCharacter_6046_a()
    N := 6046;
    order := 1;
    char_gens := [5];
    v := [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_6046_a_Hecke(Kf)
    return MakeCharacter_6046_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, -1], [-3, 0], [-3, 1], [-1, -1], [-5, 2], [-5, 0], [-6, 1], [-5, 2], [2, -2], [2, -4], [-5, 4], [-4, -5], [3, -3], [-1, -4], [0, 1], [-1, -6], [-1, -5], [-8, 0], [0, 6], [4, -8], [3, 4], [-8, 8], [2, -4], [-4, 4], [1, 1], [-15, 2], [-6, 10], [9, -11], [-10, 7], [-13, -2], [0, 10], [-6, 11], [0, 9], [1, 9], [8, -18], [-11, -2], [8, 3], [-5, -5], [-14, 16], [5, -13], [-5, -2], [-13, 12], [-12, 2], [-8, -10], [-6, 10], [-12, 9], [5, 2], [1, 4], [6, -2], [1, -3], [0, -8], [-17, 21], [-3, 15], [7, -11], [10, -15], [21, 6], [9, -12], [17, -21], [-14, 24], [-8, 4], [10, -4], [9, 12], [-10, 6], [-5, -12], [22, -15], [14, 10], [-13, -4], [-9, 22], [-5, 8], [9, 2], [15, -18], [-23, 18], [10, -18], [1, -12], [-11, -3], [25, -6], [-20, 6], [-24, 9], [-18, 14], [4, 0], [-25, 5], [9, 6], [-25, 12], [9, 16], [10, -27], [1, 14], [31, -10], [-31, 8], [15, -8], [-15, 2], [-7, -4], [23, -10], [-17, 15], [-14, -3], [1, -26], [-18, -1], [1, -7], [14, -10], [-9, 18], [-25, 19], [-38, -3], [-32, 18], [29, -26], [29, 3], [-29, 8], [-3, 6], [4, 13], [-4, -2], [26, 2], [9, -5], [-4, -1], [27, -15], [-44, 4], [3, -8], [-13, -15], [-7, -16], [-50, 1], [27, -25], [23, -8], [21, -28], [-18, 7], [-7, -12], [-2, -24], [-21, -16], [1, -19], [-10, 17], [10, 5], [9, -13], [-31, 3], [10, -34], [-15, 8], [-24, 28], [-29, 2], [-15, 36], [-4, -22], [-19, 5], [-6, 7], [-27, -12], [33, -36], [5, 10], [-30, -3], [-12, 7], [37, -16], [-16, -10], [5, 28], [26, -21], [10, 0], [14, -9], [8, -14], [-9, -17], [11, -6], [16, 6], [23, -3], [-5, 10], [14, 10], [25, 16], [26, -5], [0, -16], [-23, 49], [27, -14], [-3, -34], [-15, 3], [12, 1], [13, 23], [-21, 4], [-30, 0], [33, -10], [-18, 2], [-46, 28], [-10, 13], [-7, 10], [27, -1], [-49, 15], [25, -10], [-10, -16], [5, 0], [25, -19], [7, -25], [-23, 49], [-9, 30], [12, -31], [16, -10], [-39, 2], [14, -1], [31, 10], [20, -22], [16, -1], [-23, 8], [35, 14], [-45, -12], [20, -30], [47, 11], [11, 4], [36, -14], [35, 2], [-41, 1], [-10, -29], [-33, 7], [11, 16], [26, -6], [-12, 15], [-5, 12], [-25, -10], [-22, 36], [-14, 44], [-36, 55], [-29, 5], [-27, -16], [-21, -22], [-35, 49], [27, -39], [-17, 4], [33, -42], [-23, -2], [-7, -26], [5, 12], [25, 6], [22, 6], [-32, -13], [-21, 29], [-62, -2], [15, -12], [12, -32], [18, -11], [-5, 21], [-4, -35], [-49, 14], [15, -46], [-33, -12], [-21, 54], [17, 12], [-71, -3], [-9, 16], [-15, 2], [25, -31], [-18, 30], [-25, 35], [18, 8], [17, -17], [-1, -30], [-12, 36], [20, -28], [5, 20], [16, -4], [24, -7], [44, -36], [-28, -13], [-22, -11], [-3, 21], [49, -17], [-64, 2], [-29, 6], [-29, 30], [39, 0], [-7, 51], [32, -22], [-41, 10], [43, 15], [-44, 4], [41, -4], [15, 40], [-9, 12], [4, 32], [35, -10], [52, -18], [45, -26], [6, 43], [-39, 10], [-43, 19], [19, -18], [28, -57], [-34, -20], [6, 22], [-46, 38], [-37, 56], [-17, 34], [14, 1], [-10, -36], [-24, -20], [5, -6], [13, -23], [-37, 52], [-25, 20], [22, -29], [53, -31], [23, -15], [10, 6], [-15, 3], [7, 26], [25, -8], [-64, -2], [-42, 4], [39, -46], [16, -26], [26, -19], [-45, 49], [48, 2], [-41, 18], [15, 4], [-17, 40], [-14, -18], [52, 18], [23, -19], [13, -6], [-37, 16], [15, 20], [25, -25], [24, -17], [20, 6], [31, -24], [-13, 36], [61, -30], [77, -11], [-42, 72], [0, -3], [-2, -27], [-6, -16], [-65, 14], [-45, 3], [-37, 3], [3, 8], [21, -42], [16, 12], [18, -48], [-7, -53], [12, -1], [-4, -12], [34, 8], [-13, -7], [-52, 50], [34, 22], [79, -22], [-23, 25], [17, -42], [-17, 46], [-24, 49], [-33, -12], [28, -30], [48, -56], [-68, 10], [25, 35], [-38, 21], [3, 21], [22, -39], [-11, 10], [22, 16], [57, -30], [33, 11], [-40, -7], [-73, 16], [-23, 34], [-48, 5], [8, -52], [16, 23], [-22, -34], [-35, 25], [-67, 9], [15, -16], [-43, 13], [-17, -29], [24, -28], [27, -67], [63, 2], [3, 0], [-37, 7], [-8, 2], [63, -45], [-3, -14], [-49, 20], [4, -35], [10, 54], [-8, -56], [41, -12], [41, -20], [46, -44], [-39, -17], [18, -28], [-77, 32], [42, -60], [-52, -4], [56, -27], [-22, 75], [-41, 47], [-55, -5], [71, -18], [-55, 1], [6, 7], [29, 21], [39, -28], [-13, -4], [20, -34], [18, -70], [48, -33], [-62, -12], [30, 12], [-53, 34], [65, 20], [12, -9], [25, -33], [20, -38], [-1, 45], [-33, 8], [-51, 48], [2, -12], [15, 39], [15, 45], [-51, 59], [-79, 12], [89, -8], [3, 26], [29, -2], [-50, 9], [14, 55], [-32, 55], [30, -8], [5, 16], [-52, 5], [-66, 27], [47, -20], [-57, -8], [-5, -10], [47, -40], [-11, 45], [-40, -18], [-57, 6], [55, 4], [-6, -49], [-5, 36], [46, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6046_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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