
// Make newform 3010.2.a.b in Magma, downloaded from the LMFDB on 18 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3010_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_3010_2_a_b();".
// 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_3010_2_a_b();".
// 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_3010_a();"
function MakeCharacter_3010_a()
    N := 3010;
    order := 1;
    char_gens := [1807, 1291, 1121];
    v := [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_3010_a_Hecke(Kf)
    return MakeCharacter_3010_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], [1], [1], [3], [6], [-4], [-5], [-8], [-5], [-5], [-1], [6], [-1], [0], [-8], [-6], [0], [-5], [5], [6], [-6], [2], [-15], [8], [-15], [9], [11], [6], [-6], [-6], [-7], [22], [-12], [-18], [-1], [2], [8], [-19], [15], [-18], [-23], [1], [3], [6], [-10], [-2], [2], [-12], [13], [-6], [10], [9], [4], [17], [1], [10], [-27], [-17], [-27], [-12], [-9], [-10], [-21], [-21], [-24], [2], [-23], [2], [18], [-10], [-18], [-5], [6], [-15], [12], [-17], [13], [2], [11], [-20], [37], [2], [29], [-16], [12], [40], [16], [17], [16], [-12], [-32], [44], [40], [-16], [12], [-31], [35], [0], [38], [-32], [20], [-24], [-9], [12], [22], [-39], [-26], [-44], [10], [22], [46], [39], [-12], [11], [0], [-22], [14], [-34], [13], [49], [-34], [-14], [-36], [-36], [26], [48], [5], [-26], [4], [16], [17], [32], [-33], [-41], [2], [-24], [-40], [-18], [11], [49], [-22], [32], [32], [46], [-46], [17], [-24], [3], [21], [8], [18], [11], [-16], [29], [-48], [-8], [27], [-25], [42], [57], [18], [18], [-30], [21], [18], [-11], [38], [12], [57], [42], [12], [-27], [37], [-40], [-44], [22], [-9], [-15], [-10], [33], [54], [1], [2], [-29], [10], [-34], [-49], [-53], [-64], [-58], [12], [-23], [-62], [2], [-42], [2], [24], [-42], [-22], [-54], [22], [32], [-66], [51], [-10], [20], [12], [50], [58], [-6], [-35], [24], [-22], [48], [8], [11], [63], [9], [64], [-31], [28], [60], [-26], [-36], [-44], [20], [20], [8], [62], [-66], [46], [-52], [4], [-44], [-31], [26], [-60], [-8], [-37], [42], [8], [0], [8], [37], [-45], [14], [-12], [44], [40], [-30], [36], [58], [-45], [42], [64], [-38], [-24], [-2], [64], [-19], [-42], [-58], [17], [21], [15], [29], [-52], [4], [4], [-10], [16], [51], [0], [76], [-2], [-60], [61], [-35], [51], [-76], [10], [-72], [14], [-20], [73], [-51], [41], [-10], [-18], [-64], [-36], [61], [60], [-34], [25], [-5], [53], [-78], [-40], [64], [47], [8], [-55], [20], [16], [43], [-2], [27], [-55], [66], [49], [-10], [44], [-82], [-26], [-10], [-42], [-78], [-24], [60], [-38], [-76], [-40], [46], [-4], [56], [82], [60], [22], [53], [-6], [-2], [-44], [9], [30], [-43], [-15], [-91], [-88], [80], [8], [40], [-53], [-30], [-77], [16], [1], [66], [17], [-50], [26], [-68], [86], [-8], [14], [54], [8], [-62], [-6], [-21], [45], [-23], [90], [44], [-2], [42], [24], [-20], [42], [-51], [-10], [93], [-39], [19], [35], [-22], [-28], [3], [19], [7], [74], [-72], [6], [-50], [-81], [-75], [29], [-73], [72], [95], [6], [44], [62], [76], [-57], [-52], [58], [46], [18], [71], [66], [92], [6], [-82], [-76], [-82], [37], [56], [-30], [50], [26], [-46], [7], [-62], [-83], [4], [-19], [42], [56], [-90], [-1], [-93], [14], [42], [38], [68], [24], [-20], [12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3010_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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