
// Make newform 2704.2.a.bb in Magma, downloaded from the LMFDB on 13 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2704_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_2704_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_2704_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, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_2704_a();"
function MakeCharacter_2704_a()
    N := 2704;
    order := 1;
    char_gens := [2367, 677, 1185];
    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_2704_a_Hecke(Kf)
    return MakeCharacter_2704_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, 0], [1, 1, 0], [-1, -1, 0], [0, 1, 0], [-1, -3, 0], [0, 0, 0], [-3, 2, -5], [0, -3, 3], [3, -2, -2], [4, -3, 6], [-4, 3, -4], [-4, 3, 3], [-1, -2, -2], [7, -3, 1], [-5, 5, -2], [-3, -5, 1], [-9, 4, -6], [-12, 3, -5], [-3, -3, 5], [8, -6, 11], [-5, 1, 1], [2, 6, -1], [-6, 4, -1], [-6, 4, 5], [2, -5, 6], [4, -2, 5], [1, 5, -9], [1, 4, -3], [-2, 6, -8], [-10, 2, 1], [13, -7, 8], [2, -11, 4], [-8, 4, 0], [-7, 12, -7], [-1, 0, -3], [1, 2, -8], [0, -9, 4], [-7, 4, -1], [-8, 6, 0], [-4, -4, -8], [-16, -2, 1], [-9, 4, -15], [-1, -1, 5], [10, -6, 2], [7, 0, 16], [4, 11, -3], [17, -9, 6], [24, 1, -2], [-17, 5, -5], [-23, 11, -19], [10, -6, -1], [15, -4, 1], [1, -1, -6], [-10, 4, -2], [16, -5, 10], [0, -1, 17], [9, -7, 0], [-11, 21, -19], [5, -5, 11], [-10, -2, 1], [-6, 10, 2], [-17, 12, -15], [8, -10, -8], [-14, -7, 4], [-8, -1, 9], [-8, 6, -10], [-3, 27, -11], [-8, 0, 1], [-13, -1, -17], [6, -21, 5], [-6, -9, 8], [5, 2, 10], [3, -8, 3], [-3, -11, -1], [-5, 6, 17], [10, 0, -8], [20, -8, 14], [28, -2, 7], [11, 3, 8], [5, -1, 2], [-6, 20, -3], [-1, -5, -17], [23, -10, 22], [-19, -5, -4], [17, -20, 19], [22, 0, 6], [5, -7, -11], [-16, 12, -13], [-13, 13, -3], [12, -13, 7], [3, -8, 11], [5, 4, -15], [2, 3, 6], [6, 26, -9], [4, -8, 13], [11, -30, 11], [11, -27, 5], [7, 14, 4], [9, -3, -21], [13, -6, 18], [-8, -1, -9], [-15, -2, 3], [31, -15, 20], [-1, 25, -11], [4, -22, 3], [20, 7, 9], [-15, 3, 6], [20, -10, 0], [-12, 3, 17], [5, -12, 26], [16, -24, 1], [-23, 19, -19], [-27, 16, -32], [11, -17, -5], [10, -12, 15], [-22, 31, -31], [8, 11, -6], [16, 0, -8], [-21, 10, -13], [-4, -9, -14], [-7, 17, -16], [-12, 3, 9], [-16, 26, -26], [2, 31, -11], [-16, -5, -5], [13, -20, 24], [5, -31, 22], [-31, 11, -4], [24, 9, 4], [39, -9, 23], [18, -14, -4], [6, -25, -10], [10, -16, -2], [-13, -10, 2], [4, 13, 3], [34, 2, -9], [-5, -3, 7], [-5, -6, 9], [-2, 25, -4], [26, 2, 14], [-10, 9, 0], [-4, 13, -3], [33, -14, 14], [-24, -12, -5], [-24, 5, -7], [0, 10, -4], [-4, -8, 0], [-1, -1, -3], [14, 0, 20], [-9, -8, -14], [-10, -13, 6], [-5, -21, -11], [18, 4, -11], [-7, 14, -11], [-14, -13, 14], [13, -5, -7], [-11, 19, -9], [-19, 28, -5], [-32, 2, 15], [-21, 28, -28], [-3, 8, 18], [-6, -23, 0], [-23, -6, -15], [17, -24, 22], [2, -29, 13], [-19, 3, -20], [-5, -35, 19], [0, -1, -22], [-11, 18, -28], [-17, 12, -21], [1, -6, 16], [-7, -4, -17], [6, 12, -11], [19, -34, 4], [-11, 17, -1], [5, -26, 11], [14, 15, -1], [-20, 25, 9], [-10, 25, -9], [10, 16, -6], [-2, -6, 7], [-15, 2, -4], [-27, 12, 8], [-4, -23, 18], [-31, -3, 11], [21, -34, 4], [31, -1, 13], [-11, -10, -4], [0, 2, 21], [-29, 2, 20], [-38, 5, 12], [9, 5, 3], [-35, 4, -21], [28, -16, 20], [-28, 6, -11], [2, -8, -3], [-37, 21, -34], [23, 19, -14], [-32, 6, -17], [27, -28, 32], [-9, 12, 30], [-30, 6, -9], [-18, 1, -4], [30, -13, -16], [-27, 23, -1], [-3, 26, 0], [-14, 1, 5], [-36, -13, 10], [8, -25, 32], [-12, 1, 2], [15, -25, 15], [-7, 23, 24], [29, 8, -2], [-18, -23, -4], [-24, -8, 13], [-37, 16, -21], [-20, -19, 7], [3, 2, 16], [11, -42, 29], [11, -6, -11], [18, -34, 26], [-11, -23, 9], [-39, 42, -42], [-31, -3, -20], [10, -20, -14], [-18, 19, -28], [-21, 21, 5], [-45, 24, -25], [6, 31, -16], [-10, -2, 18], [30, -5, 30], [-30, 7, 7], [5, 15, -2], [10, -3, -13], [35, -22, 32], [-26, -14, 9], [31, -7, -6], [-39, 23, -14], [12, 31, -13], [34, -32, 38], [42, -26, 13], [-2, 5, -13], [27, -3, 40], [25, -9, 6], [-9, -25, 3], [42, -20, 15], [-15, -1, 6], [-35, 10, -20], [-23, -33, 9], [-6, 44, -5], [-11, -30, -8], [-4, 3, -21], [-11, 51, -20], [4, 4, 5], [22, -40, 17], [-35, 30, -49], [16, 24, 4], [20, -6, -6], [20, -35, 16], [-18, 21, -9], [-28, 23, -19], [-8, 4, -11], [-37, 8, 3], [11, 11, 18], [-27, -14, 9], [14, 2, 12], [-39, 8, -13], [0, -25, 22], [10, -1, 40], [-26, 23, 19], [-46, 3, -6], [33, -30, -2], [-17, 47, -22], [22, -10, 39], [-50, -5, -12], [-57, 12, -34], [1, -4, 43], [56, -1, -13], [-21, -13, 31], [28, 25, -9], [21, 27, -11], [23, -16, -10], [15, 0, 25], [3, 9, 37], [-20, 15, -18], [24, 6, -22], [13, -5, 16], [26, -36, -8], [-1, 11, -23], [23, 14, 7], [-31, -17, -3], [31, -45, 36], [-17, 33, -43], [27, -29, 26], [-19, 48, -26], [-46, 10, -7], [47, -26, 33], [-53, 21, -11], [-34, 25, -46], [25, -37, -9], [-4, -40, 4], [-15, -5, -4], [-28, -14, 7], [24, -14, -2], [40, -21, 11], [3, -33, 16], [-13, 14, -23], [45, 16, -12], [-2, -44, 5], [20, 16, -28], [52, -2, 5], [14, 22, -20], [22, -11, 10], [-22, 4, -5], [-38, 37, -3], [54, -18, 48], [-9, -16, -7], [8, 9, -3], [56, 13, -11], [-46, -11, -3], [-15, -5, 28], [16, -13, 30], [-24, 32, -28], [-1, -29, -19], [8, -40, 43], [-14, -33, 5], [-2, 12, 27], [57, -30, 34], [-29, 21, -20], [-36, 5, 28], [33, 4, -10], [20, -12, 17], [-19, 16, -42], [20, -21, -17], [11, -29, 9], [-23, 21, -46], [7, -14, 12], [60, -43, 62], [-47, 29, -36], [12, -19, 21], [82, -18, 27], [25, -6, 24], [-53, -15, 16], [-14, 39, -19], [48, -18, -20], [-22, -22, 11], [-41, 43, -44], [72, -18, 8], [25, -30, 41], [34, -39, 25], [1, 28, -32], [-27, 24, -54], [-11, -26, 37], [28, -48, 18], [-18, 19, -38], [14, 15, 21], [20, -4, 15], [-42, 24, -3], [-8, 13, 25], [35, -45, 36], [-26, 28, 21], [-9, 2, -32], [0, -7, 40], [-54, 2, -34], [-17, 2, -57], [-14, 46, -17], [17, -34, -5], [-17, -2, -3], [6, -33, -21], [27, -4, -13], [-9, 73, -32], [46, 5, -18], [-15, 12, 5], [-27, 28, -36], [30, -18, -10], [-11, -5, 30], [-9, 58, -15], [5, -5, -18], [-46, 2, -27], [15, -1, 2], [24, -16, 32], [-11, 38, 12], [16, -6, 30], [5, 10, -32], [16, -1, -20], [52, -2, 15], [-56, 18, -21], [-3, -26, 6], [41, -46, 37], [20, 38, -8], [62, -24, 28], [-1, 14, 11], [-11, -39, 6], [76, -13, 30], [-9, -18, -24], [32, -14, -8], [-53, 49, -42], [15, -14, 5], [-27, 12, -11], [-23, -11, -43], [-8, 23, 32], [38, 1, -21], [-28, -11, 27], [-14, 21, 27], [14, -64, 25], [16, -11, 2], [25, -33, 18], [-16, -10, -3], [-8, -2, 44], [-28, 71, -39], [-6, 24, -18], [-22, 5, -46], [10, -39, 51], [-36, 36, -5], [21, 33, -7], [-22, 3, -11], [-27, 23, -35], [45, -5, -21], [52, -21, 2], [-12, -23, -36], [-17, -28, 8], [-63, 15, 5], [54, -14, 49], [35, -36, 20], [30, 25, 10], [23, -20, 65], [-31, 44, 15], [73, -10, 10], [62, -20, 28], [-54, 55, -45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2704_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2704_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_2704_2_a_bb(:prec:=3)
    chi := MakeCharacter_2704_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_2704_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_2704_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2704_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 3, -4, 1]>,<5,R![-1, 3, 4, 1]>,<7,R![1, -2, -1, 1]>],Snew);
    return Vf;
end function;