
// Make newform 5600.2.a.f in Magma, downloaded from the LMFDB on 01 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5600_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_5600_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_5600_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_5600_a();"
function MakeCharacter_5600_a()
    N := 5600;
    order := 1;
    char_gens := [351, 4901, 5377, 801];
    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_5600_a_Hecke( : Kf := Kf)
    return MakeCharacter_5600_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], [-1], [-3], [7], [-4], [0], [-5], [10], [4], [-10], [8], [-1], [4], [0], [-10], [-12], [12], [2], [-11], [-8], [6], [-1], [-16], [-17], [18], [1], [-12], [0], [4], [-2], [2], [-14], [5], [-10], [18], [7], [-9], [0], [12], [-1], [-26], [-14], [20], [-23], [7], [-9], [-10], [-8], [-11], [0], [-26], [22], [-2], [6], [22], [-2], [-25], [-7], [-21], [-11], [28], [-27], [22], [-20], [-22], [-24], [16], [3], [-8], [27], [2], [0], [20], [-19], [-5], [-3], [-22], [12], [-11], [-29], [34], [14], [24], [-41], [6], [0], [-34], [-15], [-36], [-2], [-23], [-25], [17], [-6], [0], [-4], [-37], [-22], [40], [-36], [6], [-44], [-7], [-28], [9], [3], [-2], [-7], [46], [42], [-16], [-45], [30], [39], [-12], [24], [11], [28], [14], [25], [-2], [24], [27], [11], [-16], [-16], [9], [7], [24], [49], [-28], [4], [-18], [17], [47], [39], [33], [-38], [13], [18], [-2], [-34], [48], [-46], [-30], [20], [-26], [-40], [8], [2], [56], [16], [8], [-55], [24], [-13], [14], [38], [26], [-34], [-42], [-12], [37], [40], [-21], [17], [34], [-60], [46], [27], [-38], [-24], [-60], [-13], [37], [-16], [34], [-42], [-10], [8], [6], [18], [28], [-36], [39], [-59], [54], [14], [28], [41], [-6], [-24], [29], [11], [38], [-57], [-1], [18], [-2], [26], [-16], [8], [11], [22], [-46], [50], [30], [18], [58], [-26], [-37], [58], [-2], [-56], [-38], [0], [-6], [10], [14], [65], [-42], [27], [-42], [-69], [-65], [-9], [60], [26], [-66], [40], [-47], [47], [27], [-62], [36], [69], [0], [56], [20], [7], [-66], [-19], [16], [-68], [42], [61], [12], [12], [30], [-8], [-36], [-66], [-5], [-74], [60], [-3], [21], [-40], [-34], [-56], [25], [50], [-60], [-15], [-38], [-68], [-72], [-14], [-34], [-1], [-24], [-74], [79], [-36], [46], [-47], [58], [51], [-75], [-32], [-30], [27], [19], [12], [72], [-76], [68], [45], [69], [42], [30], [76], [30], [34], [-7], [-48], [-37], [31], [18], [11], [-48], [61], [68], [60], [-64], [56], [20], [-24], [47], [-46], [-10], [-72], [50], [-26], [-53], [-13], [37], [86], [6], [14], [-46], [42], [-56], [5], [4], [18], [-82], [46], [-46], [78], [-51], [76], [-93], [-47], [-86], [-40], [-21], [-2], [48], [60], [-77], [-16], [20], [-70], [-22], [0], [-49], [-32], [-10], [-27], [11], [-15], [54], [-2], [88], [-52], [-54], [-70], [64], [42], [-69], [-4], [-44], [63], [-4], [-39], [-33], [-2], [24], [15], [-70], [-2], [-60], [27], [-51], [-42], [-83], [-78], [-90], [4], [54], [-74], [51], [-65], [53], [32], [-7], [85], [3], [13], [36], [-57], [-28], [42], [-62], [35], [-102], [-6], [-60], [16], [47], [44], [30], [14], [-1], [60], [-36], [59], [-42], [24], [12], [-20], [64], [39], [-16], [-46], [63], [77], [-14], [-78], [-32], [33], [51], [4], [2], [38], [42]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5600_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5600_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_5600_2_a_f(:prec:=1)
    chi := MakeCharacter_5600_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_5600_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_5600_2_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<11,R![1, 1]>,<13,R![3, 1]>,<19,R![4, 1]>],Snew);
    return Vf;
end function;