
// Make newform 6762.2.a.l 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_l();".
// 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_l();".
// 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], [4], [-3], [0], [0], [-1], [1], [2], [-5], [-5], [-7], [3], [12], [2], [6], [-12], [10], [0], [4], [-4], [-10], [-19], [-14], [1], [4], [-1], [7], [7], [18], [-17], [-7], [12], [-17], [24], [-12], [12], [-2], [9], [-18], [-20], [-1], [-21], [23], [0], [-2], [5], [-16], [-10], [24], [-9], [-19], [-14], [-21], [2], [12], [-24], [1], [-14], [-14], [-25], [4], [-14], [-33], [4], [-20], [-3], [-26], [17], [9], [-21], [-2], [-5], [16], [-14], [-6], [18], [0], [-4], [-1], [3], [27], [-14], [-29], [-18], [-4], [30], [5], [27], [6], [13], [28], [-10], [2], [0], [-34], [34], [-24], [-2], [36], [-39], [-19], [4], [38], [-16], [-9], [-12], [0], [14], [21], [-42], [-10], [-32], [1], [-34], [0], [13], [-8], [14], [19], [-6], [-4], [-21], [-48], [-26], [43], [28], [-36], [30], [-16], [12], [-22], [10], [1], [-35], [28], [-47], [48], [-23], [54], [31], [-42], [38], [42], [-41], [3], [29], [-48], [-20], [-38], [6], [16], [-49], [-55], [60], [-21], [53], [21], [3], [-34], [52], [40], [-13], [-2], [44], [50], [-2], [-24], [54], [17], [31], [-6], [-20], [14], [-10], [26], [-61], [-6], [-20], [39], [56], [-15], [45], [-15], [-10], [-8], [-25], [-21], [46], [31], [-52], [-46], [10], [64], [38], [-46], [-18], [-51], [-18], [4], [41], [46], [-45], [12], [-29], [60], [2], [-20], [-25], [-14], [40], [48], [45], [-14], [-28], [27], [63], [9], [44], [-24], [6], [-56], [-40], [-26], [-12], [-56], [-55], [-32], [74], [-10], [40], [4], [44], [-8], [35], [-6], [55], [-20], [46], [-28], [16], [38], [1], [41], [-42], [33], [17], [63], [-47], [-30], [-13], [59], [-36], [1], [-25], [78], [-46], [32], [16], [42], [33], [6], [26], [-26], [30], [80], [-71], [58], [-47], [-76], [-11], [2], [18], [10], [65], [46], [14], [-15], [-21], [-14], [-30], [-60], [-79], [58], [68], [-66], [-30], [-29], [-48], [-69], [4], [-57], [26], [30], [63], [24], [6], [-43], [-1], [44], [-22], [3], [-23], [-55], [41], [-52], [-15], [82], [-51], [-30], [-10], [68], [20], [-14], [56], [-88], [57], [-84], [50], [26], [58], [47], [-9], [82], [-40], [57], [-23], [4], [28], [73], [46], [72], [81], [72], [-65], [46], [18], [-67], [42], [-63], [-10], [32], [-76], [69], [69], [18], [52], [-69], [-52], [13], [67], [-8], [59], [69], [6], [-60], [92], [86], [-74], [27], [-12], [-60], [-3], [71], [-68], [76], [8], [-12], [35], [-74], [60], [-56], [56], [-22], [-27], [65], [30], [12], [18], [90], [80], [-22], [-96], [53], [-15], [-67], [-1], [-38], [26], [-42], [9], [-15], [-12], [26], [33], [8], [77], [-31], [89], [54], [-30], [-84], [-90], [-86], [25], [-8], [-56], [-76], [-58], [-51], [-80], [12], [-14], [64], [54], [-34], [-82], [-102], [-82], [-76], [36], [12], [-76], [12], [-36], [56], [-45], [-53]];
    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_l();".
// 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_l(: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_l();".
// 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_l( : 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![-4, 1]>,<13,R![3, 1]>,<17,R![0, 1]>],Snew);
    return Vf;
end function;