
// Make newform 4235.2.a.y in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4235_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_4235_2_a_y();".
// 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_4235_2_a_y();".
// 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, 3, 3, -5, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [1, -4, -2, 1, 0], [0, 1, -4, -2, 1], [2, 3, -5, -2, 1]];
    Rf_basisdens := [1, 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_4235_a();"
function MakeCharacter_4235_a()
    N := 4235;
    order := 1;
    char_gens := [2542, 1816, 2906];
    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_4235_a_Hecke(Kf)
    return MakeCharacter_4235_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, 0, 0, 0, 1], [0, 0, 1, 0, 0], [-1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [-2, -2, -1, 1, -1], [-2, 1, 1, 1, 1], [-3, 2, -1, 2, -2], [5, -1, 1, 0, 2], [-3, 3, 1, -1, -3], [-2, 1, 0, -3, -2], [0, 2, 1, -2, 1], [3, -3, -3, 0, 0], [0, 3, 2, 1, 2], [0, -3, 1, -2, -1], [-2, 2, -4, 1, -3], [-2, 1, -3, 5, -3], [-6, 1, 0, -3, -1], [-1, 0, -2, -3, 1], [-4, 2, -1, 0, -4], [1, -5, 0, 3, 0], [-7, 2, -3, -2, -1], [0, 0, 1, -1, 4], [-5, 3, -4, -1, -5], [3, 1, 1, 7, 4], [6, -4, 3, -3, 4], [3, -1, -3, -1, 3], [2, 0, 0, 0, -5], [-2, -3, 0, 0, 5], [6, -5, -5, 3, 4], [-6, -2, -1, -4, 2], [0, -3, -4, -3, 3], [1, -2, 2, 1, 3], [-4, -2, -2, 5, -7], [5, -7, 3, 4, 4], [-1, 4, -1, 2, 0], [-6, 8, -5, -1, 0], [9, -1, 9, -1, 5], [-14, 3, -8, -3, -2], [-7, 3, 6, -2, -7], [-2, 3, -6, 4, -7], [4, 1, 3, -2, 2], [1, -8, -1, -1, -2], [-2, 0, 0, 1, 5], [6, -1, -1, 5, -1], [-5, 3, 0, 2, 4], [6, -6, -1, 6, -1], [-14, 4, 2, 1, 2], [-10, -1, 0, -6, 1], [-1, -7, 2, 1, 5], [-9, 1, 8, -3, -1], [8, 6, 6, -2, -2], [2, -1, -3, -3, -4], [1, -5, 6, 0, 7], [-2, -3, -1, 4, 4], [-2, -1, 0, -4, 11], [-4, 0, -4, -1, -9], [0, -8, 6, -1, -3], [-15, 8, 0, 0, 1], [3, -2, 2, -2, 5], [-1, -5, -5, 0, 3], [-3, 9, -1, 2, 1], [-3, 0, -2, 0, -4], [-4, -6, 8, -6, 7], [5, 3, 5, -3, 1], [-6, -3, -3, 0, -7], [4, -10, -6, 5, 10], [4, -3, 9, -5, 9], [-7, 4, 7, 0, -4], [-8, 2, -7, 1, 1], [11, -3, 1, -4, -4], [-11, -1, -3, -11, -6], [1, -9, -6, 4, 9], [-16, -2, 0, 3, 3], [4, -6, 1, 0, 0], [-11, 5, -6, 2, 1], [14, -3, 6, 5, -1], [-19, 0, -1, -4, 1], [23, 1, 5, -6, 5], [-5, 9, 1, 0, -11], [-8, 9, 2, -6, -6], [-6, 12, 0, -6, -3], [0, -5, -1, 2, -2], [-8, -2, -5, 0, -6], [-1, 1, -7, -5, 9], [10, 0, 0, -1, 11], [5, 9, 6, 9, 11], [2, -11, 2, -6, -6], [7, 12, 4, -5, 2], [-13, -4, 4, -13, -2], [-18, 1, -7, -2, -4], [-13, 7, 0, -11, -8], [22, -3, 4, 10, 1], [-14, 7, -1, -1, -4], [-4, 9, -8, 1, -18], [7, -1, -6, -5, -3], [18, 1, 12, -1, 9], [0, 7, 9, 8, 11], [0, -6, -2, 10, 0], [-8, 3, -4, -10, -7], [2, -9, 10, -3, 7], [-7, -3, 7, -7, 9], [6, 0, -2, 15, 6], [15, -3, -1, 8, -3], [3, -2, 11, 0, 15], [-1, 12, 10, 2, 4], [7, 4, 13, -2, 9], [-7, -5, 6, 4, 16], [5, 4, 6, -6, 2], [-8, 7, 4, 10, -13], [-2, -8, -2, -8, 13], [-30, 3, -9, -9, 0], [6, -12, -3, 2, 10], [30, -3, 7, 5, 6], [-5, 6, 4, -9, -5], [-9, 1, -5, -2, -10], [-6, -5, -4, 9, -6], [-13, 0, -4, -10, -2], [-15, -9, -5, -3, 0], [3, 3, -13, 10, -7], [-12, 4, -3, -10, -9], [-1, -4, -1, 0, -20], [20, 10, -2, -3, 4], [-11, 1, -11, 9, -8], [-23, -5, 4, -5, -8], [-26, -6, -3, 0, -4], [0, -6, 10, -8, 3], [23, 1, -3, 12, 8], [-4, -4, -7, 8, 1], [11, 0, 16, 0, 13], [14, 0, 3, -2, 3], [-15, -14, -3, 8, -9], [7, 6, 3, -7, -12], [28, -2, 2, 13, 7], [-3, 3, -1, -11, 2], [-14, 7, 8, 5, -12], [16, -10, 16, -1, 7], [20, -3, 13, -9, 13], [-4, -1, 2, 10, -6], [12, -8, 3, -1, -11], [-13, -5, 4, 2, -4], [9, 3, -3, 8, -5], [17, 3, 3, 1, -6], [-20, 14, -13, -5, -6], [-23, 6, -15, 1, -12], [-12, 15, -3, 0, -11], [-20, 15, 2, -1, -1], [-11, 3, 10, -8, -9], [1, -16, 2, 3, -7], [17, 0, -8, 12, -7], [-24, 7, -9, -7, -2], [-7, -2, 3, 8, -9], [-18, 17, 3, -14, -17], [15, 2, 6, 12, 13], [-1, 10, 5, 14, 12], [-15, 17, -16, 5, -11], [-6, 17, -12, -1, -1], [-1, 9, 15, -5, 7], [-1, -9, -8, 4, 10], [2, -15, 10, -10, 6], [-5, 7, -7, -9, -1], [-15, 7, -6, -3, -10], [2, 6, -2, 9, -8], [-8, 5, -6, 0, -15], [21, -3, 13, 8, 5], [26, -4, -4, 2, 6], [-6, -3, 7, -4, -2], [-30, 13, 6, 1, -14], [-11, 12, 12, -5, -8], [2, -11, 0, -2, -2], [1, 4, 8, -2, 11], [-22, 13, -1, -5, -7], [-10, 13, -10, 13, -7], [8, -7, 1, 2, 8], [25, -16, -9, -5, 8], [6, -2, -1, -5, 14], [-32, -4, -10, -11, -14], [35, -3, -2, 14, 8], [19, -9, -3, 1, 12], [-38, -4, 11, -9, -2], [-5, -3, -15, 3, -4], [-4, 2, -8, 8, 1], [-9, -15, 5, -9, -1], [19, -4, 16, -17, 13], [20, 5, 17, -1, 6], [31, -13, 4, -11, 9], [-36, 7, -1, 5, -10], [-26, 1, -18, 9, -17], [15, -15, 5, -1, -6], [8, 10, 4, 7, 10], [2, -13, 0, 12, 2], [-13, 2, 0, -7, -15], [-5, 14, 4, -10, -6], [-15, -12, -17, -7, 0], [-31, 6, -24, -3, -17], [30, 1, -8, 2, -11], [-37, 17, -7, -2, -8], [28, -19, 2, 6, 16], [4, -16, 0, 0, -9], [-5, 9, 18, -5, 0], [-1, 14, 14, -1, 0], [3, -16, -2, -5, -15], [-4, 1, 1, -11, 8], [-2, 7, -4, 7, -3], [-22, 1, -18, 6, -7], [-13, -4, -11, 16, -5], [25, -14, -2, -8, -5], [18, 4, 2, 9, -3], [8, 15, 8, 5, 21], [0, -8, -3, 10, -3], [-30, -4, 15, -5, 5], [-11, -2, 4, 1, 16], [-23, 24, -3, -20, -17], [1, 1, -5, -4, 8], [10, 0, 1, -5, -9], [28, -6, 1, 1, -10], [-10, -5, 12, 0, -5], [-10, 2, 0, -4, 19], [4, 9, 10, -3, 7], [-17, -1, -4, 13, -19], [-25, -12, -4, 6, -12], [14, -23, 1, 10, -3], [-13, -4, -14, 3, -17], [-7, 18, -21, 12, -12], [-7, 16, 8, -3, -1], [-15, 7, 6, -3, -5], [-22, -1, -9, -1, -9], [-5, -15, 10, 2, 21], [13, -7, -6, 5, -1], [16, 3, 4, -11, -9], [37, -8, 4, 7, -4], [-24, 9, 1, 2, 7], [25, -11, 0, -9, 6], [-25, 13, -15, -3, -22], [7, 13, 7, -16, 10], [27, -17, -2, -14, -2], [-19, 0, -15, -9, -12], [-17, -3, 6, -19, -7], [4, 21, 8, -7, 9], [7, 1, 15, 6, -7], [11, -10, 9, -9, 5], [-5, -4, 2, -2, 13], [3, 6, 12, 2, 12], [-16, 8, -9, 9, -11], [15, 9, 5, -14, 24], [29, 1, 5, -8, -4], [-20, 7, -3, 0, 8], [-26, 4, 9, -9, 7], [29, -23, -1, 12, 15], [5, 10, -16, 14, -4], [0, 8, -7, -1, -3], [-2, 18, -9, -5, -25], [6, -11, 4, -16, 1], [4, -5, 6, 6, -11], [-2, 3, -4, -14, 28], [-20, -9, 5, -7, 13], [17, -26, -12, 3, 19], [4, -10, 7, 7, 14], [19, -11, -1, 1, 17], [-10, 8, -12, 2, -5], [-26, -5, 1, -11, -14], [-40, 17, -6, 3, -13], [26, -18, 14, -13, 20], [-56, 2, -6, -19, -6], [-40, 2, -3, -4, -2], [-22, -10, -3, 4, 9], [19, -7, -10, -13, -21], [0, -2, 21, 2, 23], [-28, -9, -5, 1, 14], [10, -20, -10, 2, 2], [13, 2, 4, 8, 3], [20, -4, 8, -20, 10], [35, 3, 24, -1, 15], [6, -22, 14, 1, 4], [-23, 4, -7, -23, -12], [-6, -11, 2, -19, 20], [1, 17, 10, -2, 13], [-15, 8, 3, -5, 5], [15, 0, 4, 4, 4], [-4, 10, -7, -3, -16], [-16, 5, -19, -5, -3], [-14, 9, -1, 0, 2], [4, 7, 16, -1, 20], [-7, -12, 15, -2, 15], [-15, 6, 5, -18, 5], [-1, 1, 18, -7, 17], [2, -5, 13, -17, 17], [4, -17, -11, -16, -10], [6, 6, -12, 9, 6], [-47, -3, -29, -3, -16], [10, 13, 12, 7, 11], [59, 1, -13, 8, 8], [-17, -9, -25, 2, -26], [53, -20, 8, 8, 6], [7, 0, 17, -6, 8], [-19, 10, -16, -8, -8], [10, 7, 17, -5, 12], [-2, -5, -10, -10, -22], [-13, 10, 6, 11, -3], [-15, 1, -2, -24, -13], [9, -6, -7, 13, 4], [-38, 26, -2, -8, -18], [4, 1, -21, 18, -6], [-28, -10, -3, 0, 17], [-8, 0, 9, -9, -6], [12, 8, -1, 17, 0], [7, -5, 7, -1, 0], [10, 15, -8, -6, -5], [-16, -8, -19, 13, -17], [3, 4, 10, -13, 8], [-31, -1, 4, -20, -19], [-14, 33, 3, -11, -8], [10, -8, -6, 8, -4], [15, -23, 1, 1, -14], [-16, 7, -7, -6, 14], [-24, 13, 17, -7, 3], [-3, -15, -1, 10, 1], [11, 11, 12, 24, -6], [-10, 24, 9, -12, 0], [3, -6, 18, -27, 12], [27, -3, -14, 26, 6], [-18, 31, 18, 5, 2], [-13, 5, -21, 15, -4], [-10, -11, -11, -3, -16], [15, -7, -9, 11, -5], [-21, 7, -5, -12, -13], [18, -16, 5, 18, 25], [2, -6, -1, -11, 20], [16, -1, -14, -3, -11], [-15, -1, -1, -10, 8], [-38, -15, -3, -4, -9], [10, 21, -2, -15, -8], [-3, 6, 1, 29, -20], [13, 17, 17, 9, 13], [52, -11, -6, 3, 8], [11, 11, 3, -18, 4], [-8, 26, 11, -5, 10], [25, -9, 12, -10, 7], [-15, 18, 3, 16, -32], [28, -26, -4, -7, 9], [-18, 20, 9, -5, 5], [24, 10, 10, -16, 19], [1, -17, -6, 14, -4], [15, 6, 17, 13, -10], [2, -3, 2, 2, -27], [-7, -21, 11, -4, 13], [5, -12, -28, 3, -4], [63, -24, 15, 10, 15], [29, -10, 17, 16, 12], [19, -17, -2, -13, -3], [14, 20, 29, 9, 18], [33, 6, 25, 7, 1], [-5, 23, 17, 0, 1], [-19, -15, 10, -7, 22], [-61, 23, -1, 11, -11], [-54, 9, -20, -10, -11], [-18, 19, -11, 18, -21], [29, -3, 1, 4, 27], [25, 11, 2, 1, -6], [17, -22, -1, 5, -7], [8, -2, -12, 16, 4], [38, 6, -5, 28, 2], [7, 6, 20, -5, -5], [8, -16, -10, 19, 6], [-15, 12, -15, 8, -36], [-14, -10, -5, 5, -24], [-7, 14, -3, 17, -12], [26, -14, 12, 7, 20], [57, -28, 8, 7, 9], [19, -17, 6, 5, -13], [-23, 9, -12, -4, -6], [5, -9, 1, 24, 21], [-12, 8, 7, 13, 14], [-7, 6, -1, 5, 1], [10, -8, 3, 27, -11], [-1, -19, 20, 6, 11], [45, -15, -6, 0, 5], [4, -21, -9, 24, 5], [-7, 8, 7, -15, 22], [-43, 1, 11, 3, -6], [-46, 16, 1, -19, -11], [-46, 13, 0, 2, 0], [-22, 3, 19, -4, -8], [-23, -19, -8, 6, 22], [-18, 2, 10, 12, 18], [-29, -20, -1, -2, -21], [-18, -29, -1, 15, -4], [-35, 1, 3, -15, -8], [41, 4, 14, 29, 0], [35, 5, 34, 0, 23], [-23, -9, -12, 9, 5], [5, 1, 9, -15, 20], [-7, -14, 8, -1, 6], [12, 5, -12, 31, -10], [-32, -3, -32, 5, -13], [1, 0, -11, -13, 22], [2, 4, 21, 3, -11], [6, -19, -2, 11, 34], [-2, -15, -8, 14, -27], [17, -1, -14, -13, -22], [-16, -5, -13, 21, -12], [-36, 5, -2, 8, -23], [42, 11, -6, 20, 14], [18, -13, 12, 1, 20], [27, -4, 5, 11, 19], [66, -3, 17, 0, 14], [54, -14, 29, 0, 14], [25, 8, 15, -8, 0], [-22, 12, 2, 2, -25], [26, -29, -20, 8, 7], [-4, -9, -5, -11, 7], [-59, 15, -20, -10, -7], [7, 17, 7, -5, -19], [22, -14, -16, 0, 11], [-14, -21, 0, 13, 8], [40, 12, 8, 15, -8], [71, -29, -6, -7, 15], [-49, -5, -27, -13, -20], [5, -17, -12, 4, -8], [-37, -11, -6, -9, -12], [-12, 14, 2, 11, -16], [-28, 30, 1, -8, 7], [13, 15, 10, 18, 20], [37, -5, 1, 12, -8], [13, -24, 39, -10, 24], [15, 11, 9, -8, 8], [8, -20, -21, 19, 15], [-7, -8, 17, -9, -10], [-15, -6, 10, 14, 31], [-13, -21, -3, 21, -8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4235_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4235_2_a_y();".
// 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_4235_2_a_y(:prec:=5)
    chi := MakeCharacter_4235_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_4235_2_a_y();".
// 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_4235_2_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4235_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -4, -12, -5, 2, 1]>,<3,R![1, 1, -9, -7, 2, 1]>,<13,R![-1571, -1368, -325, 12, 12, 1]>],Snew);
    return Vf;
end function;