
// Make newform 4263.2.a.j in Magma, downloaded from the LMFDB on 29 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4263_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_4263_2_a_j();".
// 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_4263_2_a_j();".
// 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_4263_a();"
function MakeCharacter_4263_a()
    N := 4263;
    order := 1;
    char_gens := [2843, 2698, 2206];
    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_4263_a_Hecke(Kf)
    return MakeCharacter_4263_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 := [[0, 1], [-1, 0], [-2, 2], [0, 0], [1, 2], [3, -4], [-3, 0], [6, -2], [-4, 6], [-1, 0], [0, 6], [4, -2], [-2, 0], [4, 0], [-1, 6], [10, -2], [-2, 4], [4, -2], [-7, 10], [-4, 2], [-8, -2], [-14, -2], [2, 8], [-5, 0], [-10, 14], [5, -4], [0, -8], [6, -6], [7, -4], [19, 0], [10, -4], [-5, 6], [6, 4], [5, 10], [-16, 12], [8, 8], [2, 0], [-6, 0], [4, -4], [12, 8], [16, -2], [3, 0], [12, 0], [6, -4], [-18, 2], [7, -14], [6, -8], [-9, 10], [6, -8], [10, -10], [10, -12], [6, -22], [-3, 12], [3, -10], [8, -12], [-8, 24], [5, 0], [22, -8], [3, 0], [-14, 12], [0, 12], [15, -8], [4, -14], [-25, 6], [11, 0], [1, 4], [-22, -2], [-2, 10], [24, -2], [6, -12], [2, -2], [-12, 4], [-16, -4], [-14, -4], [-2, -6], [-10, 2], [5, -20], [-2, 8], [22, -10], [2, -4], [-26, 2], [-26, 16], [-8, 0], [-2, -14], [-17, -6], [-5, -2], [-17, 4], [1, 4], [6, -16], [9, -10], [12, 0], [-12, 4], [32, -8], [-8, 0], [7, 6], [-9, 30], [10, 0], [24, -12], [-3, 18], [2, -10], [-5, -14], [-18, 12], [29, -26], [13, -36], [8, -12], [36, -8], [-2, -12], [2, -22], [37, 6], [-2, 10], [6, 12], [13, 12], [10, -4], [-2, -6], [-15, 14], [21, -28], [3, 6], [-8, 10], [9, 0], [11, -22], [23, 0], [13, -28], [-7, -12], [-4, -24], [19, -22], [-8, 30], [-30, 0], [28, -36], [16, 2], [-16, 4], [0, -10], [-19, -14], [-24, 32], [-16, 8], [-22, 10], [-16, 2], [-26, 4], [44, -4], [-14, -8], [19, -28], [15, -14], [18, -12], [4, 0], [16, 24], [-8, 36], [27, -14], [0, 12], [18, -22], [22, -24], [16, -34], [14, -12], [-25, -4], [20, -12], [-23, -10], [2, 32], [17, 10], [37, -34], [38, 4], [-23, 20], [20, 16], [9, 18], [32, -16], [2, 2], [-12, -20], [36, -6], [0, -8], [-5, 34], [28, -52], [31, -12], [-9, 20], [16, -22], [-37, 0], [-24, -18], [44, 0], [-32, 4], [32, 6], [-3, 30], [7, 20], [10, -18], [37, -24], [28, 20], [-37, -10], [-7, -28], [-12, -22], [-8, 34], [12, -34], [8, 10], [18, 6], [20, 0], [2, 32], [-35, 32], [-47, 22], [32, -10], [-13, 12], [-1, -22], [-16, 14], [-28, -20], [41, -24], [14, 16], [26, -30], [30, -40], [-3, 2], [50, -26], [34, -18], [-5, -10], [2, 40], [-38, 16], [-18, -26], [-44, -2], [0, 6], [-22, 0], [-28, -18], [0, 8], [5, 14], [-47, 34], [43, 0], [-13, 2], [-5, -4], [-50, 26], [-47, -8], [12, 0], [45, -10], [-49, 28], [-12, 22], [22, 0], [26, 18], [42, -32], [-4, 28], [-20, 24], [-16, 6], [36, -4], [-24, 48], [32, -10], [-22, 28], [29, 14], [-59, 22], [-24, -2], [46, -24], [-8, 26], [-37, 30], [13, 22], [-4, 24], [21, -30], [12, 16], [2, -2], [-56, 2], [32, -40], [18, 10], [23, 14], [41, 6], [-2, -30], [-4, -26], [13, -50], [-34, -12], [58, -24], [36, -32], [50, -16], [38, -32], [66, -8], [35, -16], [16, -14], [31, -26], [-29, 28], [-56, -16], [30, 24], [44, -8], [-1, -28], [30, -24], [76, -4], [-2, -28], [-37, 40], [-57, -10], [-10, -28], [18, -26], [18, 38], [22, 8], [44, -32], [-33, 16], [46, 12], [-60, 16], [-38, -2], [-27, -2], [-14, -8], [-7, 20], [10, 14], [-43, 10], [-48, 54], [43, 0], [-25, -10], [-20, -40], [4, -34], [38, 18], [-24, 36], [-36, 28], [0, 38], [36, -22], [60, -4], [12, -12], [-4, -2], [62, 10], [12, -32], [-24, -6], [4, -28], [-32, -28], [-28, 0], [26, 24], [9, -22], [-58, 16], [2, 6], [7, 24], [10, 22], [-35, 40], [-14, 2], [-53, 34], [12, 32], [-29, 8], [52, -4], [-8, 30], [-3, -12], [81, -12], [-22, -20], [45, -44], [32, -58], [-56, 10], [32, -56], [-2, 40], [-4, 8], [-60, -8], [31, -46], [-62, 2], [52, -20], [28, 30], [0, 0], [41, -30], [-26, 36], [30, -56], [15, -20], [11, 0], [18, -20], [-65, -6], [-40, 18], [-4, -16], [25, -40], [-49, 2], [4, -60], [60, -20], [-28, 52], [-34, 74], [-43, 42], [-37, -12], [-28, 52], [73, -20], [66, -28], [-64, 40], [22, -44], [2, 8], [-23, 66], [-44, 4], [15, -24], [30, 8], [-29, 24], [28, 30], [-31, -2], [-26, 12], [-56, 6], [46, -34], [19, -24], [-27, 22], [22, -10], [-28, 60], [-39, 58], [-28, -6], [37, -24], [13, 50], [-74, -16], [7, 26], [57, -10], [-30, 12], [-16, 22], [-58, -20], [-42, 40], [52, 14], [-22, -10], [-23, 12], [24, 12], [78, -24], [28, -62], [11, 32], [22, -56], [-27, 18], [-48, 66], [8, -4], [-35, 70], [0, -6], [-7, 58], [-41, -20], [64, -28], [74, -48], [-17, 18], [-49, -8], [-46, 12], [90, 8], [54, -42], [4, -44], [4, -28], [48, -40], [-9, -36], [29, 16], [-36, -6], [2, -34], [35, -8], [22, -48], [32, -66], [-68, 20], [26, -46], [21, 24], [-55, 30], [-17, -22], [-9, -8], [0, -8], [-40, -10], [86, -8], [36, -16], [-68, 56], [-63, 28], [20, -36], [6, 36], [-5, 20], [-57, 70], [-12, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4263_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4263_2_a_j();".
// 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_4263_2_a_j(:prec:=2)
    chi := MakeCharacter_4263_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_4263_2_a_j();".
// 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_4263_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4263_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -1, 1]>,<5,R![-4, 2, 1]>],Snew);
    return Vf;
end function;