
// Make newform 4026.2.a.r 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_r();".
// 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_r();".
// 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 := [3, 4, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, 0, 1, 0], [0, -4, 0, 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], [0, 0, -1, 0], [-1, 0, 0, -1], [-1, 0, 0, 0], [-1, 2, 1, 1], [0, -1, 2, -1], [-1, -1, -1, 0], [3, -1, 1, 2], [-3, 2, 0, 1], [-1, -3, 2, 0], [-1, -3, -1, 2], [0, 3, 0, 1], [-4, -3, -1, 1], [6, -2, 1, -2], [-6, 1, -3, -1], [3, -1, 6, 0], [1, 0, 0, 0], [-1, 1, 0, 0], [-3, 3, 0, 2], [-1, 4, 0, 5], [-7, -2, 1, -3], [-3, 4, 0, 1], [0, 4, -1, -2], [-7, 5, 2, -2], [0, -4, 5, 0], [-4, 6, -1, -4], [-3, -6, 1, -3], [-7, 2, -1, -1], [0, 1, 1, -1], [-16, 1, -2, 1], [0, 1, -5, 1], [6, -3, -4, -5], [-7, -4, -1, -1], [0, -5, 0, 1], [-4, -2, 0, -10], [5, 4, -2, -1], [-1, 4, -4, -1], [-6, -1, -3, -3], [-3, 0, -8, -1], [-6, -2, -7, -2], [-4, -1, -4, -9], [3, -8, 1, -7], [-13, -1, -8, 6], [-3, 4, 0, -7], [2, 8, -4, -2], [-10, 8, 4, 6], [2, 1, 7, 5], [-3, -4, -2, 1], [-1, -5, 1, 4], [6, -2, -2, -6], [12, -4, 5, 6], [5, -1, 1, -6], [-9, 10, -2, -7], [15, -5, 2, 6], [9, -6, -4, 3], [0, 7, 2, 3], [-1, -7, 7, -2], [-7, 0, -5, 5], [-3, -6, -4, 5], [2, 3, -1, -1], [6, 11, -7, 5], [-7, -7, 7, -6], [9, 11, 3, -4], [-1, -7, -3, -2], [6, -1, -3, 3], [-7, -9, -2, -4], [2, 0, -4, -4], [-6, 2, -9, -2], [-4, -2, -4, 4], [9, -4, 1, -7], [0, 3, 8, 9], [14, -5, 6, -1], [-1, 1, 2, 12], [-10, 3, -14, -1], [-18, -1, -12, 7], [3, 2, 0, -3], [17, 3, 8, -4], [-6, 12, 0, -2], [-7, 5, -2, -2], [-9, 4, -1, 9], [5, 5, 11, 4], [-18, 1, -6, 1], [2, -9, 6, -7], [5, 0, 9, 1], [9, -15, 4, 8], [-12, -1, 6, 7], [-7, 11, -2, 0], [0, -16, -6, 4], [-1, -6, 7, -9], [-3, 3, 13, 8], [6, 5, 7, -9], [-19, 4, 0, 9], [-6, 3, -9, -3], [17, 4, 3, -3], [-9, -1, -4, -4], [-3, 1, -9, -10], [-9, -8, 2, 7], [-4, -11, 7, -11], [-16, 1, 1, 3], [-7, 0, 3, 11], [15, 3, -4, 10], [0, 7, 4, 5], [9, 13, 0, -4], [-28, 8, -1, 0], [-1, -9, -5, -4], [-9, 11, -4, 0], [0, 9, 5, 11], [-3, -8, 11, -5], [-10, 3, -6, 9], [2, 2, -5, -4], [23, -7, 5, 18], [21, -6, 4, -1], [-4, 6, -1, 0], [5, 11, -4, 4], [0, -6, -2, -6], [-10, 4, 1, 10], [12, -5, 17, 7], [0, 15, -14, 5], [-6, 14, -4, 12], [-1, 1, -7, 2], [20, 8, -1, 0], [-12, -2, -11, -6], [6, -16, 6, -2], [-1, 7, 4, 12], [-9, 9, -11, -2], [20, -10, 10, 8], [3, -10, 1, 11], [23, 11, -12, 0], [17, -5, 0, -8], [11, 0, -5, 5], [-6, -4, 14, 2], [2, 2, -11, 6], [-19, -6, 12, 1], [-21, -6, 7, -3], [-1, -3, -15, -10], [33, 0, 7, -7], [-28, -8, 1, -2], [9, 6, 1, -9], [-12, -2, -6, 14], [11, -4, 6, -13], [6, 15, -16, 5], [2, -20, 5, -2], [9, -14, 7, -15], [11, -11, 8, 0], [18, -12, -2, -6], [17, 3, 9, -6], [-12, 6, -11, -8], [-1, -8, 1, 13], [6, 16, -5, 0], [8, -16, -3, 4], [18, 2, 7, 4], [11, -11, -11, -2], [9, -12, 15, -9], [5, 0, 5, -3], [12, -11, 3, 5], [5, -12, -2, -9], [-6, -19, 2, 3], [-7, 0, 1, -19], [-30, -9, -2, 5], [21, 4, -1, 3], [15, 5, 8, -4], [-7, -8, 2, -5], [-9, -1, -16, 0], [12, -20, 1, -8], [9, -6, 13, -3], [-13, 14, 5, 3], [23, -13, -8, -2], [20, 10, 15, -14], [21, -4, 3, -5], [3, -3, -17, 0], [-4, 5, -14, -3], [15, -14, -9, -1], [26, 8, 5, -6], [-4, -10, -15, 6], [-9, 25, 2, 0], [-1, 12, 7, 15], [12, -8, 1, 6], [-1, 10, 1, 15], [41, -7, 3, 0], [-16, 20, 8, -2], [-33, 5, -11, -16], [11, 8, 12, 9], [21, 2, 3, 1], [39, -1, 14, 0], [-21, 14, 0, 1], [11, 4, 1, 11], [-1, 6, 17, 3], [17, -10, -7, -5], [-9, -7, 3, -12], [-13, 6, 5, -3], [-3, -10, -9, 9], [-22, 13, -12, -19], [-6, 15, 18, 1], [-6, 7, 11, 5], [-18, 17, -2, 11], [26, -17, -7, -5], [29, -8, 7, -3], [12, 1, 7, 13], [-33, -1, 12, 0], [30, -3, 7, -5], [-4, -12, -8, 12], [-10, 23, 3, -5], [-13, -9, -2, -22], [0, -4, -14, 4], [-3, 0, -4, 19], [5, 9, 2, -10], [-12, -15, -13, 5], [-18, 30, 7, 0], [5, 0, -12, 11], [-16, -1, -2, 15], [24, 11, 2, 11], [-25, 3, -2, -12], [-39, 3, -3, -20], [-9, 10, -5, 7], [20, -27, -7, 7], [14, -4, 23, -2], [0, -10, 15, -8], [21, 3, -5, 0], [-18, 5, -8, 5], [-1, -3, 13, 10], [26, -18, -8, -6], [-24, 15, -8, -7], [11, 0, -3, -11], [3, -19, 2, -6], [-25, 1, 10, -4], [3, -8, -7, -7], [-12, 24, 18, 0], [-4, 3, -2, 1], [-9, -11, -1, -8], [-13, 14, -30, -9], [-1, -3, 12, 12], [-1, 5, 19, 8], [-33, 12, 9, -1], [-16, 22, -1, -8], [-15, -3, -1, 10], [8, -4, 5, 12], [-18, -16, -8, 8], [12, -27, -13, -3], [6, -17, 16, 11], [18, -6, 19, 14], [5, -12, 8, 13], [5, 5, 3, -4], [-1, -6, -21, 1], [-3, 6, 0, 17], [9, -17, -2, -22], [-4, 8, -7, 14], [-18, -16, 10, -2], [-16, -10, 4, 14], [0, 13, 6, 15], [35, 16, -7, -1], [-18, -18, 20, -4], [48, -18, -12, -10], [-10, 20, -9, -10], [9, 16, -1, -13], [-24, 7, 14, 5], [-28, -10, 5, -22], [-22, -4, -4, -4], [-12, 1, 1, 17], [38, -14, 1, -8], [23, -4, -4, 17], [33, -5, 19, 0], [-16, 16, -7, 4], [-19, -9, 10, -8], [42, 11, 4, -5], [-7, -23, 17, 2], [3, -21, 7, 12], [9, -5, 2, 4], [-37, 5, -4, -8], [-33, 10, -20, 1], [-43, 1, -7, 16], [5, -9, 13, 0], [2, -8, -17, -2], [-43, -10, -6, 3], [-4, 26, -1, 22], [-22, 18, -16, -8], [-15, 5, -17, 22], [5, -1, -24, -12], [8, 4, 9, 0], [9, -9, -12, -6], [-15, 8, 20, 17], [-7, 8, 6, -7], [3, 5, 2, -2], [23, -9, -6, 10], [-55, 0, -5, -9], [-21, 4, -16, 23], [-46, 4, -3, -10], [30, -14, -9, -18], [-19, -15, 10, -8], [-12, 21, -28, -11], [-9, -6, 4, -7], [-15, 19, -8, -2], [-15, -16, 14, 9], [-30, 20, -9, 4], [5, 20, 17, -7], [21, 0, 7, 7], [11, 3, -1, 2], [-6, 6, 7, -18], [0, 12, 3, -2], [29, 9, 27, -10], [32, -12, 0, -6], [-9, -17, 8, -16], [-4, -6, 4, -24], [-9, -16, 15, 1], [-25, -16, 16, 1], [35, -6, 6, 3], [-3, 3, -28, 2], [-19, -2, -16, 17], [-12, -8, 21, 10], [11, 8, 22, -7], [15, -12, -1, 5], [-30, 22, -3, 8], [9, 0, 10, -9], [-31, -24, 2, -7], [18, 6, -5, 10], [-10, 3, 23, 11], [-15, -4, 18, -3], [-9, -16, 9, 5], [35, -12, 4, -19], [-12, -2, -2, -8], [-25, -6, -22, -5], [5, -21, 0, -20], [6, 3, 7, -5], [-49, -6, -2, -13], [-6, -13, 19, 7], [-13, 16, 15, -1], [14, 19, 11, -13], [20, 12, -4, 22], [9, 25, -19, 10], [-21, 1, -22, -4], [-46, 10, -1, 0], [42, -2, -14, -10], [-43, -15, 6, 0], [-6, 6, -13, -2], [-16, 2, -5, 24], [-18, 8, -25, -16], [-16, 10, -8, -16], [-33, 22, 19, 15], [8, 7, -1, -23], [-34, 24, 4, -2], [-1, -5, 30, 10], [-12, -4, 9, -6], [18, 2, 1, -6], [-16, 4, -6, 6], [18, 10, -5, 20], [33, -13, -4, 22], [17, 2, -10, -7], [8, 14, -7, 10], [-24, 20, -9, 22], [-6, 9, -9, 13], [-43, 19, -9, -8], [53, -8, 2, 3], [-21, 17, -19, 8], [17, 35, 4, -12], [11, 30, -30, 7], [-42, -3, -6, 1], [30, -10, 0, 0], [18, -8, -7, 12], [-24, -5, -11, 9], [33, -16, -5, -1], [41, -6, 6, -11], [-9, 23, 22, -4], [9, 23, -10, 18], [-12, -3, -14, 15], [2, -7, 29, 3], [-7, -45, -4, 8], [18, 17, -13, -11], [-25, -23, -4, 14], [-7, 6, -15, 23], [-27, 13, 17, -6], [-1, 18, -9, 13], [27, -18, 1, -25], [-18, 16, -22, -22], [-13, 28, -6, 15], [-13, -6, 9, 13], [9, -16, 22, 1], [-24, 23, 7, -1], [14, 0, 30, 0], [15, -15, -13, 0], [50, -3, 36, -5], [39, 3, 19, -2], [-39, 2, 23, 13], [32, -9, 0, 21], [30, 14, 19, -14], [-31, -1, -3, 18], [-6, -3, -3, -33], [20, 17, -14, -13], [-16, 26, 2, -16], [-13, 7, 14, 6], [-15, 31, -8, -10], [-4, -10, -18, 0], [-42, 3, -4, -7], [0, -24, -18, -8], [-31, -2, -15, 7], [6, 2, 29, 26], [-7, 29, -22, 26], [20, -7, -16, -9], [-27, -7, -7, 4], [32, -22, 26, 26], [-6, 1, -3, -1], [-4, 22, -16, 32], [-3, -5, 31, 4], [5, -25, 18, 0], [3, -2, 14, 17], [-42, 4, -25, 22], [-25, 17, 5, 18], [38, -8, -23, -10], [69, -11, 7, 18], [2, 0, -16, 18], [9, -16, 1, 19], [-34, 25, -6, -29], [0, 0, 8, -18], [15, 4, -18, -9], [20, 20, -15, -8], [-22, 12, 15, 18], [-6, -32, -4, -10], [-27, -1, -3, -12], [17, -15, -16, -28], [-6, 38, 6, 12], [3, 10, -8, -19], [63, -3, 20, -24], [38, -19, -6, 3], [6, -4, 13, -8], [63, -15, 11, 16], [-31, 1, -19, 4], [-18, -6, -33, 10], [9, -12, 10, -11], [18, -13, 2, -29], [-7, -2, 6, 13], [-18, -9, 4, 3]];
    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_r();".
// 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_r(: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_r();".
// 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_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4026_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![6, 1, -6, -1, 1]>,<7,R![-8, -15, -1, 4, 1]>,<13,R![-178, -155, -32, 3, 1]>],Snew);
    return Vf;
end function;