
// Make newform 1428.2.a.h in Magma, downloaded from the LMFDB on 16 November 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1428_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_1428_2_a_h();".
// 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_1428_2_a_h();".
// 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
        poly := [-10, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1428_a();"
function MakeCharacter_1428_a()
    N := 1428;
    order := 1;
    char_gens := [715, 953, 409, 1261];
    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_1428_a_Hecke(Kf)
    return MakeCharacter_1428_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], [1, 0], [1, 1], [1, 0], [3, 0], [3, 1], [-1, 0], [-5, -1], [1, -2], [4, -2], [-2, -1], [-6, 1], [-7, -1], [3, -2], [2, -1], [0, -3], [10, 1], [0, 1], [-10, 0], [2, -4], [6, -2], [4, -1], [6, 0], [-4, 2], [4, -4], [0, 3], [-9, 1], [5, 2], [6, 1], [-13, 2], [-13, 0], [-5, 1], [16, 1], [2, 6], [14, 2], [6, -2], [9, -5], [6, 4], [7, 1], [-7, 5], [-6, 6], [-14, 2], [6, 0], [-4, -3], [3, 0], [8, -3], [-16, -3], [-11, -1], [-7, 5], [-4, -6], [-1, 2], [10, 1], [12, 4], [-12, -3], [12, -3], [-4, 2], [9, 3], [-17, -1], [2, 6], [-20, -2], [-2, 5], [24, 0], [-12, 4], [-8, 4], [-20, -1], [2, -4], [-5, 2], [-4, -9], [-6, -6], [3, -5], [6, -3], [-10, -7], [-8, -4], [12, 4], [-12, 4], [4, 1], [0, 6], [-4, 9], [-3, 0], [5, -9], [-10, -4], [-11, 8], [24, 0], [5, -3], [-16, 3], [4, 1], [-12, 0], [27, 4], [-18, -3], [14, 6], [-2, -2], [7, 1], [-18, 4], [18, 0], [4, -1], [3, 9], [-8, 4], [-3, -3], [-20, 2], [-4, -6], [14, -3], [16, 1], [6, 6], [0, -6], [4, 8], [-27, -5], [-28, 5], [6, 3], [34, 4], [18, 7], [18, -5], [47, 0], [24, 6], [6, -5], [25, -4], [-7, 2], [-4, 0], [-10, -10], [1, -8], [24, 3], [-5, -7], [6, 4], [-19, 5], [9, -12], [-16, -3], [-28, 2], [30, 4], [-1, -1], [-8, 2], [-26, 2], [25, 2], [26, 2], [-8, 5], [7, -4], [18, 0], [-15, -5], [36, -3], [12, -11], [36, 0], [-7, 2], [-30, 4], [-19, 8], [-14, -1], [-27, 6], [14, 0], [-3, 3], [-10, -15], [-10, 14], [-20, 2], [-6, -9], [-48, 1], [18, -6], [11, -12], [33, -3], [38, 6], [-29, -2], [5, -6], [-45, -3], [8, 6], [-10, -4], [-6, 6], [-34, 5], [37, 2], [6, 12], [14, -10], [-3, 9], [-8, -4], [-10, 0], [0, -14], [-6, 12], [0, 3], [-21, 1], [45, 0], [23, 6], [29, 9], [-7, -1], [-34, -9], [-33, 0], [9, 7], [19, 5], [11, 12], [20, -4], [-36, -5], [-24, -6], [18, 6], [-6, -18], [34, -4], [39, -5], [-4, 3], [-30, 0], [10, -13], [-46, -4], [-35, -10], [24, 3], [-21, 0], [-44, -2], [10, 2], [24, -2], [34, 4], [-2, -14], [-9, 12], [-24, -2], [-33, 7], [-25, 3], [32, -1], [-2, -5], [28, 8], [0, 6], [23, -4], [-2, 20], [-60, 1], [2, 17], [24, -11], [-12, -12], [-9, -3], [-40, -6], [-3, 10], [-12, 0], [-17, 10], [-18, -9], [-63, -2], [-24, -2], [12, -12], [12, 19], [6, -12], [-20, 8], [23, 5], [-7, 20], [27, 1], [6, 0], [5, 18], [-2, 23], [6, 4], [16, 1], [-16, -6], [-2, -11], [-24, -5], [7, 4], [-1, 2], [-52, 2], [-3, 12], [-36, 10], [29, -9], [-9, -2], [17, -1], [-27, -3], [42, -2], [-25, -13], [-33, -2], [24, -6], [1, -4], [-18, -18], [-18, 9], [-28, 6], [22, 4], [-14, 1], [-52, 6], [-16, -9], [9, -21], [24, -14], [6, -14], [8, 2], [0, 19], [-48, 4], [-3, -3], [5, 3], [12, 3], [32, 5], [-36, 4], [-12, -3], [-40, -9], [-23, 2], [5, -15], [38, -6], [-2, 2], [1, -1], [-4, 8], [-39, 4], [9, 10], [20, -10], [-8, -11], [-22, 6], [52, 4], [-30, -14], [-22, 9], [-8, 4], [32, -3], [38, 8], [-13, 3], [20, 8], [-3, -6], [11, 11], [18, -12], [25, -11], [54, 1], [-21, 3], [-20, -16], [-24, 12], [11, -7], [38, -12], [41, 9], [0, 12], [-48, 4], [1, 16], [-24, -2], [6, 10], [-24, 9], [8, -21], [52, 10], [-24, -2], [8, -10], [-70, -4], [-9, 0], [-13, 18], [52, 10], [-23, -13], [-22, 14], [-9, 18], [20, -3], [-2, 7], [22, 8], [-58, 6], [-6, -9], [25, -10], [-8, -2], [13, 11], [18, -2], [6, -11], [66, 6], [5, -10], [-24, 10], [63, 6], [-30, 7], [-46, -4], [10, 17], [3, -9], [-13, 12], [15, -15], [30, -17], [-3, -5], [37, -4], [-14, -11], [39, -15], [-69, 4], [24, 0], [29, -16], [-18, -2], [-73, 0], [43, 13], [6, 0], [-19, 21], [18, 7], [54, -9], [6, -20], [35, 0], [4, 1], [-44, 13], [-22, -4], [7, 16], [-10, 8], [-16, -6], [-35, 1], [34, 13], [-52, 8], [19, -7], [9, -26], [63, -3], [-4, 24], [44, 6], [2, -19], [56, 0], [9, -6], [-6, -3], [18, -8], [-16, -24], [63, 3], [-44, 4], [1, 17], [-62, -5], [27, 13], [-37, 5], [26, -1], [34, -13], [-43, 2], [14, 9], [-3, 21], [-19, -18], [-26, 14], [-30, 1], [-12, 18], [-60, 7], [15, 3], [66, 3], [7, -1], [0, -9], [50, -9], [-36, -2], [-26, -17], [-14, 23], [-36, -9], [60, 1], [6, 27], [-41, 8], [30, -6], [14, -19], [-10, 0], [32, 6], [14, -19], [7, -1], [-3, -9], [76, 5], [50, -4], [-16, 20], [-8, 20], [-7, -12], [4, -26], [3, 18], [-58, -6], [-31, 5], [-50, -5], [-22, -4], [-30, 7], [3, 0], [-10, -1], [24, 13], [68, 8], [-38, -8], [-11, -26], [-13, 3], [-27, 9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1428_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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