
// Make newform 1305.2.a.k in Magma, downloaded from the LMFDB on 25 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1305_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_1305_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_1305_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 := [-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_1305_a();"
function MakeCharacter_1305_a()
    N := 1305;
    order := 1;
    char_gens := [146, 262, 901];
    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_1305_a_Hecke( : Kf := Kf)
    return MakeCharacter_1305_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]];
    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], [0, 0], [1, 0], [-3, 0], [3, -4], [-5, 2], [-1, 4], [4, -6], [0, 0], [-1, 0], [-8, 0], [-8, 0], [2, -4], [2, -2], [-3, 6], [8, 2], [-4, 2], [-2, 6], [-9, 4], [-6, 2], [-8, 0], [0, 10], [0, -6], [-5, 10], [4, 2], [-3, 2], [0, -12], [-10, -4], [-9, 12], [3, -8], [-6, 0], [-1, 4], [6, -8], [3, 6], [-14, 10], [0, -4], [-8, 6], [-4, 18], [8, -16], [12, -12], [2, 10], [1, -12], [-12, 0], [-6, 0], [-10, 8], [17, -6], [-18, 16], [-13, 0], [12, 10], [2, -12], [6, 12], [-2, 16], [7, 0], [15, -16], [6, -6], [-24, 0], [29, -2], [2, -20], [5, -6], [12, -18], [16, -4], [13, -8], [20, -8], [-21, 4], [-5, -10], [21, -12], [-6, 16], [-18, 4], [-20, -4], [-14, 8], [-6, -4], [12, 12], [8, -12], [6, -16], [2, -8], [4, -26], [-21, 2], [-14, -12], [28, -14], [0, -14], [-22, 20], [-8, -10], [-32, 4], [4, 14], [1, 18], [-25, -2], [-3, -2], [-5, -18], [10, 20], [-5, -4], [8, -8], [4, -4], [-12, 0], [-16, 16], [-25, -2], [17, -22], [0, 10], [22, 2], [-15, 24], [26, -20], [25, -4], [-4, -2], [-33, 18], [-1, -10], [-20, 0], [-12, 28], [8, 10], [16, -14], [-1, -16], [18, 16], [32, -14], [11, 6], [-26, 28], [-6, -4], [-15, 38], [-45, 2], [-21, 24], [-10, 2], [1, 16], [21, 0], [-23, 24], [-37, -6], [11, -16], [0, 12], [-31, 6], [-6, -18], [10, -16], [10, -2], [12, 16], [-18, -6], [18, -38], [17, 10], [36, -12], [-20, 24], [-12, 34], [26, -14], [30, -36], [-8, -16], [-2, 8], [-43, 2], [-19, 6], [18, 12], [-30, -2], [0, -12], [-20, 0], [-5, 16], [-30, -2], [14, -16], [-12, 6], [-2, 22], [34, -24], [-9, 6], [-32, 0], [31, -22], [28, 2], [23, 8], [9, -18], [42, -24], [21, 2], [30, -26], [9, -6], [2, 34], [-24, 18], [28, 8], [20, -4], [-40, -4], [-1, -38], [0, -12], [27, -24], [-3, -16], [24, -12], [-23, 8], [24, -52], [20, 16], [8, 24], [-14, -2], [13, -6], [-3, -6], [26, -24], [3, 16], [2, -26], [55, 4], [15, -42], [40, 4], [-18, -6], [-6, 38], [54, 2], [-6, 0], [-18, 18], [12, -6], [-7, -18], [13, 10], [-40, 28], [31, -26], [-9, 34], [6, 14], [4, -28], [-41, 26], [-32, 34], [-18, 12], [18, 12], [27, 10], [-2, 12], [-32, 54], [-9, 12], [20, -2], [-22, -20], [-12, 6], [-22, -2], [-40, 36], [68, -2], [56, -8], [12, 12], [-9, -18], [33, 20], [21, -12], [-51, -12], [51, 6], [-14, 28], [41, -28], [50, 6], [-17, -6], [-47, 10], [-6, -18], [10, 4], [-10, -12], [2, 40], [28, -8], [20, -12], [-12, -28], [-30, -10], [-16, 28], [38, -2], [-2, -8], [-43, 0], [-53, -2], [-10, 30], [-22, 16], [36, -20], [-13, -20], [-27, 42], [28, 0], [33, -28], [12, -4], [-4, 26], [0, -24], [16, 24], [42, 12], [3, 6], [45, -34], [36, 6], [-52, 4], [-19, -10], [20, -2], [-10, 32], [10, -26], [8, 18], [-34, 12], [46, -16], [-9, -26], [4, 44], [7, 22], [1, 48], [18, -14], [-58, -8], [6, 18], [-7, -26], [-54, 12], [-28, -12], [8, -34], [33, -16], [25, -48], [-2, 48], [18, -4], [28, 26], [-6, 12], [-12, -8], [35, -32], [12, 18], [12, -12], [-12, -26], [29, -66], [-46, 56], [-45, 0], [2, 0], [27, -16], [-36, 32], [-41, 8], [-23, -22], [16, -20], [-18, 18], [-30, 24], [-24, -32], [4, 20], [14, -50], [16, 28], [6, -10], [-4, -8], [-30, 18], [-24, -18], [40, -36], [58, -34], [-6, 46], [12, 12], [-24, 32], [-42, 60], [25, -2], [10, -48], [-60, 30], [-31, -6], [24, -30], [-17, -2], [26, -4], [45, -32], [-18, -22], [-43, -8], [64, -8], [12, -20], [33, 6], [-33, 14], [-44, -18], [-9, 42], [74, 2], [-30, 10], [-54, 18], [-4, -2], [-68, 24], [-36, 60], [-37, 50], [22, -44], [-56, 12], [38, -50], [-24, 56], [11, -22], [72, -18], [-58, 28], [63, 0], [-39, -24], [-14, 32], [-29, -12], [-54, -22], [24, -48], [-15, -18], [-69, 42], [-44, 8], [16, 16], [-38, -10], [8, 10], [21, -20], [-43, 20], [68, -32], [-5, -30], [-74, 4], [12, -20], [-26, 60], [22, 40], [29, -76], [-36, 40], [-41, 56], [-32, -26], [9, -6], [-8, -44], [-3, -22], [2, 44], [22, 6], [24, -26], [33, -80], [-57, 48], [12, -6], [4, -4], [39, 6], [-6, 42], [-49, 70], [-49, -6], [34, 8], [-57, 48], [51, 20], [28, 42], [6, 18], [-54, -12], [-6, 60], [4, 20], [-2, 20], [17, -20], [28, 36], [24, -30], [-48, 48], [-33, -30], [38, 4], [-61, 50], [-58, -18], [-58, 34], [67, -40], [-24, 4], [39, -24], [41, -54], [20, -60], [-50, -32], [43, 30], [21, 6], [-38, 12], [62, -16], [-12, -26], [-40, 4], [-46, 10], [60, -20], [-15, 6], [-13, -10], [-48, 12], [10, 20], [-33, 30], [-8, 2], [30, -66], [36, -48], [42, -48], [65, -14], [-17, 28], [27, -60], [29, -4], [52, -52], [-6, -10], [0, -42], [20, -40], [-12, 24], [-63, -18], [-42, 38], [-22, -4], [-7, -34], [45, -10], [-68, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1305_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1305_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_1305_2_a_k(:prec:=2)
    chi := MakeCharacter_1305_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_1305_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_1305_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1305_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -1, 1]>,<7,R![3, 1]>],Snew);
    return Vf;
end function;