
// Make newform 4026.2.a.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4026_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_4026_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_4026_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
        poly := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4026_a();"
function MakeCharacter_4026_a()
    N := 4026;
    order := 1;
    char_gens := [1343, 1465, 3235];
    v := [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_4026_a_Hecke(Kf)
    return MakeCharacter_4026_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], [-1, 0], [0, -2], [-1, 1], [1, 0], [0, 3], [-6, -1], [-3, -1], [2, 0], [6, -6], [-4, 6], [5, 3], [-6, 4], [-4, 2], [4, -3], [-6, 5], [-7, -3], [-1, 0], [-10, 3], [6, -2], [-6, 4], [10, -5], [8, -12], [-14, 2], [-5, -7], [-8, 10], [7, -11], [0, 3], [-3, 3], [-6, -7], [6, -6], [-8, 1], [3, -1], [-16, -2], [6, 0], [-2, 9], [7, -11], [-16, 8], [12, 0], [6, -12], [-14, 0], [-16, 9], [10, -12], [9, -21], [-9, -9], [-1, -7], [-14, 10], [-22, -2], [0, -6], [-8, 16], [5, -11], [-8, -2], [-8, 16], [-4, 17], [-14, 27], [2, -4], [-10, 0], [10, -12], [8, 10], [-1, -1], [11, 5], [-9, 11], [4, 2], [2, 8], [-2, -12], [18, -20], [15, -7], [-4, -5], [1, 13], [24, -16], [-11, 13], [-16, -3], [14, 1], [18, -16], [16, -6], [-2, 14], [-5, 23], [-10, 20], [-6, -18], [-5, -3], [21, -19], [16, -11], [10, -14], [16, -4], [32, 0], [-6, 20], [-2, -11], [20, -11], [-2, 5], [-30, 9], [12, 9], [-8, 24], [5, -1], [12, -9], [20, -28], [16, -30], [26, -19], [-20, 6], [30, -12], [-30, 6], [-14, 16], [-14, 14], [-1, 15], [-10, 0], [-4, -24], [14, -2], [0, -20], [-1, 19], [-14, 28], [6, -12], [26, -6], [40, 3], [6, -18], [-16, -8], [-2, 10], [-22, 18], [18, 1], [22, 14], [14, 3], [-8, 29], [-38, 4], [-6, 12], [-4, 4], [2, 18], [36, -16], [-22, -6], [-31, 19], [0, -25], [17, -17], [-21, -15], [6, 18], [20, 0], [-22, 11], [-6, 16], [-2, 29], [34, -28], [16, -38], [20, -16], [0, -16], [12, 0], [16, 0], [12, -10], [-52, 4], [28, -19], [10, -30], [7, -29], [26, -8], [-4, 22], [-8, 32], [-13, 15], [18, 8], [23, -37], [27, -27], [-47, 5], [29, -13], [-27, 21], [-16, 30], [-49, -1], [12, -40], [12, 2], [-20, 1], [-29, -17], [22, 20], [36, -18], [-19, 49], [26, -36], [14, 13], [-18, 12], [22, -44], [6, -24], [-58, 6], [30, -24], [19, -13], [-12, 44], [20, 8], [-30, 3], [46, -5], [38, 7], [4, 16], [-42, 24], [-18, 20], [-10, 0], [-6, 24], [-46, 8], [51, -9], [18, -12], [37, 11], [-56, 0], [-7, -5], [-28, -5], [6, -38], [-15, -7], [-12, 24], [2, 24], [34, -4], [-23, 41], [4, -12], [-15, -17], [-52, -10], [10, -10], [38, -5], [-21, 37], [23, -11], [-22, 20], [-46, -4], [-26, 36], [-30, 2], [-26, 42], [-10, -15], [38, -9], [-24, -10], [12, -24], [41, -9], [16, 1], [-16, -20], [-58, 20], [10, -24], [-8, -10], [-28, -4], [-34, 16], [-3, -1], [2, 16], [-26, -24], [20, 0], [20, -8], [-28, -4], [-38, 14], [-72, 3], [-43, 27], [9, 9], [-22, 44], [-22, 13], [24, 24], [49, -43], [32, -2], [-1, 31], [-44, 35], [-34, -12], [-8, 27], [56, -8], [25, 9], [18, 6], [14, -6], [-36, -15], [-34, 36], [20, 6], [12, -52], [50, 12], [10, -24], [-22, -18], [-24, 28], [-40, 20], [-28, 48], [-6, -38], [-58, -12], [-34, 36], [-12, 1], [-4, 16], [42, 0], [-4, 7], [46, -16], [-21, 23], [32, -11], [-48, 3], [12, 24], [-36, -20], [-2, 48], [54, 1], [44, 0], [-58, -13], [9, -13], [-60, 14], [-16, 7], [-2, 37], [15, 17], [48, 16], [7, -13], [49, -37], [47, -27], [16, -27], [20, 12], [-14, -3], [8, -19], [-54, 0], [-44, 36], [-20, 16], [-34, 48], [-62, 28], [-35, 55], [-37, 19], [26, -9], [-58, 42], [36, -44], [-6, 22], [-31, 59], [33, -55], [34, -53], [7, 35], [-19, 57], [-36, 8], [32, -42], [18, -21], [-34, 8], [-16, 27], [-23, 27], [27, 1], [-32, 18], [-46, 42], [40, -8], [28, -20], [-40, 63], [58, -26], [17, -51], [-8, -26], [4, -14], [-16, 42], [68, -32], [15, 3], [56, -17], [-10, 48], [-34, 33], [-14, -6], [0, 18], [12, -60], [-10, -51], [26, -72], [-70, 23], [65, -9], [76, -5], [36, -18], [13, -37], [-32, -4], [-32, 16], [-23, 13], [-40, -12], [56, -9], [-50, 52], [-70, 38], [24, -60], [-66, 33], [26, 36], [6, -12], [70, -11], [-6, -6], [-38, 24], [-62, 6], [13, 15], [-28, 36], [-44, 39], [-22, 6], [-48, -20], [-68, 10], [73, 1], [-2, -42], [20, 32], [-58, 30], [17, -23], [-26, 0], [18, 9], [22, -4], [-71, 39], [42, 14], [34, -74], [8, 29], [-32, 16], [24, -6], [26, 24], [42, -9], [24, -34], [25, -51], [-26, 43], [-8, 42], [39, -33], [-30, 23], [-12, 36], [20, 3], [-29, -5], [-70, 16], [-12, 60], [17, -17], [-38, -5], [-34, 40], [-26, -45], [52, -24], [33, 3], [-6, 38], [-47, 3], [28, -15], [-66, -9], [56, -31], [-57, -19], [32, 44], [-62, -16], [6, 39], [64, -28], [-20, 5], [16, -12], [-53, 55], [14, 42], [54, -5], [-6, -28], [22, -30], [-40, -4], [-20, 4], [16, -38], [10, -68], [20, 42], [68, -36], [-18, 50], [-4, 6], [4, -12], [10, 0], [4, 0], [-38, -13], [37, -17], [13, -71], [0, -40], [-62, 49], [-40, -8], [4, -10], [48, 14], [58, -4], [-65, 51], [-18, -28], [-21, 41], [-10, 56], [-12, -24], [-2, -4], [33, -45], [-15, 49]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4026_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4026_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_4026_2_a_m(:prec:=2)
    chi := MakeCharacter_4026_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_4026_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_4026_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4026_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 2, 1]>,<7,R![-1, 1, 1]>,<13,R![-9, -3, 1]>],Snew);
    return Vf;
end function;