
// Make newform 1350.2.a.d in Magma, downloaded from the LMFDB on 22 May 2024.
// 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_d();".
// 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_d();".
// 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)
    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+1)]];
    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], [3], [-4], [9], [-3], [5], [10], [0], [1], [-9], [12], [12], [2], [4], [12], [10], [-13], [-6], [-12], [-2], [15], [-2], [-6], [20], [15], [-2], [-3], [6], [2], [21], [11], [13], [-11], [12], [-18], [12], [20], [6], [10], [0], [-7], [-22], [-8], [0], [-4], [-6], [-6], [-19], [-9], [15], [-12], [-9], [8], [10], [-30], [-32], [-18], [-11], [-24], [-8], [0], [14], [-32], [0], [14], [-3], [12], [-26], [1], [-16], [9], [9], [7], [36], [23], [-3], [-4], [0], [-2], [8], [12], [-6], [28], [18], [-38], [-12], [36], [-20], [-12], [-4], [9], [9], [-12], [31], [-22], [13], [-12], [-6], [0], [-10], [-32], [18], [27], [-30], [-19], [34], [19], [-3], [-34], [-16], [30], [-23], [-12], [-36], [48], [2], [22], [-12], [48], [-10], [21], [20], [-30], [-44], [22], [20], [27], [-25], [13], [-18], [23], [42], [1], [36], [24], [38], [-42], [4], [42], [44], [6], [19], [6], [2], [-21], [1], [-18], [4], [3], [-59], [0], [-25], [36], [22], [33], [42], [-15], [-2], [-57], [-33], [-39], [5], [37], [-31], [30], [-15], [50], [-42], [-20], [5], [0], [-28], [-18], [-56], [-46], [-8], [0], [13], [15], [-48], [18], [7], [37], [-10], [42], [-14], [6], [-4], [-57], [12], [6], [-34], [-41], [66], [48], [-45], [68], [-38], [14], [21], [-60], [-31], [-66], [-18], [68], [16], [-45], [28], [-18], [-54], [23], [58], [-42], [63], [-6], [44], [41], [60], [-20], [-42], [26], [3], [18], [-8], [-45], [10], [2], [-49], [-30], [4], [12], [-61], [-48], [48], [-24], [24], [20], [46], [-34], [-18], [-48], [22], [-75], [-22], [-3], [49], [36], [24], [-46], [54], [-21], [-4], [55], [78], [-38], [52], [-6], [-70], [-5], [9], [80], [66], [24], [-23], [60], [44], [-53], [-26], [41], [-50], [-32], [-24], [44], [29], [33], [15], [-67], [-15], [8], [49], [-18], [-56], [18], [5], [42], [3], [-84], [21], [12], [-62], [6], [56], [-54], [-57], [4], [16], [0], [-7], [30], [38], [-74], [18], [-10], [18], [-71], [-39], [-66], [78], [73], [33], [-25], [21], [-24], [-44], [66], [-4], [-32], [-51], [52], [-33], [-55], [20], [-44], [33], [-36], [62], [-54], [-73], [-18], [-52], [-42], [-40], [-6], [-85], [-2], [25], [-33], [42], [29], [-12], [-39], [-34], [-44], [84], [-18], [44], [64], [-15], [82], [-4], [21], [-12], [-63], [69], [-3], [-38], [-60], [-36], [57], [-35], [-56], [84], [10], [-61], [9], [86], [-9], [-78], [-16], [49], [21], [60], [-56], [-78], [-2], [21], [-75], [-8], [-3], [38], [-21], [80], [-2], [1], [-9], [-19], [-6], [36], [-35], [-60], [-8], [-16], [-36], [-22], [-93], [-4], [81], [-68], [-51], [-54], [-88], [-47], [-6], [76], [27], [46], [-30], [-54], [-82], [-62], [-6], [66], [-56], [42], [-99], [-3], [-2], [-99], [-9], [34], [18], [-48], [-24], [74], [18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_2_a_d();".
// 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_d(: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_d();".
// 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_d( : 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![-3, 1]>],Snew);
    return Vf;
end function;