
// Make newform 9075.2.a.p in Magma, downloaded from the LMFDB on 25 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_p();".
// 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_p();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [0], [-1], [0], [2], [-3], [-3], [1], [6], [2], [-3], [3], [12], [-1], [-6], [-3], [-10], [-6], [-7], [2], [7], [-6], [-14], [3], [-11], [-8], [-8], [-12], [18], [-19], [2], [-16], [4], [15], [-20], [-18], [-10], [-6], [9], [-15], [-5], [-3], [4], [21], [-26], [16], [14], [-22], [23], [-9], [24], [22], [20], [6], [0], [-6], [19], [-10], [-17], [-1], [-21], [4], [8], [19], [30], [-16], [-34], [2], [-6], [18], [-14], [-6], [12], [-14], [-24], [-12], [2], [-22], [10], [-37], [-15], [-6], [-6], [35], [13], [0], [-2], [-38], [22], [-32], [14], [-40], [-30], [8], [4], [-34], [-28], [29], [-8], [17], [14], [36], [-39], [20], [5], [33], [6], [23], [42], [0], [-32], [18], [4], [-32], [28], [-12], [43], [2], [-34], [-29], [32], [22], [31], [-20], [23], [-9], [-4], [-8], [14], [-41], [26], [24], [10], [26], [44], [36], [37], [-52], [-31], [-47], [30], [-10], [40], [-14], [0], [6], [-23], [-6], [-24], [38], [-20], [-16], [54], [32], [29], [-25], [32], [-16], [49], [37], [-51], [-16], [51], [24], [-1], [10], [-12], [4], [4], [-26], [-34], [18], [-44], [-20], [-32], [37], [-48], [-7], [36], [-40], [-38], [-43], [18], [32], [-40], [20], [-52], [-40], [30], [30], [36], [22], [8], [-18], [12], [14], [34], [5], [-32], [15], [-40], [11], [-4], [45], [48], [54], [-6], [-55], [-28], [-28], [30], [-18], [3], [32], [23], [-21], [-65], [37], [16], [-18], [56], [72], [-26], [-6], [22], [48], [-75], [-29], [30], [-23], [-49], [13], [-59], [-10], [34], [-37], [-53], [43], [9], [-53], [-15], [-50], [-57], [39], [-22], [54], [5], [-4], [24], [48], [-29], [24], [54], [50], [32], [1], [68], [-12], [-4], [-37], [52], [-50], [14], [70], [62], [-42], [-6], [29], [41], [31], [2], [-26], [-57], [-76], [-50], [27], [10], [26], [62], [-30], [58], [52], [24], [-60], [5], [7], [-11], [-16], [79], [-24], [59], [15], [-42], [76], [30], [-18], [-8], [2], [19], [-56], [-77], [-39], [20], [-18], [42], [69], [-55], [61], [-20], [-56], [42], [-33], [-72], [36], [-24], [-75], [58], [-85], [-22], [-5], [-38], [3], [-34], [-42], [21], [-26], [-16], [-76], [1], [48], [-18], [-25], [-14], [-23], [47], [2], [-42], [9], [27], [75], [-12], [-86], [-4], [-16], [90], [-61], [78], [-90], [2], [-65], [53], [-78], [-77], [-48], [-27], [15], [42], [33], [8], [36], [-1], [5], [80], [32], [89], [-77], [16], [-4], [-40], [-10], [-60], [-51], [35], [61], [36], [20], [88], [10], [58], [24], [-22], [-69], [46], [76], [59], [-58], [-39], [-73], [-72], [7], [-60], [17], [-74], [60], [-58], [-25], [84], [48], [81], [34], [30], [16], [-28], [-61], [101], [6], [-10], [0], [43], [-70], [3], [-21], [-57], [-52], [-78], [70], [84], [16], [36], [-50], [-48], [-25], [96], [67], [-34], [59], [27], [40], [60]];
    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_p();".
// 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_p(:prec:=1)
    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_p();".
// 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_p( : 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]>,<7,R![1, 1]>,<13,R![-2, 1]>,<17,R![3, 1]>,<19,R![3, 1]>,<23,R![-1, 1]>,<37,R![3, 1]>],Snew);
    return Vf;
end function;