
// Make newform 9075.2.a.df in Magma, downloaded from the LMFDB on 24 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_df();".
// 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_df();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 1]];
    Rf_basisdens := [1, 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_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, 0, -1, -1], [1, 0, 0, 0], [0, 0, 0, 0], [-1, 1, 1, -1], [0, 0, 0, 0], [4, -2, 1, 4], [1, 2, -2, -2], [-2, -3, 0, 0], [1, -2, 1, 4], [-3, -1, -2, 1], [-2, 3, 2, 1], [-5, 2, -1, -2], [-5, 3, 1, -3], [1, -3, -5, 0], [3, -1, 3, 3], [-4, 1, 3, -1], [3, 0, -5, -1], [-9, 1, 0, 1], [0, 2, -1, 2], [2, 1, 2, -1], [0, 2, 3, -5], [-7, 0, 2, -3], [-2, -9, 2, 1], [-5, -8, 2, -1], [10, -5, -1, 1], [-7, 4, 1, 3], [-2, 1, -8, -2], [-2, -3, 0, 6], [-10, -1, -3, -4], [0, 3, 8, -3], [-8, -1, 3, -14], [-5, -1, -4, -4], [6, -6, -5, 2], [-9, 3, 3, 2], [0, 0, 7, 5], [-14, 4, -4, -9], [1, -1, -8, -7], [-1, 4, -6, -11], [-4, 8, 2, 2], [-2, 0, -1, -11], [12, -1, 4, 18], [7, -1, 8, 10], [-5, 1, 8, 5], [9, -2, -6, 0], [-11, 9, 7, 4], [1, -3, -2, -2], [-5, 11, 5, 3], [-8, 16, 6, -9], [-9, 6, -9, -7], [-4, -7, -1, -4], [1, 0, 5, 4], [5, 3, -1, -1], [-11, 0, 0, 10], [-5, 0, -4, -6], [-8, 5, -4, -12], [-11, 5, -5, -4], [-2, 5, 7, 4], [-15, 2, 1, -9], [-6, 9, -2, -3], [-5, -4, -6, -12], [-1, 6, 5, 5], [13, -3, 0, 20], [-2, -9, 1, 11], [0, -1, 9, -3], [3, -8, 8, 13], [-16, 10, -14, -18], [-3, -5, -7, 9], [4, -5, 10, 6], [-13, 8, -1, -4], [-4, 1, 2, 7], [11, -4, 6, -1], [9, 1, -1, 5], [9, 5, -3, 11], [10, -9, 6, 13], [-5, 3, -19, -8], [12, 5, 1, 9], [6, -11, 11, 15], [1, -8, -5, 9], [-10, -2, 5, -12], [-10, 0, 12, 8], [7, -7, -1, 7], [6, -7, -7, -3], [15, -8, 6, 9], [-4, -5, 10, -1], [14, -2, -3, 8], [-3, -8, -2, -15], [-3, 7, 0, -14], [18, -11, -6, 5], [-16, 8, 10, 11], [13, 10, 2, 5], [2, 0, 5, -15], [-12, 5, -4, -6], [-17, -4, 6, -9], [3, 7, 1, -14], [23, -5, -8, -1], [17, 8, -2, 6], [14, -4, -11, 6], [-30, 18, -9, -23], [-3, -1, -14, -9], [-13, -4, -9, 10], [4, 8, -8, -7], [9, -5, 7, 15], [-14, -1, -1, -23], [2, 9, -14, 2], [-18, 3, -8, -24], [18, 5, 6, 18], [1, -1, 9, 7], [10, 8, -10, 1], [8, -4, 12, 21], [-2, -10, -3, 9], [7, 10, 9, 7], [-11, 6, 9, 14], [-18, -13, 0, -7], [-1, 6, -18, -10], [31, -10, -1, 5], [-6, 5, 7, -16], [-10, 10, -12, -13], [27, 5, 2, 4], [20, -2, -4, 29], [13, -14, 8, 18], [17, -8, 0, 26], [-7, -5, 4, -2], [13, -13, 3, 24], [22, 4, -12, 7], [13, -18, -11, 12], [7, -8, 7, -3], [1, -4, -14, -25], [10, 17, 5, 2], [2, -4, 2, 26], [-9, 9, -20, -19], [-14, -7, -3, -1], [1, -5, 12, -10], [-5, 10, 1, 11], [-8, 10, 4, -26], [-4, 3, -20, -11], [-11, -18, 0, 8], [11, -7, -12, -8], [-23, -5, 12, -6], [-11, 5, -6, -4], [16, -9, -14, -2], [16, -12, 5, 15], [8, 0, -1, 6], [2, -14, -9, -21], [-7, 7, -2, 12], [-22, 9, -8, -21], [3, -18, 4, 4], [-16, 14, -5, -7], [31, -7, 7, 11], [12, 0, -11, -19], [25, -12, -15, -8], [-3, -17, 10, 13], [6, 1, 0, -23], [23, 10, 2, -5], [-3, -6, 13, -1], [3, -8, 12, 14], [16, -10, -4, 31], [-6, -1, 0, 0], [-29, 7, 0, -20], [15, 4, 13, -1], [-17, 10, 2, -28], [-35, 27, -3, -30], [-12, -8, -19, -6], [6, -4, -7, 20], [-4, -12, -18, -18], [-14, -1, 3, -18], [-29, 9, 3, 3], [-17, 9, 6, -18], [-8, -2, 14, 2], [23, -9, 4, 36], [15, -1, -1, -17], [23, -4, -5, 32], [-2, 9, 9, 9], [5, 1, 10, -14], [-8, 8, 8, 5], [-17, -7, 19, 11], [-25, 12, 8, 7], [19, 20, -10, -2], [14, 22, -12, 1], [-24, -24, 21, 0], [-7, 13, -15, -15], [-3, 11, 1, -5], [8, -4, -6, -27], [10, 20, -7, -12], [-31, 6, -8, -24], [12, -20, -3, 13], [-9, -5, -15, -23], [-21, 7, -7, -6], [-6, -8, 15, 20], [-34, 26, -10, -34], [32, -16, 7, 40], [-42, 21, -20, -43], [-3, -27, -6, 11], [-22, -18, 1, -16], [-6, 15, -10, -19], [-48, 3, -5, -26], [-44, 23, -5, -20], [14, -5, 31, 23], [22, -15, 12, 34], [6, 15, 9, -7], [4, -2, 13, 34], [12, -10, 3, 17], [-5, -3, 5, -33], [-22, 5, 16, 31], [-17, -5, 18, -22], [-31, 3, -9, 6], [-10, -2, -11, -24], [-5, 9, -3, 0], [-15, 22, -20, -21], [-4, -13, 3, -9], [-4, 7, -23, -19], [-1, -9, -2, 2], [-18, -3, -11, -42], [0, -13, -8, 7], [16, -20, 9, 28], [-22, 8, -7, 1], [7, 6, -9, -16], [-17, 12, -13, -10], [7, -18, -24, -6], [-5, 11, 0, 20], [4, 3, 2, 1], [3, -16, -13, 12], [-11, 4, 8, 0], [17, 15, -15, 14], [28, 0, 7, 11], [-1, -10, 6, 15], [4, 7, 22, 10], [-15, 24, 19, -9], [-3, -4, 19, -4], [15, -21, -19, 9], [40, -4, 18, 15], [-9, 7, 4, -25], [-28, 10, 11, -5], [0, 8, -23, -23], [20, 8, -20, -10], [-3, -1, 18, 4], [-11, -2, 24, -5], [-6, 10, 8, 36], [10, -17, 9, 24], [5, -7, 3, -15], [30, -23, 4, 37], [-1, -3, 4, -5], [12, -3, -7, -8], [-10, -6, -13, 0], [16, 18, 18, 1], [-8, 10, -14, -25], [2, -6, 7, 19], [-14, 11, 15, -18], [39, -1, -11, 12], [9, -11, -1, 19], [0, -1, 2, 26], [-23, -14, 2, -7], [3, 9, 31, 10], [-13, 3, 4, -40], [25, -7, -13, 3], [11, 2, 19, 43], [22, 3, 0, -31], [-4, -13, 32, 20], [19, -5, 4, -9], [-11, -11, -3, -12], [-18, 33, -11, -27], [-14, 5, -5, 14], [-5, -2, 2, 20], [0, 2, -10, -13], [-21, -22, -3, -16], [3, -3, -38, -3], [-38, 11, 0, -52], [28, 8, -16, -6], [-18, -6, -5, 15], [-19, 26, 16, -2], [14, 2, -12, -16], [-27, 5, 10, -32], [10, 5, 14, 8], [3, -15, -1, -10], [-22, -6, -17, 18], [-6, 11, -5, 20], [-3, -31, -1, 15], [-19, -9, -25, 12], [42, -14, 9, 24], [2, 2, 36, 5], [23, 7, -22, 1], [6, 6, 10, 5], [-34, 14, 14, 28], [-12, 0, -2, -45], [-10, 7, 17, -21], [3, 6, -2, -18], [28, -28, 0, 7], [17, 11, -10, 24], [-19, -16, -24, 9], [-7, 11, 11, -14], [9, 3, 12, 33], [-51, -5, 15, -9], [5, -7, -38, -29], [20, -20, -21, -10], [49, -5, 2, 2], [-5, 19, -2, 14], [2, 9, -25, 11], [48, 9, -5, 4], [24, -9, 6, 30], [28, 8, 20, 15], [49, -16, 15, 32], [13, 12, 29, 20], [-17, 12, 22, 15], [-12, 8, -4, 4], [52, -20, 1, 41], [20, 6, 36, 15], [14, -9, -21, -8], [-24, -2, -5, 17], [5, 23, 10, -9], [-23, 0, 9, 8], [-6, -5, -30, -20], [-4, 2, -41, -8], [1, 9, 20, -9], [0, -16, 22, 3], [-2, -21, -10, 25], [17, 11, 18, 5], [11, 2, 15, 51], [-10, -4, 24, 9], [-4, 11, 3, -42], [-45, -5, 3, -1], [-11, 16, -25, -28], [2, 20, 10, -11], [19, -2, 28, 6], [29, -25, -2, 24], [58, -11, 8, 30], [23, 21, 8, -5], [-28, 6, 33, 24], [-21, 17, 4, 11], [4, 33, 11, 7], [59, -13, 1, 39], [-46, -12, 17, 14], [-11, -24, 5, 15], [41, -5, 3, 35], [-51, 26, 0, -24], [22, -19, -9, 19], [12, -27, -8, 0], [3, -25, -8, 15], [25, -42, -20, 25], [-15, 24, 32, 4], [7, -41, -2, 9], [-15, 8, 1, -27], [-8, 30, 17, 3], [-44, -14, 13, 14], [10, -16, -3, -5], [-1, -44, 1, 10], [5, 7, 15, -5], [16, 35, -23, -2], [-15, 9, 6, 34], [18, -21, 3, 44], [36, -46, -13, 30], [48, -14, -2, -10], [14, -12, -14, 2], [-25, 24, 26, 7], [31, -43, -11, 35], [5, 1, -13, -2], [-20, 10, 25, 28], [-16, -15, 17, -25], [-16, 3, 14, -9], [4, -5, 31, 14], [-2, 2, 26, -12], [-2, -1, 0, 17], [-13, -9, -11, -45], [-31, 2, 35, 27], [-14, 16, 3, -24], [-9, -21, 6, 4], [15, -8, -16, 14], [14, 4, 22, 21], [43, 6, -4, -2], [-19, -1, 3, -31], [-40, 1, 14, -28], [-2, 1, 14, -32], [20, 1, -2, 14], [-2, -22, 18, -16], [-14, 12, -2, -30], [-29, 45, -12, -41], [-12, -34, 6, 17], [7, -21, -28, -6], [36, 11, -31, -17], [54, -27, 6, 24], [-41, -6, 16, -3], [26, -31, 27, 24], [-10, -10, 41, 39], [-32, -7, 0, 8], [63, -20, 15, 24], [-1, 40, -4, -23], [-48, 40, 19, -8], [-32, -9, -5, 7], [25, 16, 17, -4], [-20, -4, 7, -20], [40, -2, 31, 24], [23, 11, -10, 5], [-12, 1, -2, -14], [29, -33, 7, 14], [28, -13, 16, 24], [22, -9, -5, 2], [-35, -29, 25, 2], [-5, -14, -14, -16], [-26, -4, -23, -23], [-29, -5, 6, -42], [-2, 35, -2, -5], [31, 29, 4, 19], [-47, 42, 18, -10], [20, -13, -11, -16], [-41, -2, -18, -52], [33, 6, 7, 70], [27, -21, -9, 42], [14, -19, -8, 17], [17, -2, 19, 64], [-51, -12, -8, 0], [-18, 12, 24, -21], [40, -17, 2, 53], [45, -14, 7, 58], [72, -23, 13, 63], [5, -8, -4, -6], [-5, 13, 8, 30], [-5, -2, -13, -41], [-7, -22, 10, -3], [55, -6, 2, 21], [-24, 25, 12, -51], [28, -22, -29, -22], [3, -7, 2, -15], [12, -25, 27, 31], [-15, 43, -4, -20], [12, -19, 22, 20], [8, -15, -13, 4], [5, 0, 8, -25], [-36, 5, -30, -31], [-2, -22, 7, -24], [51, 8, 9, 8], [2, -2, 5, 41], [21, -36, -27, 25]];
    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_df();".
// 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_df(:prec:=4)
    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_df();".
// 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_df( : 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, 4, -4, -1, 1]>,<7,R![-5, 15, -10, 0, 1]>,<13,R![-359, 202, -16, -7, 1]>,<17,R![-59, 88, -6, -8, 1]>,<19,R![-239, -184, 6, 11, 1]>,<23,R![-5, 25, -25, 5, 1]>,<37,R![-155, 45, 65, 15, 1]>],Snew);
    return Vf;
end function;