
// Make newform 3024.2.a.d in Magma, downloaded from the LMFDB on 21 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_d();".
// 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_d();".
// 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], [-3], [-1], [0], [2], [-3], [4], [6], [0], [10], [-7], [-9], [-5], [3], [-6], [-9], [8], [-8], [-12], [-10], [-5], [9], [-18], [8], [6], [10], [-18], [-13], [18], [13], [-12], [6], [4], [-24], [1], [-4], [-11], [3], [-6], [-18], [-16], [6], [-1], [24], [-20], [4], [10], [-24], [20], [6], [6], [26], [9], [-18], [-18], [9], [-2], [-31], [6], [16], [-21], [-2], [15], [8], [-6], [7], [23], [-18], [-28], [-15], [30], [-14], [-1], [-11], [15], [-36], [14], [0], [-40], [9], [-10], [0], [26], [-8], [12], [-6], [-22], [3], [-35], [-12], [21], [-32], [6], [13], [39], [-27], [33], [-14], [-7], [19], [36], [36], [30], [-5], [-4], [-12], [9], [48], [2], [-14], [-34], [30], [16], [-47], [-24], [-14], [-24], [6], [-12], [-34], [-34], [42], [-30], [-50], [-6], [35], [-21], [-8], [8], [4], [48], [40], [11], [-21], [44], [3], [22], [30], [-30], [-2], [0], [-23], [30], [-4], [51], [-40], [-9], [-14], [18], [41], [-6], [49], [-33], [49], [48], [25], [-21], [-16], [-3], [-12], [-6], [-8], [-27], [-60], [39], [31], [44], [-31], [15], [48], [-4], [-6], [35], [-20], [9], [-20], [-60], [16], [14], [-17], [-27], [50], [21], [-24], [-9], [-34], [-62], [-34], [45], [14], [60], [-47], [15], [-36], [-3], [-46], [-37], [30], [9], [-24], [-32], [14], [26], [15], [3], [16], [24], [-30], [58], [-43], [-18], [-17], [-27], [21], [-16], [-5], [-30], [-66], [-24], [11], [-14], [-54], [43], [-3], [-55], [27], [66], [-26], [-30], [14], [-2], [7], [12], [-62], [24], [8], [36], [-6], [-45], [36], [64], [34], [2], [-42], [-69], [-26], [-39], [-59], [-6], [5], [-78], [-54], [38], [39], [-36], [23], [70], [-30], [74], [16], [-18], [8], [56], [-18], [16], [36], [-30], [13], [18], [14], [52], [-34], [-53], [-22], [52], [18], [-61], [-37], [-15], [-51], [19], [-21], [20], [-14], [12], [-19], [-36], [70], [51], [18], [57], [48], [69], [-1], [87], [-50], [-75], [33], [76], [50], [-84], [-56], [-18], [49], [50], [36], [-34], [54], [50], [0], [-18], [18], [49], [-48], [26], [-69], [-18], [-40], [-24], [-50], [53], [-57], [64], [54], [74], [-29], [28], [-48], [12], [-34], [24], [-44], [9], [-47], [75], [2], [-33], [-52], [52], [-13], [36], [21], [-8], [-6], [-36], [56], [55], [33], [-30], [58], [-79], [-6], [-8], [-37], [-39], [36], [-33], [60], [48], [-37], [27], [6], [48], [-8], [17], [-15], [-89], [83], [72], [70], [-36], [54], [-26], [-10], [-12], [-30], [-34], [-66], [32], [-45], [84], [16], [-6], [-50], [-48], [-44], [86], [-23], [12], [95], [78], [-6], [-62], [0], [-58], [-2], [69], [28], [54], [32], [24], [-23], [-21], [54], [28], [89], [54], [-8], [96], [-28], [-18], [54], [-35], [59], [54], [18], [88], [-27], [48], [30], [44], [78], [-57], [-70], [-33], [-12], [84], [70], [-48]];
    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_d();".
// 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_d(: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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3024_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 1]>,<11,R![0, 1]>,<17,R![3, 1]>],Snew);
    return Vf;
end function;