
// Make newform 6045.2.a.p in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6045_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_6045_2_a_p();".
// 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_6045_2_a_p();".
// 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_6045_a();"
function MakeCharacter_6045_a()
    N := 6045;
    order := 1;
    char_gens := [4031, 4837, 1861, 2731];
    v := [1, 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_6045_a_Hecke(Kf)
    return MakeCharacter_6045_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 := [[0, 1], [1, 0], [1, 0], [1, 1], [-2, -2], [1, 0], [2, -4], [-6, 1], [-6, 2], [3, -1], [1, 0], [-6, 2], [-7, 1], [-1, 1], [-2, -5], [4, 3], [-1, -5], [-4, 3], [-7, 1], [-4, 8], [-6, -5], [0, 5], [-9, -2], [-6, 2], [9, 1], [-2, -5], [6, -5], [3, -2], [-8, -3], [11, 4], [5, 3], [-14, 1], [0, 0], [14, 1], [7, -5], [-3, 2], [-10, 0], [8, 2], [-14, 0], [-3, -2], [-5, -9], [16, 6], [2, 6], [17, 7], [-3, 2], [4, -6], [-9, 6], [-18, 1], [6, -16], [0, -18], [-5, 14], [6, 3], [3, 14], [-17, 1], [-4, 8], [10, 5], [6, -16], [17, -6], [-5, 1], [-7, -3], [-2, 5], [-2, -1], [-14, 8], [-24, 0], [-5, 1], [6, 1], [-9, 2], [14, -6], [-10, 11], [-10, -14], [5, -6], [-31, 3], [30, -4], [10, 6], [-4, 5], [-15, 6], [25, -5], [2, 4], [16, 3], [1, -12], [-10, 6], [-12, -8], [-7, 15], [-9, -9], [1, -22], [-17, 16], [-2, 21], [-12, 17], [12, 16], [-12, -2], [-17, 10], [17, 1], [4, -3], [23, -7], [29, 6], [7, -18], [-10, 5], [10, -5], [-31, -7], [-2, 0], [2, -9], [-24, 12], [30, -4], [-16, -6], [-4, 18], [-2, 4], [5, 10], [-2, -19], [-20, -6], [6, 27], [-6, 28], [-6, 16], [-12, 2], [-19, -14], [-18, -10], [-3, 1], [6, -19], [-18, 3], [-19, 22], [4, -21], [2, -10], [13, 3], [6, 21], [18, -18], [26, 10], [-6, -12], [-16, -20], [-15, -9], [0, 17], [-7, 3], [2, 18], [-17, 6], [-9, -18], [7, 29], [42, -5], [8, 15], [-13, 4], [-10, 25], [28, -19], [-19, 11], [-18, 23], [34, -10], [15, 1], [-15, 22], [0, 14], [11, -7], [21, -3], [20, -26], [12, 0], [-11, 14], [30, 2], [31, 5], [-27, 21], [27, 12], [28, 2], [-3, -15], [-27, -4], [-24, -15], [-10, -24], [-26, 7], [-42, 4], [-26, 3], [36, 2], [-22, 12], [-12, 18], [-29, -10], [44, -1], [12, -3], [3, 14], [26, -14], [8, 6], [1, -10], [-16, -5], [-6, 20], [35, 0], [7, 1], [52, -5], [7, 13], [46, 5], [-28, -6], [-29, -11], [11, -9], [16, -21], [14, 0], [-58, 1], [19, 9], [8, -30], [-15, -1], [-44, -4], [-9, 17], [15, 17], [-8, 24], [26, -29], [4, -9], [-17, 6], [-24, 11], [0, 8], [-18, 9], [4, -41], [-14, -32], [-45, 17], [2, 31], [22, -10], [-24, -4], [20, -26], [-22, 28], [24, 17], [16, -16], [32, -14], [-12, -12], [5, -9], [3, -27], [14, -14], [-6, -17], [-46, 8], [10, -15], [18, -16], [-4, -40], [-7, -30], [24, 11], [6, 18], [36, 5], [-13, 3], [-14, -8], [20, -36], [16, -8], [-2, 12], [11, -37], [-9, -5], [1, 7], [2, 28], [-19, -38], [-8, -40], [-37, 3], [-35, 21], [16, -32], [26, -35], [8, 16], [11, -9], [27, -23], [-10, 22], [-16, -27], [-29, 19], [-33, -8], [1, 18], [68, -1], [2, -5], [-16, 20], [-17, 30], [34, -22], [-34, -16], [4, -34], [43, 0], [19, -22], [27, -4], [-26, 4], [9, 30], [-34, 0], [-44, 2], [-17, 11], [-26, -24], [20, 5], [-25, -32], [10, -39], [-28, -6], [-34, -12], [21, -15], [47, 9], [12, 28], [-27, -30], [-8, -48], [-32, 20], [-24, 8], [32, -12], [60, -13], [5, 27], [10, -9], [28, 22], [59, -12], [45, 9], [-2, -26], [34, 14], [-42, -14], [-24, -19], [21, 17], [39, 21], [-38, -18], [-13, 2], [34, 20], [37, 1], [0, -2], [-6, -34], [-28, -34], [27, -5], [17, -15], [-10, -42], [52, -7], [65, 8], [-10, 8], [-16, -33], [4, 15], [3, 10], [-18, -19], [-50, 0], [16, 32], [41, -13], [-14, 3], [-57, 6], [42, 29], [-36, -36], [-14, -35], [36, 17], [12, 41], [-34, -8], [-42, 18], [8, 43], [28, 3], [-14, -47], [34, 28], [26, 18], [40, -18], [2, -50], [-14, 21], [-19, -9], [0, 3], [-16, 35], [-30, -5], [-49, 7], [12, 3], [-26, -13], [0, 9], [-47, -16], [-18, 10], [3, -38], [0, 34], [-60, 15], [-9, 8], [20, 39], [10, 50], [-11, -1], [46, -11], [0, -9], [-52, -25], [-48, 16], [-10, -7], [-38, 38], [20, 2], [-18, -7], [-40, 25], [-17, -38], [-11, -6], [64, -15], [17, 13], [-40, 18], [22, 24], [4, 26], [-52, 14], [64, 13], [12, -9], [-18, 14], [-29, 13], [0, 38], [-8, 41], [-1, -57], [-72, 1], [-27, -39], [-34, 36], [14, -24], [75, 12], [-10, -26], [-50, -6], [-20, -43], [-40, -16], [-65, 16], [-63, -1], [-8, 29], [24, 31], [3, 69], [14, 51], [-55, 13], [-32, -16], [-17, -10], [-10, 57], [3, -38], [5, 20], [-42, -20], [-72, 12], [41, -27], [54, 6], [22, -32], [15, 44], [53, 2], [43, -13], [-12, -19], [-20, -20], [10, 40], [9, -24], [16, -25], [66, -10], [-54, -6], [-27, -28], [59, 18], [-8, -54], [-22, -21], [46, 26], [20, 48], [1, 29], [-44, 11], [44, 3], [-54, 13], [-54, -36], [-36, 34], [-10, -23], [46, -4], [64, 13], [36, 19], [-62, 0], [52, -6], [-62, 12], [27, -42], [74, 12], [-26, -22], [-70, -16], [-40, 14], [5, 55], [3, -4], [-43, -12], [26, 10], [22, -20], [-21, -37]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6045_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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