
// Make newform 3024.2.a.k in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3024_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_3024_2_a_k();".
// 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_3024_2_a_k();".
// 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_3024_a();"
function MakeCharacter_3024_a()
    N := 3024;
    order := 1;
    char_gens := [1135, 757, 785, 2593];
    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_3024_a_Hecke( : Kf := Kf)
    return MakeCharacter_3024_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]];
    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], [0], [-1], [1], [2], [0], [-5], [-2], [2], [-10], [0], [5], [-3], [7], [-3], [-6], [1], [-6], [-4], [8], [10], [3], [-13], [6], [-14], [-10], [-2], [-18], [7], [-16], [-3], [-20], [8], [-10], [6], [17], [-22], [1], [-23], [14], [0], [12], [-6], [11], [-14], [4], [-20], [4], [-12], [-20], [4], [24], [20], [-21], [18], [24], [-25], [18], [5], [-26], [26], [-3], [26], [13], [-8], [18], [-17], [3], [12], [16], [-21], [22], [-26], [-29], [29], [29], [2], [18], [-12], [-28], [3], [-18], [36], [-4], [-36], [14], [-28], [34], [5], [-31], [-8], [23], [16], [-12], [29], [9], [3], [15], [28], [-15], [-9], [44], [-16], [6], [-33], [-8], [-28], [15], [30], [-28], [36], [6], [34], [-46], [37], [22], [-26], [-24], [36], [-16], [-44], [-22], [6], [24], [-8], [32], [35], [21], [-22], [0], [12], [-6], [-12], [3], [13], [16], [-7], [30], [6], [50], [8], [4], [-7], [-48], [22], [41], [-28], [45], [10], [46], [-59], [-42], [-23], [9], [33], [-30], [-7], [-27], [26], [-25], [4], [22], [-8], [51], [12], [-15], [-53], [50], [29], [-51], [4], [22], [12], [-21], [42], [-49], [36], [-32], [16], [-34], [3], [-1], [-14], [23], [46], [-63], [-18], [28], [-6], [-33], [28], [-36], [-43], [-23], [-12], [31], [50], [31], [-54], [51], [36], [60], [-46], [-6], [21], [-3], [34], [36], [-18], [-32], [-43], [-46], [-21], [7], [-21], [-58], [11], [-14], [-16], [40], [31], [20], [-60], [-37], [-33], [5], [25], [-26], [-42], [-12], [-18], [-28], [11], [36], [-38], [-48], [64], [42], [-18], [-59], [68], [4], [16], [18], [-2], [-39], [-66], [-49], [37], [-54], [-11], [-42], [-18], [-50], [37], [-10], [-37], [-18], [26], [38], [20], [-2], [-20], [-26], [-18], [-28], [24], [-34], [29], [-54], [12], [-32], [48], [-5], [-2], [54], [32], [63], [-29], [3], [-21], [-9], [-75], [56], [66], [-28], [-51], [-26], [-14], [-75], [-18], [27], [-18], [-5], [23], [-39], [-26], [39], [-57], [-42], [16], [36], [-64], [60], [1], [-34], [28], [-70], [-52], [-58], [60], [-16], [-82], [25], [28], [-46], [33], [-2], [2], [-84], [82], [61], [45], [8], [8], [-34], [-29], [-88], [2], [-2], [14], [-38], [-66], [47], [65], [85], [-18], [77], [92], [-16], [71], [-66], [15], [-72], [54], [78], [-52], [55], [-69], [-42], [-20], [17], [-42], [78], [-41], [43], [4], [21], [-8], [86], [67], [73], [16], [8], [20], [53], [3], [-33], [43], [80], [56], [54], [-40], [-76], [-74], [84], [-4], [-8], [94], [44], [33], [50], [32], [-66], [-34], [16], [40], [16], [-67], [56], [-1], [-30], [-94], [-8], [-50], [30], [-22], [67], [12], [-38], [20], [-24], [-43], [-31], [-54], [22], [85], [-6], [-68], [-100], [-56], [76], [68], [45], [-97], [58], [-40], [38], [63], [-68], [40], [62], [44], [9], [-4], [-31], [-80], [18], [-30], [104]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3024_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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