
// Make newform 3520.2.a.bx in Magma, downloaded from the LMFDB on 01 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3520_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_3520_2_a_bx();".
// 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_3520_2_a_bx();".
// 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, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-3, 1, 1], [-3, -1, 1]];
    Rf_basisdens := [1, 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_3520_a();"
function MakeCharacter_3520_a()
    N := 3520;
    order := 1;
    char_gens := [2751, 1541, 2817, 321];
    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_3520_a_Hecke( : Kf := Kf)
    return MakeCharacter_3520_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, 0], [1, 0, 1], [1, 0, 0], [1, -1, 0], [-1, 0, 0], [-2, 0, 0], [1, 0, 1], [3, 1, 2], [2, 0, 0], [1, -2, -1], [-1, 0, -3], [-5, 1, 0], [2, 2, -2], [0, 2, -4], [2, 2, -2], [-5, 1, 0], [-2, 2, -4], [-5, -2, 1], [4, -2, 0], [-3, 0, -1], [10, 2, 2], [10, 0, -2], [2, -2, -2], [1, -3, 2], [0, 4, -2], [6, 2, 6], [8, 0, 2], [4, 0, 2], [-6, 2, -2], [4, 2, 0], [8, -2, 4], [-1, 5, -2], [-4, -2, -4], [4, 0, -4], [7, -2, -3], [-2, 0, 6], [-9, -3, -8], [1, 0, -7], [5, -1, -4], [2, -2, 2], [0, -6, 2], [-6, 2, 2], [8, 0, 4], [5, 0, -3], [4, -8, 2], [1, 0, 7], [-13, -3, 2], [18, 2, 2], [2, 4, 0], [-2, 2, -10], [-3, 0, -11], [14, 2, 4], [6, -2, -2], [6, -2, 4], [-6, -6, 2], [3, 5, 0], [12, 2, -4], [-12, 4, -4], [-8, 4, -6], [-6, 2, 6], [2, 2, 2], [2, -2, -6], [2, 0, 4], [7, -8, 5], [6, 4, 8], [-3, -1, -12], [16, 0, -4], [7, 0, -5], [-6, 4, -8], [10, 2, 2], [2, -6, 2], [0, -2, 6], [-4, 6, -8], [2, 2, 6], [-2, -6, -4], [2, -2, -2], [2, -2, -6], [-2, 4, -4], [-17, 3, -6], [0, 4, 2], [12, 2, -2], [-4, 0, 10], [16, 0, -4], [0, 4, -2], [-28, -2, 2], [0, 2, 4], [-6, 0, -4], [-5, -4, 11], [11, 2, 1], [2, -4, 12], [-19, 0, -7], [16, 6, 6], [8, 6, 4], [3, -3, 10], [-16, -6, -6], [16, 6, 0], [0, 12, -2], [-18, 4, 0], [20, -4, 2], [5, -6, -1], [-12, -8, 2], [-10, 12, -4], [-2, -4, 0], [-4, 4, 6], [-15, -9, -10], [26, -2, 6], [19, -4, -1], [18, 2, 2], [11, -8, -3], [22, 2, -6], [-9, 1, -12], [-18, 4, 4], [12, 0, -10], [-24, -2, 6], [-11, -4, 3], [-1, -5, -2], [13, 8, -3], [-10, 0, 8], [-3, -5, 16], [21, 3, 2], [-30, -4, 0], [33, 4, -3], [0, -8, 6], [31, 4, -9], [-18, -8, -2], [3, -2, 9], [-14, 0, -8], [-9, -8, 1], [-26, 0, 0], [-20, -6, -12], [-32, 0, 0], [-3, -9, -8], [-9, 12, 1], [-2, -4, 4], [-2, 6, 10], [2, 6, -18], [3, -3, 12], [-28, 0, 10], [2, -4, 8], [-6, 8, -8], [13, 3, 14], [10, 10, -2], [-16, -4, -2], [0, -8, 6], [-4, -6, 20], [20, 4, -8], [-14, 8, -12], [13, 0, 5], [-6, 2, 16], [-10, 14, -6], [2, -2, 18], [-14, -4, 8], [-13, 8, 7], [8, -2, -4], [33, 0, -3], [-23, -8, -5], [-4, 8, 4], [-5, 7, -10], [2, -2, -2], [-27, 2, -9], [15, 0, 7], [15, 4, -1], [3, -11, 4], [-4, 2, -6], [40, 0, 2], [18, 8, 0], [-20, -4, 4], [20, 10, 4], [14, -4, 0], [3, 9, 8], [-5, -3, 6], [-14, 2, -14], [22, -2, -4], [9, 4, -11], [4, 8, 4], [-17, -1, -2], [-20, 0, 0], [4, -4, 10], [7, -7, 8], [7, 6, -3], [2, -4, 16], [23, -11, 6], [-31, 3, 4], [13, 4, 1], [22, 8, 12], [14, 2, 6], [-28, -10, 0], [24, -2, -8], [10, 0, -12], [20, 6, 14], [-20, -10, -4], [8, 10, 12], [22, 0, 14], [24, 10, 8], [12, -4, 14], [-22, 0, 8], [48, -2, 4], [18, 4, 16], [-10, -6, -10], [19, 1, 12], [-19, -14, -9], [2, -10, -8], [13, 11, 16], [-16, 12, -2], [-20, -2, 10], [-37, 5, -4], [28, -4, 0], [8, 6, -24], [30, 0, 12], [-16, -2, 2], [-9, -4, 7], [40, 2, -8], [-24, -4, -2], [23, 4, 19], [0, -10, 22], [-29, -1, 6], [-25, -7, -12], [-18, 4, 8], [8, 10, 0], [17, 3, 12], [2, -6, 22], [-14, 14, -4], [5, -11, 14], [28, 6, -12], [8, 2, 0], [-33, 2, -7], [-2, 4, 0], [-15, 20, -5], [8, 10, -16], [-20, -4, -20], [10, -8, -12], [-7, 7, -6], [-10, 10, -8], [-18, -8, -16], [24, -6, 12], [-13, -7, -8], [-29, -9, -18], [30, -4, 4], [-24, -10, -2], [-17, 16, -11], [19, 12, -13], [-28, 12, -4], [-20, 4, 10], [-10, 8, -12], [14, -6, 14], [-18, -10, -16], [-16, 4, 2], [54, 4, 2], [-25, 1, 6], [47, 1, -8], [6, 8, -16], [-56, -4, 6], [26, 10, 6], [3, 7, -10], [12, 4, -10], [15, 13, 2], [-4, -12, 10], [34, -4, 8], [22, 0, -16], [15, 12, 7], [24, -2, 0], [24, -2, 12], [11, 2, 1], [46, 6, -10], [8, -10, -8], [0, -2, -2], [-44, 0, 14], [-71, 1, -2], [-4, -12, 10], [18, -4, 0], [30, -6, 14], [-17, -16, -9], [-32, -4, 14], [-58, -4, -10], [-11, -12, 25], [-14, -10, -2], [12, 6, 8], [14, 14, 10], [26, 8, 4], [25, 3, 26], [21, -13, 4], [-32, 8, 4], [32, 2, -16], [-1, 14, -15], [20, 10, -12], [-5, -12, 5], [-54, -8, 0], [-22, -4, 16], [5, 0, 11], [2, 2, -18], [48, 4, -14], [0, -6, -8], [41, 12, 13], [13, 11, -26], [-50, 6, -2], [-18, -10, -2], [28, 8, 0], [25, 11, 4], [-20, 0, -4], [38, -8, 8], [-9, 12, 7], [-32, -4, -6], [-16, -10, 6], [40, 10, 20], [-22, 4, -2], [-8, -6, -12], [0, 2, -32], [32, 6, 0], [3, 0, 5], [40, 6, -20], [-36, -14, -16], [-42, 6, 2], [-36, 2, -16], [-51, -4, 1], [17, 3, -12], [22, 10, 22], [42, 4, -14], [24, 10, -18], [2, -22, -6], [36, -14, 12], [9, -1, -2], [-2, 0, 4], [38, 10, 26], [26, 14, 14], [-29, -8, -9], [23, -5, -10], [-30, -20, -14], [-16, 6, -8], [21, 3, 0], [-12, -6, 36], [-15, -10, 19], [-30, -4, -16], [4, 6, -30], [-42, 4, -8], [7, -3, -10], [-39, 16, -3], [-54, -12, -8], [-7, -12, 5], [17, -3, 30], [5, 15, 4], [2, -20, 8], [30, 6, 10], [-23, -10, -13], [53, 8, -1], [7, -3, 0], [13, -1, -18], [12, 16, -6], [27, 0, -13], [-8, 16, -4], [-7, 7, 8], [3, 1, -26], [-38, -2, -10], [4, -2, -16], [-13, 1, 20], [19, 2, 9], [35, -12, 11], [39, 12, 5], [13, 3, 6], [34, -6, -14], [4, -2, 4], [-26, 10, 2], [-32, -4, 22], [-44, 2, 12], [-27, -9, 6], [-3, 16, 1], [-40, 10, -4], [10, -18, -6], [-51, -5, 4], [16, -12, 10], [60, 4, 4], [-8, -2, 22], [-48, -2, -16], [-5, 22, 1], [2, 2, 12], [38, 12, -20], [-64, -6, 10], [2, -6, 20], [-23, -20, -11], [36, 8, -6], [-17, -12, -9], [48, -8, 18], [26, -16, 8], [4, -2, 8], [-29, -8, -9], [8, 0, -32], [-52, -14, 0], [28, -12, -12], [1, -13, 4], [-60, 0, 14], [-14, -20, 16], [1, 13, -18], [-11, -9, 12], [8, 16, -8], [20, -18, 16], [20, 8, -8], [62, -2, 2], [14, 4, 14], [-29, -1, -6], [26, 0, -22], [-37, -6, 5], [37, -14, -5], [-6, 6, 6], [-12, -26, -8], [16, 0, 2], [-62, 6, 2], [30, 0, 6], [5, 7, 4], [2, 0, 0], [-49, -4, 7], [42, 8, -2], [30, -18, 18], [-16, 22, -12], [-32, 6, 0], [36, 4, -4], [10, 10, -38], [32, 0, 10], [-40, 0, -8], [60, 6, -8], [6, 8, 12], [89, -1, 4], [0, -10, -4], [8, -20, 18], [-40, 18, -8], [23, -11, 10], [-46, 2, 2], [-43, 7, -4], [11, 0, 23], [56, 8, -18], [-12, -18, -2], [26, 0, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3520_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3520_2_a_bx();".
// 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_3520_2_a_bx(:prec:=3)
    chi := MakeCharacter_3520_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_3520_2_a_bx();".
// 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_3520_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3520_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, -5, -2, 1]>,<7,R![26, -7, -4, 1]>,<13,R![2, 1]>,<17,R![2, -5, -2, 1]>,<19,R![184, -31, -6, 1]>],Snew);
    return Vf;
end function;