
// Make newform 3920.2.a.bz in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3920_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_3920_2_a_bz();".
// 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_3920_2_a_bz();".
// 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 := [-2, 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_3920_a();"
function MakeCharacter_3920_a()
    N := 3920;
    order := 1;
    char_gens := [1471, 981, 3137, 3041];
    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_3920_a_Hecke(Kf)
    return MakeCharacter_3920_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], [1, 1], [1, 0], [0, 0], [2, 2], [2, 0], [-2, 4], [0, -4], [7, 1], [-5, 2], [2, 2], [0, -4], [3, -2], [-3, -7], [-6, 4], [0, 4], [4, 0], [1, -4], [3, -7], [12, 0], [-2, -4], [4, 0], [9, 3], [-11, -4], [6, 0], [-3, 6], [-9, -1], [7, 1], [7, -8], [0, -8], [10, 4], [-8, 4], [-4, 0], [6, 6], [-1, -4], [14, 2], [-10, -8], [10, -4], [5, 5], [16, 4], [-2, -6], [-7, -2], [14, 6], [6, 8], [6, 4], [12, -8], [-4, 16], [-2, -12], [-14, 0], [-14, 0], [6, -4], [22, -6], [-10, 0], [2, -18], [4, -8], [3, -9], [-1, 4], [-8, -8], [6, -16], [14, 8], [-18, 0], [0, -12], [-9, -3], [-16, 4], [4, -12], [-22, 0], [-18, 6], [8, -12], [7, 13], [7, -2], [28, -4], [-2, -6], [-23, -1], [12, 0], [-16, -8], [-9, -7], [-6, -8], [-2, 16], [-21, 8], [-11, 10], [4, -8], [33, 4], [-2, -2], [-8, 8], [24, 4], [17, 1], [1, 6], [12, -12], [-10, -8], [-5, 7], [11, -19], [10, 6], [10, -20], [-10, -6], [-30, 10], [11, 5], [-25, 6], [14, -16], [6, 24], [-15, 6], [15, 9], [-6, 8], [-3, -5], [-14, 16], [4, -12], [6, 20], [34, 8], [-4, -24], [-20, 16], [-34, 0], [-23, 3], [22, -12], [-24, -8], [-14, 18], [10, 6], [-17, -22], [-26, 0], [25, 3], [-10, 4], [-24, -8], [-39, 8], [0, 4], [6, -12], [9, 5], [6, -26], [-11, 0], [7, 30], [6, -14], [-31, 5], [2, -4], [-14, 2], [15, 3], [12, 0], [6, 0], [-10, 24], [-2, -32], [30, 4], [3, 1], [-24, 8], [-19, 12], [-38, 10], [-10, 16], [11, 29], [19, 23], [-6, -8], [-6, 10], [24, 8], [-2, 12], [8, -16], [15, -29], [0, 20], [-1, 18], [-18, -8], [-19, -1], [-25, 15], [10, -6], [-12, -32], [29, 14], [-4, -16], [-10, 0], [-21, -7], [-32, 16], [29, 3], [-8, 0], [2, -20], [23, -13], [-2, 2], [-20, -4], [21, 4], [24, -8], [28, 4], [-15, -2], [2, 38], [-12, -8], [-2, -38], [-19, 8], [-4, -24], [-10, 8], [31, -15], [-9, -24], [5, 21], [6, 6], [-18, -4], [-22, 4], [-10, -4], [19, 6], [8, -12], [-6, -20], [9, 22], [-14, -22], [20, 0], [-14, -4], [-14, -22], [-23, -8], [22, 4], [-10, 8], [19, 2], [30, 0], [8, 16], [-26, 20], [-13, -10], [6, -14], [-12, 12], [13, 4], [2, 30], [0, 8], [8, 16], [30, 8], [5, 8], [24, 0], [24, 28], [-15, -12], [11, -25], [7, -21], [2, -22], [-34, -8], [49, 1], [-9, -8], [26, -28], [-8, 16], [-27, -24], [-22, 14], [33, 24], [26, 8], [11, -25], [11, -8], [-24, 8], [-26, -22], [9, 17], [-38, 2], [-10, 8], [-72, 0], [-6, -2], [-37, -14], [21, -7], [-3, 11], [33, 2], [46, 0], [-16, 36], [26, 10], [-42, -8], [12, 40], [-10, 12], [-9, -22], [-24, 12], [10, -26], [-35, -21], [-38, 10], [60, -4], [6, -12], [-24, -36], [19, -20], [1, -5], [-3, 10], [-22, 16], [36, -4], [37, -18], [11, -17], [-6, 4], [0, -12], [23, -5], [-1, -7], [-6, 0], [-30, -28], [16, 24], [-2, 34], [6, 24], [30, 8], [33, 1], [28, 24], [-11, 50], [-14, 24], [48, 12], [8, 28], [-30, 28], [30, -12], [2, 32], [-9, 6], [43, -18], [-28, 16], [7, -11], [12, 0], [42, -28], [-7, 50], [39, -5], [-24, -32], [60, 12], [32, -32], [-6, 42], [-14, 0], [-11, -44], [39, 29], [26, -4], [46, 22], [32, 36], [27, -20], [52, -8], [36, 0], [-42, -2], [-14, 24], [10, 4], [-8, 12], [10, -2], [5, 17], [26, -34], [18, -4], [42, -24], [55, -10], [34, 2], [-6, 32], [31, -25], [-2, -56], [47, -4], [73, -7], [-51, 21], [57, 12], [16, -20], [16, -28], [26, 28], [21, -22], [42, -6], [18, 28], [41, -20], [7, 37], [34, -36], [-1, -14], [-30, -18], [-39, 15], [34, 20], [12, 16], [-26, -8], [-16, 0], [64, 12], [1, 45], [-34, -18], [7, 49], [30, -16], [-54, 0], [-33, 14], [-58, 0], [48, 4], [-48, 24], [23, 0], [-8, 16], [14, -12], [8, -56], [5, -28], [3, 25], [-54, -14], [12, -4], [14, -10], [-2, 4], [5, 32], [11, -13], [-9, -30], [8, 36], [-6, 50], [66, 14], [-14, 8], [23, -3], [-16, 16], [-2, -8], [17, 33], [8, -60], [43, -1], [-34, 16], [78, 8], [2, -40], [-1, 10], [-16, 16], [-42, 10], [-53, -1], [34, -24], [36, 32], [-10, -40], [-28, -12], [18, 22], [-86, 8], [-10, -32], [24, -4], [-27, -30], [-2, 24], [-51, 13], [88, 0], [-62, -6], [-1, 15], [10, -22], [0, -56], [-27, -3], [61, 9], [-42, -16], [64, 12], [-14, -6], [-6, -40], [6, -22], [-32, 40], [-12, -44], [37, -28], [44, -12], [-11, 12], [11, 4], [14, -16], [57, -17], [20, 40], [-25, 36], [-24, -32], [-4, 8], [-21, 8], [13, -39], [-10, -22], [8, 36], [-38, -40], [38, 0], [60, 12], [-34, 8], [-18, -8], [-38, 6], [-62, 12], [6, -20], [15, 11], [-93, 8], [68, -8], [-91, -9], [-74, 10], [-6, 16], [-38, 20], [22, 0], [5, -50], [88, 8], [50, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3920_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3920_2_a_bz();".
// 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_3920_2_a_bz(:prec:=2)
    chi := MakeCharacter_3920_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_3920_2_a_bz();".
// 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_3920_2_a_bz( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3920_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -2, 1]>,<11,R![-4, -4, 1]>,<13,R![-2, 1]>,<17,R![-28, 4, 1]>],Snew);
    return Vf;
end function;