
// Make newform 7872.2.a.bc in Magma, downloaded from the LMFDB on 02 August 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_7872_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_7872_2_a_bc();".
// 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_7872_2_a_bc();".
// 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_7872_a();"
function MakeCharacter_7872_a()
    N := 7872;
    order := 1;
    char_gens := [3199, 1477, 5249, 5377];
    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_7872_a_Hecke( : Kf := Kf)
    return MakeCharacter_7872_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], [2], [-4], [-5], [4], [-5], [2], [4], [-1], [-5], [7], [-1], [-7], [7], [14], [12], [3], [2], [-3], [13], [-2], [2], [18], [-14], [-3], [7], [-10], [8], [-6], [12], [-12], [-1], [4], [10], [0], [22], [9], [0], [2], [25], [8], [20], [-20], [-10], [6], [12], [-16], [-3], [18], [6], [8], [7], [14], [3], [-23], [-16], [-27], [-19], [15], [-17], [23], [-17], [4], [16], [-3], [22], [21], [15], [-7], [-6], [-24], [-25], [-11], [16], [9], [6], [-12], [-24], [7], [-32], [-8], [16], [-5], [14], [24], [40], [-8], [30], [-12], [-6], [13], [19], [-22], [20], [27], [11], [-9], [0], [-38], [-20], [-35], [45], [0], [36], [24], [33], [-39], [32], [-30], [8], [22], [-42], [-19], [-5], [3], [-40], [12], [-27], [0], [-10], [34], [2], [-28], [-36], [2], [18], [17], [42], [25], [-41], [-10], [-38], [26], [20], [-33], [31], [17], [-6], [26], [-1], [44], [-6], [-5], [-13], [12], [18], [12], [-3], [18], [57], [0], [-6], [33], [-32], [-40], [44], [-45], [32], [50], [26], [44], [-14], [25], [7], [-6], [-52], [-20], [-55], [30], [24], [34], [56], [-21], [-4], [-3], [-22], [-18], [-26], [30], [-17], [30], [-40], [2], [-10], [-30], [2], [12], [-24], [-67], [-21], [-12], [52], [-42], [0], [28], [38], [36], [2], [-21], [4], [53], [50], [-10], [51], [-27], [-16], [-7], [-36], [15], [-68], [-61], [-32], [-8], [3], [-19], [36], [12], [39], [38], [-58], [-29], [-29], [-10], [6], [22], [-70], [-22], [-24], [48], [14], [-56], [15], [36], [-22], [24], [32], [-14], [-24], [-9], [60], [-52], [2], [-1], [24], [38], [8], [-53], [13], [38], [-23], [-44], [42], [27], [-42], [-18], [-38], [22], [-33], [-34], [47], [21], [14], [-16], [-10], [-35], [15], [-6], [60], [51], [24], [43], [-37], [5], [-42], [48], [-39], [-16], [-38], [-69], [-21], [4], [58], [-38], [-60], [47], [34], [-58], [-60], [-57], [-75], [42], [21], [36], [-10], [69], [-52], [-26], [-28], [-36], [18], [26], [-1], [-3], [-67], [82], [12], [15], [72], [78], [33], [26], [-24], [-5], [-42], [-22], [-34], [-72], [14], [-27], [20], [-38], [-10], [48], [80], [-10], [20], [-32], [-13], [30], [-52], [42], [40], [-12], [19], [31], [44], [94], [-76], [-19], [48], [-20], [10], [94], [4], [-36], [-66], [-5], [-16], [-20], [-88], [-5], [27], [-91], [-80], [22], [18], [28], [-66], [24], [-23], [-6], [-15], [4], [-22], [36], [-82], [-57], [-95], [92], [-8], [76], [51], [-88], [78], [-48], [86], [-74], [-31], [42], [3], [84], [15], [68], [82], [-50], [-20], [12], [95], [-56], [-54], [-19], [0], [52], [64], [76], [2], [-58], [-85], [90], [5], [50], [41], [-82], [0], [-10], [-37], [57], [-46], [92], [-13], [-12], [-60], [48], [-46], [-16], [66], [-42], [19], [-66], [72], [-22], [-14], [-91], [49], [32], [-27], [29], [10], [25]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7872_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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