
// Make newform 6600.2.a.s in Magma, downloaded from the LMFDB on 06 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6600_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_6600_2_a_s();".
// 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_6600_2_a_s();".
// 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_6600_a();"
function MakeCharacter_6600_a()
    N := 6600;
    order := 1;
    char_gens := [4951, 3301, 2201, 2377, 1201];
    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_6600_a_Hecke(Kf)
    return MakeCharacter_6600_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]];
    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], [0], [-3], [1], [0], [3], [3], [3], [-6], [-10], [-7], [7], [4], [9], [12], [7], [-4], [12], [-15], [4], [15], [6], [0], [-7], [-17], [-2], [-10], [-4], [4], [11], [14], [2], [12], [9], [24], [18], [-16], [-8], [9], [19], [1], [1], [4], [21], [20], [-20], [16], [14], [-3], [9], [0], [-10], [0], [22], [10], [-6], [-5], [-8], [11], [-17], [-21], [-4], [-24], [1], [0], [24], [24], [12], [26], [8], [10], [26], [2], [-14], [8], [22], [-14], [-24], [12], [1], [19], [-18], [30], [27], [-15], [-24], [10], [-34], [14], [-36], [12], [2], [2], [-24], [24], [-20], [-42], [1], [-8], [17], [2], [26], [17], [32], [-37], [-27], [26], [-13], [0], [24], [-32], [-18], [42], [-10], [-32], [10], [-19], [6], [-8], [25], [-36], [-38], [-41], [-12], [33], [-35], [-40], [-8], [-8], [25], [-8], [-44], [-2], [-30], [44], [-4], [33], [-10], [-39], [35], [2], [56], [-16], [-14], [0], [42], [-21], [-4], [40], [-14], [4], [-26], [-36], [58], [33], [-25], [16], [-2], [-13], [-31], [3], [-48], [41], [-2], [-27], [48], [14], [-36], [-24], [-38], [14], [6], [-34], [50], [-44], [-41], [-2], [-45], [30], [-54], [26], [-19], [26], [32], [-42], [-26], [36], [-10], [22], [-62], [36], [26], [-42], [-28], [-30], [-32], [30], [-17], [48], [-39], [-16], [-37], [56], [-21], [-34], [6], [42], [45], [44], [-18], [-48], [-10], [-45], [-38], [-13], [-15], [-25], [-29], [38], [50], [40], [-24], [38], [-54], [-46], [68], [-19], [-31], [72], [61], [-7], [-75], [-19], [-68], [36], [31], [11], [-19], [21], [-17], [-37], [-44], [-71], [9], [-48], [-32], [31], [-72], [36], [38], [-5], [-68], [-6], [42], [66], [51], [-32], [26], [-72], [49], [30], [40], [-26], [26], [-10], [82], [6], [5], [49], [65], [4], [-14], [43], [10], [-38], [47], [66], [-38], [28], [-66], [32], [-36], [-34], [60], [-3], [-23], [57], [-70], [23], [40], [63], [57], [50], [74], [18], [28], [42], [12], [39], [-46], [75], [21], [-44], [36], [22], [-67], [-37], [33], [-32], [-62], [-36], [59], [-58], [-74], [-40], [-21], [-42], [-67], [78], [1], [-10], [-51], [26], [-30], [85], [-10], [86], [-30], [-39], [-28], [-26], [-17], [6], [-73], [-49], [14], [42], [29], [77], [35], [-48], [30], [-12], [-14], [-44], [-39], [22], [-80], [52], [-91], [-37], [34], [29], [-68], [-73], [-49], [-12], [-85], [-32], [-26], [51], [-33], [48], [76], [67], [31], [64], [-80], [60], [40], [58], [75], [23], [-11], [-24], [-54], [16], [-30], [-40], [36], [48], [-11], [-62], [8], [41], [-2], [45], [-25], [80], [95], [-8], [27], [-18], [-16], [40], [-33], [54], [-22], [-61], [-80], [92], [72], [18], [77], [37], [6], [-30], [-8], [-7], [78], [-77], [51], [57], [38], [-30], [-64], [-78], [-98], [-78], [46], [98], [-3], [58], [-59], [0], [-69], [-77], [-90], [58]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6600_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6600_2_a_s();".
// 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_6600_2_a_s(:prec:=1)
    chi := MakeCharacter_6600_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_6600_2_a_s();".
// 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_6600_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![3, 1]>,<13,R![0, 1]>,<17,R![-3, 1]>,<19,R![-3, 1]>],Snew);
    return Vf;
end function;