
// Make newform 2178.2.a.bb in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2178_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_2178_2_a_bb();".
// 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_2178_2_a_bb();".
// 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 := [-1, -1, 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_2178_a();"
function MakeCharacter_2178_a()
    N := 2178;
    order := 1;
    char_gens := [1937, 1333];
    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_2178_a_Hecke(Kf)
    return MakeCharacter_2178_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, 3], [-4, 1], [0, 0], [2, -2], [0, 4], [2, -2], [2, -2], [-1, -1], [8, -1], [4, 4], [-2, 2], [2, -2], [0, 4], [2, -3], [2, -3], [8, 2], [4, 0], [-10, 4], [7, -7], [5, -7], [-5, -7], [8, -6], [7, -7], [-13, -1], [4, -13], [6, 1], [-10, 12], [10, -4], [-12, 0], [-6, 15], [12, -18], [-12, 2], [2, 1], [-5, 7], [2, -4], [-6, 12], [6, -2], [-6, -3], [7, 1], [-14, 4], [-20, 4], [4, 7], [3, -5], [15, 3], [-4, -14], [-5, -5], [-9, -3], [18, -8], [-4, 8], [-14, 4], [8, 9], [15, -7], [8, 10], [4, -6], [-2, -8], [-16, 12], [0, 18], [12, -18], [14, -16], [10, -21], [8, -14], [14, -16], [17, 3], [10, -16], [4, -8], [-2, 8], [10, -3], [12, -2], [8, -22], [14, 2], [-27, 17], [12, 4], [0, -6], [-12, 2], [-34, 8], [0, -16], [-14, -6], [9, -5], [5, -21], [24, -18], [-6, 2], [8, -7], [-8, 13], [6, 7], [-26, 16], [9, -21], [26, -24], [16, -5], [-14, 9], [-6, 2], [12, -21], [20, -36], [0, 12], [-8, -20], [-10, -11], [-24, 12], [-6, 22], [-10, -4], [-12, 10], [-34, 13], [-32, 24], [22, -24], [4, 22], [4, -5], [21, -5], [22, -4], [4, 20], [12, -19], [-4, 32], [18, 6], [34, 6], [-8, 28], [-19, -3], [-36, 18], [6, -8], [14, 18], [23, 3], [45, 3], [12, 10], [15, 13], [-30, 17], [-34, 19], [-4, -6], [6, 8], [14, -34], [-6, 8], [-4, -12], [40, -6], [-20, -8], [-18, 32], [-20, -16], [-12, 30], [14, 6], [-5, -15], [1, 17], [14, -38], [22, -1], [8, -36], [42, 2], [18, -5], [11, 23], [-6, -27], [-10, -28], [-8, -18], [-20, -8], [10, 2], [18, 22], [-4, -2], [18, -20], [16, 6], [34, 10], [-10, 30], [-2, 10], [-40, 6], [-41, 15], [12, -18], [-12, 25], [6, 24], [2, 7], [24, -40], [3, 27], [-8, -28], [38, 2], [-2, -18], [-29, 27], [-32, 42], [-4, 33], [-6, -9], [6, 19], [-14, -2], [8, -12], [-21, 21], [7, -13], [20, -24], [-14, 22], [-17, -5], [-49, -1], [0, -16], [-16, 0], [34, -11], [-22, 26], [50, 2], [-46, 14], [-14, 36], [54, -12], [-34, 40], [-40, 5], [-26, 18], [40, -7], [-16, 32], [18, -26], [-18, -1], [31, -15], [-2, 18], [-19, 23], [20, -4], [22, -12], [26, -44], [-23, -7], [-3, -3], [2, 12], [4, 7], [34, -31], [1, -11], [13, 21], [-43, -1], [-10, 18], [-56, 4], [-26, -12], [14, -21], [7, 19], [45, -25], [10, -14], [-8, 21], [-3, -3], [40, 2], [-34, 20], [46, -5], [24, 18], [40, -23], [-38, 16], [44, -37], [46, 11], [-58, 16], [16, -12], [-28, 14], [-36, 13], [-38, 51], [34, -34], [-22, -20], [60, -20], [40, 6], [-20, -10], [-38, 42], [35, 5], [-35, 21], [57, 11], [20, 34], [-27, -25], [30, 20], [0, -21], [-50, 10], [-38, 10], [20, -12], [-36, 28], [-38, -9], [20, -38], [6, -46], [-4, -24], [-4, 8], [42, -28], [-31, 35], [-22, 12], [31, -11], [12, -10], [10, 6], [-2, -19], [54, -12], [20, 3], [-23, 27], [0, 48], [20, -8], [32, -32], [-14, 38], [6, -45], [-40, -2], [0, 26], [-18, -27], [36, -42], [6, 24], [-32, 49], [-8, -25], [35, 13], [29, 5], [-5, 1], [-12, 0], [-4, -31], [34, 25], [-58, 20], [16, -49], [2, -34], [-58, 22], [-40, 32], [-14, 8], [-20, 31], [13, 33], [9, 33], [34, -6], [14, -25], [22, 25], [-24, -8], [28, 0], [-12, 4], [-2, -3], [28, 28], [-26, 37], [-42, -17], [8, 48], [-12, -9], [-7, -35], [-37, -9], [-29, -7], [22, 16], [-4, 39], [-57, 41], [44, -40], [28, 0], [-10, -30], [-6, -20], [-14, 29], [-4, -18], [-60, -6], [-64, 28], [47, 17], [38, 11], [-4, 30], [-28, 13], [-62, 40], [18, -34], [-3, 15], [-1, -17], [-43, 1], [-10, 38], [-44, 63], [-38, 28], [-14, -6], [-16, 4], [-34, -11], [8, 4], [-57, -9], [-28, -15], [-35, 47], [8, -36], [-27, 27], [30, 26], [-70, 20], [-67, 3], [48, -32], [-16, -6], [-76, 18], [-46, 27], [-28, 5], [29, 5], [57, -45], [-52, 34], [54, -4], [14, -18], [13, 13], [-46, 18], [51, -15], [1, 5], [-25, 51], [76, -10], [-62, 8], [32, 28], [-12, 12], [16, -56], [38, 28], [36, -12], [56, -36], [40, -50], [26, -33], [-34, 42], [-57, 5], [-6, -25], [41, -43], [10, -60], [-38, -11], [66, -54], [-24, 44], [34, -33], [-68, 1], [42, 4], [70, -5], [-10, -46], [-56, 41], [-64, 30], [4, -55], [-33, -5], [4, 26], [48, -25], [-46, 12], [-52, 66], [-2, 22], [-28, 21], [48, -14], [-32, 12], [-12, 6], [-27, 3], [-5, -13], [-25, -35], [66, -44], [14, -40], [56, -19], [-24, 17], [22, 10], [-24, -2], [1, 13], [6, -54], [28, 12], [-36, -4], [-60, 26], [43, -21], [-4, 57], [-48, 70], [-38, -34], [8, -8], [38, -3], [-44, 5], [42, -19], [76, -12], [-12, 28], [48, -21], [66, 13], [32, 20], [-19, -31], [38, 6], [34, 20], [50, 15], [30, -48], [30, -60], [53, 15], [46, 20], [-19, -15], [23, 21], [-70, 40], [22, -6], [44, -44]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2178_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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