
// Make newform 1911.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1911_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_1911_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_1911_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 := [-2, 0, 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_1911_a();"
function MakeCharacter_1911_a()
    N := 1911;
    order := 1;
    char_gens := [638, 1522, 1471];
    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_1911_a_Hecke(Kf)
    return MakeCharacter_1911_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], [1, 0], [-1, 0], [0, 0], [-2, 0], [1, 0], [0, -1], [-5, -1], [-1, -1], [-3, -3], [1, 1], [-4, 0], [8, 2], [1, -2], [1, 4], [1, -1], [2, -4], [-6, 4], [-6, -1], [-4, 2], [-7, -1], [-7, -6], [3, 6], [-3, -4], [-7, 7], [2, -4], [-4, -6], [-8, 6], [-10, 5], [-5, 7], [6, 8], [8, -3], [-12, -6], [6, 12], [-6, 10], [-8, 2], [2, 3], [8, 3], [1, -12], [12, -2], [17, 3], [6, -2], [12, 4], [-6, -1], [-18, 2], [-6, 1], [7, 10], [-15, 5], [-10, 0], [10, -6], [-17, 9], [6, 1], [-11, 5], [10, 6], [10, -6], [9, 1], [8, 15], [-14, -12], [-1, 16], [-16, -1], [-4, -2], [5, -4], [-17, 1], [-6, 1], [6, -14], [22, 3], [2, 12], [9, -14], [-4, -18], [-5, -17], [4, 14], [2, -9], [0, -1], [32, 2], [-14, -4], [-14, -12], [2, -6], [-11, 1], [-22, -1], [3, -9], [2, -10], [-16, -15], [-10, 12], [6, -9], [10, -20], [1, 3], [-14, -11], [32, -5], [16, 4], [-18, -5], [-10, -11], [11, 14], [-2, -28], [10, -12], [0, -27], [-2, 24], [-13, -10], [4, 0], [-6, -24], [0, 8], [5, -22], [8, -22], [28, -1], [-5, -23], [19, 14], [22, 8], [-9, 24], [5, 12], [5, 7], [24, -15], [-18, 8], [-16, -21], [14, 10], [4, -14], [-26, 14], [-31, 5], [-36, -2], [34, -3], [-38, 2], [-21, 3], [-3, 7], [-25, 2], [6, 21], [20, -12], [5, 19], [7, 17], [14, 22], [34, -7], [-16, 3], [21, -5], [14, -10], [-22, 1], [-1, -8], [-1, -6], [-3, 10], [-23, 3], [-20, -6], [-27, -13], [-22, -9], [-29, -19], [12, 24], [20, 13], [-6, 34], [6, 15], [-16, -19], [-14, 28], [-27, -19], [26, 2], [40, -9], [12, -24], [0, -13], [-22, -23], [28, -4], [36, -3], [15, 20], [33, 13], [14, 22], [-9, 12], [-48, 2], [-17, 0], [16, -9], [-39, -5], [26, 6], [-10, -4], [10, -4], [9, -18], [14, -24], [-20, 22], [-6, -2], [-8, -14], [-24, 19], [50, 2], [-35, 1], [-16, -28], [18, -7], [-48, -5], [4, -10], [-8, 9], [16, -3], [36, 11], [-8, -1], [-2, 24], [0, -32], [-3, 24], [36, -1], [10, 26], [-29, -12], [5, -19], [-38, -5], [25, -28], [-32, 8], [0, 17], [-7, 8], [-49, 2], [9, 1], [28, 6], [-6, 41], [9, 12], [-3, -20], [-26, 13], [22, -29], [36, 2], [7, 23], [10, 19], [-19, 4], [4, -14], [13, 7], [-21, 1], [-18, 37], [20, 25], [17, 0], [28, -28], [38, -12], [12, 12], [5, -12], [-35, 9], [7, -24], [-24, 14], [-8, -36], [-14, 3], [-5, -16], [12, 24], [-12, -30], [2, 33], [-10, -34], [-1, -6], [-28, 9], [-17, -23], [16, 27], [32, -19], [-16, 28], [-30, 23], [32, -31], [-42, -24], [-34, 16], [45, -2], [-14, -12], [54, -3], [-11, -19], [6, 12], [26, 21], [-52, 17], [-38, 7], [2, -23], [15, -26], [-20, -17], [27, -23], [-43, 18], [4, -30], [-25, 9], [24, 9], [-22, -28], [-2, 0], [34, 12], [-14, 20], [34, 13], [35, 18], [-16, -26], [8, -5], [-11, 43], [-11, 10], [-9, -43], [13, 39], [14, 28], [-24, -28], [-30, -16], [-10, 32], [-19, 4], [-18, 2], [42, 4], [46, 24], [12, 14], [20, -10], [41, 20], [6, -37], [4, -18], [-6, 17], [48, -5], [0, 29], [52, 1], [30, 17], [-10, 12], [36, 16], [-17, -41], [44, 20], [21, 15], [-21, -38], [60, 4], [-16, 2], [8, 30], [-17, 5], [40, 16], [-48, 3], [43, -12], [33, 20], [-28, 34], [46, 10], [-56, 14], [44, -15], [-15, 19], [-2, 12], [44, 12], [5, 0], [61, 13], [-47, -2], [6, 1], [-40, 8], [-24, -20], [30, -30], [15, -18], [56, 2], [-2, -28], [34, 34], [13, 30], [38, -5], [-64, -10], [27, -2], [32, 19], [33, -11], [-31, 25], [-48, 8], [-36, -22], [6, -51], [-20, 40], [-40, -20], [0, 16], [-24, 9], [-7, -47], [30, -16], [-38, 4], [46, 16], [-23, 7], [50, 16], [31, -2], [58, -13], [21, -14], [-24, -3], [28, 30], [-64, -2], [-4, 57], [-36, 30], [54, 20], [34, -16], [-90, -2], [18, -5], [-68, -14], [0, 27], [-36, 13], [1, 2], [-6, -45], [3, -13], [22, 13], [-44, -8], [20, -45], [40, -38], [58, -3], [43, 4], [3, -2], [-8, -22], [60, 11], [-18, 9], [-70, -12], [1, 27], [-84, 8], [-32, -23], [43, 24], [-29, -44], [10, -18], [-9, 34], [-50, 16], [-60, 15], [-18, 7], [31, -33], [10, -23], [-31, 16], [36, 8], [40, -36], [-2, -68], [-64, 0], [34, 12], [-45, 28], [8, -9], [-44, -15], [8, -22], [37, -17], [33, -26], [0, -24], [16, -4], [-20, 17], [8, -47], [-42, -11], [21, -40], [22, -1], [4, 66], [-8, 48], [1, 20], [-28, -8], [14, 35], [-63, 10], [-36, -26], [-7, -5], [-21, 1], [6, -43], [-5, 20], [-15, 4], [-14, -19], [48, -19], [12, -50], [19, -47], [-9, 26], [36, 4], [3, -7], [-7, -53], [-42, 22], [-23, 20], [8, -3], [-24, -26], [32, -14], [0, 42], [-4, -48], [-29, -19], [-54, -8], [-38, 25], [24, -1], [-10, -20], [37, -4], [-61, 33], [26, -15], [35, 27], [-18, 26]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1911_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1911_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_1911_2_a_j(:prec:=2)
    chi := MakeCharacter_1911_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_1911_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_1911_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1911_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-2, 0, 1]>,<5,R![1, 1]>],Snew);
    return Vf;
end function;