
// Make newform 1900.2.a.b in Magma, downloaded from the LMFDB on 23 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_b();".
// 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_b();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-2], [0], [3], [5], [4], [3], [-1], [-8], [-2], [4], [-10], [10], [-1], [1], [4], [6], [-13], [12], [2], [-9], [8], [12], [12], [8], [-10], [6], [-2], [0], [10], [-6], [-9], [11], [-3], [-15], [2], [2], [4], [6], [-6], [18], [10], [25], [-12], [-2], [-7], [18], [-2], [-4], [17], [-3], [21], [-26], [11], [-32], [21], [-24], [-8], [-1], [22], [3], [12], [-12], [7], [10], [-30], [-4], [32], [-19], [-11], [6], [21], [-16], [4], [-30], [-4], [-21], [-5], [28], [-20], [-36], [-40], [24], [-2], [2], [5], [16], [13], [-19], [-19], [5], [4], [26], [-28], [19], [36], [0], [32], [-26], [11], [-28], [-1], [-42], [-8], [20], [13], [-3], [-22], [-12], [10], [-32], [47], [-9], [4], [-7], [0], [11], [7], [27], [-34], [16], [10], [2], [20], [-33], [-10], [-6], [13], [-7], [6], [-43], [40], [-16], [5], [9], [31], [-18], [-4], [12], [39], [0], [45], [-53], [28], [-48], [-10], [-42], [-18], [1], [-6], [-34], [-51], [-1], [-22], [40], [-18], [-28], [14], [31], [-26], [12], [16], [-48], [20], [-56], [12], [-38], [-37], [4], [27], [18], [-40], [0], [-26], [-12], [-21], [20], [21], [56], [35], [17], [-8], [2], [-22], [3], [45], [-38], [-22], [-46], [-60], [-46], [-17], [-8], [-42], [-16], [60], [5], [30], [-62], [-15], [-12], [-62], [8], [38], [20], [7], [35], [-48], [-15], [50], [-2], [2], [-69], [12], [42], [6], [24], [-60], [-52], [45], [-42], [-22], [2], [-35], [22], [3], [70], [-72], [22], [45], [9], [20], [60], [34], [-47], [15], [-63], [-23], [-40], [60], [-22], [-17], [-16], [-34], [30], [-9], [17], [-16], [-16], [-39], [-34], [-37], [-44], [32], [37], [-44], [-15], [-38], [42], [-58], [26], [-6], [15], [-66], [-63], [64], [-60], [-57], [-38], [9], [0], [14], [-57], [-67], [16], [0], [27], [-20], [46], [-15], [-30], [-68], [69], [30], [23], [57], [9], [-12], [-83], [-40], [6], [-45], [-24], [14], [46], [-46], [56], [-83], [64], [-75], [47], [-62], [13], [88], [27], [-20], [36], [38], [-39], [70], [-25], [-78], [-32], [54], [-24], [48], [27], [-80], [-23], [61], [-14], [39], [42], [16], [-6], [-36], [28], [50], [2], [-77], [-77], [-66], [56], [-13], [45], [61], [36], [6], [-37], [-40], [80], [75], [-18], [-16], [-14], [40], [18], [-6], [-40], [-45], [-26], [52], [71], [54], [56], [-40], [56], [-36], [71], [54], [-37], [74], [-42], [80], [49], [46], [-18], [-30], [64], [12], [54], [-11], [-14], [65], [43], [20], [-64], [61], [-45], [24], [90], [13], [89], [-75], [-90], [64], [40], [-10], [-31], [62], [98], [-50], [-48], [65], [6], [22], [76], [-58], [-50], [-78], [20], [41], [72], [62], [96], [95], [95], [2], [14], [11], [-88], [9], [50], [59], [14], [-42], [0], [52], [-18], [-22], [72], [70], [-83], [-2], [-28], [-24], [-74], [43], [5], [71]];
    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_b();".
// 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_b(:prec:=1)
    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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 1]>,<7,R![-3, 1]>],Snew);
    return Vf;
end function;