
// Make newform 7056.2.a.m in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7056_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_7056_2_a_m();".
// 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_7056_2_a_m();".
// 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_7056_a();"
function MakeCharacter_7056_a()
    N := 7056;
    order := 1;
    char_gens := [6175, 1765, 785, 4609];
    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_7056_a_Hecke(Kf)
    return MakeCharacter_7056_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], [0], [-2], [0], [-2], [-1], [0], [1], [0], [-4], [9], [3], [-10], [-5], [6], [-12], [12], [-10], [5], [-6], [3], [1], [-6], [16], [6], [2], [-7], [-8], [9], [-10], [15], [14], [12], [-3], [12], [16], [14], [-4], [14], [8], [2], [-13], [10], [11], [-16], [0], [-4], [16], [-18], [19], [-6], [6], [-14], [8], [26], [4], [6], [16], [13], [4], [-11], [8], [-17], [6], [1], [-24], [25], [13], [32], [14], [34], [20], [-9], [23], [-3], [12], [6], [9], [36], [-5], [-30], [-7], [-18], [-31], [0], [12], [18], [-11], [20], [17], [-6], [28], [-31], [-28], [-37], [42], [2], [12], [31], [-19], [-28], [2], [26], [26], [19], [17], [-16], [-6], [12], [9], [23], [34], [6], [-29], [-8], [0], [-19], [-2], [-18], [36], [41], [-41], [12], [-12], [-37], [0], [30], [18], [-13], [15], [15], [42], [-13], [-22], [-48], [49], [-34], [40], [-8], [-30], [32], [-2], [0], [-30], [-41], [44], [-35], [-32], [-40], [-54], [-38], [24], [13], [34], [37], [-24], [-23], [14], [-15], [-4], [-10], [-44], [-19], [-36], [18], [-36], [-17], [-19], [61], [32], [48], [18], [60], [5], [-19], [-16], [53], [-10], [24], [-31], [19], [0], [41], [-28], [-54], [-52], [46], [-17], [-23], [38], [-49], [-6], [40], [-36], [52], [-24], [35], [-18], [-30], [-12], [-14], [23], [-54], [14], [-38], [-22], [24], [-42], [36], [52], [39], [-24], [-4], [-4], [-44], [-7], [40], [-20], [28], [30], [5], [61], [-50], [64], [-50], [26], [-8], [-46], [47], [-6], [-11], [4], [49], [-46], [-63], [30], [35], [10], [-60], [22], [-18], [-39], [45], [-50], [72], [20], [-5], [-50], [8], [24], [77], [-24], [10], [-37], [64], [56], [-7], [-57], [-78], [-14], [-59], [56], [43], [61], [14], [-55], [6], [58], [44], [26], [-19], [4], [-37], [-47], [-10], [-76], [-38], [-81], [43], [-8], [-56], [-63], [-2], [-55], [20], [6], [25], [-6], [53], [18], [-4], [20], [-54], [-60], [-29], [46], [25], [-28], [34], [-1], [18], [6], [-28], [28], [3], [-75], [-6], [63], [16], [19], [-36], [70], [-90], [48], [8], [7], [6], [48], [-73], [54], [-19], [-41], [-42], [1], [42], [47], [-7], [53], [-52], [-30], [-23], [66], [17], [-66], [5], [-58], [-70], [-36], [19], [-59], [-17], [16], [48], [-37], [-14], [-26], [-25], [-4], [66], [-70], [76], [-54], [62], [0], [-65], [2], [-30], [60], [-32], [6], [-6], [-26], [30], [2], [41], [70], [8], [-1], [78], [84], [21], [-6], [-54], [95], [49], [56], [-8], [34], [36], [-57], [-16], [-60], [56], [4], [60], [28], [73], [-46], [-11], [42], [25], [54], [36], [-73], [-22], [58], [-44], [-78], [-15], [-102], [-14], [52], [-16], [-6], [66], [49], [-18], [-20], [101], [36], [46], [-44], [-16], [44], [-15], [90], [66], [-79], [12], [96], [24], [41], [-88], [-2], [10], [18], [58], [72], [-12], [72]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7056_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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