
// Make newform 1512.2.a.l in Magma, downloaded from the LMFDB on 19 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1512_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_1512_2_a_l();".
// 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_1512_2_a_l();".
// 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_1512_a();"
function MakeCharacter_1512_a()
    N := 1512;
    order := 1;
    char_gens := [1135, 757, 785, 1081];
    v := [1, 1, 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_1512_a_Hecke( : Kf := Kf)
    return MakeCharacter_1512_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 := [[0], [0], [4], [-1], [4], [-1], [3], [2], [-3], [-9], [-1], [10], [10], [-1], [-10], [9], [-3], [-6], [-13], [-13], [10], [10], [4], [-9], [0], [-2], [17], [-12], [-16], [16], [16], [7], [-6], [10], [3], [18], [-3], [3], [8], [0], [4], [-5], [-20], [13], [6], [-15], [3], [-24], [-7], [-14], [-20], [-20], [-26], [0], [-14], [-21], [-4], [3], [16], [-6], [-20], [-30], [22], [-32], [-2], [18], [5], [-13], [6], [-27], [-19], [15], [-17], [34], [32], [36], [-34], [-26], [18], [10], [-23], [10], [32], [40], [-39], [6], [-28], [-5], [6], [14], [8], [0], [2], [24], [20], [-16], [-10], [-21], [16], [20], [12], [-17], [-35], [4], [37], [-38], [-39], [2], [-9], [44], [-1], [-6], [26], [-14], [-12], [-12], [4], [-34], [-19], [12], [2], [7], [-48], [24], [-8], [18], [-24], [-8], [19], [5], [4], [-47], [22], [52], [-15], [44], [28], [50], [18], [40], [-2], [13], [18], [-2], [-10], [42], [41], [33], [-22], [-37], [0], [45], [1], [-20], [-28], [24], [-10], [14], [4], [-6], [26], [-24], [-16], [-33], [10], [36], [2], [7], [-61], [-36], [54], [13], [15], [-25], [40], [-39], [-11], [-7], [48], [35], [16], [-3], [-28], [9], [31], [-30], [48], [40], [-59], [-50], [8], [14], [25], [24], [6], [9], [29], [18], [43], [36], [11], [-7], [6], [-6], [49], [-28], [63], [-8], [60], [-54], [-1], [42], [62], [9], [-54], [-40], [-18], [-30], [-3], [41], [-70], [-32], [-40], [-24], [-28], [-18], [39], [64], [-47], [38], [-40], [-48], [26], [20], [52], [4], [-22], [-17], [18], [10], [58], [26], [-7], [20], [-21], [-6], [-31], [-4], [-5], [27], [28], [-3], [-43], [26], [30], [18], [40], [32], [-32], [12], [-74], [-36], [-50], [62], [-13], [-68], [46], [-38], [9], [-38], [-23], [-36], [-4], [-20], [30], [-7], [22], [34], [-2], [15], [30], [22], [56], [11], [72], [-8], [62], [35], [-55], [-25], [-6], [-63], [-16], [-63], [-50], [14], [16], [-66], [-11], [-22], [78], [41], [-70], [66], [-31], [25], [-28], [-35], [-24], [20], [-84], [-13], [22], [13], [-87], [-56], [-19], [24], [-44], [-20], [50], [-26], [80], [-74], [8], [-80], [41], [50], [81], [-26], [8], [38], [-44], [4], [-29], [53], [6], [39], [-26], [32], [50], [-42], [48], [70], [-13], [50], [91], [39], [16], [-16], [60], [63], [5], [39], [-76], [26], [-88], [12], [78], [80], [48], [-17], [53], [46], [58], [-6], [24], [-44], [45], [18], [-4], [23], [49], [-31], [-46], [21], [-63], [48], [54], [-2], [-6], [-84], [72], [18], [36], [-42], [-14], [93], [25], [32], [23], [-8], [-6], [14], [-85], [-27], [47], [-37], [91], [-23], [-5], [-60], [54], [65], [4], [16], [48], [-36], [-56], [63], [26], [-63], [96], [57], [-13], [-50], [5], [-32], [-57], [6], [-51], [-53], [48], [35], [0], [4], [64], [-12], [-54], [72]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1512_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1512_2_a_l();".
// 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_1512_2_a_l(:prec:=1)
    chi := MakeCharacter_1512_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_1512_2_a_l();".
// 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_1512_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1512_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 1]>,<11,R![-4, 1]>],Snew);
    return Vf;
end function;