
// Make newform 2106.2.a.l in Magma, downloaded from the LMFDB on 23 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2106_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_2106_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_2106_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
        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_2106_a();"
function MakeCharacter_2106_a()
    N := 2106;
    order := 1;
    char_gens := [1379, 1783];
    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_2106_a_Hecke(Kf)
    return MakeCharacter_2106_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 := [[1, 0], [0, 0], [-1, 1], [-2, -1], [-2, -1], [-1, 0], [0, -2], [3, 2], [-1, 3], [-1, 2], [-2, -2], [-6, -2], [-9, 1], [-2, -4], [-8, 2], [-9, -2], [-4, -1], [4, -3], [4, 6], [-5, -2], [2, 2], [-1, 3], [0, 1], [-3, -3], [5, 1], [-11, -2], [10, 4], [5, 5], [1, 3], [8, 1], [10, 4], [-10, -4], [0, -10], [13, -3], [-9, 5], [6, -9], [-10, 1], [-4, 10], [-3, 6], [23, 0], [0, -4], [0, -9], [-2, 4], [5, -3], [0, 6], [-10, 6], [17, -5], [12, 3], [0, -5], [0, -2], [10, -3], [-9, 8], [-3, -1], [3, -3], [6, 13], [-21, 5], [18, 2], [10, 3], [-6, 3], [-8, -6], [10, -8], [-8, -12], [2, -16], [0, -14], [-1, 12], [-3, -11], [-16, 10], [-4, -4], [21, -1], [-14, 8], [-11, -9], [-18, -8], [11, 9], [-16, -11], [-5, -14], [3, 6], [6, 8], [-10, 10], [3, 15], [-14, -4], [21, -7], [-5, 11], [-9, -14], [7, 6], [2, -6], [-6, -2], [16, 12], [-5, 11], [-9, 3], [-26, -1], [11, -1], [-9, 10], [2, -21], [-2, -14], [25, 0], [37, -3], [-20, 4], [-6, 5], [3, 17], [11, -11], [-20, 14], [12, -8], [-7, -21], [16, -6], [-3, -5], [-36, -4], [-16, 6], [-1, -7], [-17, -13], [-11, 6], [0, 0], [32, 4], [-41, -1], [-11, 4], [-32, 3], [-20, 5], [11, -8], [13, -17], [-12, -8], [24, -4], [32, -4], [13, 10], [-3, -14], [16, 10], [31, 6], [-21, -4], [-28, -8], [17, -11], [16, -16], [-7, -11], [9, 2], [-23, -10], [0, 6], [-36, 1], [48, 0], [-6, -22], [2, 22], [-31, 6], [27, 0], [0, 15], [35, 8], [-28, 0], [0, -10], [12, 24], [-8, 19], [-16, 18], [-35, 5], [4, -9], [-1, 11], [-11, 16], [-3, 21], [30, 8], [19, 15], [-23, -15], [-6, -20], [-30, 14], [-12, 20], [-12, 2], [6, -30], [-32, -2], [18, -6], [-16, 16], [2, 27], [3, 25], [21, -17], [47, -6], [15, -3], [-10, -17], [-52, 2], [8, -4], [-30, -18], [6, -22], [1, -29], [16, -4], [-39, -13], [-20, 23], [8, -4], [-20, 2], [13, 15], [-16, -6], [12, 15], [-38, 12], [4, 27], [-22, -4], [-11, 2], [-26, 2], [28, 8], [-3, -10], [-25, 13], [24, -6], [-2, 30], [-36, -13], [1, -29], [17, -7], [19, -3], [36, 9], [-4, 0], [22, -23], [26, -6], [-14, 4], [-30, -16], [17, -19], [-22, 8], [-62, 2], [16, 3], [3, 16], [-44, 4], [-33, -1], [0, 30], [0, -12], [5, -14], [9, 26], [-49, 7], [10, -17], [-9, 16], [34, 18], [-23, 7], [44, 15], [-14, -4], [-12, 20], [-44, -6], [2, -15], [-36, -16], [-8, -25], [21, -3], [2, 19], [8, 10], [21, -5], [-29, -5], [-12, -20], [-44, -10], [4, 26], [42, 7], [22, 1], [-1, 13], [-1, 6], [4, -30], [-8, -4], [39, -11], [-34, -20], [18, 31], [-11, 9], [33, 7], [5, -15], [-16, -26], [-9, 25], [-16, 24], [28, -1], [-7, -2], [-24, -12], [11, 1], [8, 4], [1, -12], [-7, 16], [-35, -20], [-2, -3], [-12, 28], [2, 0], [27, -20], [-5, -27], [-2, -12], [39, -15], [-64, 0], [4, -15], [51, 11], [13, 5], [-41, -3], [-13, -35], [-3, -22], [-18, -12], [52, -5], [-11, 14], [-9, 25], [53, -9], [-25, 22], [-36, -16], [14, 7], [-21, 3], [19, -21], [21, 25], [62, 4], [-30, 3], [-16, -12], [29, 19], [24, -14], [10, -4], [-13, -24], [14, 0], [-4, -5], [20, 5], [15, 4], [11, 17], [-27, 7], [-40, 10], [52, -2], [-15, -8], [-42, 6], [23, -6], [-11, -21], [62, -4], [47, 10], [-7, -27], [-24, 6], [-37, -5], [40, -14], [-40, -22], [49, 19], [48, -16], [-44, 12], [78, -5], [45, -21], [-40, 6], [-30, -19], [64, -10], [35, -14], [41, 4], [36, 9], [26, -8], [17, 35], [20, -29], [47, -11], [-35, 3], [66, -8], [-28, -21], [17, 19], [7, 18], [25, 2], [-9, -6], [16, 6], [-7, -24], [13, 33], [14, 22], [26, 10], [-12, -28], [59, 8], [-52, 12], [5, 17], [-40, -20], [45, -5], [11, -21], [-21, 21], [-60, 12], [16, 30], [-17, 7], [-10, -8], [-23, 37], [28, 17], [53, -18], [35, -12], [3, 38], [-20, 0], [13, -27], [18, -24], [-79, 5], [24, -3], [-54, 17], [-15, 38], [-36, -5], [-6, -27], [-21, -16], [-41, 3], [-24, 20], [74, -4], [-58, 3], [-37, 25], [43, -8], [-3, -43], [-44, 20], [-30, -34], [-12, 18], [25, 43], [-19, -14], [-54, -2], [-9, 15], [-18, -23], [-24, 3], [-45, 5], [32, 24], [-22, -17], [19, 26], [-36, 24], [-22, 42], [-12, -17], [-5, -15], [-32, 28], [-33, -8], [12, -13], [26, 17], [8, -20], [5, 3], [-36, -4], [-26, 16], [0, 19], [38, -6], [-12, -18], [37, -20], [-42, 13], [-46, -3], [27, 9], [0, -30], [19, 29], [-64, 11], [-20, 28], [16, 10], [12, -4], [-7, 13], [31, -31], [33, 13], [64, 4], [-18, 11], [25, 2], [-12, 20], [17, 45], [-44, -12], [-82, 2], [39, -6], [-3, -38], [-26, -28], [-48, -10], [-24, 18], [-4, 12], [46, -34], [57, 10], [-6, 28], [-25, 27], [31, 1], [-4, -2], [30, -4], [-53, -6], [-83, -15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2106_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2106_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_2106_2_a_l(:prec:=2)
    chi := MakeCharacter_2106_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_2106_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_2106_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2106_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 2, 1]>,<7,R![1, 4, 1]>,<11,R![1, 4, 1]>],Snew);
    return Vf;
end function;