
// Make newform 1911.2.a.n in Magma, downloaded from the LMFDB on 24 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_n();".
// 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_n();".
// 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, -4, -1, 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_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 := [[-1, 1, 0], [1, 0, 0], [1, 0, 1], [0, 0, 0], [0, -2, 2], [1, 0, 0], [2, 2, 0], [3, -2, -1], [-3, 0, 1], [-1, 2, 1], [3, -2, 3], [4, 0, -2], [4, -2, 0], [-1, 2, -1], [5, 2, -1], [-1, -2, -3], [4, 0, 2], [-2, -4, 0], [2, -4, -2], [-2, 2, -4], [1, 2, -5], [-5, 2, -1], [1, -2, -1], [3, 4, -1], [1, 6, -5], [-4, 6, 2], [4, -8, 4], [-2, -2, 2], [10, 0, 0], [9, 6, -1], [-8, -4, 0], [0, -8, 0], [-4, -4, 4], [-10, 4, -6], [-10, 0, 2], [-8, 4, -4], [4, -4, -6], [-8, -4, 0], [7, 6, 1], [6, -6, -4], [9, -8, 5], [-6, 4, 8], [2, -2, -2], [10, 4, 0], [6, 0, -2], [12, -4, 4], [-1, 6, -9], [1, 10, 1], [8, -8, -2], [-2, -4, 0], [-1, -2, 5], [-6, -2, 0], [-11, 2, -1], [-14, -8, 2], [4, -6, 6], [-5, 12, -1], [-10, -2, -4], [0, 8, -8], [13, -2, 3], [10, -8, 10], [4, 12, -8], [5, -12, 1], [9, -6, 1], [6, 0, 2], [18, 4, 0], [4, -12, -4], [6, -12, 10], [-11, -2, 3], [14, -6, -2], [-15, 2, 3], [4, 2, -8], [-30, 2, 0], [10, 0, 2], [-2, 0, -12], [-6, 0, 2], [-4, 4, -10], [-2, 0, 8], [5, 14, -1], [-20, -4, 0], [13, -2, 7], [-6, 0, 10], [-4, -8, 10], [8, -2, -6], [0, 0, -2], [-22, 0, -6], [-3, 0, -3], [4, 0, -8], [4, 4, -2], [16, 2, -4], [-18, 4, -2], [-26, 8, -2], [7, 6, 5], [-6, 0, -2], [18, -6, -2], [12, -8, 8], [-2, 4, 2], [9, 0, 1], [2, -6, -4], [6, 4, 2], [0, 0, -2], [-11, -6, -3], [16, -12, 12], [16, 12, -4], [-1, 14, -11], [-1, 10, -1], [22, -8, 8], [-19, 2, -5], [-19, 12, 1], [1, 4, 13], [-10, 12, -12], [-2, 0, -10], [0, -4, 2], [14, 0, 6], [12, -16, 0], [10, 16, -2], [1, 10, -13], [8, 0, 4], [-10, -8, 6], [-22, 8, -8], [15, 8, -5], [-3, 2, 15], [-19, 14, -1], [16, -10, 10], [2, 14, -12], [-3, 2, 13], [-15, 14, -9], [18, 8, 0], [-22, 4, 6], [10, 12, -6], [9, 2, -1], [-14, 20, -10], [-10, 18, -12], [-1, 18, 3], [-19, 6, -1], [5, 0, -11], [15, 6, -11], [-4, -6, 4], [-13, 6, -5], [-16, 14, 2], [21, -2, 3], [12, 0, 4], [-26, 0, 10], [-32, -8, 0], [14, -14, 0], [6, 8, -8], [-4, 0, -2], [11, -22, 13], [-4, 2, -2], [-2, 0, 18], [6, 14, -8], [-4, 20, 6], [16, -2, 2], [20, 8, 0], [-24, 12, 0], [19, 6, -5], [7, -8, 7], [-16, 8, 8], [9, 0, -7], [-16, 16, -2], [47, -4, -5], [8, -2, -10], [37, -10, 3], [-2, -16, 10], [-6, 4, 6], [10, 24, -10], [-1, 10, 5], [-16, -4, -8], [-4, -28, 10], [14, 20, -8], [14, 10, -12], [-20, -2, -6], [-14, 8, 0], [-17, 8, -13], [4, 24, -2], [-4, 4, -20], [2, 10, -16], [24, -8, -4], [14, 4, 2], [6, 12, -2], [-10, -4, 0], [-20, 16, -20], [-30, 4, -18], [-26, -16, 4], [9, -20, 13], [12, 26, -6], [-20, 14, -10], [-5, 2, 17], [-5, 14, -9], [42, -12, 4], [-25, 18, -7], [12, 8, -10], [8, 14, 2], [-1, -14, -9], [45, -4, -7], [-21, 0, 15], [-6, 10, -12], [-10, -4, 4], [25, 6, -5], [19, -4, -1], [-22, 0, 2], [-20, 4, -4], [-36, 12, 4], [29, -6, 19], [0, 16, 10], [1, 14, -5], [-18, 18, -16], [-1, -26, 15], [-11, -20, 5], [24, 8, -4], [6, -8, 10], [-25, 10, 13], [10, 14, -4], [48, 0, 0], [-20, 4, 6], [29, -6, 11], [-9, -14, -3], [-1, 6, -5], [2, -6, -8], [-22, -2, -8], [-20, 0, -8], [-15, -26, 7], [32, -16, -8], [4, 16, -8], [-14, 0, 6], [46, -12, -2], [3, 2, 9], [6, -18, 12], [23, 4, 3], [18, -4, -14], [4, 10, -14], [18, -8, 4], [-32, 20, -4], [-20, -16, 12], [14, -8, -12], [-30, 0, 6], [-15, -18, -5], [14, -4, -4], [-16, 12, 4], [-21, 20, -17], [14, -12, -2], [-22, 22, 4], [10, 12, -10], [8, -12, 8], [-10, -4, 0], [-1, -4, -21], [16, -20, 20], [41, 10, -11], [11, -18, 13], [24, -20, 8], [-49, 4, 3], [-20, 4, -6], [28, 18, 0], [-12, -2, 6], [-6, -8, 0], [16, -26, 14], [-54, 10, 4], [11, 18, -19], [-12, -40, 12], [-6, -22, 12], [9, 10, -1], [-37, 2, -1], [-25, -20, 11], [5, 14, -13], [-50, 0, -4], [-60, 2, 4], [34, -20, -2], [-22, 24, -6], [19, 0, 3], [30, -20, 26], [42, 0, -8], [-2, -4, -8], [-16, 24, 4], [-14, -4, -8], [-27, -18, 1], [36, -4, -6], [-24, 8, -16], [-38, 18, 0], [40, -8, 10], [8, -16, -2], [16, -4, -16], [26, -4, 18], [18, -20, 2], [-36, 16, -12], [5, -26, 7], [-20, 32, -8], [45, -20, 5], [-1, 2, -11], [-4, -20, 0], [-24, 24, 12], [-6, -18, 20], [-53, 6, -7], [0, 0, 28], [2, -32, 14], [-25, 14, 9], [-23, -10, 7], [10, 10, -4], [22, -8, 6], [22, -18, 0], [52, 4, 8], [23, -18, -1], [-30, 16, -4], [24, 16, 8], [-29, -2, -17], [-11, -20, 1], [37, -22, 21], [-30, 0, -12], [-6, 42, -14], [-24, 8, 22], [-32, -10, 18], [27, -14, 5], [12, 16, -24], [58, -12, -6], [58, -4, 4], [-11, -6, 5], [-22, 6, -24], [-8, -12, 22], [39, -6, 25], [-8, -22, -6], [-1, -30, 9], [-19, -6, 23], [-20, 12, -8], [48, 0, -2], [-28, 6, 22], [-8, 4, 20], [40, -24, -20], [68, -4, 10], [-32, 20, 24], [-11, -6, -3], [14, -34, 10], [-2, 0, -4], [-30, -16, 0], [-13, -22, -3], [-70, 4, 2], [13, -22, -13], [38, -8, 14], [19, 22, -7], [20, 20, 6], [-68, 6, 0], [22, 16, -12], [38, -20, 38], [24, 12, 2], [26, -4, -12], [-28, 22, 4], [20, 4, -4], [44, -8, 12], [2, -2, -6], [-34, -16, 8], [-24, 36, 8], [-33, 18, -39], [-36, -26, 6], [-17, -18, 7], [42, -4, 4], [-24, 28, -12], [-38, 24, 10], [6, 32, -4], [-4, -2, -10], [-39, 30, 19], [33, 6, 3], [26, -16, 28], [-32, -18, -6], [-26, -16, 0], [-4, 26, 10], [-19, -12, 9], [10, -30, 16], [30, -12, 10], [-21, 18, -35], [-3, 24, -19], [-18, 16, 10], [35, -22, -11], [-38, 18, -2], [46, 0, 18], [-10, 10, 4], [27, -2, 1], [-40, 8, -8], [-1, 10, -19], [20, -20, 38], [-10, 42, -14], [2, 0, -28], [22, -14, -4], [58, -20, -4], [-15, -36, 21], [10, -20, 10], [-4, 0, -12], [4, -40, 8], [9, 18, -11], [33, -2, -9], [4, 16, 12], [16, -28, 18], [4, -28, 12], [44, -28, 0], [-14, -20, -4], [-69, 12, -9], [6, -6, 8], [40, -4, -4], [14, 34, -12], [-51, 14, -13], [-32, 24, 24], [12, 30, -14], [13, 6, -11], [0, 16, 0], [-13, -22, -3], [-25, 18, -15], [38, 12, 6], [19, -12, 15], [5, -8, 37], [-16, -12, -24], [12, -8, -14], [32, 0, 28], [-15, 42, -7], [9, 34, -25], [-8, 44, -14], [-43, -18, -5], [-29, 4, 7], [40, -28, -12], [-29, 10, 13], [70, 6, -8], [2, 6, 16], [-8, 24, -16], [8, 2, 24], [24, 12, 4], [3, -6, 5], [6, 20, -28], [34, -14, -24], [-44, 24, 4], [-6, 28, 4], [-47, 20, -27], [13, -24, -19], [24, 36, -20], [17, -6, 5], [38, -16, -10]];
    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_n();".
// 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_n(:prec:=3)
    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_n();".
// 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_n( : 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, -3, 2, 1]>,<5,R![8, -4, -3, 1]>],Snew);
    return Vf;
end function;