
// Make newform 7935.2.a.h in Magma, downloaded from the LMFDB on 01 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7935_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_7935_2_a_h();".
// 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_7935_2_a_h();".
// 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_7935_a();"
function MakeCharacter_7935_a()
    N := 7935;
    order := 1;
    char_gens := [5291, 4762, 7411];
    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_7935_a_Hecke( : Kf := Kf)
    return MakeCharacter_7935_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], [1], [2], [-1], [6], [-2], [-3], [0], [-10], [3], [-4], [9], [-8], [-6], [0], [0], [-13], [-2], [7], [-6], [-5], [16], [14], [-12], [3], [14], [0], [1], [-12], [-12], [-21], [2], [11], [5], [-3], [-8], [2], [-12], [24], [19], [21], [0], [-26], [-12], [-7], [1], [14], [-18], [-13], [10], [1], [-13], [9], [-4], [-22], [15], [8], [-4], [-29], [-20], [-8], [22], [16], [-14], [2], [-13], [-32], [28], [-18], [14], [-24], [-10], [-20], [20], [30], [5], [20], [-27], [-1], [35], [-33], [27], [12], [-40], [-14], [-34], [24], [-1], [-6], [-18], [-11], [6], [-36], [-1], [38], [-26], [-35], [-34], [23], [-12], [-38], [22], [-27], [39], [8], [-28], [6], [-27], [41], [-14], [-20], [-4], [-3], [-17], [-13], [28], [-12], [28], [-15], [3], [-30], [28], [42], [7], [18], [-10], [-24], [16], [0], [3], [26], [-16], [14], [-13], [15], [-42], [-26], [34], [-15], [-5], [-19], [-46], [22], [-29], [35], [20], [-18], [36], [36], [-14], [38], [36], [-30], [-36], [-15], [-49], [15], [0], [13], [26], [-38], [22], [-56], [-54], [-42], [40], [22], [-46], [-30], [-52], [59], [15], [-34], [-37], [63], [-52], [23], [-36], [-3], [40], [60], [2], [42], [40], [3], [32], [8], [23], [-3], [56], [56], [-36], [-19], [26], [-56], [30], [8], [12], [24], [-25], [-61], [10], [-53], [-37], [6], [49], [-6], [-10], [59], [30], [-2], [-46], [70], [-9], [63], [-48], [-10], [30], [28], [-50], [45], [69], [-44], [44], [-13], [0], [-48], [-56], [28], [4], [12], [-32], [-7], [32], [18], [-22], [-48], [5], [-36], [-12], [-15], [60], [13], [26], [-53], [40], [63], [-49], [26], [60], [-63], [30], [-54], [42], [60], [-10], [30], [16], [-78], [22], [-38], [-71], [-44], [20], [13], [-33], [17], [-20], [-66], [50], [-20], [-20], [-31], [18], [70], [-12], [-11], [51], [-43], [64], [-5], [-76], [10], [-28], [0], [-14], [-78], [11], [23], [-6], [-68], [-4], [-28], [26], [46], [5], [-84], [48], [62], [62], [58], [-40], [-56], [-25], [72], [42], [-21], [31], [38], [38], [6], [-34], [28], [54], [-26], [87], [-72], [14], [59], [11], [60], [9], [34], [-36], [-10], [69], [-42], [0], [18], [-51], [-6], [31], [-12], [-49], [8], [-18], [70], [90], [-58], [-62], [-80], [15], [23], [-4], [-36], [-90], [-44], [0], [34], [-55], [58], [-27], [-56], [-74], [-28], [-21], [-3], [-22], [-26], [-10], [51], [-24], [76], [44], [-44], [-20], [4], [43], [-31], [44], [12], [-39], [-95], [38], [-76], [55], [74], [-86], [38], [2], [-30], [54], [22], [-36], [102], [-69], [14], [-10], [76], [82], [16], [51], [58], [15], [-12], [52], [-69], [93], [-87], [62], [-34], [-42], [72], [-70], [-49], [-48], [-50], [42], [-59], [16], [60], [34], [80], [8], [-17], [-83], [58], [-46], [-46], [-23], [104], [-72], [-29], [-4], [14], [56], [87], [4], [55]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7935_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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