
// Make newform 6300.2.a.x in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6300_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_6300_2_a_x();".
// 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_6300_2_a_x();".
// 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_6300_a();"
function MakeCharacter_6300_a()
    N := 6300;
    order := 1;
    char_gens := [3151, 2801, 3277, 3601];
    v := [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_6300_a_Hecke(Kf)
    return MakeCharacter_6300_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], [0], [1], [-1], [4], [-2], [-4], [-7], [9], [-2], [1], [-8], [-9], [-4], [-6], [-4], [4], [9], [-5], [10], [-15], [6], [-8], [10], [-6], [-4], [-4], [1], [-13], [9], [-18], [2], [-10], [3], [11], [20], [12], [16], [-8], [-4], [-10], [-20], [-17], [15], [8], [-4], [-6], [0], [22], [-19], [16], [0], [2], [-26], [15], [-18], [-24], [2], [-19], [-22], [-24], [-22], [-2], [4], [31], [-23], [-22], [27], [-28], [-18], [35], [4], [11], [-23], [12], [-27], [10], [33], [40], [-30], [-17], [-24], [0], [20], [-20], [-13], [-5], [40], [-4], [38], [-36], [3], [3], [4], [14], [28], [-6], [-40], [-25], [-35], [-1], [30], [45], [-23], [8], [30], [12], [-35], [-4], [0], [29], [-31], [16], [-27], [33], [28], [-46], [-26], [-4], [-16], [2], [-18], [19], [28], [-18], [-26], [-24], [30], [-36], [-9], [24], [40], [-7], [4], [40], [26], [26], [54], [23], [-6], [-10], [-11], [-33], [-34], [42], [28], [4], [14], [-33], [-34], [54], [1], [-52], [24], [9], [-59], [26], [36], [-54], [-36], [-21], [40], [24], [33], [58], [37], [-28], [-49], [-6], [-19], [20], [13], [2], [-58], [14], [-55], [42], [44], [18], [19], [44], [25], [-38], [-19], [46], [7], [14], [5], [10], [14], [13], [-41], [-10], [-33], [36], [65], [-47], [12], [-6], [-30], [42], [50], [60], [-56], [20], [-6], [36], [35], [0], [-35], [6], [31], [-36], [-6], [-26], [47], [28], [-23], [-67], [41], [-18], [63], [37], [28], [70], [46], [-3], [-14], [-9], [-35], [-10], [-48], [63], [20], [-14], [-20], [-5], [35], [28], [21], [52], [-42], [59], [64], [14], [-22], [78], [40], [24], [-14], [0], [-24], [-46], [24], [-60], [-19], [-6], [12], [-76], [16], [11], [58], [-2], [2], [48], [51], [78], [-49], [21], [-44], [-20], [-24], [81], [42], [62], [-13], [-34], [-41], [14], [-66], [-40], [52], [-62], [2], [27], [71], [43], [-20], [-6], [-49], [62], [73], [42], [-69], [26], [20], [-12], [-4], [10], [-22], [-46], [-31], [67], [29], [-70], [81], [24], [-3], [-46], [-6], [-2], [21], [60], [-63], [-18], [-78], [44], [-20], [-63], [-38], [-54], [-12], [1], [-29], [-50], [-23], [54], [-63], [-39], [-6], [33], [50], [-58], [-88], [72], [-23], [-24], [68], [-74], [-86], [-79], [16], [-35], [29], [11], [-54], [-65], [-80], [-70], [-74], [31], [-62], [-20], [75], [16], [-6], [58], [-66], [-64], [3], [10], [60], [-77], [-36], [-74], [46], [3], [-5], [11], [-90], [-59], [-38], [-22], [47], [-28], [-37], [86], [92], [78], [2], [-21], [77], [-17], [2], [-56], [71], [34], [31], [48], [85], [-26], [-29], [-14], [11], [-11], [-96], [-56], [20], [-99], [-8], [19], [49], [84], [-36], [52], [51], [-34], [-48], [26], [96], [-43], [72], [73], [-51], [-76], [0], [-50], [-84], [-106], [-82], [66], [-48], [-24], [-46], [42], [31], [18], [-62], [-66]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6300_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6300_2_a_x();".
// 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_6300_2_a_x(:prec:=1)
    chi := MakeCharacter_6300_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_6300_2_a_x();".
// 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_6300_2_a_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6300_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![1, 1]>,<13,R![-4, 1]>,<17,R![2, 1]>,<37,R![-1, 1]>],Snew);
    return Vf;
end function;