
// Make newform 1274.2.a.j in Magma, downloaded from the LMFDB on 11 July 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1274_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_1274_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_1274_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1274_a();"
function MakeCharacter_1274_a()
    N := 1274;
    order := 1;
    char_gens := [885, 197];
    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_1274_a_Hecke( : Kf := Kf)
    return MakeCharacter_1274_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 := [[1], [-1], [0], [0], [-3], [-1], [0], [-2], [-3], [0], [-5], [-7], [-3], [8], [3], [-12], [-6], [1], [5], [12], [-11], [-1], [-12], [18], [-17], [3], [-14], [0], [2], [9], [-7], [0], [-6], [4], [-15], [8], [13], [20], [24], [18], [-6], [7], [0], [-4], [-3], [16], [-22], [1], [24], [4], [3], [6], [-26], [15], [-24], [24], [9], [-11], [26], [12], [31], [-18], [16], [-30], [-26], [-3], [-19], [-31], [24], [10], [-15], [-24], [28], [-4], [-16], [-3], [-36], [-20], [24], [22], [-21], [-37], [-6], [-38], [-26], [24], [-6], [26], [-24], [-40], [-12], [-24], [2], [12], [23], [-12], [30], [-6], [7], [-34], [8], [-15], [39], [21], [-22], [-2], [-18], [6], [39], [10], [-14], [-25], [18], [10], [-34], [-33], [-32], [-12], [24], [42], [-32], [-1], [39], [-27], [-8], [-36], [35], [-6], [-26], [4], [-16], [-24], [-31], [38], [-3], [13], [54], [-32], [-9], [30], [-20], [-6], [41], [-36], [-38], [21], [-44], [-54], [-23], [12], [-13], [-6], [2], [-42], [26], [12], [-25], [9], [52], [-30], [48], [-42], [-22], [21], [18], [0], [11], [37], [-16], [-18], [36], [-14], [-15], [44], [-50], [36], [-37], [42], [52], [19], [-46], [-3], [14], [-21], [-36], [42], [56], [-8], [-4], [-9], [52], [33], [2], [-30], [18], [18], [-40], [26], [-30], [24], [51], [64], [-32], [-26], [66], [-30], [-20], [66], [18], [31], [29], [21], [-1], [0], [-51], [-35], [-31], [60], [-18], [15], [-22], [-41], [36], [-34], [33], [-28], [24], [-9], [-8], [15], [-4], [52], [32], [3], [1], [63], [-5], [45], [0], [-60], [-57], [61], [-32], [-34], [-63], [66], [43], [-18], [5], [15], [23], [-54], [-6], [46], [63], [-48], [38], [-26], [-27], [7], [8], [18], [-50], [25], [21], [-8], [-69], [-39], [-13], [-12], [49], [-25], [37], [-40], [22], [-56], [12], [17], [-52], [-36], [-54], [-22], [42], [10], [4], [-51], [-7], [-66], [-71], [60], [-30], [-45], [-30], [-18], [62], [42], [-44], [-45], [-27], [-62], [22], [-15], [-16], [60], [68], [56], [-18], [22], [-30], [-16], [18], [-42], [69], [-58], [-6], [16], [12], [30], [46], [-87], [37], [-4], [-3], [38], [-18], [-2], [-7], [28], [-24], [-66], [-37], [-24], [10], [60], [11], [-54], [38], [-69], [-50], [-2], [26], [-3], [66], [71], [-9], [-36], [-2], [44], [-63], [-87], [-14], [92], [-69], [-26], [50], [-36], [-75], [-90], [27], [84], [-46], [42], [-15], [57], [7], [-1], [12], [74], [65], [-42], [97], [-18], [-96], [-32], [92], [96], [75], [25], [-96], [28], [36], [36], [-52], [72], [-68], [24], [-10], [103], [20], [0], [26], [6], [51], [-44], [-18], [-13], [25], [-48], [50], [-54], [40], [-18], [-76], [27], [36], [-20], [53], [-12], [-104], [24], [10], [84], [-42], [-100], [-85], [-30], [42], [64], [21], [6], [-30], [-2], [-36], [-60], [70], [-24], [6], [72], [34], [-30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1274_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1274_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_1274_2_a_j(:prec:=1)
    chi := MakeCharacter_1274_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_1274_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_1274_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1274_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<5,R![0, 1]>,<11,R![3, 1]>,<17,R![0, 1]>],Snew);
    return Vf;
end function;