
// Make newform 9075.2.a.z in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9075_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_9075_2_a_z();".
// 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_9075_2_a_z();".
// 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;
    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_9075_a();"
function MakeCharacter_9075_a()
    N := 9075;
    order := 1;
    char_gens := [3026, 727, 5326];
    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_9075_a_Hecke(Kf)
    return MakeCharacter_9075_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, -1], [-1, 0], [0, 0], [-2, -2], [0, 0], [0, 2], [2, 0], [5, 0], [3, 1], [-4, 3], [7, 0], [-5, 4], [5, 4], [1, 5], [2, -5], [-7, 1], [-3, 6], [7, 0], [-10, -1], [-8, 0], [-11, 4], [-5, 5], [-2, 6], [9, -3], [9, -4], [5, 9], [3, 1], [1, -3], [6, 3], [3, -4], [11, -8], [7, -10], [15, -6], [15, -10], [9, -18], [-12, -2], [1, 7], [8, -9], [-12, 13], [-2, -9], [-17, 4], [-4, 2], [3, -12], [-13, 13], [13, -2], [13, -11], [-2, 3], [0, -13], [21, -8], [15, -5], [-14, 15], [1, 13], [-1, 1], [10, 4], [-5, 9], [-13, 23], [-4, 3], [20, -1], [0, 14], [7, -5], [5, -13], [19, 4], [1, -18], [19, -4], [-2, -4], [23, -12], [8, -22], [-24, -3], [12, 10], [29, 2], [-21, 24], [13, -6], [-7, 18], [-2, -19], [-5, 0], [-19, 20], [-34, 8], [27, -15], [-5, -16], [19, -28], [11, -22], [1, -3], [10, -16], [20, -13], [14, 7], [16, -15], [-10, -15], [-1, -4], [21, -8], [-24, 15], [-5, -16], [26, -12], [-8, 10], [25, -11], [-5, 10], [-12, 16], [3, 4], [-3, 20], [7, -2], [0, -1], [-13, 20], [11, -33], [32, -7], [-8, -9], [-3, -5], [-25, 34], [-20, -1], [29, -16], [-21, 2], [22, -20], [-33, 0], [7, -2], [-16, 36], [17, 16], [17, -35], [1, 2], [-25, 7], [-4, 22], [29, 9], [21, 13], [7, 5], [10, -28], [-7, 8], [-6, -6], [16, -28], [21, 12], [35, -10], [35, -5], [33, -7], [0, -3], [-20, 0], [9, 14], [-36, 16], [-18, 10], [31, -13], [14, 2], [0, 17], [-15, -11], [25, -6], [41, -7], [-13, 35], [37, -10], [23, -4], [-32, -12], [-7, -16], [-9, 28], [-9, 20], [14, -34], [-15, -15], [2, 13], [14, -4], [-22, 3], [20, 2], [39, -24], [19, 16], [-28, 50], [-19, -2], [-6, -3], [35, -11], [0, -6], [-10, 9], [41, 5], [-44, 7], [17, -30], [-38, -5], [-19, 0], [-8, 0], [-21, 6], [16, -2], [14, 4], [-54, -2], [22, 15], [-34, 37], [-1, 19], [5, 35], [-13, -9], [1, -38], [-5, 9], [3, 6], [29, -13], [32, 0], [-3, 10], [25, -18], [47, -10], [-20, 12], [47, -9], [-10, -16], [1, -20], [-6, 17], [-18, 0], [21, 15], [33, -29], [-40, 39], [27, 5], [33, -32], [4, 39], [29, -19], [-34, 25], [12, -5], [-12, -4], [20, 0], [-46, -4], [18, -12], [-9, 28], [-10, -15], [2, 0], [16, -42], [38, -24], [27, -29], [-14, -8], [-28, 15], [36, -28], [44, -21], [-27, 18], [-36, -8], [22, 10], [-35, 44], [-13, -15], [37, -45], [32, -27], [-34, 12], [-12, 34], [20, -50], [29, 24], [-3, 5], [-36, -8], [6, -5], [7, -4], [-30, -26], [28, -62], [28, 26], [8, -1], [20, -21], [36, -8], [-37, 41], [18, -12], [44, 2], [42, -2], [-12, 29], [35, -46], [-38, -7], [42, -45], [-2, -4], [-50, 35], [6, 40], [-29, -22], [7, -20], [10, 4], [-74, 8], [55, -23], [-51, 6], [-33, 20], [-47, -12], [-10, 30], [-42, 6], [-16, 17], [-18, -5], [-51, 6], [-3, -10], [6, -13], [-10, -28], [-15, 24], [-37, -16], [61, -30], [-45, 34], [-52, 9], [41, -57], [-12, -7], [-18, 18], [30, -3], [19, -9], [1, -13], [-60, 22], [-17, -11], [-53, 20], [23, 6], [25, -31], [37, -34], [-3, 30], [11, 32], [36, 15], [0, -31], [21, 17], [11, 22], [-48, 50], [-28, 25], [18, -24], [-45, -16], [-18, 26], [21, 3], [-43, 10], [33, 18], [49, -16], [-30, 39], [-3, -2], [46, -2], [-3, -50], [-39, -30], [-26, -3], [-4, -18], [-11, 14], [25, 14], [20, 25], [12, -52], [-31, 36], [7, -35], [13, -7], [-42, 4], [7, 1], [59, -36], [27, -72], [22, 1], [-43, -10], [-1, -21], [33, -27], [-45, 55], [15, 5], [3, -32], [28, 1], [-27, 54], [42, 0], [-21, -24], [36, 2], [-33, 13], [35, 12], [-22, 33], [-32, 44], [8, -9], [-9, 22], [23, 11], [62, -10], [26, 22], [-37, 4], [35, -8], [-21, -14], [-7, 8], [-2, 34], [15, -63], [-6, 36], [-8, -35], [-25, -28], [33, 8], [10, 5], [-23, 5], [5, -3], [-32, -21], [-18, -25], [-27, -22], [-10, 9], [70, -16], [-14, -18], [22, -30], [41, -58], [58, -29], [0, -20], [-7, -19], [-31, 37], [57, -10], [56, -3], [7, 18], [-25, 29], [-69, 12], [-75, 14], [-57, 49], [7, -15], [-22, -24], [19, -9], [24, -51], [-28, -30], [-60, 64], [28, -26], [44, -6], [-1, -23], [-13, 40], [-22, 18], [-8, 1], [47, 10], [48, -9], [-22, -41], [39, 26], [-24, 12], [-11, 24], [-31, 16], [19, 16], [-50, 25], [65, 17], [12, -15], [28, -42], [-30, 12], [72, 5], [29, -58], [28, -54], [-25, -5], [-34, -3], [24, 16], [-60, -8], [13, -36], [-21, -8], [38, -27], [-2, -42], [41, -22], [-9, -50], [-66, 41], [33, -22], [48, -66], [-48, 40], [-22, 13], [-45, 49], [-9, 45], [57, 21], [77, -7], [-4, -48], [2, -2], [-21, 46], [3, -2], [24, -29], [11, 23], [52, -25], [-38, -20], [-38, 63], [-20, 25], [47, -20], [2, 55], [-20, 30], [-47, 91], [-25, 24], [40, -28], [-13, 36], [1, 42], [78, -11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9075_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9075_2_a_z();".
// 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_9075_2_a_z(:prec:=2)
    chi := MakeCharacter_9075_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_9075_2_a_z();".
// 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_9075_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9075_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1, 1]>,<7,R![4, 6, 1]>,<13,R![-4, -2, 1]>,<17,R![-2, 1]>,<19,R![-5, 1]>,<23,R![11, -7, 1]>,<37,R![-11, 6, 1]>],Snew);
    return Vf;
end function;