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