
// Make newform 1334.2.a.h in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1334_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_1334_2_a_h();".
// 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_1334_2_a_h();".
// 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, 6, 0, -8, 0, 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], [5, -7, -8, 1, 1], [-6, 8, 15, -1, -2], [-16, 16, 31, -2, -4]];
    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_1334_a();"
function MakeCharacter_1334_a()
    N := 1334;
    order := 1;
    char_gens := [465, 553];
    v := [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_1334_a_Hecke(Kf)
    return MakeCharacter_1334_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, 0], [-1, 0, 0, 1, 0], [-1, 0, 0, 0, -1], [-1, 0, 1, -1, 1], [-1, 1, 0, -2, 1], [-1, 1, -2, 1, -2], [-1, -2, -1, 0, 1], [-2, 0, 2, -1, 0], [-1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [-3, -1, 0, 0, 1], [0, -3, 0, 0, 4], [-2, 1, 0, 4, -2], [-1, -1, 0, 0, -3], [-2, 2, 3, -1, 0], [-1, 0, 0, 4, 1], [-6, 0, 2, 1, -1], [-2, -1, -2, 2, -4], [3, -4, 3, -3, 6], [-4, -4, 4, 2, 0], [0, -1, 0, 1, -3], [-6, 3, -3, 4, -1], [-3, 1, -1, 0, 2], [-6, -3, 2, 4, 1], [-1, 5, 1, 0, -4], [7, 4, -7, 2, -3], [-4, 8, -2, -1, -3], [6, 0, 0, -2, -2], [-7, -6, -2, 0, 4], [4, 6, -4, -4, -4], [0, 0, -4, -4, 2], [6, -4, -4, -2, 5], [-2, -1, 0, -4, 3], [-3, 4, 1, 0, -8], [0, 5, -1, -1, 6], [-3, 3, -3, 0, 2], [0, -3, 8, -4, 6], [4, 5, -5, 4, -1], [1, -7, 3, -2, 4], [10, -2, 4, -2, 2], [-3, -4, 5, -2, 6], [5, 4, 0, -2, -2], [3, 3, -1, 1, -7], [-4, -2, 2, 1, -5], [9, 3, 5, -3, 1], [4, 4, -8, 4, -4], [-2, -11, 1, 2, 7], [-9, -11, 3, 0, 6], [-10, 1, -2, 1, 0], [-8, -3, 4, 1, -5], [1, 2, -2, -4, -6], [2, -7, 8, -7, 2], [-9, 3, -2, -1, -2], [-1, 5, -6, 8, -9], [-3, 4, 0, -6, -1], [-2, 5, -5, 0, -9], [16, 3, 0, -2, 3], [0, 2, 7, -1, -8], [-10, -4, -2, -3, -4], [3, -3, -4, 11, -6], [-4, 11, 2, 1, -10], [-6, -7, 4, 6, 8], [7, 2, 2, -9, -4], [7, -1, -3, -1, 5], [-2, 2, -5, 2, 5], [5, 12, -5, -2, -5], [-6, 9, -1, 2, 2], [9, -1, -5, 2, -10], [8, -4, -4, 3, 3], [-5, -1, -2, -10, 6], [7, -7, 1, 1, 6], [-1, -2, 4, -7, 5], [-12, -2, -6, 6, -1], [1, -4, 8, 4, 1], [8, -14, 8, -6, 14], [3, 10, -1, -7, -1], [4, -12, 4, -1, 3], [12, 4, 7, 3, 7], [-13, -5, 6, 4, 6], [-12, 3, 0, -3, 9], [-2, 11, -4, 7, -6], [-12, -4, 6, -5, 3], [-16, 6, -4, 2, -8], [-15, 2, -5, 10, 3], [-12, -3, -8, 9, 2], [5, -1, 3, 3, 10], [18, 1, 4, -5, -3], [-12, -12, 2, 4, 10], [-1, -2, -5, -10, -5], [2, 4, 0, 2, 6], [-18, -6, -7, 2, 2], [-5, 14, 6, -1, -10], [11, 0, 5, -7, 8], [4, -5, -3, -2, 13], [4, 12, 10, -6, -2], [-3, -12, -2, -7, 11], [0, 14, -5, 4, -3], [-12, -8, 3, 8, -1], [-25, -3, -1, 0, 6], [-1, 4, 3, -8, 7], [5, 4, -1, -10, -6], [14, 4, -4, 2, -7], [0, 2, -1, 1, 0], [2, -10, 0, -4, 2], [-4, 8, -2, -6, 10], [2, 5, 2, -15, 3], [-6, 6, -4, -5, -5], [-3, -16, 2, -4, -3], [-3, -7, 6, 0, 3], [-6, 2, 16, -7, 9], [1, -9, 6, 5, 1], [-4, -3, 1, 19, -9], [6, 12, -8, -2, -12], [-5, 3, -4, -1, -15], [-16, 6, -10, 5, -5], [-8, 6, 4, 0, 2], [-1, 2, -9, -5, -2], [-8, 5, -4, -1, -4], [6, 0, 0, 0, -6], [19, -5, 2, -11, 9], [-19, 1, -1, -11, 3], [5, -12, 4, 0, 8], [6, 3, 6, 4, -2], [4, 10, -2, 10, -14], [1, -2, -1, -16, 10], [-3, -10, 12, -2, 12], [3, -18, -6, 4, 13], [22, -2, -4, 4, 2], [6, 14, 8, -14, -5], [24, -3, 0, -4, 4], [21, -4, 0, 3, 7], [10, 2, 0, -16, 3], [3, -5, 11, 3, 7], [-10, 12, -10, -1, -11], [-12, -2, 2, 2, -1], [-7, 1, -5, 0, 18], [12, -1, 8, 1, 1], [-3, -8, -11, 13, -6], [2, 6, 16, -17, 5], [8, 3, -12, 12, -12], [0, -4, 2, 1, 13], [0, -16, -5, 1, -1], [4, -8, -4, 1, 0], [-1, -17, 4, 1, 9], [-17, -1, -13, 6, -6], [23, 0, 0, -15, 2], [-9, 3, 11, 10, -8], [12, -3, 3, -1, -7], [-12, -13, 3, -10, 8], [5, 6, -7, 19, -10], [11, -13, -12, 5, 8], [11, -6, -3, -6, 3], [2, -12, 0, -3, -7], [-12, 12, -3, 6, 6], [10, -8, -2, 8, -10], [12, -3, -19, 10, -12], [-1, -14, -15, 10, 2], [8, 2, -2, -18, 9], [-25, -1, 7, 7, -9], [-14, -13, -1, -15, 9], [15, 0, 0, 3, -1], [2, 6, -5, -3, -1], [15, 5, -10, 5, -1], [29, 3, 7, -7, 3], [-15, -1, 0, 11, -8], [-3, 4, 4, 17, -9], [-16, 7, 12, -5, 10], [-13, 12, -7, 8, -17], [-18, 6, -5, 6, -23], [13, -5, 13, 0, 20], [5, -6, 11, 7, 12], [-14, 10, 5, -2, -15], [-23, -14, 9, 2, 0], [-9, 5, 1, -8, 0], [16, -4, 8, -12, 2], [-22, -10, 6, 7, 14], [-5, 12, -11, 18, -18], [-9, -6, -15, 16, -5], [7, -6, 8, -27, 11], [8, 10, -2, -16, 5], [34, -4, 1, 7, 0], [-6, -4, -11, -10, 16], [7, 5, -5, 11, -1], [-7, 2, 8, -2, -5], [-7, -4, 11, 0, 4], [14, 11, 9, 15, -10], [-1, -4, -1, 2, 3], [-25, -5, 1, -9, 7], [-2, -4, 18, -10, 12], [14, 0, -16, 8, -8], [18, -7, 13, -23, 13], [-33, 10, 6, -5, -5], [-3, 11, -6, -3, -3], [-2, 8, 0, 22, -18], [-16, 4, 0, 18, -6], [-9, 1, -17, 19, -13], [-7, 14, 1, 6, -3], [-21, -3, 25, -1, 4], [-5, 31, 2, -5, -12], [-5, -5, 1, 2, 2], [-26, 1, 20, 3, -11], [1, 7, -7, -14, 4], [30, -1, 0, -6, 13], [-14, -2, -20, 16, 0], [22, -2, -18, -7, 10], [11, -27, 6, -7, 22], [0, -13, -3, 4, 14], [43, -2, 5, -5, 9], [7, 2, -4, -16, 19], [-13, 2, -8, 3, -18], [-6, 3, -6, -6, 2], [0, 4, 0, -11, -4], [26, 9, -5, -8, -6], [14, -6, 1, 1, -20], [17, 11, 11, 19, -9], [-17, 1, 20, -12, 4], [0, -9, 2, 21, -4], [28, 2, -24, -1, 1], [13, 10, -15, 1, 11], [46, 5, -10, 8, -7], [-30, 5, 16, 8, -19], [-16, -12, 4, -12, 6], [32, 10, 6, -14, -8], [22, 11, 3, -4, 6], [-16, -6, -10, 3, -7], [30, 11, -2, 10, -7], [-19, -11, 7, 28, 2], [2, -10, 14, -27, 18], [-9, 2, 16, -5, -2], [-9, -8, -5, 11, -3], [-13, 9, 9, -8, 2], [15, -2, -13, -11, 26], [-9, 11, 1, -7, -14], [18, 17, -14, -15, -7], [-9, 3, -3, 10, -24], [18, -12, -4, 2, 3], [9, 6, -15, -2, -9], [8, 6, 0, -10, 12], [-16, 6, 10, 18, -12], [-1, -9, -18, 16, -15], [5, 9, -12, 9, -3], [-22, 0, -12, 14, 8], [7, -23, -19, 8, 8], [-13, -18, 9, -12, 19], [15, -1, 21, -19, 12], [21, 4, -19, 9, -20], [10, 10, 0, 10, 8], [-22, 17, 0, 3, -22], [-5, -5, -3, 24, -2], [-30, -7, 11, 4, 12], [32, -16, -6, 20, -16], [-21, 17, -6, 14, -14], [0, 5, 1, 4, -2], [-12, 0, 10, -4, 16], [-16, -13, 0, -12, 11], [-14, 0, -2, 13, -23], [20, 0, 4, -15, 5], [-9, -5, -2, 4, 1], [24, -18, 0, -1, -2], [-29, -2, -6, 2, 17], [2, 10, 4, -8, -7], [-11, 5, 18, -8, -11], [-24, 12, 2, 0, -16], [-12, 5, -16, 23, -1], [12, -3, -12, -15, 7], [-13, 1, -8, 26, -23], [-10, 17, -4, 3, -17], [-16, -17, 2, -6, 13], [16, 24, 8, 4, -10], [-18, -22, 5, 0, 17], [23, -1, 6, -24, 20], [-13, -7, -7, -4, -24], [-22, 14, -9, 2, 15], [-15, -1, 3, 1, 12], [24, -7, 6, 0, 8], [2, -10, 7, 4, 8], [-29, -5, 9, 23, 0], [22, 2, 11, 12, -3], [-43, -7, -5, 10, 8], [-4, -1, -10, -11, -6], [-9, 6, -5, 27, -22], [-15, 6, -5, 3, -3], [-6, 4, 0, -5, -9], [9, -23, -1, -11, 26], [-11, 19, 3, -1, -16], [20, 22, 12, -11, -8], [-7, 8, -11, 28, -5], [-12, 5, 18, -17, 5], [-29, 10, 11, -7, 0], [-45, 4, 2, 2, 3], [24, -9, -13, 5, 8], [-21, -13, 7, 22, -8], [-14, -11, -19, 7, 15], [4, -12, 13, -8, 8], [-7, 8, 1, -6, -7], [33, 10, -8, -16, -11], [-33, 8, 16, 17, -32], [-6, -2, 9, 8, -19], [-20, -24, 12, -2, 20], [-23, -7, -7, -1, -9], [37, 20, -3, -14, -17], [-15, 29, -5, 7, -32], [9, 9, -23, 9, -19], [6, -5, 9, 32, -3], [9, -5, 3, 31, -11], [-14, -15, 1, 5, 5], [-21, 14, -8, -5, 5], [-2, -7, -7, -1, 7], [-9, 8, 1, 11, -3], [12, 14, 25, -8, 3], [-17, -9, 23, -16, 12], [22, 10, -4, 16, -10], [22, 16, 20, -10, 4], [10, -4, -24, 19, -9], [30, 8, 18, -28, -2], [-49, 11, -10, 2, -12], [7, -9, 1, 1, 10], [-15, 16, -11, 5, -16], [25, 13, -4, 11, 4], [-10, 1, 4, -27, 15], [13, -5, -4, -34, 17], [23, 15, -6, -9, -12], [7, -1, -17, -7, -17], [-10, -22, 17, 2, -6], [-47, 3, 2, 11, -6], [14, 15, -4, 0, -11], [-17, -30, 17, -9, 6], [25, 8, -25, 6, -10], [-8, -17, -11, -4, 2], [-20, 11, -7, 13, -16], [17, -3, 5, 0, -10], [-32, -16, -5, -3, 17], [10, 7, 20, -9, 10], [-4, -4, 18, 4, -29], [-3, -9, 8, 9, -1], [14, -6, -4, -6, -4], [2, -18, 12, -4, -9], [-10, -7, -14, 8, 7], [14, -16, 6, 3, -3], [43, 14, -15, 0, -10], [-28, -26, 14, 20, 10], [-7, -1, 13, 13, 5], [-6, 17, -10, 0, 11], [-21, 10, -7, 35, -13], [-24, 20, -18, 4, -31], [15, -6, 0, 3, 15], [-5, -13, 7, -14, 4], [-19, -11, -1, 27, 2], [5, 4, 0, -5, -2], [6, 0, 2, -20, 10], [-14, 10, 18, -11, 23], [-6, -12, -4, 10, -1], [-4, 33, -12, 6, 7], [23, -2, -13, 0, -12], [-34, -19, 16, -2, 16], [-34, -3, -2, 29, -13], [20, -1, -35, 12, -13], [0, 13, 20, -11, 22], [14, -6, 8, -7, -5], [30, -21, 18, -31, 38], [11, 2, 6, 10, 17], [9, 36, 0, -14, -27], [-43, 9, -6, -13, -9], [-5, -5, 17, 6, 24], [-11, 36, -10, 7, -13], [18, 21, -14, -5, -1], [19, 13, -11, 10, -14], [-15, 10, 7, 33, -25], [-31, -26, 29, 8, 19], [-25, 18, -10, 23, -24], [21, -32, 1, 20, 8], [5, -10, 19, -11, 8], [-8, -23, -10, -13, 11], [13, -2, 1, 25, -19], [38, 14, 3, 9, 3], [-16, -22, -22, 22, 5], [28, 9, -15, 2, 10], [11, 8, 15, 24, -21], [-24, -4, 7, -16, -3], [0, -1, 7, -3, 16], [-26, -13, -6, 9, -13], [-5, 5, 10, 1, -18], [-12, -2, 21, -3, 24], [-38, 4, 6, -10, 12], [-24, -14, -8, 8, -4], [23, 9, -19, -6, 2], [-28, 12, 8, -15, -6], [36, -6, -9, 11, -21], [40, -6, 11, -9, 8], [8, -20, -18, 14, 11], [-15, -15, 25, 14, 8], [-25, -3, 6, 28, -8], [-30, 3, -11, -4, -6], [-16, -19, 9, 28, 11], [25, 4, -20, -1, 3], [13, -9, 12, -19, 32], [10, -14, 6, -8, -6], [-15, -3, 13, -26, 18], [14, 9, -12, 5, -32], [6, 15, -14, 20, -21], [-12, -6, 14, 34, -10], [-32, 18, 22, -6, -10], [18, -14, -2, 20, -20], [-12, -28, 1, 2, -7], [0, -34, -1, 17, 13], [32, 17, -12, -23, -4], [-23, 2, 10, -2, 12], [28, 21, -6, 8, -16], [3, 7, 8, 8, 15], [-9, 14, -11, -14, -32], [11, 25, 5, 3, -24], [7, -25, -16, 15, -4], [-26, -2, -22, 18, 2], [-18, 16, -6, 2, 18], [-7, -8, 5, -8, -21], [18, -17, 6, -12, -9], [6, 10, 17, -24, -2], [-8, 14, 40, -18, 18], [30, -26, 26, -32, 36], [8, -25, 3, -6, 11], [-19, 29, -9, -15, -16], [-14, 23, -4, 3, 11], [13, 7, -22, -8, -15], [-9, 16, -18, 35, -29], [17, -18, -2, 26, -3], [2, 12, -19, 14, -5], [10, 17, 4, -5, -6], [42, 0, 6, 2, -10], [25, 24, -3, 13, -19], [3, -5, 24, -13, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1334_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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