
// Make newform 1350.2.a.t in Magma, downloaded from the LMFDB on 14 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_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_1350_2_a_t();".
// 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_1350_2_a_t();".
// 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_1350_a();"
function MakeCharacter_1350_a()
    N := 1350;
    order := 1;
    char_gens := [1001, 1027];
    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_1350_a_Hecke( : Kf := Kf)
    return MakeCharacter_1350_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], [0], [0], [2], [3], [5], [-6], [-4], [3], [0], [2], [11], [-6], [-4], [-3], [12], [-9], [11], [14], [15], [2], [-10], [0], [-6], [-7], [-18], [14], [-15], [-10], [-18], [2], [-21], [12], [14], [-18], [-16], [2], [2], [-3], [6], [15], [-7], [0], [-10], [0], [2], [-4], [-4], [-21], [-7], [-6], [9], [-19], [27], [18], [3], [0], [20], [-22], [0], [-16], [-6], [-10], [27], [-10], [-12], [-10], [-22], [12], [26], [-24], [-3], [-28], [-10], [-34], [21], [-12], [-1], [-6], [-31], [24], [-19], [9], [35], [14], [27], [42], [17], [-12], [-4], [-21], [24], [38], [24], [20], [0], [-6], [-42], [-4], [5], [8], [42], [-39], [42], [26], [23], [-12], [-36], [-12], [-13], [14], [11], [18], [2], [20], [-6], [50], [33], [30], [12], [23], [-1], [-6], [-15], [-10], [-30], [-43], [21], [32], [-31], [-34], [3], [-40], [41], [-6], [14], [-12], [8], [12], [12], [26], [-6], [32], [51], [-7], [9], [-1], [48], [-40], [-48], [-1], [0], [-22], [-21], [-28], [33], [44], [-30], [-13], [42], [12], [12], [-4], [3], [-12], [21], [32], [-1], [41], [-12], [-24], [2], [9], [-43], [50], [48], [-40], [-54], [-16], [23], [44], [-39], [-7], [24], [0], [24], [2], [-28], [17], [21], [-31], [-15], [14], [-36], [39], [0], [-13], [53], [-18], [48], [-6], [-28], [5], [-55], [-3], [-24], [-40], [9], [60], [-58], [-34], [-24], [-10], [33], [3], [62], [-52], [12], [9], [6], [53], [74], [-66], [20], [51], [-1], [-36], [-45], [44], [-12], [-55], [2], [2], [24], [26], [-9], [5], [60], [36], [-39], [-60], [20], [-46], [47], [-60], [-9], [14], [-39], [-52], [-3], [5], [72], [45], [-19], [78], [-51], [14], [8], [-12], [11], [38], [36], [-22], [23], [30], [-28], [6], [0], [68], [72], [-1], [2], [17], [14], [29], [-76], [-12], [14], [-73], [-27], [-27], [50], [-63], [-1], [14], [45], [29], [12], [-64], [66], [-42], [-12], [-30], [27], [50], [-30], [74], [6], [12], [8], [-13], [-72], [-82], [-39], [-4], [17], [15], [-82], [-51], [74], [48], [66], [36], [-46], [-12], [17], [-60], [-45], [-22], [54], [44], [59], [60], [80], [-54], [65], [8], [50], [75], [-36], [-55], [12], [8], [51], [-10], [-60], [50], [-30], [-7], [-52], [-61], [54], [24], [38], [84], [84], [26], [-40], [57], [-72], [8], [29], [-36], [50], [50], [12], [-57], [36], [18], [-69], [-61], [-6], [45], [57], [-34], [38], [-72], [2], [47], [-84], [32], [39], [-6], [-76], [14], [-36], [75], [-34], [24], [-70], [12], [54], [-52], [48], [-40], [-84], [-22], [-67], [56], [48], [50], [-54], [-36], [-82], [-96], [-10], [-16], [60], [92], [-12], [95], [54], [38], [60], [-72], [20], [-7], [30], [-4], [15], [-49], [-60], [-45], [-82], [-46], [24], [60], [74], [-30], [-24], [-54], [-46], [33], [84], [74], [-6], [-60], [-48], [-10], [15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_2_a_t();".
// 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_1350_2_a_t(:prec:=1)
    chi := MakeCharacter_1350_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_1350_2_a_t();".
// 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_1350_2_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, 1]>,<11,R![-3, 1]>,<13,R![-5, 1]>,<17,R![6, 1]>],Snew);
    return Vf;
end function;