
// Make newform 6762.2.a.y in Magma, downloaded from the LMFDB on 20 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_y();".
// 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_y();".
// 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], [4], [0], [1], [3], [6], [-9], [-9], [-3], [7], [-4], [-6], [-10], [4], [-6], [8], [8], [-4], [14], [7], [14], [-5], [8], [3], [9], [7], [6], [-15], [-9], [16], [15], [8], [16], [20], [6], [19], [2], [-12], [-17], [-23], [5], [-12], [14], [-11], [-12], [-10], [-12], [5], [-19], [26], [21], [6], [-20], [20], [23], [6], [-6], [-15], [28], [-34], [5], [8], [-12], [23], [26], [29], [-1], [-31], [22], [-25], [0], [18], [-34], [38], [-16], [4], [-21], [21], [-23], [10], [25], [30], [24], [22], [13], [-13], [-30], [13], [-12], [34], [30], [-44], [6], [-42], [-28], [22], [24], [-15], [-13], [-20], [30], [12], [-29], [-40], [28], [-30], [25], [-6], [-2], [16], [15], [26], [24], [31], [-12], [38], [19], [-46], [-4], [5], [36], [-34], [7], [44], [16], [26], [40], [-40], [-22], [42], [-5], [-19], [40], [49], [-16], [-33], [-30], [7], [-30], [-38], [-6], [-7], [-33], [-13], [-8], [-36], [-6], [54], [24], [-53], [-49], [24], [-9], [-25], [-3], [-31], [34], [4], [24], [13], [54], [-36], [46], [38], [44], [-18], [47], [33], [58], [-20], [2], [-26], [6], [1], [14], [28], [-33], [40], [-43], [-21], [25], [-34], [-44], [-1], [-9], [-2], [-59], [28], [42], [-54], [-36], [-22], [2], [42], [9], [-14], [20], [31], [2], [-5], [52], [-23], [-52], [22], [-44], [23], [-42], [-64], [-32], [41], [-18], [-12], [-17], [-31], [-13], [-44], [0], [42], [44], [-60], [26], [32], [24], [-61], [-72], [54], [-50], [20], [12], [-44], [-32], [-47], [50], [29], [-60], [-10], [36], [56], [38], [-11], [5], [-30], [-7], [29], [-23], [-59], [-42], [-75], [25], [40], [-21], [-37], [-74], [62], [-8], [-64], [-30], [-65], [-2], [18], [26], [26], [-24], [5], [-26], [23], [-68], [-17], [-14], [-38], [22], [-5], [-2], [-22], [-15], [63], [-2], [26], [16], [-1], [-66], [-76], [-2], [-22], [39], [-24], [3], [-12], [39], [-34], [62], [-51], [-36], [-54], [43], [-59], [-84], [-10], [73], [53], [-23], [-13], [-4], [-9], [14], [-87], [-66], [82], [32], [-4], [14], [8], [-16], [11], [-60], [-54], [38], [50], [79], [-39], [-34], [-32], [71], [87], [-4], [-8], [67], [30], [84], [-27], [-72], [-21], [66], [-38], [-65], [-30], [-25], [54], [-44], [-84], [-41], [-45], [10], [0], [-13], [-76], [61], [-63], [16], [47], [57], [-22], [60], [-44], [58], [-26], [-73], [-40], [-76], [3], [39], [-44], [-40], [64], [-36], [13], [90], [84], [-16], [-32], [-58], [35], [99], [-42], [68], [-62], [-18], [16], [26], [24], [-95], [-87], [59], [-29], [46], [-54], [-6], [51], [-1], [-52], [86], [-61], [64], [-71], [51], [-9], [46], [38], [84], [-6], [-50], [-67], [-4], [-52], [20], [58], [7], [52], [-92], [14], [-12], [-30], [-50], [-30], [74], [90], [-40], [28], [16], [0], [12], [-72], [-88], [21], [-41]];
    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_y();".
// 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_y(: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_y();".
// 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_y( : 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![-4, 1]>],Snew);
    return Vf;
end function;