
// Make newform 1472.2.a.s in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1472_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_1472_2_a_s();".
// 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_1472_2_a_s();".
// 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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_1472_a();"
function MakeCharacter_1472_a()
    N := 1472;
    order := 1;
    char_gens := [1151, 645, 833];
    v := [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_1472_a_Hecke(Kf)
    return MakeCharacter_1472_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 := [[0, 0], [0, -1], [1, -1], [-1, -1], [-3, -1], [-3, 0], [3, -1], [-2, 0], [-1, 0], [3, 0], [0, -3], [-1, 1], [1, -2], [0, 0], [0, 1], [4, -2], [2, 2], [-2, 4], [-5, 1], [-10, -1], [11, -2], [2, 4], [-11, 1], [-6, -2], [11, 3], [0, -2], [-7, 5], [0, 6], [0, 0], [11, -1], [14, -3], [12, 3], [-4, -8], [-4, -3], [-6, -8], [-2, -1], [-2, 6], [-8, 1], [-6, 2], [-14, -4], [-6, 3], [-1, -7], [15, 5], [1, 4], [-3, 2], [19, -3], [-10, -6], [-4, 0], [-1, -5], [12, 0], [-11, 2], [-16, 1], [-3, -9], [9, -3], [-3, -2], [6, -4], [-1, 4], [-8, 0], [-11, -2], [-11, 1], [21, 3], [6, -2], [14, -2], [-2, -5], [2, 10], [-12, -6], [-4, -7], [10, 6], [8, -8], [-11, -6], [-13, 10], [2, 8], [-7, 5], [-1, -3], [2, 10], [-16, 4], [-30, 2], [11, 6], [-3, -5], [-1, 10], [-18, 6], [17, -3], [22, -2], [29, -5], [12, 3], [18, 9], [-6, -4], [15, -9], [-3, 2], [20, 0], [-22, 4], [-7, -11], [8, 3], [24, -7], [26, -3], [18, 4], [-3, 14], [18, 6], [21, 9], [21, 6], [4, -15], [-6, 6], [-24, -4], [-11, -5], [-21, 3], [5, 8], [-18, -3], [6, -4], [-16, -8], [29, 8], [-22, -2], [1, -3], [-12, 2], [6, 6], [10, -10], [14, -14], [-5, -11], [0, -3], [7, 14], [5, -7], [14, 4], [3, 0], [-18, 0], [2, 11], [16, -4], [15, -5], [13, 13], [12, -4], [21, 3], [29, 1], [38, -5], [-21, -9], [22, -10], [23, -11], [15, 14], [-3, -9], [10, -2], [38, -6], [12, 10], [30, -8], [-40, 7], [30, 4], [6, 15], [6, -2], [0, -18], [21, 9], [24, -6], [-3, 2], [-10, -3], [-12, 15], [32, 2], [33, 5], [4, 0], [6, -13], [0, -18], [0, -14], [-21, -9], [-33, 4], [23, 5], [9, -7], [-22, 5], [16, 2], [6, -15], [12, 2], [-39, 7], [36, 2], [-24, 0], [10, -12], [0, 6], [25, 4], [-5, 5], [-1, 16], [-23, 13], [0, 0], [-46, 1], [-51, -3], [24, -15], [-3, -24], [18, 12], [-17, -9], [-24, -9], [-16, 20], [-31, 10], [-6, -12], [-9, -15], [-9, 3], [-28, 14], [-40, 6], [-3, 0], [0, 24], [45, 6], [2, -10], [25, -9], [-6, 8], [59, 1], [18, 14], [13, 19], [-10, -18], [18, -14], [-36, 11], [36, -8], [4, 12], [-19, -6], [-3, 3], [-18, -6], [3, 4], [3, 21], [4, -1], [-3, 26], [-42, -9], [17, 18], [-45, -2], [-2, -10], [-4, 2], [-12, 8], [20, -12], [18, -21], [9, 0], [-9, -15], [15, -2], [-5, 6], [9, 3], [-9, -22], [-19, 13], [-26, 5], [-9, 6], [-15, -13], [6, -7], [10, -4], [-24, 16], [-2, 0], [61, 5], [15, -27], [2, 4], [-40, 4], [-33, -13], [-22, 18], [13, 11], [-14, 1], [26, 5], [4, -28], [0, -9], [32, 9], [-43, 0], [-2, -4], [-44, 5], [-2, -21], [20, -14], [18, 0], [-19, -13], [13, -7], [-37, -11], [32, 14], [-15, 9], [6, -24], [14, 11], [-19, -9], [-3, -9], [37, -2], [39, -6], [-14, 22], [-12, -24], [22, 16], [-27, -15], [-34, -4], [48, -6], [-1, 1], [0, 4], [-22, 20], [45, 2], [-49, 8], [8, -6], [20, 12], [-17, 15], [25, -12], [54, 3], [42, -2], [26, -8], [-17, 21], [2, 26], [0, -17], [47, 5], [3, -35], [8, 22], [-2, 22], [18, -6], [-34, -4], [-6, -16], [14, 6], [20, -22], [18, -4], [69, 5], [-54, -8], [-8, 10], [-23, 2], [48, 10], [5, -3], [-27, 0], [-46, -17], [-28, 13], [59, 3], [42, 4], [-47, -15], [24, -11], [34, 6], [-23, -18], [36, 8], [-14, -2], [-23, 23], [-14, 4], [36, -3], [-42, 12], [23, -17], [46, -9], [-36, 18], [-5, 7], [30, -17], [22, 11], [28, 12], [39, 8], [46, -10], [-47, 1], [55, 2], [2, -30], [-27, -9], [30, 6], [25, 3], [36, -3], [39, 9], [23, 23], [9, -6], [63, 6], [-8, 19], [-12, -3], [-40, 10], [-12, 13], [33, -21], [-15, -3], [-15, 6], [6, 18], [-1, 26], [4, 4], [-48, 10], [-42, 12], [63, -3], [-18, 10], [9, 24], [28, -8], [34, 8], [55, 1], [-52, -1], [-1, -42], [-22, -4], [-32, -6], [23, 23], [66, 12], [-3, -3], [27, 17], [-17, 10], [-14, 14], [-41, -3], [-43, -8], [-60, 3], [11, 1], [-28, -19], [-1, 22], [-65, -10], [1, -9], [54, -12], [-40, 17], [-12, 0], [48, 21], [-1, 35], [22, 22], [-39, 0], [4, 5], [61, -5], [8, -14], [8, 4], [7, 32], [13, 7], [48, -14], [0, 24], [15, 24], [-13, 11], [-54, 9], [8, -1], [2, -12], [-49, -15], [7, 11], [-17, 19], [-54, 0], [24, -9], [-12, 24], [81, -3], [-13, -19], [-2, -30], [-55, 5], [19, -21], [8, -22], [-21, -30], [39, 6], [-63, -3], [67, 7], [43, -26], [-20, -11], [-28, -6], [-57, 14], [53, -3], [-64, 16], [47, -12], [1, -8], [-3, -5], [-10, 16], [-8, -18], [17, 2], [4, -16], [10, -18], [-18, 30], [-34, -14], [-93, 3], [-80, 0], [-32, 20], [0, -20], [13, -12], [-3, 32], [-34, 4], [-4, 10], [-26, -7], [-66, -9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1472_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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