
// Make newform 9072.2.a.i 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_i();".
// 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_i();".
// 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_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], [-1], [-1], [6], [6], [-2], [-7], [1], [2], [-10], [-6], [-8], [10], [-8], [2], [0], [7], [12], [-15], [-2], [-1], [-12], [4], [-2], [3], [-6], [-12], [10], [-9], [-5], [-17], [14], [-3], [-14], [5], [-15], [-10], [-12], [14], [10], [5], [5], [9], [6], [-2], [4], [0], [1], [5], [-7], [-5], [4], [-13], [18], [-15], [-3], [-8], [4], [-3], [13], [-9], [23], [-24], [2], [-18], [-14], [2], [-24], [-10], [6], [-33], [-32], [2], [-6], [6], [-20], [22], [-21], [0], [7], [10], [-36], [-26], [0], [34], [1], [-11], [-3], [-23], [-12], [-34], [-1], [6], [-16], [32], [-30], [-12], [-29], [-14], [8], [-44], [23], [30], [40], [36], [5], [-12], [32], [-14], [2], [-20], [-30], [33], [-5], [43], [-4], [-12], [44], [34], [-25], [19], [-42], [-18], [-41], [-26], [-44], [12], [28], [31], [38], [-44], [-5], [34], [6], [10], [31], [20], [9], [-6], [0], [0], [16], [0], [50], [12], [-23], [-6], [20], [43], [14], [40], [26], [0], [28], [-19], [17], [4], [-42], [-33], [-28], [-14], [3], [-55], [6], [-18], [48], [19], [-30], [-59], [26], [21], [15], [13], [-24], [-4], [-50], [-48], [-58], [7], [-31], [-32], [-62], [-38], [45], [6], [-46], [-5], [51], [48], [44], [-54], [-8], [-15], [14], [0], [-47], [-16], [58], [20], [14], [30], [23], [40], [63], [-33], [-26], [12], [14], [65], [-69], [-6], [-4], [-9], [-32], [-30], [63], [-4], [48], [16], [0], [-10], [41], [-48], [-16], [20], [24], [-17], [-40], [72], [-20], [25], [23], [10], [71], [18], [44], [-66], [-28], [-30], [28], [28], [-56], [58], [30], [20], [2], [31], [-12], [37], [-28], [-64], [-49], [0], [58], [72], [2], [31], [-9], [0], [-8], [48], [66], [7], [24], [4], [70], [64], [-36], [-36], [34], [8], [-52], [-24], [-66], [-8], [52], [34], [38], [-75], [-48], [40], [42], [51], [-53], [63], [45], [-68], [-54], [30], [48], [71], [-67], [-28], [14], [-47], [-6], [53], [-60], [-44], [8], [-84], [-39], [-24], [-54], [71], [-48], [-89], [-76], [74], [-14], [86], [46], [-58], [-17], [-32], [-1], [-7], [34], [18], [4], [-13], [-78], [-43], [29], [-52], [20], [56], [-9], [-6], [-18], [-24], [32], [17], [70], [-23], [82], [-26], [62], [8], [-6], [15], [6], [-41], [-28], [-30], [49], [8], [50], [-22], [-17], [-83], [0], [-24], [-48], [6], [6], [-83], [21], [24], [32], [6], [12], [-84], [-48], [53], [-66], [0], [49], [40], [-56], [-21], [76], [-70], [54], [47], [-21], [20], [2], [-44], [25], [-79], [29], [-57], [-35], [-24], [16], [-37], [-74], [32], [26], [-65], [6], [63], [44], [-25], [32], [34], [-82], [90], [87], [17], [72], [48], [5], [70], [74], [37], [-15], [60], [36], [-42], [-32], [-46], [-87], [-3], [-64], [-94], [-18], [20], [78], [-49], [27], [63], [24], [-102], [-52], [-51], [43], [86], [-88], [52], [10], [18], [43], [-60], [-55], [68], [46], [34], [-75], [41], [-34], [57], [68], [99], [60], [-48], [26], [50], [-16], [-78], [88], [-40], [-53], [-36], [10], [-7], [-5], [-53], [0], [97], [94], [70], [88], [-83], [29], [-36], [-93], [-43], [-100], [-86], [50], [75], [-60], [-66], [80], [44], [-78], [-108], [-104], [-12], [86]];
    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_i();".
// 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_i(:prec:=1)
    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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9072_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 1]>,<11,R![-6, 1]>,<13,R![-6, 1]>],Snew);
    return Vf;
end function;