
// Make newform 6776.2.a.o in Magma, downloaded from the LMFDB on 23 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6776_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_6776_2_a_o();".
// 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_6776_2_a_o();".
// 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 := [-3, 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_6776_a();"
function MakeCharacter_6776_a()
    N := 6776;
    order := 1;
    char_gens := [1695, 3389, 969, 3753];
    v := [1, 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_6776_a_Hecke(Kf)
    return MakeCharacter_6776_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, 0], [1, 1], [0, -2], [-1, 0], [0, 0], [3, -1], [-5, -1], [-2, -2], [-2, -2], [6, 2], [1, 5], [6, -2], [9, 1], [-8, 2], [3, -1], [2, 6], [3, -1], [7, -1], [6, -2], [2, -2], [-11, 1], [0, 2], [-2, 2], [6, 0], [10, 4], [-1, 3], [13, -3], [-16, 0], [-2, -2], [10, 0], [8, 0], [2, 10], [10, -6], [10, -6], [0, -8], [4, -2], [12, 2], [2, -2], [-8, -4], [-3, -3], [8, -4], [4, 10], [-8, -4], [0, -4], [4, 0], [1, 9], [20, 4], [9, 9], [-18, 6], [-8, -2], [2, -14], [4, 12], [17, 1], [1, -11], [6, 8], [-20, -4], [-8, -10], [4, 12], [-16, 8], [-14, -6], [2, -14], [3, -5], [-2, 6], [5, 13], [10, -8], [-6, -8], [-4, 12], [22, -6], [0, -2], [-13, 11], [-2, 0], [4, -14], [-1, 3], [16, -12], [6, -14], [7, -17], [14, 12], [4, 10], [10, -8], [-3, 9], [25, 9], [-2, 2], [-12, -2], [-10, 0], [-24, 4], [-12, 0], [6, -6], [-4, 0], [33, 5], [14, -6], [-21, -5], [24, -4], [14, -10], [12, 2], [10, -14], [-28, 4], [0, -2], [30, 0], [30, 2], [20, 8], [-16, 8], [16, 4], [30, -2], [18, -2], [4, 12], [18, 4], [-17, 7], [-1, -1], [-6, 6], [1, -23], [32, 4], [-10, 18], [-14, -14], [3, 3], [-4, 0], [6, 14], [5, -15], [-7, 5], [-10, 20], [0, 14], [8, -14], [-22, 2], [27, 7], [-4, -24], [-35, 5], [-18, 14], [-10, -4], [-21, -5], [1, -11], [35, 11], [-4, -4], [-20, -12], [34, -6], [10, 4], [9, 13], [23, -1], [32, -6], [14, 2], [8, 14], [0, 28], [6, -22], [0, 0], [8, -12], [12, 6], [-28, -6], [-41, -9], [-5, 7], [9, 5], [1, -11], [12, -16], [-46, 2], [6, -16], [20, 8], [0, -12], [-6, 10], [-6, 10], [4, 12], [2, -16], [-33, -1], [23, -17], [-16, 24], [-20, 12], [-36, 2], [15, 15], [-46, 8], [3, 15], [6, 18], [-7, 17], [-4, 0], [-12, 6], [12, -28], [-24, 2], [-8, 2], [10, 10], [5, -3], [-14, 0], [-20, -2], [-18, -10], [28, 0], [-1, 3], [-28, 12], [-18, -10], [10, 20], [-15, -15], [-12, 28], [4, -14], [16, 4], [1, -27], [-30, 2], [-32, 0], [-2, 4], [-32, -8], [2, 26], [-56, -6], [-28, 18], [-62, 4], [-10, 2], [-26, 22], [-9, 31], [12, -12], [20, -12], [12, 4], [-16, -14], [-11, -23], [-7, -11], [-48, 10], [-29, -1], [-32, -8], [0, 28], [-17, -5], [-18, 10], [16, 18], [52, 4], [11, 23], [16, 0], [42, 16], [24, -10], [19, 19], [-10, -22], [-2, -20], [-2, -6], [-4, 0], [-14, -10], [-36, 4], [30, 18], [-22, -22], [-42, -4], [60, 4], [28, 8], [16, 18], [34, -14], [-30, -10], [28, -12], [-16, -16], [25, -3], [-60, 0], [10, -20], [4, -36], [-18, 22], [3, -5], [-14, 30], [34, 18], [-23, 29], [-26, 18], [-35, 13], [0, -20], [-27, 1], [-19, 29], [12, -4], [-20, 4], [4, -8], [9, 5], [6, -14], [18, -12], [-25, -1], [24, 0], [18, 26], [38, -14], [-24, 2], [-3, -11], [-44, 10], [-60, 12], [-63, 5], [13, -3], [-46, -4], [-5, -21], [26, -2], [2, 8], [28, -18], [-18, 10], [-16, 6], [-46, 6], [38, 0], [12, 12], [-19, -15], [-31, -15], [0, 8], [52, -8], [52, 8], [30, -6], [-20, 12], [14, -22], [-20, 28], [-3, -3], [22, 18], [30, -26], [18, -26], [36, 4], [-15, -31], [3, 31], [-2, 10], [-17, 7], [-6, 30], [26, -22], [16, 8], [69, -7], [-15, 29], [-48, 14], [-6, -26], [6, 26], [-1, 23], [-38, 18], [0, -14], [26, -2], [-2, -30], [-10, 46], [8, 0], [-20, -18], [0, -16], [-4, 20], [12, -8], [-6, 4], [-30, 34], [4, -12], [-48, 14], [-41, -9], [31, 7], [36, -12], [-10, -24], [10, 10], [-10, -10], [74, 8], [11, -5], [-28, 0], [-36, 8], [6, -24], [-14, 30], [59, 3], [12, -10], [50, -14], [-48, -4], [18, 2], [-16, -40], [58, -6], [28, -2], [-39, 13], [-14, 2], [9, 17], [2, 28], [68, 4], [6, 8], [-2, 22], [17, 9], [-20, 16], [-6, -12], [-48, 0], [16, 18], [-54, 14], [-24, -32], [12, 22], [10, 2], [-26, -6], [-22, 0], [-24, -24], [24, 8], [-39, 9], [-27, 37], [-10, -30], [40, -24], [12, 4], [-8, 48], [33, 1], [72, 8], [76, 6], [33, -35], [-14, -6], [45, 29], [-24, -40], [-44, -8], [-6, 10], [3, 39], [-36, 20], [-20, 0], [-56, 0], [30, -6], [51, -5], [-12, -10], [23, 11], [19, -25], [35, 31], [-40, 18], [30, -30], [-32, -2], [-84, 4], [-14, -6], [45, 5], [32, -20], [16, 22], [-28, -12], [21, -27], [50, 2], [44, 26], [-34, -18], [27, 19], [-16, -8], [62, 6], [52, -20], [-54, 28], [22, -18], [30, -18], [33, 5], [-18, 32], [56, -24], [22, 32], [75, 7], [16, 44], [58, -16], [-20, 8], [9, -15], [-67, 13], [-17, -33], [14, -6], [0, 56], [-44, -18], [-50, -18], [-32, 38], [32, -16], [11, -13], [-50, 0], [-44, -4], [-62, -4], [31, 7], [-66, -6], [18, 38], [82, -12], [-16, 14], [-50, 2], [-26, 14], [27, -1], [24, 40]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6776_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6776_2_a_o();".
// 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_6776_2_a_o(:prec:=2)
    chi := MakeCharacter_6776_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_6776_2_a_o();".
// 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_6776_2_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6776_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -2, 1]>,<5,R![-12, 0, 1]>,<13,R![6, -6, 1]>,<17,R![22, 10, 1]>],Snew);
    return Vf;
end function;