
// Make newform 6026.2.a.c 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_c();".
// 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_c();".
// 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], [3], [2], [-1], [-6], [1], [-2], [-1], [-2], [-4], [2], [-9], [-5], [-10], [-2], [6], [-7], [-6], [2], [4], [-4], [0], [0], [2], [0], [13], [-7], [5], [0], [-4], [1], [-3], [19], [-10], [-3], [-10], [-15], [-7], [5], [20], [12], [18], [15], [-11], [25], [-10], [-26], [18], [0], [-21], [-12], [15], [12], [-24], [26], [-14], [-9], [2], [-3], [-8], [-18], [34], [19], [10], [-12], [16], [8], [-13], [-26], [9], [-15], [-22], [12], [5], [6], [-12], [-8], [-22], [1], [-12], [6], [-36], [-25], [-27], [12], [-30], [-4], [-37], [24], [25], [-11], [-31], [-15], [21], [-3], [9], [-17], [18], [15], [-5], [9], [0], [24], [-40], [-1], [30], [8], [-27], [35], [22], [-7], [1], [34], [26], [28], [32], [11], [16], [27], [28], [14], [30], [14], [-12], [2], [-42], [-43], [-19], [8], [10], [51], [19], [-11], [-50], [28], [-14], [7], [7], [-36], [-50], [22], [-16], [44], [14], [10], [-10], [0], [-8], [56], [8], [2], [-27], [-41], [-1], [48], [-25], [25], [50], [-22], [12], [-12], [-20], [40], [-54], [24], [-40], [-42], [-61], [9], [12], [-38], [46], [49], [-4], [30], [-4], [-8], [34], [25], [17], [36], [14], [7], [-46], [57], [11], [-29], [10], [-36], [34], [-27], [15], [19], [-24], [15], [17], [46], [-38], [-15], [-10], [-52], [-14], [-43], [5], [63], [38], [-5], [0], [-20], [28], [-51], [16], [42], [21], [-28], [-32], [0], [-13], [-38], [5], [54], [14], [26], [-48], [53], [-26], [-13], [57], [15], [-6], [20], [7], [0], [32], [50], [-14], [-15], [-8], [-12], [10], [35], [56], [-32], [14], [-30], [-52], [-14], [28], [-40], [-30], [10], [-20], [-59], [20], [-36], [-54], [5], [26], [-18], [-26], [-10], [-65], [-19], [-51], [34], [0], [47], [-23], [1], [0], [-23], [-6], [5], [21], [40], [-12], [2], [-78], [-63], [-28], [65], [-78], [-46], [-40], [-48], [-32], [27], [-40], [1], [4], [-48], [0], [0], [44], [40], [8], [77], [45], [-40], [14], [6], [62], [-24], [59], [61], [-42], [10], [-84], [-11], [-20], [28], [-1], [11], [79], [29], [-32], [-21], [65], [3], [-56], [-66], [88], [14], [35], [68], [20], [-26], [-9], [6], [-24], [39], [-59], [46], [-80], [-19], [44], [-6], [-84], [-20], [6], [-42], [-71], [-40], [34], [72], [-26], [-81], [-9], [62], [-10], [-38], [59], [60], [14], [54], [-50], [21], [-3], [1], [40], [40], [71], [45], [76], [-6], [9], [40], [-18], [19], [-4], [-34], [38], [-2], [-6], [13], [-30], [50], [41], [80], [-50], [-38], [-73], [-66], [-61], [40], [-14], [101], [-76], [49], [-29], [74], [89], [67], [-16], [-51], [-84], [46], [48], [-42], [72], [90], [34], [78], [-40], [60], [-81], [-42], [-76], [12], [14], [-22], [-36], [-80], [-37], [30], [-30], [8], [-2], [28], [-67], [38], [55], [25], [-60], [8], [52], [36], [-92], [72]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : 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![-3, 1]>],Snew);
    return Vf;
end function;