
// Make newform 1350.2.a.u in Magma, downloaded from the LMFDB on 18 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_u();".
// 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_u();".
// 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], [4], [3], [1], [0], [2], [-9], [-6], [-10], [7], [6], [10], [9], [6], [3], [-7], [4], [-15], [-2], [8], [-12], [-12], [19], [-12], [-14], [-9], [2], [6], [-2], [15], [-6], [-4], [-18], [2], [-14], [10], [21], [0], [-21], [-1], [12], [10], [-24], [-22], [8], [-2], [-3], [-1], [12], [15], [5], [15], [-12], [15], [-12], [20], [-2], [6], [-26], [-24], [-26], [21], [-14], [18], [-10], [-2], [12], [-10], [-6], [27], [-8], [22], [-10], [9], [6], [-5], [-12], [-7], [-12], [-37], [27], [-11], [-4], [-3], [18], [19], [-24], [22], [-3], [24], [4], [36], [-16], [-12], [-30], [24], [4], [35], [28], [-12], [27], [-18], [-34], [13], [-12], [12], [12], [35], [22], [-29], [-18], [2], [-10], [-12], [-14], [-15], [36], [36], [-31], [1], [18], [-9], [-46], [36], [-1], [-21], [4], [13], [-16], [3], [-4], [-23], [-18], [-46], [-42], [-8], [6], [42], [32], [-6], [-26], [45], [47], [-9], [55], [-12], [50], [-24], [43], [36], [52], [3], [46], [39], [-46], [42], [1], [-12], [24], [36], [-32], [27], [-48], [9], [32], [-53], [41], [-24], [0], [2], [15], [31], [44], [-54], [56], [-6], [22], [-19], [-50], [-3], [-11], [-6], [-12], [-30], [-2], [-32], [-31], [39], [7], [27], [-28], [-18], [21], [48], [23], [37], [42], [24], [-54], [-10], [-23], [-19], [-51], [18], [20], [39], [30], [20], [-62], [12], [10], [51], [-51], [-10], [22], [18], [-3], [6], [59], [56], [54], [70], [33], [-7], [-54], [9], [-32], [-48], [-11], [56], [-40], [-12], [10], [15], [-31], [-48], [36], [-21], [60], [-34], [46], [29], [-66], [-63], [52], [-27], [44], [9], [49], [-12], [-15], [17], [30], [-27], [-22], [-62], [66], [25], [-26], [36], [-58], [19], [18], [62], [-12], [54], [-14], [-54], [-43], [34], [-17], [-76], [19], [-14], [-24], [38], [-13], [-3], [-75], [-58], [-15], [-19], [-32], [-33], [-41], [42], [26], [30], [78], [-60], [0], [39], [-50], [24], [62], [-66], [-12], [46], [13], [48], [20], [51], [68], [7], [-75], [26], [-21], [34], [24], [-24], [-30], [-32], [-48], [65], [84], [33], [34], [60], [-28], [73], [12], [76], [36], [-43], [44], [-14], [63], [12], [-1], [66], [32], [-39], [-46], [-24], [-58], [78], [41], [-56], [19], [18], [-78], [-22], [-48], [36], [-46], [28], [3], [-84], [-70], [-29], [24], [4], [14], [-18], [45], [12], [-42], [3], [91], [6], [9], [-15], [-56], [22], [-18], [-56], [23], [-84], [-100], [15], [-18], [14], [-2], [-84], [21], [-14], [-66], [-2], [66], [-60], [52], [18], [-94], [-24], [32], [-59], [34], [48], [2], [60], [-24], [-14], [-48], [-26], [44], [30], [68], [-102], [41], [30], [10], [-96], [30], [2], [1], [72], [-104], [-69], [-11], [-12], [-51], [44], [-74], [18], [72], [-62], [-96], [96], [-24], [-38], [-75], [-72], [-38], [-42], [84], [36], [-64], [-3]];
    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_u();".
// 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_u(: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_u();".
// 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_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, 1]>,<11,R![-3, 1]>,<13,R![-1, 1]>,<17,R![0, 1]>],Snew);
    return Vf;
end function;