
// Make newform 6762.2.a.bf in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6762_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_6762_2_a_bf();".
// 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_6762_2_a_bf();".
// 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_6762_a();"
function MakeCharacter_6762_a()
    N := 6762;
    order := 1;
    char_gens := [2255, 3727, 3823];
    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_6762_a_Hecke(Kf)
    return MakeCharacter_6762_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+1)]];
    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], [1], [-3], [0], [2], [-5], [-4], [6], [1], [1], [-4], [1], [1], [1], [-9], [-6], [8], [-12], [-16], [0], [-10], [6], [12], [-4], [-3], [4], [-5], [-12], [-19], [13], [-11], [-12], [-15], [-19], [10], [5], [10], [-8], [8], [-18], [-9], [14], [-4], [27], [-21], [-7], [10], [-22], [3], [-4], [16], [-16], [11], [-13], [2], [11], [0], [18], [-18], [15], [16], [10], [-1], [-12], [-22], [23], [-8], [14], [-13], [10], [3], [17], [-7], [-10], [19], [6], [-6], [-26], [22], [-30], [28], [21], [-37], [15], [-40], [-19], [26], [-16], [0], [-41], [33], [2], [7], [-12], [34], [-12], [2], [38], [-14], [-28], [38], [-12], [-33], [-1], [-28], [-10], [-6], [9], [14], [44], [22], [-21], [26], [-20], [-18], [-25], [26], [20], [21], [50], [34], [-1], [-26], [20], [-21], [48], [-14], [19], [36], [34], [-44], [32], [14], [-10], [42], [-7], [-39], [22], [37], [-14], [-3], [46], [-27], [6], [-6], [-8], [37], [-47], [9], [-20], [20], [-30], [-36], [28], [35], [-27], [52], [-3], [5], [-15], [-51], [-42], [-32], [-4], [37], [-36], [32], [22], [6], [-8], [24], [7], [3], [-46], [44], [54], [12], [-26], [-11], [8], [-64], [-31], [12], [-53], [33], [53], [20], [32], [-61], [-29], [-22], [21], [4], [40], [0], [12], [-56], [-38], [48], [-7], [6], [36], [-37], [-18], [49], [-12], [49], [-52], [60], [24], [-25], [66], [-50], [-48], [21], [50], [-24], [25], [-9], [-27], [-18], [-68], [60], [28], [32], [-6], [-26], [-30], [11], [4], [-36], [-8], [-28], [-26], [-26], [12], [-37], [-24], [57], [-68], [-16], [-20], [-10], [-76], [19], [61], [-34], [63], [5], [-21], [-21], [-28], [-33], [51], [66], [-29], [45], [74], [66], [-2], [-74], [24], [-17], [52], [-42], [58], [16], [-68], [57], [-26], [-5], [-12], [1], [70], [-62], [-64], [27], [10], [44], [-9], [3], [-78], [-82], [32], [53], [-60], [34], [-20], [10], [37], [0], [25], [76], [-79], [74], [2], [73], [-58], [34], [-51], [39], [-38], [-26], [61], [41], [-39], [19], [-22], [37], [88], [-63], [60], [-82], [50], [88], [-86], [-6], [-44], [-75], [18], [-18], [22], [-68], [29], [89], [-34], [-76], [1], [57], [-44], [-48], [-27], [0], [-52], [-31], [-14], [53], [-74], [14], [47], [74], [-61], [30], [12], [0], [3], [-37], [22], [-16], [-9], [8], [37], [43], [32], [1], [11], [20], [-60], [18], [6], [-22], [-11], [-12], [42], [29], [59], [-8], [30], [-98], [0], [-1], [12], [-54], [32], [66], [-64], [-71], [73], [-26], [-98], [-90], [26], [0], [-6], [82], [-91], [-17], [-49], [71], [-80], [-50], [-54], [95], [-75], [72], [-74], [-53], [-10], [-27], [-3], [-49], [-28], [-62], [-84], [-14], [50], [91], [-86], [14], [20], [62], [41], [-36], [-44], [-68], [70], [-70], [16], [48], [78], [18], [-26], [-42], [2], [-96], [-74], [-74], [-28], [-45], [-93]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6762_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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