
// Make newform 4026.2.a.t in Magma, downloaded from the LMFDB on 18 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_t();".
// 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_t();".
// 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 := [2, 1, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, -1, 1, 0], [1, -3, -1, 1]];
    Rf_basisdens := [1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0, 0], [1, 0, 0, 0], [-1, 0, -1, 0], [-1, 0, 1, -1], [-1, 0, 0, 0], [-2, -1, 0, 2], [-3, 2, 2, 0], [-3, 2, 0, 1], [-1, -3, 0, 0], [-1, -2, -1, 1], [-4, -1, -3, 4], [-1, 1, 0, -4], [-3, 1, 2, -3], [0, -1, 1, -5], [-3, 3, 1, 1], [2, 0, -3, 4], [2, -1, 5, -2], [-1, 0, 0, 0], [2, -3, -1, 0], [-2, 4, -1, -3], [-3, 7, 1, -2], [-4, 1, -4, 2], [-1, 1, -1, 4], [3, -4, -1, 0], [-2, -2, -5, -1], [-1, -1, 3, -3], [-1, 0, 1, -6], [-4, 4, -4, -3], [-2, 3, -4, -4], [2, 4, -1, -4], [3, -4, 4, 2], [-8, -3, -3, 3], [9, -11, -2, 1], [2, 2, 0, 5], [5, -3, 4, -11], [6, -4, -4, 0], [-7, -6, -9, 7], [-5, -8, -3, 5], [4, -6, 3, -2], [-15, 2, 3, 1], [7, 6, 9, -4], [-3, 8, 2, -2], [-4, 5, -2, -2], [-2, -1, 5, 2], [-3, -2, -5, 7], [-2, 1, 4, -3], [-6, 8, 2, 2], [0, 4, -9, 8], [1, 2, -11, 7], [-9, 2, 8, -3], [6, 8, 6, -4], [-15, -5, -5, 11], [-1, -5, 6, -6], [5, 2, -1, -3], [6, 3, -7, 6], [-3, 8, 7, 3], [3, -3, 12, -5], [5, -9, -4, -4], [-10, 1, -6, 14], [11, -4, 9, 9], [-8, 4, -7, 4], [0, 1, 9, 1], [-3, -1, 6, 10], [7, -4, -6, 3], [-5, -6, 6, -9], [12, -7, 3, 3], [8, 4, 9, -1], [-2, 10, 8, 2], [9, -16, -1, -2], [-22, -5, 0, 7], [4, 5, -6, 8], [7, -4, -6, -6], [-1, -7, -6, 5], [6, -4, 5, -9], [11, -9, 4, -1], [1, 5, -10, 3], [9, -8, -1, -1], [-4, 8, 13, 1], [-6, 1, 0, 9], [0, -3, 17, -2], [4, 11, -4, 4], [13, 5, 14, -10], [-5, 11, 14, -1], [-3, 13, -6, 7], [4, 4, 10, -3], [6, -6, -5, -1], [19, 1, -2, -5], [6, 7, 1, 4], [-14, 11, 4, 9], [2, 4, 4, -11], [11, 6, 2, 5], [-4, 4, 1, 0], [-3, 0, 1, -3], [16, -6, 5, 0], [-6, 8, -6, 5], [-10, -9, -5, 10], [-5, 2, 2, 5], [5, -2, -5, -1], [-4, -1, 1, -1], [8, -15, -7, -1], [14, -5, 6, -16], [-6, 9, -1, 0], [-3, 13, -4, -5], [-12, -1, -17, 10], [-1, -1, 3, -17], [-9, -8, -4, 5], [4, 1, 11, -12], [2, -23, 3, 5], [-8, -4, 12, 5], [-5, 2, -2, -16], [-3, -12, -3, 6], [-15, -16, 4, 3], [23, 5, 5, -2], [5, -5, 9, -7], [-6, 3, 1, 18], [-24, -1, -4, 5], [-7, 0, 13, -8], [14, 3, 1, -15], [5, 1, 4, 3], [-8, 1, -4, -3], [5, -18, 8, -1], [-11, 3, 9, -9], [9, 11, -1, -11], [32, -3, 6, -11], [-6, 1, -3, 8], [-13, 0, 20, -9], [-4, -5, -14, -5], [-20, -3, -12, 14], [-2, 7, 5, -8], [2, -19, 7, -2], [8, -4, -10, 1], [0, -7, -18, 5], [-21, 4, 5, 8], [-19, 14, -5, -5], [-16, -1, -20, 0], [-5, -2, -10, 7], [-12, 20, 6, -7], [11, 23, -5, -3], [-24, 5, -6, -4], [4, -2, -10, -2], [9, -3, 3, -12], [5, 3, 6, -7], [-17, -9, -11, -1], [-2, -4, -2, -15], [-18, 3, 1, -14], [-8, -20, -16, 14], [-11, 2, -6, -13], [1, 13, -9, 7], [4, 3, 4, 10], [9, 5, -9, 7], [17, -6, -13, -10], [21, -17, -11, -7], [9, -7, 0, 8], [8, 10, 0, -21], [0, 4, -4, 17], [14, 6, -5, 0], [-21, 7, -9, 20], [27, -21, -4, -9], [-12, -4, 8, -5], [-13, 5, 8, -1], [26, -7, -14, 4], [8, 8, -15, 3], [-13, 7, -1, 32], [-2, -6, 21, 1], [27, -5, 13, 3], [16, -21, 0, -6], [-8, -1, -8, -6], [10, 0, -9, 15], [-33, -9, 9, -5], [18, -5, -20, 0], [-3, 10, -14, -17], [-1, 23, 16, -11], [0, 4, -10, 15], [3, -22, 3, 18], [7, -3, 3, -9], [-8, -1, 21, -10], [26, 5, 4, -10], [-17, 15, 1, 19], [6, 3, -6, -18], [-7, -7, -26, 14], [-4, 10, 6, -8], [-5, -4, 24, -15], [-3, 28, 1, -9], [-12, -7, -2, -14], [-8, -19, 9, 8], [1, 2, -13, 17], [-28, -15, 0, 12], [22, -19, -12, 8], [4, 15, 0, -4], [3, -18, 4, 11], [10, -15, 2, 8], [10, -11, 4, 4], [-1, 15, 10, -13], [1, 12, -8, -14], [40, -6, 7, -14], [-37, -1, 0, 15], [-10, -1, -19, -5], [-30, 0, -4, 19], [-16, 10, -1, 16], [14, 1, -13, 16], [-28, 17, -1, 21], [-16, 18, -12, -22], [-10, 6, -5, 0], [-16, -11, -13, 8], [22, 1, 8, 7], [41, -3, 11, -14], [2, 15, 3, 14], [-4, 6, 13, 20], [-13, 0, 3, -8], [9, 11, 17, -10], [-31, -4, 4, 0], [-17, -10, -14, -6], [-28, 2, -3, 5], [23, -22, -14, 9], [-16, 30, -6, -11], [22, -4, 3, -10], [-13, 5, -5, 17], [19, -5, 9, -3], [-1, 0, -2, -19], [-1, 7, 20, -9], [1, -4, -12, 11], [8, 11, 18, -19], [23, 10, -18, 2], [-26, 20, 22, -3], [28, -9, 9, -10], [-2, 14, 1, 9], [-20, -7, -16, 12], [14, 0, 10, 0], [-13, 23, -2, -17], [-7, 5, 8, -10], [-19, 15, 7, 12], [28, -19, -1, -18], [21, 4, -8, 19], [24, 2, 8, -31], [5, -9, -11, -31], [5, 19, 8, 4], [-31, 1, -13, -15], [2, 18, 0, -22], [-8, -22, -3, -8], [-37, 19, -4, 3], [-25, 15, -11, -1], [-7, -14, 13, -3], [-1, 4, 8, -13], [2, -21, 12, 2], [11, 3, -1, -26], [-10, -5, 11, -20], [7, -14, -9, 8], [20, 10, -4, 4], [-22, -18, -4, 26], [1, 15, -16, -11], [-38, 15, -2, 10], [-20, 8, -18, 10], [-10, 3, -14, 5], [-9, -7, 3, -25], [-4, 12, -8, 15], [-23, 19, 0, 23], [3, -23, -11, -9], [-6, -16, -16, -4], [-12, -6, -13, 12], [-9, 7, 5, -7], [7, 3, 27, -18], [1, -13, -14, 6], [-13, -31, 1, 19], [-36, 7, -15, -12], [-11, 29, 22, -11], [-1, 12, 38, -17], [3, -16, 14, -7], [20, -7, 15, -22], [4, -23, 3, 14], [-43, 3, 19, 0], [-41, 14, 6, -7], [5, 26, -10, -7], [21, 7, 11, -15], [-23, -4, -15, -11], [-21, -15, 1, -11], [28, 5, 16, -3], [19, 10, 12, -27], [-10, 19, -1, -4], [3, 21, 3, -23], [-40, 3, -15, 34], [-9, 35, -9, -8], [15, -7, 25, -8], [-28, -3, -23, 14], [-28, -6, -19, 9], [6, 6, -12, 21], [13, 2, 17, -29], [-11, -31, 1, 27], [27, -6, -13, -14], [24, 0, 23, -7], [-27, -7, -14, 1], [21, -6, 27, -11], [20, 8, 31, -23], [-1, 6, -13, -11], [-23, -13, -35, 19], [-18, 3, 22, -4], [-20, 2, 20, -15], [-29, 17, 10, 8], [-15, -15, -39, 19], [33, -15, 11, -5], [25, 25, 6, -24], [-32, 4, 10, -14], [-52, -3, 1, 8], [-38, 29, 4, -3], [20, -5, -4, 8], [3, -4, 1, 7], [33, 3, 19, 2], [16, -9, 1, -14], [-27, -4, 3, 25], [-33, -7, -25, 41], [3, -5, 3, 36], [-38, -10, -14, 1], [5, -34, 3, 12], [-21, 5, 1, 4], [27, 14, 13, -23], [23, -5, 11, 5], [0, 16, -3, -2], [-43, 16, 19, 1], [-32, -4, 12, 3], [-19, -3, -27, 8], [20, 27, -18, 15], [27, -12, -11, -1], [-20, -25, 7, 8], [34, -28, -15, -26], [-21, -10, -7, 3], [-12, -13, -21, 29], [6, 13, -8, 24], [8, -33, -3, -1], [4, 29, 0, 9], [19, 11, 6, -8], [-6, 17, 21, -16], [-23, 9, -15, 17], [-22, 3, 4, 1], [2, 5, 13, 26], [1, -20, 19, -2], [59, 7, -19, 9], [-31, 31, 9, -9], [18, -26, 18, -4], [-26, 13, -4, -4], [-6, 16, -3, 18], [-22, 6, -22, 8], [14, 7, 23, -10], [-7, 10, -3, -10], [1, -17, 3, 13], [34, 14, 24, -24], [-21, 28, 5, 14], [-2, 1, -23, 30], [-21, 19, 5, 2], [17, 20, 11, -26], [-27, -26, 7, 20], [4, -3, 5, -5], [55, 1, 18, -40], [21, -12, 1, -9], [-25, 18, 18, -17], [4, 26, -17, -3], [-19, -4, -43, 11], [-25, -17, -6, 1], [-32, 8, 14, -14], [11, -13, -9, 15], [12, -41, -25, 15], [-28, 4, 8, -7], [-21, 18, 21, -17], [-30, 7, -21, 0], [16, -25, 19, 30], [-19, 21, -6, 11], [56, 14, 17, -36], [-16, -11, -5, 10], [-36, 20, -15, 2], [-26, 37, -7, -4], [-6, 16, 4, 31], [-27, 16, 14, -5], [6, -1, 14, 8], [-20, -9, -16, -12], [-60, -1, 6, -9], [1, -30, 7, 1], [30, -7, -24, -4], [-19, 14, 9, 3], [24, -27, -5, -9], [12, 16, 6, -16], [-9, -24, -6, -5], [-7, 3, 16, 21], [-25, 8, -20, 21], [22, -15, -20, 22], [45, -35, -28, -3], [-15, -31, 11, 1], [5, -10, -12, -1], [38, -27, -13, -3], [51, 10, -2, -22], [28, 29, -22, 9], [-56, 7, 5, 12], [24, -3, -3, 18], [-4, 12, 8, 38], [-5, -14, -2, 0], [-18, -15, -8, 19], [46, -7, 2, -16], [-11, 5, -3, 27], [36, -19, 9, -26], [19, -5, -16, 7], [-13, -24, 8, -1], [-48, 14, -2, 26], [30, 9, 45, -15], [26, 4, -10, -30], [-9, 7, -38, 36], [-10, -21, -13, 16], [-57, 1, 5, -8], [-45, -9, -9, 31], [19, -19, -26, -14], [17, -17, 7, -25], [65, 14, 8, -5], [-14, 20, 2, 14], [-10, 29, 10, 16], [-35, 29, 20, 21], [-24, 4, 6, -6], [15, 18, 7, -31], [45, -1, 9, -45], [47, -25, -1, -27], [2, 28, 18, -18], [9, 2, 0, -21], [54, -22, 1, -1], [-30, 10, 24, -8], [-17, 14, 13, -1], [-30, -4, -3, 11], [27, -16, -2, -24], [3, 5, 25, 23], [21, -32, -2, 1], [-31, 41, 6, -12], [13, -13, 5, 37], [1, -16, 25, -19], [-27, 3, -2, -15], [41, 5, 15, 8], [13, -23, -6, 7]];
    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_t();".
// 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_t(:prec:=4)
    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_t();".
// 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_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4026_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, -7, 1, 4, 1]>,<7,R![-8, -5, 7, 6, 1]>,<13,R![-22, -39, -12, 5, 1]>],Snew);
    return Vf;
end function;