
// Make newform 2704.2.a.c 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_c();".
// 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_c();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-1], [-2], [-1], [1], [0], [3], [7], [-1], [3], [8], [1], [-11], [-11], [12], [-6], [-9], [-9], [-3], [-5], [2], [12], [-4], [1], [1], [-17], [8], [-17], [-10], [11], [-13], [-12], [9], [9], [1], [16], [10], [-5], [-7], [-9], [-9], [-14], [-7], [5], [13], [-3], [-1], [1], [-1], [6], [-26], [-24], [-11], [13], [-13], [31], [-5], [-7], [-21], [-14], [-25], [9], [-20], [-8], [30], [2], [27], [6], [-27], [9], [25], [-24], [15], [11], [-15], [-33], [6], [-19], [-27], [-35], [-21], [22], [-11], [19], [35], [-12], [21], [-7], [-3], [24], [8], [-27], [-13], [3], [36], [25], [1], [-42], [19], [-30], [-12], [-19], [9], [-17], [20], [-22], [21], [-14], [44], [-21], [13], [-39], [-47], [-20], [27], [11], [19], [3], [-9], [29], [25], [39], [-6], [-9], [25], [-22], [29], [-39], [8], [-46], [-11], [29], [-17], [47], [-3], [5], [-3], [-21], [23], [27], [32], [5], [29], [20], [3], [27], [-10], [-18], [-20], [-16], [1], [-45], [12], [27], [-25], [16], [-15], [5], [-2], [-14], [-39], [-9], [-16], [-27], [9], [32], [-13], [-25], [34], [-54], [-36], [-15], [41], [21], [-8], [-21], [5], [-42], [-13], [-17], [52], [-20], [26], [50], [33], [-45], [26], [-52], [57], [-21], [35], [19], [-8], [-67], [-11], [27], [-2], [-1], [42], [-64], [5], [-31], [-43], [-10], [-67], [3], [-20], [-59], [-27], [1], [23], [38], [51], [31], [39], [-22], [-8], [-9], [-27], [30], [-61], [-8], [-34], [19], [3], [18], [23], [41], [17], [40], [15], [19], [-15], [-6], [52], [-16], [-55], [69], [-39], [-69], [45], [-5], [-59], [53], [9], [24], [23], [-35], [-49], [-17], [-23], [33], [-32], [-73], [-54], [-1], [23], [21], [-38], [33], [-32], [27], [30], [59], [25], [53], [57], [42], [-9], [-45], [2], [52], [-27], [-19], [7], [25], [-33], [54], [73], [-75], [3], [5], [12], [-31], [44], [24], [14], [-82], [-57], [51], [-9], [-3], [-47], [55], [43], [66], [-88], [27], [-17], [17], [-13], [18], [39], [12], [-31], [-23], [64], [2], [-15], [-38], [81], [65], [-66], [-9], [55], [-17], [27], [48], [13], [3], [68], [50], [-57], [77], [-42], [-65], [20], [-45], [-81], [47], [-67], [-30], [-49], [-9], [37], [28], [-15], [-27], [13], [8], [-50], [15], [-38], [63], [41], [68], [-62], [27], [21], [67], [32], [77], [-71], [53], [35], [-10], [19], [-65], [22], [16], [1], [15], [39], [57], [75], [31], [1], [-81], [-74], [-47], [-43], [-16], [26], [47], [67], [-24], [89], [45], [-81], [19], [78], [-83], [-64], [42], [79], [73], [-45], [-6], [-16], [-19], [-15], [45], [-52], [-61], [-13], [63], [5], [-6], [4], [69], [49], [83], [13], [-30], [81], [-83], [97], [61], [44], [25], [62], [31], [81], [41], [-93], [46], [11], [-80], [-51], [57], [11], [94], [21], [-12], [49], [-63], [-52], [74], [19], [-63]];
    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_c();".
// 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_c(:prec:=1)
    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_c();".
// 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_c( : 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]>,<5,R![2, 1]>,<7,R![1, 1]>],Snew);
    return Vf;
end function;