
// Make newform 2646.2.a.bo in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2646_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_2646_2_a_bo();".
// 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_2646_2_a_bo();".
// 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 := [-7, 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_2646_a();"
function MakeCharacter_2646_a()
    N := 2646;
    order := 1;
    char_gens := [785, 1081];
    v := [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_2646_a_Hecke(Kf)
    return MakeCharacter_2646_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], [0, 0], [1, 1], [0, 0], [1, 1], [2, 1], [-1, -1], [-2, 0], [4, -2], [5, -1], [2, 1], [-4, -3], [-3, -3], [5, 0], [3, -3], [6, 0], [-11, 1], [-10, 1], [3, -2], [13, 1], [0, -4], [-2, 5], [8, 2], [3, -3], [-3, -4], [-11, 1], [4, -3], [-6, 0], [-6, 1], [5, -1], [4, -1], [4, 4], [-4, 2], [9, -4], [15, 3], [-6, -5], [4, 0], [-1, 0], [-2, 4], [4, 4], [9, 3], [8, -2], [3, -9], [-7, 0], [10, -2], [-14, 3], [-1, 6], [-2, 6], [-6, 0], [12, -1], [-14, -2], [-3, -3], [-5, 0], [18, 0], [0, -6], [3, -3], [22, -2], [8, -5], [-10, 3], [1, 7], [-3, 2], [-15, 3], [3, -4], [-5, 7], [-18, 2], [3, 9], [-16, -6], [-20, -4], [-12, 0], [-12, 5], [12, 0], [-10, 8], [-14, -6], [-6, 4], [15, 4], [-10, -4], [14, 2], [14, 1], [3, -9], [1, -6], [-21, -3], [-20, 2], [15, 9], [19, 0], [-4, -8], [-14, -2], [5, -1], [-3, -2], [-11, -5], [24, -2], [13, -5], [-1, -1], [8, 6], [-6, 12], [15, -8], [12, -6], [-24, 6], [24, -6], [1, 0], [-20, 8], [13, 2], [-19, 5], [8, -10], [-9, -3], [4, 2], [27, 2], [-25, 5], [-33, -3], [-6, 6], [-11, -6], [-16, 4], [-8, -13], [-17, 7], [3, 2], [14, -3], [-5, -5], [19, -6], [6, -6], [-6, 0], [-11, -5], [-18, 8], [-16, 12], [30, 6], [-3, -9], [7, 12], [-16, -4], [14, 9], [-15, -3], [-12, 5], [-22, -5], [-5, -10], [-21, -3], [-26, -10], [4, 17], [8, -4], [-30, -4], [4, 16], [17, -2], [-9, 9], [26, -4], [24, 2], [10, 4], [-6, -11], [-12, -12], [24, 2], [44, 2], [-32, -6], [3, 9], [7, 0], [8, 8], [24, 1], [-12, 6], [-4, -6], [0, -6], [31, 2], [21, 3], [42, -5], [9, 3], [13, 12], [19, 13], [29, -7], [10, 16], [44, -3], [-6, 6], [-36, -6], [3, -9], [-34, 3], [16, -15], [17, 0], [6, 0], [23, -7], [-18, 8], [18, 6], [10, -4], [-34, 1], [4, 10], [1, 8], [13, 13], [-56, -3], [28, -3], [34, 2], [26, 2], [-42, 7], [1, 1], [20, 8], [18, 6], [-26, 5], [10, 0], [25, 8], [-33, -9], [-6, 8], [21, 3], [33, 4], [-31, 11], [-3, 9], [26, -10], [-10, -6], [-12, -11], [30, -6], [18, 12], [54, -6], [20, -5], [28, 3], [-25, 4], [21, 3], [-39, 3], [16, -3], [-30, -6], [36, 0], [31, 6], [-1, 0], [64, -2], [-2, 5], [55, 1], [6, 12], [-23, 0], [6, -2], [-49, 5], [25, 1], [19, -11], [-24, -11], [0, 5], [12, 0], [24, 10], [15, -21], [-22, -9], [14, -16], [5, 11], [8, 4], [-15, 9], [-32, 2], [6, 20], [-18, -5], [3, -21], [25, 12], [6, 12], [-36, 8], [51, 3], [30, 12], [-23, 19], [25, 7], [-2, 0], [16, 12], [4, -1], [23, -1], [-39, -9], [-4, -17], [26, -10], [44, -6], [9, 9], [-24, 7], [36, -6], [-6, -12], [45, 8], [-28, -10], [-2, -8], [-16, -15], [-49, -2], [-50, -8], [-26, 12], [18, -2], [-37, 11], [-6, 17], [-42, -13], [-6, 0], [15, -4], [18, 0], [-23, 19], [-30, -20], [0, 12], [8, 10], [17, 0], [17, -8], [-22, 3], [18, -10], [-46, -5], [-5, -11], [-26, 17], [-27, 16], [-6, -12], [63, -3], [16, -1], [-9, 9], [22, 9], [23, -14], [58, -2], [43, 2], [-35, 7], [28, -3], [-48, -12], [3, -3], [-33, 9], [3, 9], [-32, 10], [8, -15], [-24, -18], [-20, 21], [42, 6], [-33, 15], [-19, -8], [9, 14], [-12, 12], [18, -14], [39, 3], [-25, 18], [23, -12], [-52, -10], [-44, -12], [-17, -23], [-70, 0], [-39, 9], [2, -10], [-31, 5], [17, 6], [2, 32], [-11, -30], [-30, -12], [5, -7], [13, -18], [-24, -6], [-26, 0], [-12, -20], [30, 12], [-48, -5], [32, -16], [7, -12], [41, 6], [-51, 2], [-41, -11], [-20, 22], [-16, 15], [-50, -14], [20, -20], [8, 26], [-75, 4], [-53, 7], [-8, -13], [-17, 1], [1, 12], [18, 11], [-34, 15], [-72, 0], [-12, 6], [-8, 32], [-12, -6], [6, 6], [10, 27], [14, 24], [-18, -18], [-57, 9], [25, 18], [23, -12], [-12, -12], [44, 4], [48, -11], [23, -19], [-26, -26], [63, -3], [-53, 13], [-14, 10], [12, -5], [-58, 2], [-55, 5], [-14, -2], [-3, 26], [-13, 18], [-24, -6], [28, 23], [51, -14], [10, 28], [15, 26], [-51, -9], [-13, 17], [6, 14], [-42, 1], [-24, -18], [-74, 4], [33, 8], [5, 29], [4, 12], [3, 9], [20, -22], [-78, 1], [-42, -12], [21, 26], [49, -11], [-58, -9], [-6, 35], [-60, -2], [-40, -10], [53, 12], [24, 18], [37, -17], [-17, 6], [11, 11], [-17, 20], [-60, 5], [98, 2], [-29, 8], [13, 31], [64, -12], [-39, 3], [-60, -14], [22, 4], [-9, -3], [4, 21], [-84, 7], [-6, -6], [49, -12], [-7, 17], [24, 8], [28, -14], [25, -23], [-41, -16], [17, -12], [-22, 2], [-8, 4], [24, 8], [9, -9], [-29, 7], [64, 10], [76, 3], [-71, -11], [-12, 24], [-26, -24], [4, -2], [35, -1], [21, -15], [26, -20], [71, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2646_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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