
// Make newform 1449.2.a.j in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1449_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_1449_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_1449_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 := [-3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1449_a();"
function MakeCharacter_1449_a()
    N := 1449;
    order := 1;
    char_gens := [1289, 829, 442];
    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_1449_a_Hecke(Kf)
    return MakeCharacter_1449_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, 0], [3, -1], [-1, 0], [5, 0], [0, 1], [1, 2], [3, -2], [-1, 0], [3, -4], [3, 0], [-9, 0], [3, 4], [-6, 5], [4, 2], [1, 5], [3, -3], [-8, 3], [-5, -3], [6, -3], [7, -4], [-1, 0], [-1, -2], [-4, -3], [-13, -2], [-7, -1], [-4, 0], [4, -5], [3, -3], [-3, -1], [4, -1], [-15, 2], [-3, -6], [9, 3], [-4, -2], [12, 2], [10, -6], [7, -9], [11, -6], [9, 4], [5, -1], [7, -6], [0, 2], [-14, 10], [14, -3], [1, 5], [-9, -8], [13, 3], [-5, 11], [-9, 5], [-11, 11], [21, -3], [-11, 10], [-10, -6], [-4, -10], [-15, 2], [6, -3], [-1, 2], [-10, -1], [-14, -6], [15, 1], [-12, 16], [9, 4], [-2, 5], [-8, 4], [19, 5], [-10, 12], [-18, 1], [13, -12], [-17, 3], [11, 0], [1, 15], [10, 5], [7, 4], [-4, -8], [9, -6], [9, 12], [-32, 2], [-5, 8], [1, 10], [1, -7], [12, -1], [-12, 9], [2, -10], [11, 4], [-4, 16], [15, 9], [-27, 7], [13, -9], [-5, -6], [-19, -2], [9, 4], [13, -6], [-12, 13], [25, 3], [3, -9], [-8, 18], [6, -12], [18, -8], [8, -6], [13, -9], [18, -10], [18, 11], [-20, 4], [1, 4], [-18, -8], [0, 17], [-14, -10], [28, 5], [11, 13], [-36, 5], [-11, 6], [6, -9], [26, -7], [-35, 10], [-24, 15], [-14, 25], [9, -11], [-19, -5], [-15, -12], [7, 6], [1, -12], [2, -17], [-17, 8], [-20, -5], [-9, 15], [-22, -11], [-5, -4], [13, -26], [-22, -2], [-25, -8], [-19, -5], [11, -1], [-31, 12], [-12, 0], [14, -18], [5, -16], [-7, 17], [16, 10], [4, -13], [-15, 2], [24, -2], [-5, 5], [3, 3], [11, -18], [-36, -1], [-26, -14], [18, 14], [34, 4], [38, -14], [-24, 4], [30, 6], [-30, 5], [-18, 13], [31, -17], [-8, 14], [-15, 2], [-15, -11], [-23, 8], [-36, 16], [-14, 12], [26, 11], [-14, 24], [42, -3], [8, -17], [9, 6], [24, 5], [23, -10], [-19, -1], [14, -7], [-18, 9], [22, -4], [12, 21], [-11, 16], [20, 0], [-19, 8], [-8, 9], [-9, -7], [47, -5], [31, 9], [13, 7], [-24, 15], [-29, 7], [26, -1], [3, 12], [16, 15], [-46, -4], [-31, -4], [-13, 23], [-39, 14], [35, 11], [-19, 13], [-14, -14], [-3, 24], [24, -19], [36, -15], [-22, 3], [-22, 10], [6, 0], [-27, -15], [2, -4], [-8, 16], [17, 13], [16, -9], [-23, 0], [-38, 0], [-37, -8], [13, -7], [17, -5], [23, -10], [-28, 10], [39, -9], [5, -28], [52, -8], [38, -1], [3, 1], [3, 20], [40, -17], [-11, -14], [19, -10], [4, 7], [-6, 16], [6, -29], [8, 12], [33, 4], [17, -9], [-13, -24], [24, 4], [10, 25], [63, 0], [-15, 16], [2, -13], [11, -15], [-24, 8], [-52, -5], [-26, 17], [8, 2], [-23, 6], [-41, -4], [-39, 22], [25, -4], [9, -9], [58, 2], [35, 14], [-23, -16], [14, 9], [24, -20], [44, -16], [-1, 14], [35, -2], [7, -32], [-42, 0], [-45, -4], [-1, -4], [43, -2], [-30, 10], [17, -36], [41, -14], [20, 1], [53, -6], [-28, 15], [-30, 16], [11, -33], [-43, 0], [48, -11], [-5, -8], [34, -16], [9, 8], [-43, 8], [-19, -9], [-5, -18], [7, 10], [-4, 17], [16, 22], [-1, 26], [-58, 0], [-67, 0], [31, 14], [-25, 20], [-3, 22], [12, 10], [40, -7], [5, 2], [53, -22], [-23, 25], [-15, 0], [47, 8], [-22, -8], [52, -5], [-24, 36], [-6, -19], [36, 11], [-42, -9], [3, -12], [8, -28], [-55, 0], [0, 16], [-42, 1], [39, -20], [-7, 36], [-10, 13], [-42, -12], [-31, 8], [-1, 15], [-52, 4], [37, 2], [37, -19], [19, -40], [42, 14], [38, -7], [21, 0], [-21, 10], [-7, 31], [-55, 10], [-23, -6], [-20, 4], [-7, -20], [-23, 8], [25, -36], [-12, -6], [6, -4], [-10, -7], [-1, 7], [-17, -26], [-69, 0], [25, -9], [31, 0], [31, 19], [24, -50], [46, -22], [-44, 0], [17, -2], [-6, -13], [-51, 33], [48, -14], [6, -16], [-42, 26], [-24, 6], [29, 9], [17, -13], [-27, -20], [-38, 24], [-18, -9], [-53, 6], [-30, 28], [-40, -21], [-15, 37], [1, -27], [-45, -3], [11, -10], [4, -33], [13, 20], [33, -22], [5, -23], [35, 2], [60, -20], [26, -14], [51, -24], [5, 32], [-19, -8], [43, -10], [-1, 24], [-17, 8], [4, 24], [48, -10], [-48, 28], [-8, -15], [56, -10], [70, -19], [54, 9], [17, -32], [0, 24], [78, 6], [-8, 16], [-95, 0], [-31, 27], [-41, -17], [24, -10], [-6, 12], [-53, 14], [-53, 30], [-54, -9], [-56, -18], [82, -9], [-69, -9], [-50, 3], [0, -13], [-14, -24], [-35, -26], [34, -22], [21, 22], [39, -33], [-6, 0], [4, 10], [52, 3], [11, -19], [7, 6], [-11, 14], [-20, 35], [-33, 6], [33, -46], [14, 11], [62, 14], [48, 15], [48, -9], [-70, -1], [-28, 28], [22, 30], [-8, -8], [-31, 7], [-4, -39], [80, 2], [44, -40], [-20, 3], [8, -5], [42, 12], [-51, 30], [23, -12], [-57, 0], [32, -14], [-27, -18], [13, -30], [5, -7], [-2, -39], [60, -37], [-24, 6], [6, -1], [-50, 26], [33, 27], [-62, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1449_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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