
// Make newform 4026.2.a.k 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_k();".
// 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_k();".
// 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, 0, 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], [-3, 1], [2, 0], [-1, 0], [3, 0], [0, -2], [4, 2], [0, 2], [-3, -4], [5, 1], [0, 6], [-1, 7], [-6, 0], [-6, 0], [8, 2], [3, -8], [-1, 0], [0, -6], [6, 0], [4, 4], [0, 0], [6, 8], [-3, 6], [5, -4], [3, -6], [-4, 0], [5, -1], [-5, -2], [6, -10], [0, 0], [3, -5], [18, 2], [11, -5], [16, 2], [0, 6], [5, -1], [1, -4], [-4, -4], [-1, -14], [18, 2], [23, -1], [2, 10], [5, 3], [6, 14], [-10, -12], [9, 9], [-2, 0], [-12, 0], [8, 4], [0, -6], [8, -2], [4, 0], [-3, -6], [-6, -8], [-18, 6], [-9, 9], [4, 4], [6, -12], [0, -16], [12, -6], [24, 4], [3, 15], [4, 16], [-4, 10], [11, 5], [-8, 6], [21, 3], [15, -7], [-4, -14], [-2, 8], [15, 12], [14, -2], [-16, 12], [-1, -14], [2, -22], [12, -4], [-1, -19], [5, -8], [-17, -1], [-20, -4], [-19, 3], [-22, -2], [-8, 2], [7, 6], [2, -4], [20, 14], [0, 6], [6, -2], [-22, 6], [-9, -8], [16, -4], [8, 4], [2, 8], [10, -14], [6, -12], [-12, -2], [2, -16], [37, 1], [0, 30], [7, 21], [1, -20], [14, -4], [17, 5], [16, -10], [20, -4], [7, 22], [14, 4], [-4, 2], [26, 12], [-11, 20], [23, -6], [-1, 2], [11, -24], [-22, -12], [18, -4], [2, -16], [-6, 18], [-36, 0], [-21, -9], [-19, -15], [11, -13], [-10, 4], [-18, 12], [13, 14], [5, 8], [-5, -13], [-42, -4], [8, -26], [18, -12], [21, -9], [27, -4], [22, 0], [-16, -20], [12, -12], [7, -23], [-19, 11], [-7, -1], [-20, 2], [15, 9], [10, -24], [-14, 8], [-5, -5], [-38, 4], [-44, -4], [-41, 1], [-29, 10], [-25, 17], [19, -2], [-33, -3], [4, -28], [-4, -32], [-32, 6], [0, -40], [-16, -2], [-15, -9], [-11, 30], [-48, -2], [2, 6], [31, -14], [24, 24], [-22, -16], [13, 12], [16, 4], [8, -8], [-30, -8], [22, -26], [-28, 24], [5, 15], [-36, 2], [26, -8], [-2, 8], [11, 16], [-6, -18], [14, 24], [12, -34], [-4, 0], [24, -24], [-40, -14], [-26, 12], [-31, -21], [36, -4], [-32, -8], [0, 30], [-3, -23], [0, -32], [-22, -16], [-9, 18], [-32, 6], [-27, 16], [8, -6], [15, -27], [-23, -18], [-5, 13], [-18, 30], [-30, 4], [4, -18], [-3, 3], [-8, -34], [2, 10], [-26, -14], [30, 0], [-11, 17], [-47, 5], [0, 40], [9, 7], [5, 11], [-46, 8], [-8, 10], [-46, -12], [-10, -14], [16, 14], [10, -20], [-31, 4], [-11, 2], [-16, -12], [-49, -6], [-32, -2], [-27, -25], [30, 20], [25, -20], [-37, 14], [23, 20], [46, 6], [-18, 12], [8, -30], [-21, 12], [-18, 24], [2, 6], [-2, -16], [5, 45], [32, 6], [-22, -10], [-6, -14], [35, 20], [-19, -14], [62, -8], [7, 26], [39, -12], [7, 11], [25, -10], [34, 12], [35, 13], [-28, 14], [12, -12], [40, 26], [24, 36], [10, 22], [26, -24], [16, -28], [-60, 12], [35, -5], [-36, -16], [-22, 18], [12, -6], [24, 30], [25, -5], [36, 0], [-30, 6], [-35, 21], [-45, -12], [-9, -21], [-34, -4], [11, -38], [-70, 8], [45, 0], [15, 21], [-34, 20], [10, 30], [28, -4], [32, 6], [13, 26], [-59, 8], [16, 8], [13, -9], [20, -42], [3, -26], [-26, -16], [4, 2], [53, 7], [37, -10], [-20, 32], [-24, 12], [32, 22], [-17, -9], [69, 7], [-16, -4], [-30, 0], [16, 4], [18, -30], [60, 6], [-12, -30], [57, 7], [30, 34], [-5, -28], [28, -8], [0, -30], [18, -2], [62, -8], [-26, 0], [-10, 0], [2, 10], [32, -12], [28, -32], [22, 20], [-50, 0], [-8, 20], [-8, -16], [-20, -8], [-60, 0], [24, 36], [0, 42], [54, -10], [-7, 22], [38, 10], [16, 16], [4, -14], [-84, -4], [-11, -12], [6, 22], [-4, 30], [-68, 12], [-6, -40], [-55, -5], [12, -6], [8, 44], [28, 30], [28, 0], [-8, 28], [-2, -32], [53, 24], [44, -34], [10, -30], [9, 53], [23, -37], [9, 48], [-24, -6], [-3, 35], [-50, -12], [-18, 18], [-52, 12], [-1, -44], [-36, -22], [29, 9], [-24, 30], [-24, -24], [-4, -26], [-42, -12], [24, -48], [-15, -21], [-2, -36], [-16, -54], [-18, 54], [-40, -36], [-50, 8], [48, -2], [5, 53], [36, -20], [-36, -4], [6, -30], [-2, 56], [12, 22], [-28, 38], [-5, 37], [67, 2], [-10, 54], [-33, -6], [-40, -2], [-36, -30], [-37, 32], [70, -14], [68, -22], [-78, 4], [16, 18], [-8, -24], [-9, 24], [-12, -36], [27, 27], [40, -26], [-16, -54], [2, 8], [29, 34], [-56, 18], [-15, 37], [72, -12], [-6, -36], [-34, 10], [17, 3], [2, 36], [-3, -33], [-69, 6], [36, 18], [-66, -16], [50, -22], [50, -32], [-43, -23], [-62, -22], [-42, -20], [81, 12], [42, 12], [43, -2], [3, -8], [3, 36], [-66, 8], [29, 38], [-3, 18], [20, 20], [48, -10], [45, 0], [-60, 6], [-4, -22], [-66, -4], [25, -20], [-14, -14], [-56, -2], [30, 14], [6, -26], [-4, 22], [29, -22], [-20, -28], [-12, 50], [20, -10], [-15, -45], [24, 6], [-23, -54], [18, -26], [7, 22], [27, -41], [-78, 18], [25, -8]];
    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_k();".
// 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_k(: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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4026_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![7, 6, 1]>,<7,R![-2, 1]>,<13,R![-3, 1]>],Snew);
    return Vf;
end function;