
// Make newform 2704.2.a.x in Magma, downloaded from the LMFDB on 15 April 2026.
// 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_x();".
// 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_x();".
// 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 := 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, -2, 1], [-3, 0, -1], [-2, 2, -3], [1, 2, -1], [0, 0, 0], [-2, -1, 3], [3, -1, 4], [-1, 2, 2], [-2, 2, -3], [2, -2, -1], [-5, 5, -6], [-9, 2, 0], [-4, 7, 0], [-1, -4, 1], [-4, 5, -4], [5, -6, 0], [5, -1, 6], [-2, -3, 0], [-3, 1, 1], [2, -5, 2], [-7, 3, -9], [3, 1, -1], [-9, 3, 1], [8, -6, 5], [-5, -7, 5], [4, -3, 6], [8, 1, 5], [-2, 8, 2], [-7, 5, 5], [9, -2, 1], [-8, -2, 3], [-4, 0, 4], [4, 1, 5], [-14, 3, 5], [-3, -8, 8], [0, -4, -3], [-6, 1, 9], [-8, 0, -6], [16, -4, 4], [-3, -3, -11], [-2, -3, -5], [12, -5, -6], [0, -6, -12], [-3, 12, 0], [11, -5, 8], [3, -4, 1], [8, -4, -5], [14, -5, 14], [4, 7, 0], [15, -5, 3], [-2, 3, -5], [-11, -2, -3], [-8, 10, -6], [-2, -14, 3], [-9, 11, 4], [-3, -12, -5], [-10, 9, 8], [-2, 7, 2], [-9, -5, 3], [16, -10, 8], [2, -21, 13], [4, -4, -10], [0, -14, 7], [-1, -3, -4], [2, -18, 4], [-2, 13, -10], [11, -3, 11], [-14, -15, 4], [-17, -9, 8], [-18, 0, -5], [-5, 14, -2], [0, -5, -17], [10, -17, 16], [6, 19, -3], [2, -4, 0], [-2, -10, 2], [19, -3, 13], [1, -20, 15], [-7, 14, -7], [-13, 1, -1], [12, 1, -14], [-19, 6, -22], [-11, 0, -19], [-2, -9, 7], [8, -22, 14], [-12, 23, -18], [-1, 5, -9], [-14, -5, 6], [7, 7, 10], [8, -5, -5], [-20, 15, -1], [14, -20, 21], [-23, 15, -9], [-21, -1, -15], [12, 7, 1], [-30, 15, -26], [-29, 4, -10], [-8, 25, -18], [13, -26, 12], [1, 9, 14], [-6, 5, 1], [-21, 2, -3], [14, 5, 10], [3, -17, 19], [9, 7, -4], [1, 4, -13], [-20, 12, -14], [-33, 15, -16], [-1, 2, 14], [-39, 13, -21], [12, 3, -4], [15, 4, -4], [30, 7, 0], [-13, -7, -1], [1, 29, -16], [20, 8, -3], [16, 4, -16], [4, 15, -13], [-16, 12, -29], [27, -16, 17], [27, -3, 16], [14, -22, -12], [3, -3, 0], [15, -17, 18], [-15, 4, -4], [17, -6, -1], [-3, 26, -5], [-14, 18, -1], [0, 1, 14], [30, -8, 2], [-10, 12, 17], [16, -14, 34], [-11, 14, -12], [-21, -3, -8], [-11, 9, 5], [20, -7, -12], [-10, -1, -15], [2, 28, -13], [-4, -2, 24], [0, -6, -23], [9, -21, 14], [17, -14, -14], [-19, 13, -33], [-17, 21, -26], [-4, 0, 14], [12, -12, 12], [42, -7, 16], [26, -20, 12], [-27, -10, 4], [8, 22, -15], [6, 17, -12], [-9, 13, -21], [-8, -7, -5], [2, -4, -9], [-14, 3, -14], [16, -3, -12], [14, -3, 19], [-35, 7, -21], [-27, 4, 12], [-1, -30, 16], [-2, 0, -21], [-8, 23, 9], [-7, 26, -20], [-9, 19, 8], [-21, -6, 1], [-2, -35, 2], [-22, 34, -33], [-29, 0, -6], [-20, 19, 5], [49, -16, 12], [2, -3, 23], [-9, 25, -5], [-23, 28, -6], [-36, 5, 14], [34, -9, 7], [37, -9, 2], [1, 3, -6], [-29, 25, -24], [-48, 22, -34], [-5, -7, -27], [11, -28, -8], [17, -20, 0], [-14, 14, -13], [-4, -9, -18], [-15, 4, 6], [-6, 5, -24], [21, -4, -12], [33, -21, -1], [-13, 20, 20], [-26, -16, 3], [-20, 15, 14], [2, 19, -17], [-16, -4, 0], [33, -7, 17], [1, 1, -13], [19, -30, 35], [-39, -10, -1], [-29, 21, -35], [-15, 0, -18], [3, -26, -18], [33, -37, 31], [18, 20, -19], [2, -16, -11], [-16, 27, 12], [-3, -16, 18], [-5, 1, 14], [24, 0, 23], [-12, 16, 31], [-24, -20, 1], [-16, 15, -14], [5, -8, -15], [1, -26, 28], [-28, -10, 17], [-33, 23, -43], [28, -35, 39], [17, -3, -20], [11, 16, -10], [-2, -21, 21], [14, 35, -9], [4, -22, 12], [6, -15, 36], [-27, 26, -28], [31, -2, -1], [-8, -30, 10], [22, 0, -15], [34, -11, 6], [4, -17, 19], [24, -14, 41], [-48, 18, -20], [-44, 18, -33], [-17, 33, -30], [-55, 16, 3], [-45, 23, -32], [21, 4, -16], [-35, -1, -1], [-13, 26, -17], [29, 14, 13], [33, 13, -10], [-8, 18, -42], [-15, -1, 27], [-29, 37, -12], [-41, 34, -23], [21, 2, -23], [16, -31, 10], [29, 27, -3], [-23, 44, -29], [9, 4, 8], [10, -3, -2], [-11, 7, -19], [27, -20, 10], [-5, -43, 10], [11, 26, -19], [-49, 1, 15], [9, -27, 35], [-14, 9, -9], [28, -12, -12], [22, -2, 16], [12, -4, -9], [-7, -23, -20], [15, 15, 0], [25, -19, 39], [32, -31, 39], [-23, -6, 11], [-20, -9, 7], [-6, -32, 14], [6, -15, 31], [-2, -46, 21], [-32, 2, -37], [-33, 19, -30], [-32, 22, -17], [-37, 14, -14], [-25, 18, -23], [41, 11, -1], [42, -28, 17], [49, -18, 8], [-2, -51, 17], [-1, -23, 22], [-20, 17, 38], [9, -3, 20], [18, 7, 22], [-15, 26, -8], [2, 33, 1], [26, -21, 38], [-32, -12, 5], [34, -42, 12], [1, -12, 41], [-22, 0, -16], [-28, 21, 6], [36, -21, 15], [24, 1, 8], [-9, 14, -37], [2, 3, 30], [55, -4, -5], [7, 54, -30], [1, -27, 17], [26, 1, -13], [-34, 9, 18], [-34, 0, 13], [4, 3, 8], [-68, 8, -8], [-37, 24, 3], [-25, 23, -17], [22, -42, 36], [17, 21, 6], [-23, -16, -5], [-22, 13, -45], [-15, 12, 20], [1, -45, 13], [-8, 32, 12], [57, -7, -3], [-30, 4, -22], [-12, -2, -23], [-35, 19, -19], [-1, 21, 14], [-6, 4, 6], [22, -17, 43], [-19, 41, -2], [-31, -25, 2], [-35, 9, -10], [-19, 22, -5], [-10, 30, -15], [-4, 32, -32], [-16, -11, -42], [43, 25, -9], [-11, -11, -12], [-13, -3, -1], [15, -2, -34], [-9, 10, -43], [40, -8, 27], [9, -10, 14], [-9, 37, 11], [25, -14, -8], [-29, 43, -38], [-52, 33, -26], [41, 4, -19], [17, 28, -2], [30, -42, 47], [47, -20, -19], [35, 19, -18], [-15, 21, -23], [1, -16, 14], [-7, -8, -11], [9, -25, -28], [40, -28, -14], [-11, -21, 31], [-1, -4, 9], [40, -36, 54], [32, -5, 9], [5, 13, 50], [-47, 40, -22], [-55, 6, -2], [12, 35, -9], [-22, 6, 6], [-4, -14, 31], [37, 25, -8], [29, -67, 51], [17, -5, -31], [-37, 9, -2], [65, -6, 25], [55, -9, 21], [7, -24, 2], [-54, 14, -21], [-32, -10, -20], [32, -21, 1], [-41, 19, -5], [-26, 29, -43], [46, 31, -15], [43, -37, 2], [-56, 11, -45], [11, -42, 29], [-18, 36, 39], [-20, 25, -17], [23, 0, -22], [-20, -14, 0], [-35, 28, -41], [-38, -3, 11], [61, -38, 61], [-11, 25, -11], [-31, 34, -25], [-8, -28, 8], [3, 8, -50], [62, -34, 28], [47, -24, 42], [-18, -18, 3], [-71, 29, -47], [-3, 5, -7], [67, -18, 36], [-8, -1, 29], [44, -40, 18], [-6, 68, -24], [4, 25, -27], [-31, -16, 29], [64, 0, 19], [51, -24, 32], [28, 16, 14], [23, 16, 1], [10, 25, -19], [0, 25, -11], [-52, 39, -2], [-32, 48, -1], [31, 3, -4], [-5, -9, 40], [-31, 5, -24], [15, -17, 5], [44, -56, 41], [-67, 38, -43], [-35, 23, 7], [20, -4, 62], [73, -31, 20], [36, -6, 22], [0, -66, 25], [75, -19, 44], [-5, 19, 33], [-32, 45, -10], [53, -23, 36], [18, -35, 58], [-12, 37, -44], [18, -22, 45], [-62, 50, -65], [83, -28, 40], [-32, 23, 4], [49, -17, 3], [37, 24, 10], [36, -14, 31], [30, -41, -7], [-70, 35, -21], [-19, -2, -36], [-46, 12, 12], [35, -15, -10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2704_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2704_2_a_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2704_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-7, -7, 0, 1]>,<5,R![13, 19, 8, 1]>,<7,R![-29, -16, 1, 1]>],Snew);
    return Vf;
end function;