
// Make newform 3549.2.a.l in Magma, downloaded from the LMFDB on 24 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_l();".
// 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_l();".
// 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, -5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, 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, -1, 1], [-1, 0, 0], [-3, -1, 1], [0, 0, 0], [4, -1, 0], [-1, 2, 0], [-2, 0, -1], [3, 1, 0], [-2, -3, 1], [1, -1, -3], [-2, 4, 0], [-2, 0, -1], [-2, 1, -3], [-5, 0, 2], [-2, 2, -5], [7, -2, -2], [-7, 3, 0], [-7, -2, -1], [5, 0, -1], [0, -3, -1], [-11, 3, 1], [1, -4, 0], [8, 3, -3], [2, 6, 1], [3, -2, 4], [1, -2, 3], [-3, 3, 2], [-2, -5, 3], [-3, 5, 1], [-7, -1, 1], [-3, -2, -2], [1, 1, 0], [-1, 1, -7], [-4, -4, 2], [-6, -7, -1], [15, 0, 4], [1, 0, 4], [0, 0, -3], [-1, -9, 2], [4, 8, -3], [12, 6, -1], [4, -4, 7], [11, 2, 3], [7, 10, -1], [10, -2, -5], [11, 2, 2], [-2, -5, 5], [-10, -12, 5], [-5, -4, -4], [-20, -2, 0], [0, 9, -7], [-14, 1, -3], [3, 0, 5], [1, 8, -5], [-6, 1, 5], [10, -5, 0], [-10, 12, 6], [-2, -3, -3], [9, 5, 2], [-13, 9, 1], [-9, -5, -4], [4, 3, 2], [21, 3, -3], [-8, 9, 0], [-29, -1, 2], [-2, 7, -3], [-1, 3, -8], [-3, 7, -6], [6, -3, -7], [-14, 0, -4], [6, 0, 7], [-6, -4, 9], [6, 10, -8], [0, 0, -8], [10, 6, 0], [-5, -7, -7], [-7, -5, 4], [1, 5, -6], [-7, -1, -5], [12, 15, -5], [-10, -5, -1], [11, -6, 2], [-5, 5, -12], [-7, 8, 2], [1, 11, 3], [6, -10, 9], [0, -9, 11], [22, 2, -3], [-7, -11, 2], [5, 4, -1], [25, 3, -4], [-1, 1, 2], [8, -3, -8], [15, 12, -8], [-4, 6, -6], [-15, 1, 4], [4, 11, -3], [5, -1, 0], [-6, -11, 8], [-15, -3, 0], [8, -13, 0], [-2, 8, 5], [6, -3, 8], [8, -4, 1], [-34, 5, -1], [1, -13, 6], [-11, -2, 2], [-1, -1, 1], [14, -13, 2], [15, -11, 3], [-1, 5, -1], [-12, 6, 0], [-20, -3, 6], [-14, 0, 1], [-21, 8, 0], [7, -1, 2], [-21, -8, 10], [24, -5, 5], [-6, -5, 7], [2, -18, -1], [5, 11, -2], [-14, -2, 3], [-2, 4, -9], [-23, -3, 10], [-19, 0, -9], [-17, 16, 3], [7, -3, 4], [2, -15, -8], [-4, -22, 1], [21, 1, -2], [-13, 5, 8], [10, 8, 5], [18, -5, 5], [-6, 18, 6], [18, -13, 4], [3, -5, 12], [-1, -14, -9], [-26, 11, -2], [-3, -6, 13], [24, 10, 2], [-7, 2, 0], [12, 5, -14], [0, 12, -4], [7, -11, -12], [5, 10, -13], [-9, 3, -10], [-4, -7, -11], [-2, 12, 7], [21, -3, 16], [17, 7, -12], [-10, 9, 5], [-14, -4, 4], [-3, 5, -7], [9, -6, -16], [-6, -3, 3], [-37, 10, 5], [36, 2, -8], [-7, -13, -7], [-40, 13, 5], [0, -5, -8], [-17, 6, 0], [27, 0, 6], [-10, -6, 1], [-19, -4, 2], [-15, -9, 4], [12, 8, -12], [7, 10, 0], [-26, -15, 2], [-1, -17, -4], [5, 8, -1], [8, -17, 4], [4, -6, 2], [36, -3, 0], [20, 0, -2], [-31, -15, 7], [10, -6, -1], [24, 8, 0], [-2, 10, -3], [20, 27, -10], [-1, -15, 10], [-33, 4, -6], [15, -5, -5], [-24, -10, -3], [-23, 9, 2], [-38, 0, -9], [-18, -18, 4], [20, -10, 4], [-28, -2, 11], [-22, 11, -5], [-25, -5, 10], [0, 14, 12], [-14, 3, -9], [-39, 3, 3], [-26, -14, 0], [-25, -3, 3], [-5, -6, 9], [-12, 10, -1], [7, 3, -16], [22, -21, -13], [-12, -10, 4], [8, 9, 9], [14, -4, 17], [-20, -9, 8], [0, 0, 14], [-14, -10, 3], [1, -5, 4], [24, 0, -5], [-8, -4, 14], [-27, 11, 7], [0, -15, 12], [-16, 8, -4], [-4, 23, -1], [-3, 1, -6], [24, -17, -4], [-26, 4, 5], [-19, -13, 5], [-11, -3, 5], [-44, 3, -10], [14, -22, -4], [-19, -2, 16], [-4, -2, 7], [-18, 5, 1], [-13, -27, 4], [4, 3, 6], [9, 6, 3], [18, 21, -13], [33, -7, -9], [-26, -3, 9], [-20, -8, 6], [-10, -26, 4], [0, -15, 1], [-38, -4, 4], [24, 15, -5], [-3, -21, -6], [17, -7, 22], [26, 9, 6], [-18, -3, 2], [3, -8, 8], [20, -21, -12], [-13, -24, 5], [-3, 9, 11], [-15, -6, 6], [2, 26, 3], [29, 0, -8], [-6, -21, 8], [0, -1, -1], [15, 12, -2], [14, 18, -5], [-10, -16, 16], [19, -21, -12], [30, 20, -1], [19, -17, 4], [5, -14, 2], [-7, -14, -2], [-6, -10, -2], [9, 5, -6], [-19, 16, 5], [-2, 6, 16], [13, -5, 0], [-22, 13, 3], [11, -7, 7], [39, 16, -1], [-14, -9, 11], [15, 6, 13], [-22, 11, -11], [-16, 25, 5], [-7, -3, -13], [9, -22, -6], [-22, 14, -4], [-43, -7, 0], [35, 15, 0], [-57, -5, 0], [9, -14, 10], [-21, -9, 5], [38, -15, 3], [27, 1, 18], [35, 1, -8], [-29, -4, 1], [11, 2, 6], [-26, 26, 11], [-17, 19, 10], [21, 3, -2], [6, 1, -1], [49, 18, -12], [-10, 3, -13], [-17, -14, 3], [27, -3, 1], [52, 16, -7], [12, 8, -13], [32, 16, -7], [-32, 16, 12], [8, -12, 7], [31, 6, -12], [-49, -8, 12], [3, -29, 1], [8, -4, 28], [-5, 12, -26], [-43, -10, 10], [-21, -14, -9], [-2, 4, -10], [-37, -16, 10], [-2, 8, -18], [35, 17, -13], [-2, -22, -5], [-36, -8, 15], [-8, 20, -7], [5, -10, 0], [15, -36, -6], [-34, 0, 3], [12, 10, -11], [-7, -14, -18], [-22, 2, 7], [18, 7, -4], [-44, 4, 5], [-26, -22, 1], [13, 14, -3], [54, -9, 2], [51, 24, -9], [-25, -33, 18], [-23, 16, 17], [13, -11, 15], [29, -5, 8], [7, -4, -2], [13, -9, 20], [19, 26, -13], [-4, -28, 11], [-8, -24, 15], [19, -3, -22], [-11, 7, 1], [50, -20, -1], [-43, -18, 8], [30, 10, -16], [-23, 4, -1], [-4, -6, -3], [-17, 13, 5], [17, 8, -8], [-8, -9, 0], [29, -3, 14], [42, -11, -5], [27, 10, -13], [9, 34, -10], [-12, -21, 11], [31, 11, -22], [-25, 6, -8], [-7, -3, -7], [20, -10, 5], [-7, -8, -12], [7, 13, -8], [-47, -3, 5], [28, 14, 1], [-9, 15, -9], [-10, 16, 1], [5, 12, -24], [68, 4, 4], [22, -2, -17], [33, 7, -8], [-60, 6, -12], [12, 26, -5], [43, 14, -14], [26, 21, -14], [4, -1, -32], [-6, 37, -5], [15, -13, 0], [-23, -25, 17], [-22, -20, 20], [22, -7, 3], [-41, 14, 4], [36, -18, -6], [24, -6, 9], [66, 12, -4], [11, 2, 27], [-44, 1, 12], [21, 14, 11], [20, -2, 23], [20, -14, -1], [3, 22, 6], [-30, -20, 2], [-44, 19, 15], [-64, -3, 4], [15, -34, 5], [-14, -10, 5], [8, -20, -4], [-12, -15, 11], [32, -30, -9], [39, 25, -23], [54, 4, 13], [-3, 21, -11], [-24, 11, 4], [-6, -5, -19], [-35, -10, 17], [-28, -17, 18], [-45, 15, 14], [62, 11, -8], [-56, -7, 11], [-30, 7, 5], [-21, -6, -24], [-12, -13, -3], [-28, 20, 0], [1, -22, 14], [-54, 21, 0], [26, 19, -14], [3, 8, 23], [43, -21, -12], [-32, -28, 9], [9, -12, -7], [7, -8, 37], [17, -1, -24], [25, -1, 10], [11, -2, -8], [-11, 3, -2], [-18, 0, 12], [-50, -35, 19], [-4, 14, -21], [-4, -4, 6], [28, 28, 4], [44, 6, -9], [30, -2, -2], [-25, 17, -1], [41, 5, 7], [18, -8, 31], [9, 32, -30], [11, -12, -24], [32, 10, 15], [9, 7, -6], [-86, -14, 6], [-23, 13, -3], [17, 25, 0], [40, 6, -1]];
    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_l();".
// 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_l(: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_l();".
// 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_l( : 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, -5, 0, 1]>,<5,R![-9, -9, 2, 1]>],Snew);
    return Vf;
end function;