
// Make newform 6552.2.a.w in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6552_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_6552_2_a_w();".
// 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_6552_2_a_w();".
// 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_6552_a();"
function MakeCharacter_6552_a()
    N := 6552;
    order := 1;
    char_gens := [1639, 3277, 5825, 5617, 2017];
    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_6552_a_Hecke(Kf)
    return MakeCharacter_6552_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], [3], [1], [-6], [-1], [8], [-1], [-1], [5], [3], [12], [-10], [-11], [3], [1], [8], [2], [2], [-8], [11], [13], [7], [-7], [-1], [-6], [16], [-12], [14], [15], [20], [0], [-8], [10], [10], [8], [-16], [-12], [-7], [-24], [7], [14], [8], [-14], [6], [16], [-15], [1], [-12], [14], [-3], [24], [-1], [18], [-30], [21], [4], [0], [-11], [-22], [-4], [-5], [-27], [-30], [10], [28], [-18], [9], [16], [-17], [10], [-8], [6], [22], [34], [4], [26], [7], [-12], [-29], [-18], [-8], [-2], [16], [-10], [-29], [-20], [0], [6], [-6], [2], [17], [14], [-28], [8], [30], [-29], [28], [-42], [36], [-13], [-8], [32], [21], [37], [18], [15], [-33], [31], [26], [34], [8], [18], [-28], [-2], [-45], [16], [-10], [-34], [-31], [43], [9], [-14], [-16], [-7], [11], [-18], [34], [-6], [-33], [-10], [-12], [-23], [5], [43], [5], [-30], [-17], [18], [-5], [-4], [-42], [-40], [12], [42], [24], [-7], [-26], [-42], [-12], [-8], [30], [-36], [-8], [37], [29], [-40], [-33], [-12], [-15], [-50], [-37], [22], [42], [58], [-51], [-36], [-8], [-10], [-36], [-34], [30], [-11], [-8], [12], [8], [-12], [6], [-2], [-38], [32], [-6], [-58], [-13], [-42], [58], [3], [-17], [-14], [-19], [32], [46], [-3], [19], [13], [60], [-34], [-39], [33], [-30], [-60], [-32], [3], [28], [15], [-48], [-1], [31], [40], [-58], [59], [0], [16], [-4], [3], [9], [-59], [-8], [28], [24], [-23], [-56], [-44], [46], [42], [67], [-36], [-15], [-26], [-18], [18], [52], [56], [42], [22], [3], [62], [-36], [-63], [-54], [-36], [-46], [44], [-78], [21], [-28], [-23], [-55], [-44], [73], [32], [-6], [-14], [-50], [-14], [0], [27], [-52], [-56], [51], [-43], [61], [31], [-62], [18], [70], [6], [-3], [6], [-74], [-14], [-16], [-70], [-5], [-8], [-16], [64], [4], [-72], [-24], [6], [26], [-16], [-17], [-76], [-45], [-37], [84], [-40], [-52], [21], [52], [-46], [5], [1], [-20], [78], [36], [20], [-61], [-14], [12], [57], [-1], [35], [-54], [4], [28], [50], [-13], [80], [-74], [-38], [59], [12], [36], [-15], [-10], [-63], [15], [40], [4], [-58], [-56], [-60], [-8], [8], [-47], [-68], [10], [-30], [-23], [-26], [-33], [-46], [57], [4], [46], [50], [-18], [-24], [-70], [-26], [24], [-96], [24], [42], [72], [-27], [-46], [11], [-10], [68], [-46], [-66], [14], [51], [7], [6], [26], [34], [78], [-21], [-16], [98], [-17], [-73], [14], [-25], [-12], [38], [36], [93], [68], [-25], [28], [-96], [22], [-16], [86], [-89], [-26], [-44], [72], [21], [91], [-20], [-80], [-64], [12], [-34], [-51], [-48], [36], [-12], [-23], [80], [-66], [23], [8], [-71], [-79], [-58], [-39], [-49], [60], [-12], [-52], [61], [-45], [-52], [-17], [-87], [28], [71], [-36], [68], [68], [-50], [68], [17], [38], [-12], [-36], [-22], [-33], [91], [-84], [-59], [-70]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6552_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6552_2_a_w();".
// 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_6552_2_a_w(:prec:=1)
    chi := MakeCharacter_6552_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_6552_2_a_w();".
// 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_6552_2_a_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6552_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-3, 1]>,<11,R![6, 1]>,<17,R![-8, 1]>],Snew);
    return Vf;
end function;