
// Make newform 1056.2.a.d in Magma, downloaded from the LMFDB on 20 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1056_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_1056_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_1056_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_1056_a();"
function MakeCharacter_1056_a()
    N := 1056;
    order := 1;
    char_gens := [991, 133, 353, 673];
    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_1056_a_Hecke( : Kf := Kf)
    return MakeCharacter_1056_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], [-1], [0], [-2], [-1], [4], [-2], [0], [-2], [-2], [-4], [6], [-6], [-12], [-6], [0], [0], [0], [4], [-10], [2], [2], [-4], [-14], [-2], [-10], [8], [4], [20], [-14], [10], [-4], [-18], [-16], [-14], [10], [10], [4], [12], [22], [16], [-14], [10], [6], [6], [24], [-4], [-4], [12], [-6], [-6], [-12], [22], [24], [26], [0], [-24], [-2], [-8], [-18], [20], [-14], [8], [14], [-22], [-4], [-4], [18], [12], [-12], [-6], [-36], [-20], [28], [-20], [-10], [-16], [-22], [22], [22], [-32], [-34], [-8], [26], [26], [-24], [14], [-18], [42], [8], [20], [0], [8], [12], [-44], [-44], [-8], [38], [-36], [-4], [32], [18], [-28], [22], [-32], [-18], [24], [22], [-26], [-14], [26], [-8], [-14], [-20], [-44], [-10], [20], [-18], [44], [-20], [2], [-34], [6], [-16], [28], [18], [-38], [30], [24], [-12], [4], [36], [-52], [22], [6], [38], [16], [28], [-48], [-30], [44], [46], [-36], [-12], [-34], [-38], [-16], [18], [12], [-6], [36], [10], [4], [44], [44], [-18], [-10], [14], [-38], [54], [-12], [-14], [58], [48], [-34], [14], [44], [20], [22], [28], [60], [2], [-28], [-22], [-20], [-6], [-8], [4], [-26], [20], [-60], [-28], [54], [-38], [14], [20], [0], [44], [46], [0], [-10], [12], [12], [0], [28], [2], [-14], [-46], [-62], [-40], [18], [-10], [66], [-14], [8], [-44], [-56], [-52], [54], [-4], [-34], [36], [-36], [36], [44], [-26], [-62], [-66], [54], [-36], [-16], [-14], [30], [-44], [-52], [-28], [-30], [-54], [50], [-68], [46], [-20], [-2], [-26], [-52], [48], [-30], [42], [-64], [-54], [-28], [-28], [36], [2], [-42], [-60], [-40], [68], [-40], [4], [-8], [18], [42], [70], [10], [-44], [-10], [12], [-28], [14], [14], [-44], [4], [-12], [-18], [-28], [-60], [58], [-32], [46], [34], [52], [-50], [-46], [82], [64], [-68], [-24], [-22], [-44], [-24], [32], [4], [-20], [80], [-58], [30], [54], [-40], [-42], [0], [72], [-50], [4], [-44], [-70], [-16], [-72], [28], [-52], [30], [34], [62], [20], [4], [-22], [-20], [54], [26], [-12], [60], [36], [66], [-68], [-40], [10], [12], [-16], [2], [66], [16], [22], [-38], [8], [-42], [-34], [20], [-44], [60], [6], [-56], [-40], [-50], [-28], [36], [44], [-86], [-74], [-38], [10], [26], [78], [-70], [68], [56], [-36], [-38], [-28], [52], [48], [-20], [66], [40], [42], [80], [-54], [22], [60], [-86], [18], [24], [-34], [30], [28], [36], [-70], [-30], [-22], [-34], [-40], [-36], [-40], [46], [10], [46], [4], [-84], [-14], [42], [6], [48], [54], [-70], [-50], [-12], [-54], [36], [-10], [-68], [-70], [70], [28], [64], [-28], [-46], [-26], [78], [-42], [-92], [38], [-48], [-2], [30], [102], [42], [78], [54], [66], [-68], [60], [-54], [-22], [84], [-64], [-94], [100], [-4], [24], [-2], [-4], [-20], [8], [-18], [-84], [22], [-40], [-36], [-54], [-28], [-40]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1056_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1056_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_1056_2_a_d(:prec:=1)
    chi := MakeCharacter_1056_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_1056_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_1056_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1056_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<7,R![2, 1]>,<19,R![0, 1]>],Snew);
    return Vf;
end function;