
// Make newform 1900.2.a.i in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1900_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_1900_2_a_i();".
// 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_1900_2_a_i();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 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_1900_a();"
function MakeCharacter_1900_a()
    N := 1900;
    order := 1;
    char_gens := [951, 77, 401];
    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_1900_a_Hecke(Kf)
    return MakeCharacter_1900_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, 0, 0], [1, 0, 1], [0, 0, 0], [1, -2, -1], [0, 0, 1], [1, 1, 1], [1, 2, -1], [1, 0, 0], [5, 1, 0], [2, -2, 1], [-1, 3, 1], [-4, 0, 1], [0, -3, 0], [5, 0, 2], [1, 5, -1], [1, -4, 0], [-2, 2, 2], [-3, 5, 1], [4, 4, -3], [-1, -2, -2], [4, 1, -2], [-1, 0, -5], [10, -1, 0], [3, 3, -2], [1, 1, 5], [1, -4, -5], [-3, 8, 3], [9, -3, -2], [4, -5, 2], [6, -3, -3], [3, -7, -2], [6, 3, -4], [10, -1, 2], [-9, 2, -6], [8, -5, -4], [-10, -3, -3], [-7, -3, -4], [3, -1, 3], [0, 3, 2], [-11, 2, -5], [-5, 8, -2], [-7, 0, 0], [-2, -4, -1], [-2, 1, 2], [6, 6, 1], [-2, -2, -9], [17, 0, 4], [-1, -6, -8], [-4, 1, -4], [8, -3, 5], [6, 0, 11], [-13, -5, 3], [-8, 7, 0], [6, 3, 9], [3, -12, -1], [3, -9, 1], [-28, 1, -1], [0, 2, -5], [-5, 4, -4], [4, 8, 2], [-2, -5, 8], [-17, 11, 2], [1, 7, -10], [19, -1, 1], [8, -6, 3], [-14, -1, -10], [0, -1, 11], [1, -5, 3], [6, -6, -9], [0, 5, 5], [4, 11, 1], [-15, -3, -7], [4, 13, -8], [-17, -5, -1], [7, -17, -3], [15, 3, 1], [-13, -2, -16], [-6, -1, -1], [9, 0, -3], [1, 1, -4], [2, 1, 11], [7, 1, -7], [-8, 8, -1], [-17, 1, 4], [10, 4, 13], [18, -3, 6], [3, -9, 7], [-23, 1, -1], [8, 13, 1], [-10, 9, 1], [12, -9, 2], [-12, 6, 6], [22, -5, 8], [4, -1, 8], [-13, -6, -7], [-13, 10, 7], [-8, 11, 12], [-24, -6, -6], [-3, -4, -11], [-8, 4, -13], [-6, -7, 5], [25, -10, -7], [2, 4, -1], [-4, 10, -14], [-12, 11, -2], [11, 6, 9], [36, 0, 3], [-7, -11, -11], [-2, 8, 1], [-22, 3, 2], [-30, -7, 0], [16, -5, 11], [8, -14, -10], [-6, 11, -2], [28, -5, -2], [13, -4, 0], [-22, 0, 0], [5, -5, 10], [-11, -1, -6], [-24, 15, 3], [0, -1, 1], [9, -7, -12], [12, 0, 9], [11, 10, 9], [6, -4, 16], [14, 7, 7], [-25, -3, -15], [13, -1, 11], [-21, -4, 5], [-9, -10, -2], [8, -21, -9], [11, -11, -8], [-13, -3, 10], [-3, 5, -2], [-10, 13, 14], [6, 14, 0], [-7, 1, 4], [-21, -1, -5], [-16, -11, 6], [5, -11, -9], [10, -23, -7], [4, 5, -6], [8, 3, 3], [16, 17, -7], [10, -2, 4], [-3, 21, 7], [16, -14, 3], [26, -5, 5], [12, -19, 8], [39, -6, -2], [12, -16, 4], [23, -5, 6], [9, 14, 7], [-1, 10, 17], [-19, 3, 6], [-11, -7, 11], [-10, -15, 7], [0, 9, 18], [29, -18, -9], [26, -11, -2], [-1, -17, -14], [18, -9, 0], [30, -1, 3], [0, -6, 8], [1, 11, 7], [25, -4, -4], [-6, -13, 16], [13, 13, -4], [20, -12, 9], [18, 12, 4], [1, -19, -7], [5, 18, 20], [14, -23, -7], [14, 0, 6], [19, 19, -12], [-11, 17, -1], [-6, 20, 8], [12, 9, -9], [-20, 10, 1], [12, 8, 20], [13, -8, -10], [0, -27, 6], [-3, -7, -13], [29, 7, -1], [15, -12, -1], [-33, 12, 3], [-26, -8, -13], [24, -10, -9], [19, 4, -7], [2, -8, -17], [-19, 0, -12], [36, -12, -1], [-14, -17, -16], [33, 0, 8], [-23, -4, 8], [-26, -10, -6], [21, -16, -14], [-3, -7, 0], [-8, -10, -13], [4, 2, 0], [-33, -9, 7], [-30, 11, -5], [23, 6, 10], [26, -9, -5], [14, -29, -15], [16, 14, 21], [-11, -5, 17], [-14, 11, 13], [11, -26, 3], [3, 11, -12], [-12, 17, 9], [-13, -14, -2], [13, -5, -18], [-39, -6, 1], [14, -17, -2], [-30, -7, -9], [-34, -9, -12], [21, -24, -1], [-18, 6, -5], [-17, 14, 13], [-2, -14, -13], [-28, -3, 1], [-27, 15, 11], [-28, 33, 9], [11, 7, -8], [-35, 4, 0], [-19, -14, -18], [9, 9, -6], [22, 16, -4], [-26, -1, 1], [-29, -17, -7], [19, 1, -10], [32, 9, 12], [-11, -1, -26], [-21, -10, -8], [-10, -11, 7], [9, -22, 6], [-6, -18, -13], [-4, 13, 1], [42, -3, 10], [18, 9, 1], [1, -8, 2], [6, -10, 16], [19, 7, -9], [6, -21, 3], [15, -15, -3], [-20, -14, 8], [-21, 3, 1], [-46, 6, -5], [2, -14, -14], [-23, 7, -1], [21, -12, 16], [20, 7, -14], [16, -20, 14], [-5, -25, -1], [-13, 19, 3], [37, 1, 8], [-11, 4, 11], [-23, 35, 8], [17, -9, 15], [17, 12, 12], [9, -3, 10], [-36, -16, 0], [-20, 16, 5], [61, -1, 5], [19, 7, 11], [6, 3, 15], [-11, 5, 1], [-41, 7, -13], [-14, -16, -15], [32, 12, -3], [-27, 8, -8], [54, -13, 1], [-22, 18, 0], [12, -4, -3], [10, -23, -1], [-19, 4, -12], [-28, -15, 8], [-13, 3, 5], [45, -18, -8], [-20, 11, -2], [30, -4, 7], [-13, 7, 5], [-23, -8, -3], [-10, 0, 6], [8, -14, 2], [38, 6, 25], [-42, 21, 10], [-18, -4, -1], [14, -2, 5], [10, -4, 23], [10, -13, -2], [-7, -8, -14], [-25, 16, -12], [17, 12, -1], [27, -27, -1], [-37, 18, 12], [20, 4, 30], [19, 17, 27], [4, -5, 10], [-39, 20, 7], [-44, -7, -16], [8, -21, -7], [25, 2, 24], [61, -2, 7], [39, -16, -7], [0, 9, 3], [18, -22, -17], [19, -19, 20], [-24, -22, 12], [-33, 27, 5], [-61, 13, -2], [-19, 25, -2], [-47, 1, -7], [36, -24, -14], [-1, -6, -24], [42, -3, 20], [26, -14, -5], [12, 5, 20], [-2, 26, -13], [8, -33, -2], [-7, 27, 16], [8, 34, -2], [44, -9, 13], [-12, -3, 7], [4, -32, -11], [5, -18, 5], [-4, -3, -4], [22, 2, 6], [-29, 8, -16], [25, -23, -17], [-47, 8, -14], [22, -20, 11], [23, 10, -17], [-13, -6, -30], [36, 12, 27], [-43, 12, 12], [-9, 9, 8], [-12, -22, 9], [-25, 24, 0], [11, 30, 3], [17, 10, -22], [-57, 3, 3], [50, -6, -12], [-52, 1, -5], [-47, -4, -31], [-5, 19, -10], [-8, 16, -7], [-48, -3, -16], [-58, -2, 7], [-36, -4, -11], [12, 17, -18], [-21, 0, -3], [-40, -3, -12], [-46, 0, -6], [13, -22, -9], [47, 1, 13], [-47, 23, 2], [-9, 18, -4], [6, -18, 14], [38, 6, -3], [-5, 17, -26], [-29, 11, 9], [37, -1, 8], [-12, 35, 19], [1, -20, 2], [-17, 5, -25], [49, 7, -8], [-14, 7, 7], [-13, 28, -11], [17, 21, -15], [33, -3, 26], [-1, 25, 2], [-7, 6, 7], [51, 5, 7], [-32, -1, -10], [-4, -32, 13], [19, 1, -22], [27, 3, 4], [-29, 31, -7], [-50, -13, -9], [9, 27, 21], [51, -4, 19], [2, 34, 19], [-12, 14, -6], [45, -18, -2], [-4, 18, 14], [6, -7, -29], [12, -25, -5], [-12, -15, -30], [36, -1, -7], [14, 1, 2], [25, -13, -25], [30, 5, 18], [-62, 11, 6], [-32, 28, 11], [-20, 1, -2], [28, -31, -18], [6, -25, -25], [21, 0, 39], [-19, 3, 3], [10, 29, -19], [-16, 0, 0], [-34, 7, 14], [-35, 8, -15], [19, 25, -4], [36, -31, 4], [-10, 31, -11], [38, 6, 21], [7, -19, 6], [42, -16, 11], [-23, 5, 3], [7, 26, 14], [13, -14, -20], [-1, 21, 9], [16, -28, -2], [44, -35, -15], [26, -27, 9], [-38, 20, -5], [5, 7, 19], [-22, 1, -22], [23, -15, 5], [-12, 39, 2], [24, 15, -6], [22, 4, 20], [16, 2, -5], [9, -18, -2], [-1, -29, 22], [33, -10, -7], [16, -10, -7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1900_2_a_i();".
// 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_1900_2_a_i(:prec:=3)
    chi := MakeCharacter_1900_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_1900_2_a_i();".
// 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_1900_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![9, -5, -2, 1]>,<7,R![47, -19, -2, 1]>],Snew);
    return Vf;
end function;