
// Make newform 9075.2.a.w in Magma, downloaded from the LMFDB on 20 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_w();".
// 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_w();".
// 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_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 := [[-1, 1], [1, 0], [0, 0], [1, 1], [0, 0], [0, -2], [-1, 1], [-5, 1], [1, 0], [-4, -2], [0, 6], [-3, -2], [1, -7], [6, -4], [1, 6], [2, -4], [11, 0], [-6, 2], [-6, -4], [5, -2], [6, -2], [-9, 3], [-4, -6], [-2, -4], [3, -2], [-5, 7], [-8, 4], [-6, -8], [6, 8], [-10, 0], [-3, 3], [-4, 2], [2, 10], [2, -12], [5, 9], [-14, 0], [6, 0], [-4, -14], [-2, 14], [-3, -11], [-3, -14], [-5, 12], [9, 2], [8, 8], [-9, -3], [8, -2], [2, -8], [-24, -2], [10, -6], [-11, -6], [-1, 11], [-18, 4], [0, 10], [-8, -12], [-2, -8], [-6, 12], [4, 14], [1, 7], [-2, 2], [-25, 5], [-9, -7], [-19, -1], [-18, -8], [8, -4], [-13, 10], [28, -2], [-18, 10], [10, 10], [24, 2], [-6, -6], [4, 6], [-24, -6], [-10, -8], [18, -4], [12, 2], [20, 0], [-12, 4], [-2, 24], [12, -14], [-10, -10], [-17, 6], [-27, 0], [-4, -2], [-2, 8], [-15, -9], [9, 12], [2, 6], [-18, -10], [-4, -26], [18, -12], [-12, -16], [16, -6], [2, 6], [10, -10], [38, 2], [6, -20], [-18, -16], [-22, 10], [-21, 15], [0, 8], [-9, 19], [8, 2], [-4, 8], [-11, 3], [26, 12], [7, -12], [-31, 4], [16, 14], [25, -8], [12, -2], [-14, -12], [42, 0], [-24, -10], [16, -16], [4, -16], [-34, 6], [-16, 12], [23, 4], [-32, 6], [16, 22], [-29, 4], [-6, 4], [-32, 6], [21, -6], [-10, -18], [23, 13], [-15, -10], [4, 4], [0, 12], [-18, -10], [-19, -1], [0, 22], [-8, 28], [-22, 8], [8, -2], [2, 4], [2, -2], [15, -5], [24, 12], [5, -9], [11, -15], [4, -14], [2, -12], [24, -8], [-14, -24], [-36, -8], [22, -2], [7, 21], [-12, -6], [-40, 8], [16, -22], [-24, 0], [16, 16], [8, 10], [6, -6], [37, -6], [-23, 15], [6, -14], [16, 0], [13, 7], [-17, -14], [5, 17], [-38, 0], [-39, -8], [4, 40], [23, 20], [-14, -20], [2, 32], [14, 24], [-14, 14], [14, 10], [14, 8], [-14, 6], [6, -16], [18, 18], [-14, 14], [-31, 13], [-26, -2], [5, -1], [-2, 0], [-4, 12], [4, -22], [-5, -8], [-24, 14], [4, 12], [30, 10], [12, 24], [24, 4], [46, 4], [30, 22], [26, -16], [-8, 28], [6, 32], [4, 12], [22, 30], [4, 44], [-34, -10], [-42, 12], [-3, 1], [44, -4], [-15, -23], [-14, 24], [-15, 12], [38, 12], [25, -14], [2, -10], [-2, 24], [6, 2], [-1, -1], [-36, 0], [-12, 16], [46, 0], [-4, -30], [63, 0], [-4, -12], [13, -26], [-33, 21], [63, -7], [-13, 14], [22, -14], [-18, 10], [22, 8], [-28, 32], [0, -10], [-16, -30], [-42, -14], [42, 18], [-9, 32], [-65, -3], [-34, 2], [13, -30], [47, -9], [-37, 13], [19, 27], [-18, -16], [-28, 10], [-49, 4], [39, 19], [19, 14], [-9, 0], [-5, 24], [21, 29], [30, -12], [-9, -20], [15, 11], [36, -18], [18, -40], [-27, -2], [-10, -24], [34, -4], [0, -44], [21, -3], [-16, -8], [14, 8], [0, 42], [24, 12], [-33, -14], [-2, -4], [34, -6], [10, -48], [59, -3], [26, 8], [-6, 10], [60, 6], [12, -18], [-52, -2], [6, -16], [28, 2], [-15, -1], [-27, 13], [-11, 18], [10, -24], [18, 4], [-19, -5], [-34, -28], [20, 10], [-3, 42], [18, -10], [-52, -2], [38, 22], [48, 22], [-12, -22], [-8, -24], [-2, 0], [-6, -44], [7, 44], [7, 30], [55, -11], [-8, -20], [-23, 17], [0, -24], [-9, -12], [-39, 27], [-6, -22], [-16, -20], [-12, 18], [26, 24], [-36, -8], [28, -18], [-39, 13], [-58, -16], [-61, -17], [19, 25], [-12, 8], [0, -6], [58, -12], [-41, -2], [-15, 16], [35, -36], [20, -28], [18, -24], [-28, 6], [-13, -23], [16, -48], [-56, 12], [-32, -28], [3, -32], [-32, -26], [49, -8], [8, 6], [27, 27], [-34, -24], [17, 13], [-22, 36], [24, -42], [61, -12], [-2, 40], [14, 26], [-6, 4], [-45, 1], [-10, -12], [30, -12], [-45, -9], [4, 14], [5, 5], [23, -4], [62, 20], [24, -18], [-3, -32], [-27, 21], [-5, 38], [-60, 4], [-28, 38], [4, 12], [18, -2], [36, 6], [-9, -4], [18, 28], [-22, -6], [-34, 20], [35, 19], [-29, 40], [20, 10], [37, -7], [-24, 44], [37, 13], [23, -6], [2, 2], [11, 1], [24, 8], [42, -20], [-5, 21], [-31, 36], [-30, -12], [-34, 18], [35, -28], [45, 23], [10, -36], [-58, -8], [-16, 0], [32, -10], [94, -4], [-83, 3], [-11, -25], [27, -20], [-28, 8], [12, 24], [-40, 32], [-40, 38], [28, -18], [12, 8], [0, -30], [-15, -35], [8, -10], [30, -16], [41, 34], [2, -8], [-47, -14], [55, 17], [24, -52], [-39, 14], [34, -18], [33, 26], [0, -14], [-8, -48], [-84, -10], [39, 11], [12, -24], [-2, 22], [-19, -21], [48, -38], [46, 24], [-6, -48], [-2, -42], [-25, 29], [7, -23], [6, -24], [-32, 18], [50, -10], [-53, -2], [6, -54], [11, -9], [25, -10], [25, 27], [-24, -20], [-2, -48], [-24, 42], [70, -6], [72, 8], [32, -16], [-44, 14], [74, 8], [25, 42], [28, -28], [21, -12], [36, -18], [-7, -10], [-69, -11], [-48, -40], [-10, 24]];
    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_w();".
// 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_w(: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_w();".
// 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_w( : 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, 2, 1]>,<7,R![-1, -2, 1]>,<13,R![-8, 0, 1]>,<17,R![-1, 2, 1]>,<19,R![23, 10, 1]>,<23,R![-1, 1]>,<37,R![1, 6, 1]>],Snew);
    return Vf;
end function;