
// Make newform 6045.2.a.j in Magma, downloaded from the LMFDB on 25 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_j();".
// 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_j();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := [[1], [1], [-1], [0], [4], [1], [2], [-4], [0], [-6], [1], [6], [6], [-4], [0], [6], [-8], [6], [12], [-4], [10], [4], [0], [6], [-2], [-10], [12], [20], [-10], [6], [16], [12], [6], [16], [2], [0], [-18], [-4], [-12], [18], [-4], [6], [0], [-2], [-22], [20], [4], [-24], [20], [26], [-10], [24], [22], [12], [6], [8], [26], [-24], [6], [22], [-8], [26], [12], [-16], [-6], [2], [20], [2], [-12], [14], [-18], [-20], [-8], [-26], [-20], [12], [-14], [-30], [30], [-34], [-12], [30], [-12], [-14], [0], [4], [30], [26], [-14], [16], [-28], [-28], [-16], [-36], [-12], [24], [2], [-30], [-20], [-42], [16], [42], [-12], [-2], [32], [-2], [8], [30], [0], [2], [-28], [-2], [-42], [12], [32], [-10], [-12], [-32], [-30], [-4], [-18], [2], [14], [-12], [4], [-10], [-30], [8], [28], [-22], [-20], [-36], [-32], [-10], [22], [-14], [34], [52], [30], [30], [-52], [-6], [-32], [48], [-42], [12], [34], [-42], [16], [-12], [-46], [-2], [12], [0], [-24], [40], [16], [14], [-22], [2], [-24], [-22], [40], [20], [-34], [20], [36], [-2], [-50], [22], [36], [50], [24], [-26], [-40], [30], [-28], [18], [-12], [14], [-32], [20], [-26], [-2], [16], [50], [-2], [36], [6], [4], [-46], [-36], [-16], [-30], [-12], [42], [-2], [30], [-18], [-56], [18], [44], [10], [50], [40], [-2], [-56], [-4], [30], [-44], [2], [66], [4], [60], [48], [66], [-20], [18], [-20], [34], [-58], [-40], [6], [-8], [-20], [-26], [6], [-24], [-32], [24], [14], [-4], [40], [6], [12], [-68], [18], [-54], [60], [-32], [68], [32], [-8], [-38], [-10], [0], [-56], [44], [12], [-8], [-54], [14], [36], [26], [-38], [64], [-58], [60], [66], [14], [-20], [20], [-38], [-26], [70], [-36], [-30], [22], [-4], [-6], [-50], [-4], [-22], [-20], [18], [16], [52], [10], [70], [-12], [-24], [56], [16], [-10], [-52], [40], [-14], [-78], [-32], [-2], [54], [-68], [62], [0], [-82], [-22], [52], [-62], [-36], [44], [-14], [66], [-52], [-4], [-40], [86], [-28], [14], [32], [62], [0], [42], [-14], [-36], [8], [-22], [-68], [72], [-10], [-74], [-24], [-38], [-18], [0], [-42], [10], [44], [76], [24], [-74], [-50], [-38], [-72], [48], [68], [-84], [18], [30], [-94], [-72], [-18], [-6], [-54], [-92], [-30], [12], [70], [-52], [-88], [-30], [20], [-6], [42], [16], [-10], [10], [-64], [-36], [26], [32], [18], [6], [32], [-48], [-80], [90], [-78], [88], [58], [52], [20], [24], [78], [16], [-66], [84], [-48], [14], [66], [58], [-62], [22], [-72], [6], [12], [-72], [80], [38], [-28], [32], [-50], [50], [24], [8], [12], [2], [-56], [-70], [64], [-54], [-86], [-58], [16], [-26], [90], [-80], [58], [-98], [76], [100], [-78], [-38], [12], [48], [58], [-66], [104], [44], [-82], [40], [-102], [22], [84], [92], [22], [58], [-28], [54], [-76], [0]];
    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_j();".
// 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_j(:prec:=1)
    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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6045_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>,<7,R![0, 1]>,<11,R![-4, 1]>],Snew);
    return Vf;
end function;