
// Make newform 8775.2.a.k in Magma, downloaded from the LMFDB on 08 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_8775_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_8775_2_a_k();".
// 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_8775_2_a_k();".
// 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_8775_a();"
function MakeCharacter_8775_a()
    N := 8775;
    order := 1;
    char_gens := [326, 352, 8101];
    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_8775_a_Hecke( : Kf := Kf)
    return MakeCharacter_8775_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 := [[1], [0], [0], [-5], [2], [1], [4], [3], [-6], [8], [-1], [-1], [-12], [-1], [8], [-2], [12], [11], [4], [-6], [-15], [3], [-14], [-16], [-7], [0], [7], [-10], [-5], [2], [8], [14], [2], [21], [-24], [19], [9], [-12], [-12], [6], [0], [-10], [-12], [-25], [12], [-16], [-12], [-7], [8], [-25], [8], [0], [-14], [-30], [-14], [10], [-6], [17], [-25], [-30], [1], [-16], [-29], [8], [-14], [12], [27], [-2], [-2], [-15], [24], [20], [8], [-19], [16], [24], [-16], [15], [-14], [6], [20], [-17], [2], [-19], [21], [-8], [-6], [10], [10], [9], [-8], [24], [-32], [36], [13], [-24], [24], [18], [3], [-25], [15], [2], [4], [-8], [21], [7], [20], [34], [38], [-17], [-25], [-9], [30], [-17], [16], [8], [4], [-50], [-6], [-30], [41], [9], [-6], [-40], [-20], [-8], [-17], [-14], [-45], [2], [-12], [-18], [-25], [7], [0], [26], [-46], [-47], [-30], [16], [21], [2], [28], [20], [25], [56], [-6], [6], [-23], [30], [-57], [-58], [-11], [-40], [-23], [-12], [-25], [34], [45], [-36], [30], [-30], [-1], [20], [42], [16], [-33], [46], [-61], [14], [-2], [-43], [-34], [-55], [28], [16], [-47], [2], [0], [35], [56], [58], [31], [8], [-54], [54], [42], [-20], [-29], [44], [-49], [-6], [-49], [-18], [-42], [50], [-43], [-29], [-42], [-36], [2], [43], [-43], [-19], [0], [22], [-61], [26], [18], [-40], [18], [-44], [-4], [30], [-60], [37], [19], [56], [46], [-34], [1], [-11], [-28], [-8], [-38], [-46], [-64], [60], [0], [-38], [55], [52], [41], [72], [47], [0], [-5], [26], [-66], [0], [-64], [-4], [63], [34], [-36], [-32], [17], [-62], [-9], [-30], [14], [62], [30], [-62], [36], [-48], [-75], [-60], [32], [-6], [21], [-12], [39], [13], [-78], [-4], [-4], [12], [-36], [-36], [-13], [29], [26], [32], [-73], [27], [50], [25], [57], [30], [-56], [0], [42], [54], [8], [-22], [18], [-32], [-57], [-28], [54], [-46], [14], [-24], [-35], [46], [63], [58], [12], [-53], [29], [32], [-35], [-24], [-43], [9], [12], [-59], [-2], [29], [-30], [-42], [-48], [17], [-24], [-59], [58], [-18], [-39], [-30], [19], [54], [-30], [37], [52], [-3], [-15], [-53], [-36], [-2], [-38], [78], [60], [-6], [69], [24], [-35], [-64], [-65], [32], [-37], [-18], [30], [17], [30], [-80], [33], [-17], [54], [2], [-13], [37], [62], [13], [34], [66], [-58], [-84], [-42], [-54], [-45], [42], [-58], [-72], [-57], [-71], [-28], [-87], [70], [32], [-29], [36], [40], [-47], [87], [-30], [-8], [62], [-30], [91], [-30], [8], [67], [72], [-67], [-44], [55], [39], [-55], [42], [83], [-16], [12], [64], [102], [55], [-56], [72], [5], [-24], [-2], [28], [3], [-36], [-54], [40], [5], [42], [-12], [6], [57], [66], [-102], [-52], [-41], [-30], [0], [47], [-22], [40], [-66], [7], [-64], [44], [14], [72], [-4], [-64], [-25], [-16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8775_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8775_2_a_k();".
// 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_8775_2_a_k(:prec:=1)
    chi := MakeCharacter_8775_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_8775_2_a_k();".
// 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_8775_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8775_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>,<7,R![5, 1]>,<17,R![-4, 1]>,<19,R![-3, 1]>],Snew);
    return Vf;
end function;