
// Make newform 6011.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6011_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_6011_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_6011_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_6011_a();"
function MakeCharacter_6011_a()
    N := 6011;
    order := 1;
    char_gens := [2];
    v := [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_6011_a_Hecke(Kf)
    return MakeCharacter_6011_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], [-3], [1], [2], [0], [0], [2], [0], [0], [4], [4], [-9], [5], [2], [6], [0], [6], [-8], [5], [5], [-4], [7], [8], [-14], [-6], [-9], [-12], [6], [14], [-22], [3], [-15], [-12], [18], [0], [-24], [2], [15], [8], [-15], [10], [-6], [14], [-15], [-25], [2], [4], [18], [-27], [10], [-14], [4], [-7], [-6], [-26], [25], [32], [-11], [18], [-13], [-2], [5], [25], [-6], [12], [4], [3], [-27], [7], [-20], [20], [-25], [14], [2], [-6], [-34], [-25], [-25], [38], [-30], [20], [33], [38], [-2], [4], [31], [-4], [28], [27], [0], [-12], [-12], [-20], [-1], [-19], [-33], [10], [-38], [-17], [37], [31], [10], [24], [-41], [-24], [-40], [-2], [40], [-33], [-8], [-5], [-27], [22], [8], [-15], [11], [-4], [-31], [-30], [-20], [26], [20], [24], [8], [15], [-42], [-38], [0], [3], [-24], [-9], [-11], [-46], [22], [33], [43], [12], [0], [5], [-17], [20], [16], [26], [-22], [18], [39], [48], [4], [6], [-28], [-26], [-37], [-13], [22], [55], [-41], [-45], [33], [-45], [-24], [-44], [-11], [-48], [40], [-25], [-16], [46], [30], [42], [-4], [15], [-18], [24], [-15], [60], [26], [-30], [-4], [22], [38], [12], [-14], [-38], [-9], [-16], [30], [-17], [-44], [-50], [-34], [-64], [11], [-50], [-31], [26], [19], [-64], [-17], [-8], [-62], [-15], [-58], [-22], [31], [18], [20], [-4], [66], [-28], [-8], [-24], [-28], [33], [0], [13], [32], [0], [-26], [-37], [-53], [-40], [-24], [-50], [-58], [18], [66], [65], [27], [29], [-64], [-2], [9], [-25], [70], [8], [13], [10], [-30], [-60], [60], [-28], [-64], [-68], [-38], [48], [-60], [-36], [32], [6], [-42], [39], [38], [-34], [-78], [-40], [10], [59], [-3], [6], [-41], [64], [56], [1], [10], [-26], [52], [-9], [-10], [-43], [4], [10], [38], [-3], [28], [-26], [-44], [2], [38], [-12], [46], [-38], [-10], [67], [29], [48], [-7], [-58], [-8], [55], [13], [-10], [-49], [-65], [53], [60], [27], [5], [74], [37], [34], [-82], [0], [36], [79], [-64], [-4], [-80], [-37], [-16], [-49], [-27], [-90], [17], [-10], [83], [-34], [53], [-36], [-74], [-56], [-67], [15], [38], [54], [-12], [19], [-70], [-47], [-36], [18], [18], [-1], [66], [-47], [18], [-1], [-36], [60], [56], [-24], [28], [-30], [-3], [-21], [30], [21], [26], [39], [-8], [-36], [22], [-11], [95], [-15], [19], [50], [56], [-30], [64], [-48], [92], [-48], [-40], [44], [17], [-66], [17], [-95], [-12], [4], [46], [-36], [4], [-37], [-24], [-81], [0], [-47], [46], [-30], [64], [-58], [-2], [60], [-15], [20], [-69], [-59], [-6], [-40], [46], [57], [43], [-59], [34], [-76], [-57], [-22], [49], [-46], [-51], [-10], [82], [-27], [16], [-68], [-38], [36], [-30], [-26], [-83], [22], [89], [58], [99], [-3], [83], [66], [-85], [18], [-11], [68], [-50], [-19], [3], [24], [-69], [-56], [40]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6011_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6011_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_6011_2_a_c(:prec:=1)
    chi := MakeCharacter_6011_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_6011_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_6011_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6011_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>],Snew);
    return Vf;
end function;