
// Make newform 6026.2.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6026_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_6026_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_6026_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_6026_a();"
function MakeCharacter_6026_a()
    N := 6026;
    order := 1;
    char_gens := [787, 4325];
    v := [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_6026_a_Hecke(Kf)
    return MakeCharacter_6026_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], [2], [-1], [2], [-5], [-2], [-3], [-6], [-1], [-2], [4], [2], [7], [-1], [-6], [6], [10], [-3], [-10], [-2], [-16], [4], [-12], [-16], [10], [16], [1], [13], [1], [-12], [16], [1], [1], [3], [-6], [-11], [-10], [1], [9], [21], [-12], [-20], [14], [23], [21], [-3], [-14], [14], [10], [16], [-5], [-12], [11], [0], [-8], [-10], [6], [7], [-14], [1], [-16], [18], [6], [-5], [-22], [0], [-16], [-28], [27], [-2], [-23], [-11], [14], [-16], [-23], [-26], [24], [-36], [-22], [9], [-16], [22], [-16], [19], [-19], [12], [-22], [-28], [-21], [32], [-3], [-39], [17], [-7], [29], [-39], [25], [35], [-34], [-9], [-29], [5], [24], [40], [32], [23], [30], [44], [45], [3], [-22], [-3], [-27], [-2], [-30], [0], [-16], [3], [24], [15], [-8], [-46], [18], [2], [-28], [26], [-10], [-43], [-7], [-8], [-34], [39], [7], [17], [-10], [-20], [18], [43], [-29], [24], [-10], [-6], [-44], [-52], [2], [-6], [-26], [0], [56], [-32], [32], [2], [29], [47], [-29], [40], [51], [41], [-14], [30], [-36], [-12], [-12], [0], [-58], [-48], [-8], [-14], [39], [1], [36], [58], [-18], [5], [-28], [2], [28], [12], [-14], [-43], [-23], [12], [38], [-33], [-10], [-11], [-29], [-1], [34], [4], [42], [5], [-37], [3], [-32], [19], [-51], [-26], [-22], [9], [-22], [28], [-22], [-23], [-39], [55], [-18], [-21], [-56], [-8], [-68], [69], [16], [2], [-27], [24], [-20], [-12], [15], [-54], [-43], [46], [54], [-26], [-12], [5], [-54], [3], [61], [-17], [46], [4], [-53], [-32], [64], [30], [14], [45], [64], [-48], [34], [51], [32], [36], [-18], [-42], [-32], [-10], [12], [20], [-54], [-46], [68], [-15], [-56], [-28], [-38], [33], [-26], [-2], [-18], [26], [31], [-15], [29], [26], [36], [-5], [61], [-71], [56], [61], [-54], [-55], [-3], [-16], [72], [34], [-30], [-83], [-72], [37], [10], [2], [8], [60], [44], [-41], [8], [1], [72], [4], [-60], [52], [-40], [0], [44], [-59], [21], [40], [-34], [14], [-50], [-36], [-41], [13], [58], [-54], [-48], [21], [32], [-20], [11], [-5], [83], [17], [0], [11], [-19], [27], [16], [46], [-72], [-26], [-81], [8], [-88], [-10], [43], [70], [20], [-73], [-59], [38], [16], [77], [-4], [-78], [40], [16], [-50], [6], [-79], [80], [18], [-52], [-62], [-9], [-45], [2], [-22], [74], [27], [28], [-14], [30], [-6], [-23], [-3], [-47], [-56], [88], [-41], [97], [56], [98], [81], [32], [-34], [3], [20], [-94], [-50], [58], [-30], [-27], [94], [-38], [-3], [92], [-42], [-78], [15], [-6], [-9], [-96], [-74], [29], [-52], [45], [23], [-86], [49], [-13], [4], [-7], [80], [-54], [16], [-58], [-44], [42], [-38], [-42], [60], [-12], [35], [-18], [12], [-36], [-22], [-54], [0], [8], [-49], [14], [14], [-48], [14], [56], [73], [-74], [39], [-39], [-44], [44], [-52], [-44], [-16], [56]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6026_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6026_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_6026_2_a_d(:prec:=1)
    chi := MakeCharacter_6026_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_6026_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_6026_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6026_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<5,R![1, 1]>],Snew);
    return Vf;
end function;