
// Make newform 9660.2.a.c in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9660_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_9660_2_a_c();".
// 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_9660_2_a_c();".
// 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_9660_a();"
function MakeCharacter_9660_a()
    N := 9660;
    order := 1;
    char_gens := [4831, 3221, 5797, 2761, 6721];
    v := [1, 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_9660_a_Hecke(Kf)
    return MakeCharacter_9660_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], [1], [-1], [4], [6], [7], [-1], [-6], [4], [-2], [9], [2], [7], [5], [7], [-7], [-2], [4], [-10], [-6], [16], [4], [-10], [-11], [-1], [4], [-10], [-18], [13], [21], [-11], [-12], [5], [-9], [23], [-7], [-5], [6], [-12], [10], [9], [3], [-12], [7], [-29], [8], [0], [9], [-18], [-6], [-17], [24], [3], [-31], [-14], [10], [13], [6], [24], [0], [-24], [31], [-1], [22], [15], [-20], [26], [0], [-10], [-8], [-11], [6], [-2], [16], [30], [-28], [-3], [24], [-16], [-26], [3], [-19], [-4], [-22], [10], [-4], [-14], [-7], [-10], [-16], [16], [24], [-16], [6], [37], [8], [-19], [-1], [36], [30], [-8], [45], [-4], [28], [-5], [-30], [40], [18], [-2], [-16], [-46], [20], [8], [-15], [-21], [20], [16], [-12], [17], [-37], [-12], [-4], [-48], [-5], [32], [40], [39], [34], [16], [29], [0], [-52], [23], [26], [12], [-13], [-8], [48], [20], [18], [7], [-3], [-2], [12], [0], [19], [-18], [-24], [13], [12], [-20], [-12], [32], [-44], [52], [50], [-35], [-44], [10], [-51], [32], [24], [5], [-54], [19], [30], [52], [-21], [-17], [46], [7], [34], [-18], [-6], [-35], [10], [-63], [-14], [-21], [42], [-25], [15], [21], [54], [-29], [32], [-31], [-56], [-46], [-20], [66], [-15], [-47], [14], [32], [-38], [-42], [-25], [-9], [10], [-20], [-59], [18], [-63], [-20], [26], [-8], [-26], [19], [-33], [-56], [22], [32], [-14], [23], [-6], [-12], [28], [-29], [35], [-20], [-64], [47], [-19], [-26], [6], [0], [4], [-21], [-60], [-18], [-36], [-1], [46], [-49], [42], [-30], [8], [59], [38], [10], [35], [43], [-1], [24], [-40], [20], [-61], [22], [0], [-53], [-31], [14], [14], [-30], [-53], [25], [-42], [-64], [-15], [50], [19], [25], [-9], [31], [-72], [-26], [-14], [-38], [54], [6], [24], [-50], [-56], [-30], [-25], [-40], [-18], [-49], [-68], [18], [-10], [38], [-58], [-54], [-79], [82], [-66], [37], [20], [40], [-4], [-34], [44], [-48], [5], [71], [66], [38], [18], [16], [-86], [74], [37], [16], [79], [-41], [-26], [-35], [74], [-45], [-56], [-15], [-45], [27], [-30], [61], [10], [-71], [-4], [-3], [11], [-27], [-61], [-2], [-52], [-63], [-85], [46], [-60], [-80], [59], [30], [33], [90], [-66], [-8], [48], [54], [-81], [59], [12], [81], [-6], [-28], [67], [54], [62], [-8], [-43], [-80], [91], [-70], [51], [6], [42], [38], [-32], [76], [-41], [-18], [-3], [64], [-55], [21], [60], [-90], [26], [96], [34], [-63], [77], [-34], [16], [-35], [41], [-22], [-72], [16], [-6], [3], [-62], [-76], [89], [13], [44], [-66], [-82], [-90], [-21], [84], [-78], [49], [-22], [35], [0], [2], [-24], [-22], [-84], [-48], [98], [31], [-28], [54], [-102], [-4], [-44], [40], [16], [-43], [30], [48], [-66], [16], [18], [48], [-4], [46], [29], [30], [-24], [-58], [55], [-25], [54], [-16], [3], [45], [-49], [-83], [20], [-76], [82], [85], [85], [5], [-61], [-76], [-15], [-31], [24], [68], [66], [-86], [24], [-58], [23], [52], [96], [6], [-85], [40], [64], [49], [16], [45], [-35], [37], [-34], [93], [-94], [-62], [1], [76], [-34], [74], [-52], [-89], [62], [7], [49], [60], [43], [-110], [37], [-49], [-94], [36], [20], [-42], [58], [-32], [-13], [-76], [9], [106], [-40], [46], [8], [4], [-26], [-84], [-49], [-3], [-77], [35], [-73], [82], [-112], [51], [-102], [2], [-97], [66], [80], [-63], [44], [84], [6], [-34], [-11], [4], [52], [26], [62], [-52], [-56], [86], [75], [78], [6], [27], [84], [65], [109], [-8], [-63], [-106], [1], [40], [-33], [-108], [6], [72], [14], [29], [74], [96], [-82], [-104], [25], [-17], [40], [46], [-92], [37], [64], [66], [116], [4], [30], [-69], [-121], [17], [18], [52], [27], [66], [-81], [2], [-115], [104], [118], [0], [62], [30], [-60], [-101], [70], [-124], [-3], [-84], [-30], [-14], [-37], [-51], [91], [1], [-106], [-67], [-79], [68], [8], [-14], [-58], [48], [-21], [8], [-74], [-95], [44], [-41], [36], [63], [-117], [44], [-75], [-3], [96], [-56], [52], [-84], [122], [34], [5], [1], [-14], [-28], [23], [60], [2], [-11], [-82], [36], [-2], [94], [117], [0], [-67], [-76]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9660_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9660_2_a_c();".
// 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_9660_2_a_c(:prec:=1)
    chi := MakeCharacter_9660_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(4603) - 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_9660_2_a_c();".
// 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_9660_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9660_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![1, 1]>],Snew);
    return Vf;
end function;