
// Make newform 1210.2.a.f in Magma, downloaded from the LMFDB on 10 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1210_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_1210_2_a_f();".
// 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_1210_2_a_f();".
// 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_1210_a();"
function MakeCharacter_1210_a()
    N := 1210;
    order := 1;
    char_gens := [727, 1091];
    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_1210_a_Hecke( : Kf := Kf)
    return MakeCharacter_1210_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], [1], [-1], [0], [-4], [0], [-4], [0], [-6], [-10], [8], [-3], [-1], [9], [-12], [6], [11], [-1], [-6], [8], [14], [-12], [-15], [8], [-3], [-16], [3], [-7], [6], [17], [0], [0], [-22], [-15], [-10], [8], [-13], [3], [24], [-18], [5], [-24], [26], [-18], [2], [14], [-7], [-3], [23], [-24], [12], [17], [-6], [-6], [12], [21], [-16], [2], [6], [17], [18], [32], [24], [8], [18], [-4], [-4], [-27], [-22], [6], [-36], [-19], [14], [2], [-24], [-3], [20], [27], [-13], [0], [35], [6], [14], [8], [-21], [27], [-10], [-15], [5], [-9], [-30], [-16], [18], [14], [-9], [15], [-33], [-4], [-7], [-28], [12], [-33], [-45], [-22], [14], [-15], [-12], [24], [2], [32], [-10], [-6], [8], [20], [18], [-25], [-45], [30], [-30], [11], [-22], [-36], [3], [-40], [-6], [-1], [0], [-37], [-4], [-46], [-21], [2], [20], [6], [26], [42], [23], [-18], [42], [-34], [-45], [23], [-33], [-19], [42], [-16], [18], [20], [3], [26], [9], [-52], [-21], [-31], [54], [20], [6], [2], [21], [-36], [-60], [56], [-36], [12], [-9], [20], [-4], [29], [6], [42], [-19], [18], [26], [14], [-39], [8], [-15], [-52], [-34], [53], [60], [-4], [42], [-3], [-30], [2], [-64], [-13], [-18], [-34], [36], [-40], [-54], [-51], [24], [-22], [-40], [-30], [39], [-45], [14], [38], [41], [-12], [0], [-4], [-69], [9], [-28], [-52], [-45], [-28], [-12], [6], [-55], [17], [-18], [33], [54], [-58], [32], [-6], [-37], [-51], [53], [-60], [-30], [44], [12], [-40], [26], [-46], [57], [-13], [-9], [-61], [-30], [18], [24], [-36], [-70], [35], [-61], [24], [-24], [47], [60], [-4], [-39], [-52], [-42], [-39], [38], [-6], [-6], [65], [-1], [6], [8], [53], [33], [11], [50], [30], [-76], [27], [15], [-7], [36], [50], [-1], [-4], [-58], [-22], [56], [12], [35], [-79], [54], [-9], [74], [-9], [-19], [44], [-54], [-16], [54], [50], [-30], [-54], [12], [12], [6], [-28], [-18], [26], [42], [-12], [-13], [38], [-48], [32], [81], [14], [38], [-3], [71], [78], [-46], [33], [18], [51], [-31], [-57], [2], [24], [12], [56], [-45], [-58], [-82], [-30], [83], [-60], [53], [-70], [83], [-51], [54], [2], [-48], [-16], [81], [56], [-60], [-43], [78], [5], [8], [-46], [-54], [42], [-28], [-36], [90], [-70], [-28], [12], [-12], [-22], [80], [51], [71], [35], [54], [0], [-54], [90], [36], [-88], [87], [-63], [-6], [-28], [62], [66], [29], [-43], [36], [50], [69], [9], [14], [74], [84], [90], [32], [15], [92], [-51], [-72], [-64], [-42], [38], [81], [-28], [32], [-16], [-93], [62], [-42], [48], [-73], [18], [-76], [74], [-75], [-4], [-21], [41], [60], [-31], [-42], [93], [38], [-34], [51], [-4], [-30], [-46], [-66], [36], [2], [14], [-18], [-66], [101], [12], [0], [18], [2], [27], [-66], [26], [-60], [75], [42], [74], [-96]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1210_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1210_2_a_f();".
// 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_1210_2_a_f(:prec:=1)
    chi := MakeCharacter_1210_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_1210_2_a_f();".
// 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_1210_2_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1210_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<7,R![1, 1]>,<13,R![4, 1]>,<17,R![0, 1]>],Snew);
    return Vf;
end function;