
// Make newform 1911.2.a.d 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_d();".
// 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_d();".
// 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_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], [-2], [1], [2], [5], [1], [-3], [1], [4], [6], [-1], [-3], [-11], [-4], [-2], [-8], [-8], [-1], [-5], [13], [-15], [-5], [6], [12], [8], [-4], [-13], [-8], [-14], [-8], [-14], [-18], [-4], [10], [6], [-21], [-16], [5], [14], [0], [-12], [10], [22], [15], [-9], [-24], [22], [1], [30], [-1], [6], [-26], [-21], [-26], [0], [21], [16], [8], [-5], [23], [-16], [-14], [-18], [-22], [5], [12], [-25], [-6], [-10], [20], [-18], [22], [8], [18], [19], [-18], [-33], [-2], [-6], [30], [38], [-14], [-15], [-14], [-2], [-14], [16], [-8], [-21], [22], [20], [14], [-42], [-21], [28], [-2], [-20], [5], [28], [34], [-39], [-5], [38], [-15], [-5], [-47], [-28], [22], [-38], [-18], [-24], [22], [3], [-28], [36], [30], [23], [-45], [1], [0], [-44], [-1], [-17], [-18], [-16], [-4], [-41], [-30], [6], [23], [1], [11], [5], [-6], [-43], [12], [-21], [52], [32], [-40], [6], [28], [-36], [1], [22], [48], [-52], [10], [52], [-20], [26], [-41], [-21], [0], [7], [44], [57], [20], [-57], [2], [30], [42], [19], [-8], [-44], [-54], [20], [-12], [-42], [11], [-28], [-2], [-34], [-44], [12], [60], [28], [62], [-42], [-38], [-33], [0], [54], [39], [49], [-32], [15], [20], [56], [51], [43], [23], [28], [-32], [-27], [-63], [44], [-50], [8], [27], [-22], [5], [48], [-47], [33], [-58], [52], [47], [-4], [4], [36], [-43], [-59], [19], [-40], [64], [30], [-15], [-32], [-40], [52], [6], [67], [18], [-9], [-24], [-12], [-2], [74], [30], [54], [54], [33], [50], [-42], [-29], [-42], [66], [-32], [-46], [-72], [-27], [-38], [15], [-37], [20], [47], [-38], [50], [6], [46], [38], [-42], [-5], [-24], [-30], [-33], [-29], [-9], [-25], [30], [14], [2], [6], [45], [58], [74], [42], [64], [-54], [-11], [-58], [-52], [18], [46], [22], [30], [32], [54], [24], [-1], [44], [45], [15], [-16], [-4], [60], [53], [-36], [36], [-17], [29], [36], [-2], [-8], [-14], [17], [54], [-72], [27], [33], [-3], [-8], [60], [-52], [6], [-37], [36], [66], [-54], [-11], [-22], [32], [-9], [-60], [-35], [15], [-48], [72], [76], [68], [-60], [-8], [-74], [75], [60], [6], [22], [5], [42], [-3], [-52], [27], [-26], [-66], [-6], [8], [76], [-42], [54], [16], [-66], [20], [68], [78], [27], [-24], [1], [-68], [-60], [-16], [-10], [-36], [65], [-35], [78], [64], [8], [-6], [45], [48], [20], [-9], [3], [-34], [-13], [28], [-40], [26], [41], [-10], [23], [-60], [-48], [34], [-76], [54], [-37], [64], [-70], [-76], [3], [-31], [-60], [-28], [-54], [-90], [-24], [1], [-74], [76], [-60], [17], [80], [100], [-95], [-52], [5], [45], [-28], [21], [-17], [-98], [10], [-72], [31], [-103], [16], [3], [-33], [-20], [-85], [30], [-96], [12], [-50], [48], [-23], [34], [-86], [-14], [38], [7], [93], [22], [91], [42]];
    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_d();".
// 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_d(:prec:=1)
    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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1911_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>,<5,R![1, 1]>],Snew);
    return Vf;
end function;