
// Make newform 3549.2.a.s in Magma, downloaded from the LMFDB on 19 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_s();".
// 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_s();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 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 := [[1, -1, 0], [-1, 0, 0], [1, -2, 1], [1, 0, 0], [3, 0, 1], [0, 0, 0], [1, 1, 0], [3, 0, 2], [3, 1, 1], [-4, 3, -2], [0, 4, -3], [-1, 2, -1], [-2, 4, 0], [-7, 1, -1], [8, -2, 5], [5, -2, 0], [1, -1, -1], [5, -2, 0], [-2, 3, 2], [-4, -1, -5], [-2, 3, -5], [-2, -2, -7], [-5, 6, -7], [3, 6, -4], [-8, -2, 1], [7, 1, 1], [-1, -8, 2], [-8, 3, -1], [8, -3, 0], [-6, 2, -7], [1, -4, 3], [15, 2, -3], [1, 0, 8], [4, -1, 0], [7, -2, 1], [2, -6, -2], [14, -2, 3], [11, 4, 0], [-5, -2, -8], [15, -5, 1], [0, 3, 8], [-3, 3, -5], [-1, -1, 1], [-13, 5, 3], [-6, 11, -13], [6, -3, 11], [-13, 3, -9], [13, -10, 4], [2, 8, -11], [7, -1, 3], [-13, 0, 2], [6, 2, 0], [-2, 4, -7], [-4, 6, 1], [8, -3, 9], [10, -7, 11], [-20, 6, 1], [9, 3, 10], [-8, -2, -6], [-10, -2, -13], [2, 5, -10], [11, -8, 1], [12, -11, 4], [-9, -5, -2], [-9, 8, -9], [-7, 7, -8], [6, -7, 8], [4, -2, 3], [-10, -11, 10], [12, -1, -6], [4, -6, 1], [-6, -8, 0], [5, -11, 13], [-5, 3, -3], [24, -2, 4], [8, 0, -4], [-8, 14, -4], [-1, -2, 11], [8, 1, 6], [-14, 5, -2], [9, 8, -1], [-20, -8, 5], [-14, 2, -15], [-3, 14, -4], [10, 3, 12], [3, -6, 0], [17, -10, 11], [-31, 1, -7], [-2, 10, -13], [-3, 1, -7], [8, -9, 14], [16, -13, -1], [6, -1, 2], [6, 1, -8], [15, -3, -2], [-7, 6, -8], [0, 4, 10], [-26, 1, 4], [0, -6, -11], [18, 11, -10], [-23, 9, 6], [-10, 15, 6], [5, 1, -8], [-19, 3, -5], [-19, 21, 2], [-23, 3, -1], [-10, 12, -5], [2, -11, -2], [25, 8, -8], [13, 0, 3], [-1, 13, -8], [-3, 2, 13], [-11, -12, 3], [-6, -10, 0], [-7, 19, -4], [1, 15, -13], [-19, -2, -14], [-8, 5, -6], [-7, -6, -8], [-6, -24, 19], [0, -16, 3], [11, 7, -1], [-10, -3, -10], [-23, 7, -3], [-3, -3, 13], [12, -19, 12], [0, 1, -9], [10, -1, -9], [14, -9, 12], [-21, -11, 2], [11, -7, 1], [16, 9, -12], [14, -15, 18], [-13, -1, 5], [26, 4, -11], [-30, 4, -2], [11, 1, 4], [-4, -11, -8], [-8, 17, -17], [39, -5, 6], [18, 7, -11], [-4, -16, 14], [7, -14, -12], [7, 17, -18], [12, -12, -4], [8, 1, -8], [-16, 21, 7], [16, 9, -10], [2, 12, -3], [15, -15, 5], [-20, 1, -6], [8, -21, 4], [-10, -4, -9], [-6, 12, -12], [1, 4, 7], [7, -22, -2], [-4, -2, -7], [-6, 23, -7], [-2, -2, 8], [-13, 6, 1], [16, 6, -5], [31, -19, 12], [-19, 18, -16], [-9, -16, 18], [-1, 1, 19], [-7, -24, 14], [2, -21, 22], [-8, -12, 8], [13, 6, 20], [-5, -7, -6], [-10, 5, -6], [-2, 23, -9], [31, -11, 8], [8, -4, -10], [-23, 13, 2], [22, -18, -2], [39, -6, 13], [49, 3, 1], [24, -16, -4], [1, -11, -9], [23, -23, 20], [6, -1, -6], [-11, -18, 22], [15, 8, 7], [33, -11, 27], [20, -1, 10], [-23, 25, -1], [4, 14, 0], [18, -22, -4], [23, -1, 23], [0, 8, -17], [28, -13, 16], [14, 22, -12], [24, -2, -1], [21, -18, 27], [12, -22, 12], [13, 18, -7], [-14, 1, -11], [-5, 7, -13], [-2, -5, 4], [2, 18, -23], [18, 2, 8], [-46, 4, -23], [3, -17, 23], [25, -3, 4], [-6, -2, 10], [23, 7, -3], [-8, 9, -22], [33, -7, 1], [6, -2, -22], [5, 8, -11], [-1, -1, -20], [-24, 24, -24], [22, -26, 3], [-4, 11, 2], [15, -17, 30], [-13, 19, 1], [-29, 14, -19], [25, -14, -7], [17, -13, 2], [-24, 2, 16], [-43, 0, 10], [35, -5, -7], [14, -24, 3], [-16, 17, -28], [-9, 5, -12], [30, -15, 39], [-16, 4, 9], [-9, 12, 5], [26, 10, -13], [6, -22, -2], [56, 2, 4], [44, 16, -9], [38, 4, -12], [-6, 12, -21], [6, -23, 10], [2, 13, 14], [1, 5, 14], [33, -15, 22], [-35, 2, -4], [-5, -11, -4], [-22, 25, -23], [7, 28, -11], [49, -8, 30], [-7, -25, 27], [-61, 6, -8], [-43, -1, -14], [14, 22, -17], [21, 18, -14], [17, 7, -15], [-10, 20, 12], [-2, -21, 0], [15, 17, -3], [0, 29, -12], [-37, 18, 10], [-3, 4, 20], [38, -16, 26], [30, -19, 6], [30, 1, -15], [-12, -6, 20], [-22, -17, 2], [-16, 24, -19], [5, -8, -7], [20, -29, 19], [0, -6, 19], [20, -17, 29], [-44, 0, 3], [-2, 18, -15], [15, -18, 37], [9, -44, 28], [8, -18, -4], [-32, 29, -22], [-8, -15, 28], [-12, 19, 10], [27, -2, 24], [33, 4, 11], [-4, 12, -3], [-16, 31, -28], [-14, -15, 2], [8, 5, -11], [-23, -2, 6], [3, 27, -29], [0, 5, -18], [-4, -13, -14], [-2, 18, 7], [-21, 6, -10], [-22, 24, -23], [46, -1, -9], [27, 6, 3], [3, 19, 1], [25, 5, 5], [-33, 11, 17], [-8, -24, -8], [-7, -19, 3], [-23, 18, -32], [41, -6, 16], [17, 8, 15], [44, -12, 36], [-13, 0, 10], [23, -10, 20], [-42, 9, -5], [36, -30, 22], [-35, 14, -26], [16, -22, -2], [13, -34, -3], [-21, 15, -33], [-3, 1, -23], [-39, 3, -37], [-13, 22, -18], [-3, -30, 26], [-9, 17, -21], [-19, 9, -21], [1, -12, 28], [-5, 23, -1], [-35, 9, -24], [-19, 23, -13], [-33, 25, 1], [-46, 1, 9], [-25, -3, 12], [8, -19, 35], [-10, 35, -10], [18, -13, 17], [7, -10, 11], [-46, -9, -2], [53, 14, -4], [34, -27, -4], [-4, 7, -21], [-53, 9, -27], [-7, -3, -11], [-38, -7, -4], [-45, -2, -9], [-1, 5, 9], [13, 0, -26], [-20, -14, -4], [28, -15, -5], [13, -3, -7], [19, -8, 27], [-5, -6, -12], [19, -29, 18], [22, -3, -2], [0, -2, 25], [2, -13, 3], [-49, 26, -2], [-4, -36, 17], [40, -13, -12], [5, 22, -6], [13, -10, -17], [75, -11, 1], [3, -18, 24], [-12, -43, 24], [13, 10, 19], [27, -3, 5], [15, -10, 27], [59, 11, -13], [69, -8, 8], [-44, 12, -8], [9, -17, -5], [12, 15, -12], [2, 6, -32], [11, -21, 33], [-25, 28, 6], [-5, 9, 26], [-13, 45, -36], [-4, 32, -19], [-48, 17, 8], [-9, -2, -5], [-42, 32, -28], [-24, -14, -19], [65, -6, -8], [-44, 4, -26], [-13, 9, 15], [-14, 40, -4], [42, -1, -17], [25, -3, -22], [-22, 27, -49], [59, -21, 11], [-37, -5, 1], [-31, 14, 8], [8, 30, -14], [-22, 36, -41], [27, -9, 12], [32, -11, 5], [-47, -3, 9], [-4, -16, 4], [36, -14, 19], [-9, 19, 15], [35, -4, -9], [11, 7, 3], [-7, 28, -21], [-35, 37, -24], [-40, -6, -17], [-12, -9, 21], [9, -29, -2], [2, 11, -26], [37, 5, 12], [6, -26, -7], [22, 6, -3], [3, 32, -16], [-62, 10, -29], [0, -16, -12], [23, -22, 24], [-73, 15, -12], [-47, 9, 0], [10, 27, 3], [26, -1, 40], [-35, 15, -21], [-42, -5, 5], [-2, -37, 41], [42, -19, 32], [30, 9, -22], [47, -36, -10], [-46, 19, 4], [-14, 20, 16], [-56, 2, -39], [-11, 23, -17], [38, -34, 38], [-8, -16, -4], [-55, 19, -47], [2, 32, 6], [-39, 38, -25], [-45, -16, 23], [9, -23, 17], [23, 2, 36], [-31, -10, -16], [-15, 47, -35], [46, -19, 6], [10, 20, 2], [21, -46, 29], [-28, 11, -16], [-5, 23, -5]];
    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_s();".
// 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_s(: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_s();".
// 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_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3549_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![5, -3, -2, 1]>,<5,R![-13, -13, 0, 1]>],Snew);
    return Vf;
end function;