
// Make newform 9072.2.a.bq in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9072_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_9072_2_a_bq();".
// 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_9072_2_a_bq();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-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_9072_a();"
function MakeCharacter_9072_a()
    N := 9072;
    order := 1;
    char_gens := [1135, 6805, 3809, 2593];
    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_9072_a_Hecke(Kf)
    return MakeCharacter_9072_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], [0, 0, 0], [-2, 0, -1], [1, 0, 0], [1, -2, -1], [1, 0, 0], [-4, 1, 1], [1, 1, 1], [-1, 1, -2], [0, 1, 0], [2, -2, 1], [0, 0, 3], [-7, 0, 1], [0, 4, 1], [3, 3, 3], [-5, -1, 2], [4, -1, 2], [-1, -1, 2], [-2, 7, 1], [-2, -1, 2], [-1, 1, -5], [-3, -5, 1], [4, -1, -1], [1, -6, -1], [2, -5, -2], [-3, -1, 3], [11, -1, 2], [-1, 0, 4], [-9, 3, -3], [-2, 6, -4], [-5, 2, -1], [-8, 1, -4], [-8, 2, -1], [-1, 1, 1], [3, -6, -3], [0, -5, 4], [3, 1, 1], [0, -7, -1], [1, 4, -4], [2, 6, 1], [1, 3, 5], [14, 2, 5], [-6, 2, 3], [-10, 9, 0], [2, -7, -2], [3, -9, -6], [-1, 0, -6], [5, -6, -6], [6, -3, 0], [9, -10, -4], [-6, -6, 3], [-11, 2, 2], [-3, -7, -10], [-2, -5, -7], [-8, -2, 2], [-3, 5, -3], [-14, -1, -4], [11, 6, -3], [-2, 3, 3], [12, -1, 9], [-6, -4, -7], [-12, 11, 0], [12, 5, 5], [3, 6, -3], [-8, 7, 4], [-15, 6, -3], [8, 5, -1], [-12, -5, -8], [-15, -5, -3], [10, 6, 0], [-21, -5, 0], [-14, -3, -7], [-16, -2, -11], [12, 2, -1], [4, -7, 2], [2, 4, 1], [15, 3, -3], [-2, -10, 5], [-13, 4, 1], [-16, -6, -6], [-15, 3, 6], [-17, 1, -11], [-30, 3, 0], [-21, 10, -2], [10, 5, 2], [-10, 10, -2], [0, -3, -3], [-9, 7, 1], [22, -11, -1], [-17, 1, -2], [8, 4, 7], [-17, -3, -1], [-2, 7, 4], [-2, -6, 5], [20, -12, -6], [-9, 12, 3], [11, -9, -8], [-19, 10, -2], [-24, -1, 2], [-7, 0, 6], [-3, 5, -4], [24, 1, 12], [-11, -14, 5], [-3, 4, 6], [-12, 1, -14], [1, 3, 6], [-27, 2, -3], [-13, 13, 1], [-16, -2, 4], [7, -10, -1], [5, 8, -4], [25, -6, 0], [-7, -2, 1], [-15, 5, -10], [-19, 14, -1], [-11, -7, -10], [6, 1, 4], [3, -11, -15], [-8, -1, 11], [1, -7, -1], [-2, -9, 12], [1, 12, -3], [10, -7, 2], [8, -14, 10], [29, -4, -7], [10, 14, -10], [0, 6, -12], [14, 7, -2], [-20, 6, 3], [9, 12, 0], [4, -19, -4], [18, -9, -9], [-9, 5, 11], [-24, -7, -1], [-4, 10, 4], [15, -7, 14], [-5, -14, -4], [-2, -14, 7], [24, 7, 9], [6, -9, 9], [13, -9, 6], [-25, -3, 1], [36, 0, 0], [22, -13, -10], [9, 11, -1], [7, 16, 14], [-19, 9, -9], [-33, 7, 0], [-1, 2, -16], [12, -15, 3], [-20, 9, 3], [2, 10, 1], [18, -8, -11], [31, -9, -4], [-31, 8, 2], [-8, -13, -10], [23, -10, 11], [4, -5, 14], [12, 3, 3], [-22, 12, -5], [23, -13, -8], [-18, 8, 12], [8, -21, 9], [2, 13, -5], [-11, -16, -4], [15, -3, 18], [7, 3, -3], [-30, 16, 4], [26, -13, -1], [19, 1, 11], [-4, 19, 10], [-7, -2, -5], [5, 4, 16], [21, -4, 8], [21, -2, 10], [-9, 2, -21], [-16, 0, 3], [-12, -14, -9], [-11, 11, 14], [-2, -12, 9], [-17, 3, -6], [-33, -9, 9], [-26, 10, -8], [3, -1, -9], [-27, -3, -18], [1, 7, -1], [-24, -8, 1], [6, 5, 11], [51, 4, 1], [23, -9, 1], [-14, 27, 18], [14, -8, 1], [-2, 15, 12], [17, 16, -11], [-20, -2, -7], [-1, -23, 10], [1, -17, 1], [-9, 3, 9], [-2, 17, 17], [41, 4, 16], [3, 2, -6], [-23, 0, -24], [-2, 17, 14], [7, 12, -9], [7, -12, 5], [11, 6, 13], [-44, 2, -4], [-27, -3, 0], [6, -18, -12], [-15, -4, 11], [11, 10, -11], [29, -5, -11], [14, -24, -6], [47, 6, 7], [34, 3, 5], [22, 3, 0], [21, 1, 4], [0, -20, 15], [18, -1, 9], [-12, -21, -12], [-20, -11, 4], [10, -8, -20], [-20, 28, -4], [-12, 4, 1], [16, 6, -4], [-4, -15, -15], [23, -10, -11], [7, 21, 14], [25, -24, 3], [32, -20, 1], [12, -2, -11], [-24, 38, 8], [-18, 4, -14], [15, -11, 15], [-30, -6, -6], [-10, 28, 13], [-16, -16, 2], [7, 25, -4], [30, 6, 3], [39, -5, -9], [11, 4, -5], [24, -3, -12], [-17, 14, -19], [-4, -1, 8], [-19, 19, -8], [22, -11, -13], [-30, -7, -28], [-17, -6, -25], [-1, -3, -15], [-3, 0, -6], [11, -18, -21], [10, 2, 2], [21, -13, -12], [-8, 3, 3], [33, 13, 9], [-12, 7, 15], [-39, 17, -7], [47, 7, -5], [-8, 20, -7], [17, -6, -12], [7, 3, 18], [18, 7, 27], [-13, -12, -9], [23, -12, -12], [-16, 24, 16], [-62, 6, -6], [19, 5, 11], [2, 8, -5], [31, -2, 7], [-13, -1, -14], [18, -17, -17], [-11, 9, 9], [-11, -12, 18], [-22, -1, -7], [6, -17, -2], [9, -26, 10], [31, 19, 2], [-27, -21, 9], [6, -26, -2], [18, -8, -3], [-25, -10, 16], [25, 20, 17], [35, 5, -14], [-4, 5, -22], [-48, -11, 1], [-47, 5, 5], [-5, -9, 9], [44, -5, -8], [-16, 23, 8], [2, -11, 1], [23, -7, -2], [2, 12, -8], [-3, -15, -27], [-5, 11, -7], [13, 9, 18], [2, -28, -23], [-6, -1, -16], [-36, 26, 0], [50, -10, 1], [-23, 18, 12], [-31, 22, -8], [7, -1, -22], [-12, -19, 20], [5, 9, -5], [-17, 14, 2], [6, 21, -6], [-33, 21, 12], [-6, -15, -6], [13, -2, 2], [-29, -24, 9], [-24, 24, 9], [-14, 19, 17], [8, -8, -11], [-32, 23, -1], [-8, 15, -1], [-22, -3, 6], [20, 4, 10], [8, -8, 7], [-31, 14, 8], [18, 12, 12], [-17, -15, -12], [-11, 27, 9], [44, -11, 4], [3, -26, 16], [-43, -11, -8], [16, 9, 27], [-3, 5, -16], [-14, -15, -9], [-25, -16, 19], [17, -5, 4], [24, 22, -2], [-15, -18, -6], [-41, -6, 0], [-59, 5, 5], [-4, 18, -21], [31, -11, 2], [4, 4, 13], [-1, -11, -5], [24, 5, -13], [33, 5, -7], [1, 0, 6], [-6, 14, -3], [22, 2, 35], [24, -1, 8], [-36, -10, -27], [16, -29, -13], [27, 22, 7], [-32, 22, -8], [7, -10, 14], [69, -1, -3], [33, -43, -19], [6, -18, 24], [31, 21, 2], [33, 3, -6], [-7, -19, -22], [-28, -9, 10], [23, 1, -8], [-37, 16, 1], [-24, 2, -12], [19, 17, -7], [-8, 32, 14], [22, -21, -4], [-4, 4, 1], [37, -9, 5], [54, 10, 4], [0, -14, 10], [25, 25, 14], [7, 19, 22], [9, -15, -18], [-38, -13, -1], [-24, 15, -6], [-32, 17, 20], [2, -26, -20], [-17, 3, 3], [38, -4, 5], [-34, -6, -29], [-9, 32, 9], [47, -3, 3], [-2, 20, -19], [20, -26, 4], [-22, 15, 22], [-20, 14, -7], [-43, 3, 6], [-2, -35, 20], [-43, 22, 10], [-36, 40, 12], [38, 17, 20], [0, 10, 4], [-2, -15, 3], [-1, 16, 13], [-11, 6, 0], [16, -13, -10], [28, 11, -13], [10, -15, -12], [-38, -6, -19], [29, -22, 2], [-40, -24, 3], [-3, -9, 9], [-20, 5, -4], [36, -18, 0], [-20, -2, -5], [24, 2, 33], [82, 1, 4], [12, 9, 30], [-6, 18, -3], [-6, 5, 14], [31, -22, -13], [-25, -15, 4], [52, -33, -3], [46, 5, 26], [-2, 28, -20], [13, -32, 17], [64, -3, 8], [-9, 11, -13], [20, 7, 7], [-28, 4, -26], [-40, -8, -35], [-4, -13, 11], [-9, -30, -3], [22, -25, 8], [5, -2, 7], [44, -7, 8], [-19, -13, -26], [-2, 30, -13], [-14, -14, 7], [-34, 28, 22], [-16, 36, 10], [19, -34, 17], [30, -33, -9], [0, 0, -18], [-25, -17, -14], [14, 10, -5], [-22, -20, 4], [26, 15, 22], [39, -7, 8], [-31, 13, -8], [-20, 30, -6], [28, -14, 19], [19, 29, 5], [-29, 33, 3], [-70, 24, 13], [-53, 12, -4], [-34, 1, 19], [25, -6, 26], [-38, 14, -13], [35, -21, -14], [-24, -5, -2], [52, -19, 11], [-22, -22, 17], [-30, 13, 4], [-14, -10, 8], [14, -31, 7], [-81, 12, 6], [57, -3, 24], [-5, -43, 20], [-23, -11, -22], [24, 28, -11], [-19, 32, 25], [-10, 17, 14], [-60, -15, 15], [23, 3, 0], [-30, -16, -22], [55, 13, 5], [10, -2, -8], [-39, 9, -30], [-53, -4, -13], [6, -21, -12], [38, -20, 10], [24, -38, -12], [2, -3, -3], [45, -8, -11], [-36, 29, -9], [14, -4, -26], [4, -34, -16], [-50, 44, 11], [-20, -36, 6], [-17, -5, 2], [-39, -5, -17], [-36, -16, -12], [-92, 9, 2], [-48, -16, -31], [-7, 22, 22], [-12, 0, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9072_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9072_2_a_bq();".
// 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_9072_2_a_bq(:prec:=3)
    chi := MakeCharacter_9072_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(3457) - 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_9072_2_a_bq();".
// 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_9072_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9072_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-11, 2, 5, 1]>,<11,R![47, -19, -2, 1]>,<13,R![-1, 1]>],Snew);
    return Vf;
end function;