
// Make newform 3549.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3549_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_3549_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_3549_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
        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_3549_a();"
function MakeCharacter_3549_a()
    N := 3549;
    order := 1;
    char_gens := [1184, 1522, 3382];
    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_3549_a_Hecke(Kf)
    return MakeCharacter_3549_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+1)]];
    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, 0], [1, 0, 0], [1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, 0, 0], [-3, 1, -1], [2, 0, 3], [-4, -1, -1], [1, -3, 1], [-1, 1, -1], [1, 0, -4], [-3, -2, -3], [-8, 0, 0], [-4, 3, 3], [-3, 8, -2], [-5, -4, 2], [-8, 1, -3], [-6, 3, -3], [3, -3, 0], [-1, 3, -3], [-6, 7, -2], [-1, 6, 1], [3, 4, -6], [5, -3, -4], [0, -6, 8], [-4, -7, 0], [6, -3, 10], [1, -3, 2], [9, -8, 10], [7, -13, 7], [-5, 1, -4], [7, -8, 13], [-15, 1, -5], [-4, 4, -11], [11, 0, 8], [-9, 2, 5], [9, 0, 3], [4, 6, -1], [-5, 14, -10], [-11, 8, -1], [-1, -5, 6], [4, 0, 13], [-3, -7, -7], [-4, -2, 5], [-14, 9, -5], [-4, -8, -5], [10, -17, 9], [7, -3, 3], [9, -11, 16], [-4, -5, -11], [-3, -7, 6], [15, -11, 10], [7, -5, -5], [-6, 17, 0], [13, 3, -1], [9, -20, 16], [-24, 8, -12], [-6, 12, 14], [-23, 12, -20], [20, 1, 8], [18, -16, 19], [7, -21, 1], [1, 3, -12], [-14, -2, 1], [12, 7, 3], [-15, 11, -13], [-1, 6, -14], [11, 4, -3], [-5, 3, -14], [17, -4, 9], [5, -7, -7], [-25, 1, -9], [8, 6, -14], [14, -8, 25], [-30, 6, -10], [7, -2, -18], [14, -7, 4], [5, -6, -12], [3, -9, 15], [-15, -4, 6], [-10, 3, 5], [-9, 13, -6], [4, -14, -12], [-13, 10, 3], [-1, 0, -14], [-33, 8, -13], [-4, -10, -1], [10, 12, 1], [-5, -7, -4], [-5, -9, 7], [18, -17, 21], [-27, 6, 1], [6, 14, -3], [0, -3, -10], [6, -9, -22], [14, -6, -3], [-8, -1, -13], [15, -7, 31], [14, 10, 1], [-13, -23, 12], [8, -23, 0], [-6, -5, -14], [5, 5, 3], [0, 26, -11], [-12, 19, -10], [25, -18, 0], [27, 4, 7], [-17, 4, -9], [-14, 6, 0], [-21, 10, -27], [-2, 13, -6], [-10, -10, 11], [-13, 20, -10], [-8, 31, -17], [8, 15, 0], [-21, 9, 1], [27, -24, 20], [16, -13, 2], [-5, -17, 8], [-13, 4, 8], [16, -17, 24], [20, 4, 1], [-8, 20, 18], [2, 28, -10], [-17, 21, -23], [18, -9, 23], [-14, 19, -22], [-5, -15, 17], [35, 2, -1], [11, -29, 15], [16, -24, 32], [1, -1, -1], [22, -27, 14], [29, -10, 7], [8, 4, -14], [42, 1, -2], [-21, 14, -34], [27, 5, 11], [30, -14, 37], [6, 29, -18], [-20, 18, -23], [-24, 8, -24], [-6, 25, -13], [-12, 14, -30], [-10, -2, 15], [11, 15, 4], [21, -5, -10], [10, -23, 6], [-14, 24, -29], [-16, 29, -3], [-4, -7, -26], [-17, 42, -29], [-9, 31, 7], [1, -1, 0], [9, -5, 9], [4, -3, -11], [5, 14, -10], [-14, -15, -4], [-27, 10, -4], [4, -9, 9], [-13, 21, -1], [13, 18, 4], [3, 10, -16], [-18, 6, 9], [-4, -4, -18], [-1, 17, 3], [36, -14, 35], [-35, 3, -25], [36, -12, 5], [-2, -12, -7], [-1, -1, 6], [7, 5, -8], [-33, 22, -31], [-4, 33, -8], [20, -32, -1], [-36, 10, 3], [-27, 15, 5], [20, -26, 7], [2, 8, 23], [7, 7, 31], [11, 2, 17], [-5, 9, -9], [22, 17, -7], [-35, 6, -21], [-18, 32, -15], [-14, 23, -19], [5, -34, 29], [36, -2, 11], [-5, 36, -23], [-29, 23, -32], [-19, -3, 15], [25, -35, 22], [41, -4, 3], [-23, 1, 3], [33, -29, 47], [-4, 15, 20], [17, -12, 3], [-12, -21, 12], [14, 13, 13], [-27, -14, 17], [-24, 11, 4], [-4, 38, -6], [-8, 14, -22], [42, -10, 13], [39, -5, 19], [2, -6, -29], [-45, 19, -16], [-15, -12, 27], [-23, -10, 23], [-22, 40, -10], [-13, -7, 6], [15, -2, -19], [12, -2, -17], [-2, -18, -4], [-48, 7, -15], [-4, 2, -17], [-19, 18, 7], [19, -16, -2], [-10, 17, -30], [-30, -2, -32], [-11, -24, 0], [26, -22, 0], [-54, 11, -20], [-35, -8, 4], [8, -16, -17], [-24, 25, -16], [-22, -7, -32], [31, -37, 33], [41, -26, 30], [14, 2, 23], [-1, 18, -11], [-1, 43, -9], [35, -8, 8], [-31, 21, -15], [7, -3, -31], [8, -40, 26], [23, 29, -5], [-5, -8, 36], [-12, 31, -28], [1, -19, 31], [-26, 2, -33], [28, -11, 16], [19, -22, -20], [-47, -3, -13], [30, -22, 30], [21, 12, 8], [-13, 7, 19], [10, -15, -1], [33, -26, 44], [12, 10, 18], [32, -3, 0], [-30, -1, -25], [-40, 22, -8], [-42, 36, -50], [-14, 23, -17], [14, 13, 13], [-25, 21, 32], [-14, -4, 28], [-9, 42, -25], [55, -19, 36], [-51, 0, -16], [-24, -5, 12], [8, -6, 5], [53, -23, 3], [-35, -9, 14], [-7, -6, 6], [-39, 8, -15], [41, -1, 7], [32, -38, 21], [17, -38, 10], [-36, 11, 2], [8, 8, -33], [0, 2, 8], [-1, -5, 32], [-22, -19, 23], [-22, 4, -35], [-63, 19, -22], [-37, -1, 4], [-35, -16, 10], [-18, 22, -19], [-4, 5, 2], [-29, 14, 16], [-26, 7, -53], [-2, 8, 12], [-11, -37, 7], [8, -6, 13], [27, -45, 29], [8, 5, 29], [14, 22, 10], [-34, 5, -18], [-57, 3, -14], [35, -35, 42], [36, -2, 14], [-41, -17, 8], [31, -36, 10], [-10, -20, 23], [-18, 41, -35], [-43, 18, -19], [-19, 58, -27], [38, -20, -2], [-2, 2, 17], [46, -22, 29], [-40, 21, -2], [-15, 29, 11], [-38, 24, -4], [-53, -20, 7], [11, 2, -23], [13, -9, 39], [34, -11, 50], [-5, 26, -42], [-58, 17, 7], [13, 4, -10], [-65, 16, -30], [-28, 37, 2], [6, -19, 0], [-13, -4, -34], [-15, -44, 31], [32, -36, 42], [-10, 36, -36], [-24, 21, 22], [-21, 18, 20], [0, 21, 8], [-6, -26, 10], [-58, 24, -12], [37, -45, 57], [21, -5, 20], [34, -29, 15], [-2, -61, 28], [54, -18, -21], [-2, -1, -44], [60, -2, 25], [1, 25, -29], [15, 41, -23], [11, 46, -17], [64, -30, 21], [-2, -11, -5], [15, 11, 2], [48, -13, 55], [9, -1, -12], [-28, 13, 18], [38, -38, -6], [31, -6, -22], [-32, 4, -23], [-39, 44, -34], [-48, 24, 27], [35, -6, 24], [-15, -2, -26], [6, 34, -16], [-52, 31, -36], [-1, -1, 0], [48, -54, 67], [4, -16, 13], [3, 35, 14], [-23, 0, -42], [14, 6, -19], [-60, 17, -39], [30, -12, 10], [19, 6, -13], [-9, -10, -21], [43, -27, -10], [33, -15, 19], [15, 18, 7], [-18, 21, -11], [14, 52, -24], [12, -46, 6], [-2, 25, -37], [-25, -18, 5], [38, 11, -14], [-60, 15, -48], [1, -24, -2], [11, -23, 0], [-5, -10, 13], [35, -39, 1], [16, -31, -7], [-5, 10, -28], [-4, -17, 17], [-20, 46, 19], [38, -31, 20], [30, -14, 27], [78, -47, 84], [-11, 62, -15], [46, -32, 23], [-14, 31, 17], [-30, 52, -28], [14, -1, 52], [42, -12, -16], [-2, 37, -4], [-30, 20, -9], [41, -28, 7], [18, 11, -33], [-2, 18, -1], [-25, 44, -9], [-28, -15, -28], [-24, 67, -35], [-6, 36, -11], [31, -17, 26], [-22, 33, -18], [4, 13, 7], [-45, 14, 9], [65, -25, 44], [32, -68, 31], [15, 15, -3], [-22, -21, 22], [-30, 8, -63], [-3, -17, -26], [18, -2, -24], [7, 14, 16], [-9, 1, -16], [-40, 1, 11], [12, -58, -4], [5, 8, 18], [-10, 26, -57], [-70, -12, 9], [6, 40, -4], [34, -32, 49], [59, -9, -9], [-31, 50, 26], [-54, 30, -59], [-26, -5, -44], [32, 0, 2], [-61, 44, -26], [-13, -15, -6], [1, -18, -19], [5, 16, 9], [1, -17, -27], [30, -12, 18], [42, -16, 45], [-24, -20, -4], [-11, 52, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3549_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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