
// Make newform 2704.2.a.z in Magma, downloaded from the LMFDB on 01 February 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_z();".
// 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_z();".
// 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, -1, 0], [-1, -1, 0], [2, -1, 2], [3, -1, 0], [0, 0, 0], [1, -2, 3], [0, 1, -3], [1, 2, 0], [0, -3, -2], [2, -3, -2], [4, -1, -1], [-5, 6, -2], [-3, -3, 1], [7, -1, 2], [-3, 7, -3], [5, 0, -4], [0, -1, -5], [-1, 5, 1], [10, 0, 3], [7, -3, 9], [-4, 8, -9], [4, 2, 7], [-6, 0, -7], [-2, 7, -6], [-4, 10, -7], [3, 1, 7], [-3, 2, -5], [10, -6, 4], [10, -2, 1], [5, -1, -8], [8, -1, 6], [8, 0, 4], [5, -6, -5], [3, 0, -3], [3, 2, 10], [0, -5, 4], [-15, 2, -3], [-4, 14, -12], [-8, 8, 8], [-6, 4, 1], [15, -8, 9], [9, -9, 13], [-2, 10, -2], [3, 0, 8], [0, 11, -5], [-7, 5, -10], [6, 3, 0], [1, -3, -5], [-15, 7, 1], [-6, -2, -1], [19, -6, 3], [-11, 11, -10], [10, -16, 14], [16, -5, 18], [4, -13, 7], [-7, 1, -4], [7, 9, 5], [5, -5, -5], [-2, -6, 1], [-2, 14, 6], [-1, -16, 9], [-12, 10, -12], [-4, 3, -18], [-16, 7, -3], [4, 18, -10], [-9, 11, -11], [-16, 12, -7], [5, 7, -5], [-10, 3, 1], [-2, 7, -8], [-1, 18, -8], [-1, -6, 17], [5, 5, 11], [-13, -12, -1], [14, -16, 8], [-4, 16, -18], [4, -10, -1], [19, -9, 8], [5, -21, 6], [24, -2, -7], [-13, -5, 11], [1, 10, -16], [-11, 7, -12], [5, -14, 5], [-14, -4, -2], [1, -11, 5], [-8, -8, -9], [-5, -7, 13], [8, -5, 13], [-1, 30, -11], [25, 2, -5], [8, -31, 20], [-20, 8, 3], [-10, 6, 9], [-9, 24, -3], [-9, 9, -7], [-17, -2, 12], [19, 5, 3], [21, 6, -6], [-4, -5, 17], [13, 2, 7], [15, 3, 4], [-17, -3, -7], [14, -4, 11], [24, 3, -11], [-31, 21, -30], [-20, 14, -28], [-4, -5, -9], [9, 0, 6], [22, -22, 13], [-15, 7, 5], [21, -20, 0], [-7, 3, -9], [-32, 18, -21], [30, -1, -3], [-14, 5, 12], [12, -16, 4], [19, -14, -1], [-26, 1, -8], [-7, 17, 8], [12, 11, 13], [-32, 6, -10], [6, -17, 7], [-16, -13, 5], [-31, 20, -16], [-3, 5, 26], [-7, 13, -4], [-6, 11, -14], [-21, 27, -25], [-14, 2, 8], [28, -7, 8], [-22, 16, -6], [-29, 22, -22], [-4, 9, 15], [6, -38, 15], [-33, 1, -9], [-1, 24, -5], [-18, 9, -24], [-22, -6, -10], [20, 3, 14], [-12, 21, -27], [11, 6, 12], [-2, -30, 7], [20, 5, -3], [28, -14, 28], [-36, 0, 4], [23, -1, -7], [14, -12, 20], [9, 8, -16], [10, 11, 22], [-21, -13, 1], [-16, -14, -7], [-7, -8, 3], [-4, 9, -16], [-13, -21, 9], [-21, 7, -5], [17, -4, -5], [20, 6, 3], [-1, 12, 0], [-9, 8, -28], [30, -27, 36], [17, -24, 7], [-5, 8, -24], [26, -1, 1], [5, 33, -20], [1, 25, -13], [16, -13, 2], [29, -26, 4], [7, 24, -1], [15, 10, -2], [5, 12, -29], [-28, 6, -27], [-29, -2, -4], [27, 9, 11], [25, -10, 23], [2, 3, -11], [20, -3, 9], [42, -19, 9], [22, 0, 6], [-4, 4, 11], [-9, 10, 18], [-3, 20, -16], [36, -19, 30], [27, -19, -9], [21, -30, 28], [-17, 3, 21], [19, -6, -10], [-16, 14, -39], [37, 2, 10], [-6, -3, -32], [-9, -15, 15], [33, -10, 21], [48, -8, 28], [38, -24, 49], [-2, 28, -11], [-5, -11, -18], [-25, 11, -10], [52, -14, 23], [-35, 28, -38], [15, -28, -10], [12, -8, 7], [22, -11, -4], [14, -9, 28], [3, -1, -13], [25, 14, 0], [-14, 9, -9], [42, -11, 12], [8, 19, -28], [6, -13, -4], [15, -1, 7], [25, -1, 32], [-13, 16, -24], [24, -37, 10], [34, -18, -19], [-9, -4, 15], [28, -3, 5], [-45, 10, -32], [-17, 4, 7], [39, -14, -3], [14, -46, 22], [23, -39, 9], [13, 34, -2], [-15, 35, -12], [-10, -32, 22], [34, 7, -16], [-21, -23, 1], [-1, 18, -19], [-32, 9, -6], [34, -18, 26], [34, -25, 34], [-30, 19, -3], [-11, -7, -18], [-18, 33, -29], [-15, 26, -26], [16, -20, 9], [63, 1, -2], [21, -17, -22], [4, -5, 13], [-18, -16, -14], [-32, 12, -15], [10, 5, -31], [-21, 7, -44], [29, -13, 34], [27, -5, 27], [16, -38, 7], [13, -19, 6], [19, 26, -6], [15, 19, -7], [-4, 22, 23], [25, 6, -4], [0, -1, -25], [-7, -23, 4], [0, 20, -15], [18, -12, -19], [33, -8, 5], [-32, -16, 20], [44, -6, 2], [36, -27, 32], [-2, -19, 7], [-8, 19, 3], [-14, -6, -35], [7, -20, -29], [-13, 23, -2], [-7, 34, -31], [30, -2, 36], [29, 0, 23], [-8, -25, 14], [-4, -3, 14], [-18, 35, 15], [26, -13, 26], [31, -2, -8], [-53, 19, -30], [0, -28, -5], [-2, -45, 12], [-23, 28, 32], [29, 2, 17], [-12, -5, -5], [-9, 3, -1], [12, 41, -3], [35, -33, 49], [-7, 0, 20], [15, -42, 31], [-41, -19, 5], [-26, 53, -36], [12, -22, 2], [5, -25, -32], [38, -40, 52], [-43, 23, 1], [7, 26, -9], [-11, 15, -19], [19, -23, 32], [-25, 21, 25], [3, 21, -26], [13, 12, -18], [6, 2, 1], [-1, -4, 11], [-1, -15, -39], [0, 3, 28], [7, 35, -21], [28, 20, -12], [-47, 31, -52], [-26, -20, 15], [48, -18, -22], [-28, 35, 9], [-1, 3, -36], [-37, 44, -17], [-27, 12, -20], [32, -26, 33], [-48, -16, -8], [-50, 32, -51], [-34, 18, -48], [-14, -27, 6], [-4, 6, 23], [-22, 17, -41], [-18, 58, -8], [7, -14, 35], [32, -19, 55], [-20, -31, 21], [6, -43, 25], [5, -7, -36], [4, -21, 42], [-8, -8, 24], [-43, -25, 1], [-8, -8, 39], [-6, 47, -3], [44, -6, 19], [-29, -26, 16], [23, -21, 8], [-20, -27, 12], [25, -20, 22], [28, 0, 13], [3, -48, -4], [8, -25, 29], [33, -1, -15], [-31, 51, -14], [-57, 26, -48], [-20, 17, -18], [21, -7, 0], [8, -19, 23], [-50, -26, 7], [9, 2, 16], [-65, 25, -16], [-14, -29, -9], [0, -14, 16], [-44, 20, -29], [-9, -21, -4], [44, -26, 48], [53, -32, 43], [6, -35, -7], [-5, 12, -14], [-31, -4, 30], [-3, -2, -19], [12, -24, 10], [-14, 11, -26], [-34, 27, -19], [26, -6, 19], [76, -30, 53], [20, -15, -27], [-29, 17, 8], [-14, -36, 5], [-45, 18, -16], [34, 23, -14], [-2, -30, -10], [-5, 0, 25], [38, -38, 39], [-15, 14, 11], [19, -56, 7], [-22, 23, -21], [19, -62, 45], [27, 7, -20], [-44, 47, -52], [-15, 16, 21], [43, 0, -6], [-34, 18, -2], [25, -43, -22], [23, -16, -25], [41, -9, -14], [-38, 34, -7], [15, -45, 14], [-12, 8, -44], [13, -46, 20], [52, -38, 42], [5, 14, -12], [-42, -7, -14], [-18, -8, 3], [22, -48, 31], [-3, 38, -46], [-15, 0, -33], [-76, 6, -12], [42, -36, 40], [-21, 18, 43], [-11, -33, 38], [-2, -15, 32], [13, 46, 6], [16, -26, 28], [15, 19, -18], [-33, 2, 1], [41, -42, 31], [21, 9, 17], [24, 7, 20], [-10, 21, 31], [20, -43, 57], [-38, 21, -5], [-26, -20, 33], [34, -57, 28], [-51, 47, -14], [16, -26, 49], [-28, 22, -32], [-16, 23, -1], [34, -32, 10], [46, 21, 10], [-38, -3, 29], [-30, 14, 3], [-23, 21, -47], [30, -21, 9], [19, -49, -15], [-53, -17, 11], [0, 15, -6], [-34, -9, -2], [31, -52, 40], [-55, 7, -35], [-20, 16, 13], [1, 40, -6], [-50, 17, -42], [-49, 52, -55], [-39, -26, 13], [-27, -14, -26], [50, 28, -16], [26, 27, 5]];
    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_z();".
// 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_z(: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_z();".
// 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_z( : 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, -1, -2, 1]>,<5,R![-1, 3, 4, 1]>,<7,R![13, -4, -3, 1]>],Snew);
    return Vf;
end function;