
// Make newform 2704.2.a.j in Magma, downloaded from the LMFDB on 11 December 2025.
// 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_j();".
// 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_j();".
// 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], [-3], [3], [0], [0], [-3], [6], [-6], [0], [0], [-3], [0], [-1], [3], [-6], [-6], [-8], [12], [-15], [-6], [-10], [-6], [6], [-12], [-12], [14], [12], [9], [-6], [-2], [3], [-18], [-5], [-6], [-15], [-22], [6], [-12], [6], [15], [-2], [-12], [-6], [3], [-20], [23], [9], [12], [-9], [21], [-9], [30], [12], [-3], [-24], [0], [15], [-8], [30], [4], [9], [18], [-18], [19], [18], [-30], [-13], [-33], [21], [6], [24], [-8], [4], [6], [9], [30], [-18], [-30], [-6], [-15], [-15], [15], [11], [-10], [21], [-24], [18], [-15], [-24], [-12], [39], [12], [27], [36], [6], [-6], [27], [16], [15], [37], [27], [39], [-45], [-23], [-42], [-18], [-36], [30], [37], [22], [6], [-12], [24], [-15], [18], [-36], [-42], [-36], [0], [-30], [1], [18], [6], [0], [-42], [6], [0], [28], [-9], [-36], [39], [32], [-2], [30], [24], [21], [-12], [-18], [15], [0], [45], [14], [18], [20], [24], [39], [-18], [-40], [39], [3], [33], [-11], [12], [-17], [-12], [20], [-36], [-2], [-45], [48], [-9], [-3], [-27], [-12], [-9], [-2], [8], [6], [36], [-24], [-45], [12], [-24], [-40], [-45], [0], [-30], [-16], [10], [-12], [12], [4], [-42], [-24], [-30], [-38], [-6], [-24], [0], [29], [24], [-47], [30], [-27], [-54], [60], [26], [42], [-54], [21], [-62], [-57], [-55], [24], [-42], [-39], [36], [24], [-23], [2], [12], [26], [-42], [-39], [-30], [32], [-63], [72], [-21], [32], [9], [-36], [9], [-27], [10], [39], [-30], [-62], [60], [-14], [-20], [0], [3], [1], [27], [66], [39], [-60], [-12], [-66], [7], [-4], [39], [36], [-30], [33], [-60], [36], [-6], [-63], [0], [-27], [35], [-66], [24], [-38], [-18], [42], [18], [64], [-33], [-21], [-16], [-48], [35], [9], [30], [36], [36], [-22], [42], [-36], [50], [58], [24], [-78], [-54], [0], [-63], [6], [45], [-48], [-30], [-42], [-78], [-11], [3], [-21], [-30], [-48], [-33], [36], [0], [44], [-60], [28], [36], [-15], [-12], [31], [-3], [20], [36], [13], [18], [3], [-40], [-36], [56], [6], [-81], [27], [-4], [-87], [25], [-54], [-60], [-36], [30], [-28], [48], [42], [81], [24], [-38], [-36], [-36], [18], [-6], [30], [48], [-10], [-54], [0], [72], [66], [24], [-90], [-52], [21], [-57], [21], [62], [-9], [75], [-38], [18], [45], [12], [30], [12], [-15], [64], [-40], [-6], [69], [60], [-33], [69], [78], [-42], [12], [6], [-52], [89], [27], [96], [-47], [-27], [65], [-9], [30], [68], [-52], [-24], [-18], [66], [90], [82], [90], [84], [-12], [-12], [-6], [-9], [-45], [-58], [-6], [-18], [-54], [-69], [54], [-73], [75], [49], [21], [-15], [68], [-75], [9], [-54], [-27], [-18], [-9], [38], [3], [60], [-24], [84], [1], [78], [81], [-73], [-23], [42], [21], [-28], [12], [54], [30], [18], [-48], [45], [-54], [18], [39], [24], [0], [-60]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : 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![3, 1]>,<7,R![-3, 1]>],Snew);
    return Vf;
end function;