
// Make newform 5700.2.a.o in Magma, downloaded from the LMFDB on 13 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5700_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_5700_2_a_o();".
// 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_5700_2_a_o();".
// 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_5700_a();"
function MakeCharacter_5700_a()
    N := 5700;
    order := 1;
    char_gens := [2851, 1901, 3877, 4201];
    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_5700_a_Hecke( : Kf := Kf)
    return MakeCharacter_5700_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], [-1], [0], [-4], [0], [1], [6], [-9], [-4], [8], [-3], [-4], [-6], [3], [-3], [11], [-10], [-9], [11], [2], [-6], [-15], [-10], [12], [-4], [3], [-4], [-6], [-16], [6], [12], [-19], [-24], [-4], [-7], [11], [3], [9], [-9], [-16], [12], [14], [-18], [17], [-16], [8], [15], [-22], [-6], [12], [-10], [-24], [-21], [30], [18], [11], [-1], [6], [-4], [30], [-28], [24], [-10], [33], [2], [-22], [6], [5], [-12], [-12], [8], [-22], [-16], [-21], [-24], [2], [-6], [14], [-6], [-10], [-3], [-10], [2], [30], [-33], [29], [-12], [8], [-12], [0], [-4], [24], [17], [24], [-15], [33], [14], [-10], [-28], [12], [9], [-9], [47], [-10], [-12], [0], [0], [-40], [44], [29], [18], [-7], [20], [42], [-31], [24], [36], [12], [-40], [32], [-9], [15], [-28], [-18], [35], [24], [-37], [-31], [-13], [-15], [2], [-31], [-18], [-13], [-51], [8], [21], [-30], [2], [-6], [-55], [36], [-10], [-9], [-25], [9], [29], [3], [20], [36], [-7], [48], [44], [-27], [11], [-18], [-19], [-30], [-24], [-9], [-31], [21], [42], [-24], [50], [26], [44], [-30], [33], [8], [30], [-22], [20], [0], [-1], [-12], [-16], [35], [-28], [45], [-22], [27], [-12], [18], [44], [-10], [-4], [48], [-16], [-6], [-10], [-6], [36], [-30], [-31], [41], [18], [36], [-6], [8], [44], [-10], [-60], [-12], [20], [9], [48], [-40], [11], [24], [11], [57], [9], [62], [-19], [-30], [48], [-42], [-4], [50], [30], [-49], [12], [59], [39], [45], [-28], [54], [41], [-76], [44], [-27], [-19], [6], [-25], [-24], [66], [33], [51], [-19], [-64], [32], [30], [6], [65], [-60], [-40], [6], [-67], [60], [-24], [-76], [-66], [36], [-61], [2], [-33], [-22], [62], [-15], [5], [38], [-54], [-34], [-69], [0], [-16], [-66], [14], [38], [-10], [11], [-22], [-16], [0], [80], [20], [-60], [-27], [59], [66], [-52], [-7], [6], [-46], [6], [53], [75], [24], [-60], [27], [-63], [-34], [-30], [-10], [-12], [-60], [32], [41], [-30], [-64], [51], [44], [-70], [-84], [26], [-84], [26], [78], [78], [45], [-22], [-24], [50], [-42], [57], [26], [36], [26], [-7], [-33], [38], [42], [-58], [-4], [20], [24], [24], [-82], [3], [17], [84], [-37], [-24], [-16], [-39], [-7], [47], [44], [0], [-21], [-16], [-21], [15], [-91], [-52], [0], [-6], [92], [62], [24], [32], [-52], [-78], [66], [-90], [-12], [-96], [17], [12], [-75], [-12], [-52], [20], [-66], [-64], [-52], [72], [-70], [66], [39], [80], [-70], [-21], [-6], [-49], [6], [8], [-33], [-60], [-61], [-66], [-70], [-96], [-88], [23], [-25], [-9], [44], [-54], [54], [35], [-81], [2], [-52], [-93], [32], [48], [-64], [72], [-22], [-57], [-63], [-64], [-46], [27], [20], [60], [44], [48], [-36], [-55], [-73], [-42], [81], [-46], [-66], [-57], [-21], [-28], [72], [-75], [-4], [-39], [57], [-48], [29], [42]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5700_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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