
// Make newform 3249.2.a.s in Magma, downloaded from the LMFDB on 10 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3249_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_3249_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_3249_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, -3, 0, 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_3249_a();"
function MakeCharacter_3249_a()
    N := 3249;
    order := 1;
    char_gens := [362, 2890];
    v := [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_3249_a_Hecke( : Kf := Kf)
    return MakeCharacter_3249_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 := [[-1, 1, 0], [0, 0, 0], [1, 0, 1], [0, -1, 0], [0, -1, -1], [0, 2, 1], [-2, 1, -1], [0, 0, 0], [2, -2, 0], [-5, 0, 1], [3, -1, -2], [0, -2, 3], [-4, 3, -4], [0, 5, -3], [2, 1, -3], [-2, -3, 1], [-7, -2, 0], [3, 4, -4], [-6, -6, 2], [-10, -2, 0], [0, -4, 0], [3, 7, -6], [0, 6, -9], [-5, -1, 3], [-5, 2, 2], [5, 4, -3], [6, -4, 1], [0, 3, -6], [-5, 2, -4], [-3, -1, 8], [1, -7, 8], [7, -7, 6], [-10, -1, -5], [6, 5, 0], [-8, 3, 4], [10, 0, 3], [-3, -8, 5], [0, 3, -5], [-11, 0, -8], [2, -12, 14], [-9, -9, 3], [-2, 8, 2], [-9, -11, 7], [-9, 2, -5], [6, 1, 10], [12, -8, 8], [-3, -7, 1], [9, -4, 1], [-6, -9, 6], [3, -8, 14], [1, 5, 9], [3, 10, 1], [-9, 3, 2], [2, 10, -3], [7, 2, 3], [1, -13, 9], [-4, 3, -13], [-7, 13, 1], [5, 12, -9], [4, 13, -10], [-7, 1, -8], [3, 1, 7], [-11, 5, -13], [-9, -7, 5], [-10, 10, 7], [28, 1, -1], [-15, 4, 6], [-15, -8, 3], [1, -3, -2], [0, 17, -6], [15, 3, -6], [-14, 6, -5], [-9, -6, -8], [-14, -21, 15], [-15, 5, -8], [-16, 5, -11], [8, 1, -9], [-12, 3, 10], [5, -7, 4], [7, 2, 14], [-3, 5, 11], [-2, -4, 2], [-17, -9, 13], [9, 17, -8], [18, -9, 8], [-7, 2, -20], [15, -11, 16], [0, -3, 13], [25, -1, -6], [-15, -6, 16], [-21, -3, 3], [-4, 1, 18], [1, 9, 3], [7, 1, -16], [-3, -12, -2], [-1, 0, 17], [1, 1, 20], [-18, 8, -16], [0, 21, -19], [9, -1, -3], [-6, 4, -6], [-13, 6, -1], [-9, 19, -14], [-12, -12, 3], [0, -4, -6], [-7, -6, 3], [28, -7, 6], [8, -2, 0], [-17, 13, -22], [27, 13, -6], [6, -11, 24], [14, -2, -2], [23, 23, -11], [18, -2, 8], [18, 0, 10], [14, -1, -8], [33, 4, 5], [3, 14, 5], [-27, 0, 0], [1, 25, -19], [10, 2, 11], [0, 1, -9], [0, -1, 5], [12, 4, 1], [8, -12, -12], [-11, -21, 19], [-21, -7, 12], [13, 29, -21], [27, 21, -17], [-25, -6, 0], [3, -2, -13], [17, -12, 8], [3, -13, 7], [18, -15, 4], [3, 1, 4], [21, 1, -1], [-2, 0, 13], [-12, -9, -13], [9, -11, -11], [-27, 19, 4], [-2, -1, 8], [8, 3, -13], [26, 1, -11], [37, 0, -2], [21, 7, -9], [-19, 12, 8], [-15, -29, 11], [-16, -7, 4], [-3, -1, 9], [-6, 28, -11], [15, -2, 9], [-33, 1, 7], [-15, 17, -18], [-23, -21, 4], [1, 23, -25], [-36, 10, -11], [3, 13, -22], [-11, -19, 12], [-9, -1, -6], [-23, 20, -6], [4, -13, 9], [14, -8, -9], [24, -8, 8], [-22, 8, -20], [-3, -18, -6], [-7, 27, 11], [0, -28, 7], [12, 14, -3], [10, -22, 2], [8, -28, 16], [0, 3, -21], [-18, -14, 24], [7, 19, -22], [9, -21, 4], [12, 30, -16], [23, -17, 12], [-30, -8, 5], [13, -29, 14], [24, 28, -12], [-3, 7, 23], [-7, 7, 7], [-21, -32, 25], [-6, 26, -17], [-31, 4, -15], [30, -14, 1], [9, 8, 8], [28, -13, -4], [-27, 19, 6], [-8, 21, -21], [27, -13, 14], [-18, 10, -24], [-13, -19, 10], [-6, -21, 17], [-13, -11, 12], [-19, -31, 22], [-8, 18, -23], [26, -26, -14], [3, 31, -22], [-12, -5, -8], [12, -32, 4], [-5, 9, 7], [-5, -1, -13], [-3, -35, 21], [15, 15, -22], [-23, 0, 13], [11, 41, -26], [-25, 4, -11], [16, -2, -19], [-5, -4, 12], [-24, -4, -8], [-6, -12, 22], [-16, -4, -20], [15, -14, -22], [1, 10, -1], [-15, 6, 12], [-21, 3, -22], [-28, -17, 10], [-33, -10, 17], [3, 26, 8], [-5, -19, 33], [15, -11, -15], [-27, 12, -4], [35, -12, -13], [27, 2, 15], [-1, -14, -12], [-9, 6, 19], [24, 26, -4], [-13, 3, 29], [10, -13, 26], [36, 7, 4], [-21, -37, 18], [0, -29, 21], [-29, -27, 15], [-27, -13, -4], [2, -3, -24], [-41, 16, -10], [3, 23, 9], [27, 23, -19], [46, -10, 9], [-26, -20, 23], [50, 14, -11], [2, -12, 15], [6, -2, -13], [3, -35, 18], [14, 7, 0], [-6, -2, -5], [-16, -2, 7], [-11, 22, -7], [-3, 5, -41], [-4, 20, -11], [-12, 29, -9], [-8, -42, 28], [9, -8, 1], [-17, -40, 11], [13, -10, -12], [-31, 23, -17], [-3, 0, -23], [-9, 2, -20], [-22, -46, 25], [-3, 8, -12], [6, -1, -14], [5, -41, 12], [-27, 21, 7], [-21, -6, -4], [2, -43, 13], [-9, 0, 26], [-9, -26, -11], [-21, 14, -4], [0, -6, 5], [17, -30, -13], [-48, 12, 8], [-2, 15, -39], [32, -17, 19], [-1, -9, 33], [-3, 12, 32], [0, -13, 24], [21, 3, 3], [-27, -15, -13], [42, 11, -17], [8, 10, -6], [-9, 8, 20], [5, -27, 27], [32, 9, 2], [27, -21, 14], [-31, 10, -2], [17, -21, 17], [33, 44, -30], [-5, -4, -21], [30, -2, 2], [-3, 22, -2], [-21, 5, -16], [-15, 17, -37], [25, 6, -23], [-6, -11, -2], [6, -26, 3], [42, -15, 27], [22, -1, 11], [25, 6, -8], [-22, 33, 20], [-12, -15, -29], [-16, -26, 4], [-7, -3, -22], [33, 12, 13], [18, -28, 44], [27, 4, 5], [15, -37, 4], [4, 20, 18], [-33, 7, 6], [11, -28, 40], [-3, -7, -3], [15, -7, -25], [-2, 40, -34], [-8, 31, -7], [-3, -28, -5], [4, -20, 44], [19, -21, -18], [-7, 37, 0], [-19, -2, -12], [30, 29, -30], [27, 6, 6], [15, 35, 7], [6, 29, -18], [25, -30, 7], [18, -18, 23], [8, -10, 52], [6, -28, 1], [-36, 28, 6], [-9, 4, 9], [-31, -23, 12], [-1, -17, 24], [-30, -9, 25], [35, -5, 0], [-7, -14, -2], [51, -4, 2], [17, -17, 10], [17, 15, -34], [15, 15, -31], [33, -8, 37], [18, -6, -17], [-12, 8, -21], [4, -31, 8], [-38, 4, 20], [19, 8, 33], [7, 30, 9], [43, 6, 19], [-19, 10, 15], [14, -5, 16], [16, -28, 23], [-31, 1, -24], [-15, -5, -14], [39, -24, 14], [21, -8, 3], [26, -20, 3], [34, 9, -30], [-17, 35, -49], [12, 34, -11], [4, -7, -27], [4, 20, -27], [-1, 38, -23], [10, 13, -34], [-28, 1, -44], [11, -16, 19], [34, -12, -20], [-24, -21, -12], [2, 28, -32], [13, 17, -22], [-27, 0, 30], [-15, 8, 34], [33, -18, 32], [29, 31, 0], [57, -17, 0], [19, 22, -13], [35, 16, -18], [24, 2, -24], [-24, 33, 10], [-1, 34, -39], [39, 22, -35], [-34, -23, -5], [-49, -7, -11], [-3, 42, -25], [69, -8, 7], [-6, 37, -53], [26, -23, -20], [-11, 42, -23], [51, 28, -9], [32, -21, 56], [24, -21, 16], [17, 13, 1], [-67, -23, 19], [18, -33, -3], [-27, 0, 11], [41, 20, -20], [3, -55, 14], [21, -15, 52], [-62, 12, 10], [19, 29, -4], [15, 11, -35], [42, -17, 40], [27, -37, 10], [-14, 15, -41], [-36, 2, -26], [-47, -41, 17], [16, 0, -3], [29, 2, 7], [-8, 50, -45], [-54, 34, 14], [27, -7, 6], [9, -19, -13], [40, -19, 23], [0, -15, 6], [-69, 19, -3], [26, -22, 46], [-9, -25, -10], [-3, -32, 47], [-64, 18, -9], [0, -19, 35], [25, -32, -19], [7, -24, 0], [35, -7, 19], [-56, 8, 24], [17, -8, 3], [42, 49, -21], [51, 48, -27], [-2, 24, -14], [-15, -25, 13], [-12, 22, 4], [15, -24, 0], [4, 9, -2], [-18, 23, -9], [-32, 2, 18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3249_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3249_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_3249_2_a_s(:prec:=3)
    chi := MakeCharacter_3249_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_3249_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_3249_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3249_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, 0, 3, 1]>,<5,R![3, 0, -3, 1]>,<13,R![-37, -21, 0, 1]>],Snew);
    return Vf;
end function;