
// Make newform 6762.2.a.bs in Magma, downloaded from the LMFDB on 19 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_bs();".
// 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_bs();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [-1, 0], [1, 1], [0, 0], [-2, -1], [3, -1], [-4, -2], [-2, 3], [1, 0], [3, 5], [-2, -1], [-9, -1], [1, -2], [-3, -4], [9, 1], [8, -1], [4, -3], [2, -7], [2, 8], [6, -7], [-2, 3], [4, 7], [6, 6], [-8, -3], [1, 4], [-2, -1], [7, 9], [4, 4], [-19, -1], [1, 6], [9, -9], [16, 3], [-1, 10], [15, 4], [8, 9], [13, -5], [16, -5], [-12, 2], [12, 6], [-2, -2], [-1, -4], [-2, -6], [-2, 0], [-11, 8], [11, -9], [-7, 9], [-14, -5], [6, -4], [13, -6], [12, 4], [-20, -3], [16, -4], [1, -16], [-9, 0], [8, 8], [-11, -9], [2, 15], [4, 3], [12, 1], [-1, -20], [4, -1], [-2, 6], [3, -12], [-6, 0], [6, 4], [11, -9], [0, -10], [-2, 3], [-3, 2], [12, -2], [27, 6], [9, 17], [9, -9], [6, 0], [-9, 0], [16, -11], [18, 0], [12, -6], [-4, -2], [14, 7], [18, -10], [-15, 3], [15, -9], [-5, -10], [10, 1], [7, 2], [2, 18], [4, 8], [-6, 23], [25, 9], [1, -26], [2, 12], [-1, 9], [-18, -6], [-2, -24], [30, 7], [12, -3], [-22, 2], [-2, 12], [0, -16], [6, -12], [24, 0], [-13, -4], [-13, -10], [-28, 8], [26, -10], [10, 11], [5, -16], [16, 13], [0, 8], [-10, 6], [-21, 3], [6, -16], [-16, 9], [36, 5], [35, -4], [14, 14], [24, -2], [-13, 1], [-14, -1], [22, -10], [3, 22], [14, 20], [14, 2], [11, -20], [16, 14], [-22, -14], [-21, 7], [6, -16], [12, 9], [-20, -9], [4, -24], [4, 5], [4, -18], [4, 8], [-43, -8], [37, -9], [-18, -3], [-5, 11], [2, 7], [29, 2], [20, -18], [9, -1], [14, 24], [6, -18], [-6, 13], [13, -5], [-9, 0], [7, 16], [16, 4], [28, 10], [-18, 22], [12, 1], [0, -34], [11, -2], [29, 15], [-16, 30], [47, -6], [5, -4], [9, -29], [-19, -12], [-4, 8], [-20, 2], [22, -28], [-45, 6], [18, 1], [-8, 22], [2, 2], [6, 4], [16, 22], [-20, -13], [-21, 19], [5, -31], [-22, -18], [8, -18], [-22, 2], [4, 39], [6, 12], [-33, 5], [6, 23], [0, -6], [1, 32], [8, 8], [25, -12], [21, -13], [3, 7], [2, -23], [-4, 2], [-1, -18], [-15, -25], [-34, 10], [-21, 12], [-6, -10], [-34, -19], [-4, -33], [4, -6], [-40, 3], [-6, -44], [-28, 7], [17, -17], [26, 8], [-36, -6], [61, 1], [30, 16], [-21, 24], [20, 8], [3, 23], [-38, -6], [0, -37], [6, 8], [31, -20], [-46, -16], [-28, -23], [16, 12], [-33, 17], [4, 18], [32, -14], [-55, 2], [-21, 19], [3, 43], [28, -19], [-16, -38], [40, 1], [16, -10], [32, 20], [22, -10], [-26, -25], [20, 17], [5, -39], [-38, -8], [34, 17], [-24, -9], [52, -10], [30, 27], [-26, -5], [8, -26], [-51, 6], [42, -9], [41, -8], [-10, 40], [-12, -17], [54, 6], [20, 11], [18, 29], [-31, 32], [9, 23], [2, -44], [-5, -20], [-3, -38], [49, 13], [5, -15], [-48, -13], [-5, -15], [-23, -14], [-36, -1], [15, -10], [-7, -5], [-18, 0], [18, -2], [-18, 7], [28, -1], [-8, -37], [-25, 11], [-22, -9], [-6, -28], [-30, -12], [34, 1], [8, 18], [-5, 38], [-26, -16], [-51, -7], [-14, 34], [-23, 30], [6, 14], [22, -6], [-14, 25], [-41, 6], [10, 40], [-36, -25], [-31, -6], [-17, -9], [-30, -16], [66, 2], [-4, -2], [9, 22], [-18, 21], [6, -1], [-50, 19], [-66, -2], [-49, 2], [-40, -10], [-23, 10], [32, -2], [5, -4], [22, 4], [-46, -8], [59, -7], [32, 31], [54, -20], [-49, 18], [-5, -32], [40, -3], [22, -8], [-7, 12], [19, 10], [15, 14], [-17, 10], [-36, 3], [-35, 19], [-30, -17], [-63, 11], [30, -41], [-56, 8], [10, -11], [-8, -22], [-44, -14], [6, -43], [-48, 16], [1, 46], [-26, 15], [22, 38], [-22, -2], [-14, -23], [-3, -25], [25, -20], [8, 16], [30, -20], [-39, -28], [39, -3], [20, 30], [-28, 6], [-49, 11], [66, -9], [36, 0], [59, -6], [-26, 19], [25, 27], [66, -12], [-2, 28], [-13, -7], [-2, 14], [41, -4], [-10, -52], [12, -16], [0, 6], [23, 8], [69, -9], [6, -14], [-48, -10], [23, 1], [10, 12], [3, -42], [-63, -17], [-40, 4], [3, 19], [19, 0], [54, 17], [62, -6], [6, -43], [-6, 28], [0, 42], [31, 6], [-64, 8], [22, -31], [17, 16], [-33, -2], [20, 22], [44, 21], [-58, -13], [6, -44], [33, -36], [14, 27], [16, -5], [26, 48], [4, -21], [16, 17], [-17, 7], [-75, 4], [-62, -12], [-26, 27], [34, 12], [-8, 4], [-8, 32], [6, 34], [6, -35], [31, -11], [41, -13], [33, -3], [-27, 22], [22, -9], [54, -10], [-58, -22], [7, -8], [-25, 12], [-12, 30], [6, -28], [-1, 25], [-22, 1], [49, -4], [-53, 7], [33, 43], [-56, -25], [-26, 6], [-44, 28], [-58, -16], [-10, 50], [-11, -27], [-26, 53], [82, 3], [-48, 26], [54, -6], [35, 47], [48, -6], [-6, -26], [-40, -23], [-44, -27], [-66, -2], [54, 5], [44, -15], [-6, 40], [-26, -24], [56, 9], [-16, 1], [10, -27], [20, -2], [12, -11], [-2, -23], [64, 18], [-13, -32], [27, 35]];
    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_bs();".
// 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_bs(:prec:=2)
    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_bs();".
// 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_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6762_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, -2, 1]>,<11,R![2, 4, 1]>,<13,R![7, -6, 1]>,<17,R![8, 8, 1]>],Snew);
    return Vf;
end function;