
// Make newform 2300.2.a.f in Magma, downloaded from the LMFDB on 21 August 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2300_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_2300_2_a_f();".
// 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_2300_2_a_f();".
// 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_2300_a();"
function MakeCharacter_2300_a()
    N := 2300;
    order := 1;
    char_gens := [1151, 277, 1201];
    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_2300_a_Hecke( : Kf := Kf)
    return MakeCharacter_2300_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], [2], [-4], [-1], [0], [-4], [1], [-7], [-7], [4], [3], [-6], [13], [-10], [-8], [0], [-8], [13], [-11], [4], [4], [-6], [2], [10], [-4], [4], [10], [10], [-5], [1], [12], [-5], [-22], [-19], [-22], [-13], [8], [2], [-13], [16], [-10], [13], [13], [16], [16], [-8], [-2], [2], [15], [-19], [-14], [-8], [15], [8], [21], [-20], [21], [-22], [-14], [-8], [-28], [1], [28], [-18], [-9], [26], [-12], [-27], [25], [20], [0], [6], [8], [-6], [16], [31], [14], [29], [6], [30], [-22], [-14], [19], [13], [-18], [-28], [9], [4], [-6], [24], [-41], [-33], [41], [-30], [-15], [12], [38], [-35], [-1], [38], [24], [22], [12], [37], [-3], [-18], [-16], [-35], [0], [32], [36], [4], [-2], [-18], [2], [-23], [3], [0], [-10], [7], [-10], [39], [8], [30], [10], [-20], [-14], [40], [-49], [-44], [-10], [-28], [45], [50], [-42], [40], [-48], [-30], [-27], [42], [-39], [-12], [-26], [-42], [-14], [-45], [-31], [39], [-26], [12], [-20], [33], [-28], [24], [-34], [27], [-48], [-4], [-43], [22], [-13], [6], [-52], [42], [-32], [14], [12], [-21], [-40], [-7], [-32], [16], [-41], [42], [-33], [31], [-32], [-56], [-25], [6], [-47], [42], [-46], [40], [-18], [-64], [9], [24], [19], [-24], [34], [26], [66], [34], [-4], [-24], [-4], [-45], [-60], [8], [-23], [56], [-24], [-35], [-16], [37], [-65], [-61], [39], [15], [42], [62], [-12], [-38], [41], [-43], [-42], [-29], [-25], [12], [-39], [-6], [-47], [-21], [8], [15], [-58], [28], [62], [-74], [34], [-46], [4], [66], [76], [-36], [9], [-25], [8], [29], [-43], [-13], [6], [25], [-55], [6], [34], [54], [-60], [-22], [-58], [10], [18], [-41], [-60], [38], [-31], [-67], [52], [-50], [30], [-14], [-42], [-28], [-60], [-42], [-20], [9], [-39], [78], [6], [-78], [-47], [5], [52], [-2], [82], [24], [-37], [58], [56], [-38], [-72], [32], [-26], [-12], [-44], [-6], [-54], [-12], [22], [-16], [-19], [-10], [56], [35], [71], [23], [-26], [52], [60], [35], [4], [55], [-36], [64], [30], [-26], [69], [-8], [16], [59], [60], [62], [59], [5], [84], [-25], [-10], [10], [-81], [64], [6], [-80], [-6], [-37], [12], [-36], [53], [35], [-61], [-9], [-52], [-73], [74], [38], [-49], [82], [67], [70], [82], [10], [90], [-60], [43], [64], [-66], [-82], [-31], [-63], [14], [-38], [-88], [-6], [40], [-90], [21], [80], [58], [57], [-13], [-46], [-81], [-19], [-33], [-20], [50], [59], [-20], [-39], [-8], [80], [-29], [-101], [48], [-10], [-12], [-37], [46], [32], [56], [-37], [-38], [87], [-1], [14], [30], [24], [64], [-42], [-3], [4], [42], [-46], [14], [46], [92], [74], [11], [-95], [70], [48], [11], [-47], [4], [-55], [-46], [92], [95], [-61], [-48], [-14], [-4], [13], [-48], [-72], [-90], [-98], [58], [-22], [-8], [-36], [41], [39], [72], [14], [13], [41]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2300_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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