
// Make newform 1911.2.a.b 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_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_1911_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_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], [-4], [0], [-5], [1], [-3], [5], [6], [7], [0], [0], [-8], [2], [-9], [9], [9], [-1], [7], [-3], [6], [-10], [0], [8], [-18], [-2], [-14], [-8], [0], [-11], [18], [2], [0], [12], [-18], [-1], [-7], [1], [-7], [-11], [-10], [-1], [4], [-4], [10], [-6], [-14], [-7], [-12], [-2], [9], [-21], [16], [14], [22], [16], [9], [5], [31], [-16], [14], [10], [17], [0], [-2], [-6], [20], [7], [-28], [2], [14], [32], [-18], [-25], [-12], [-24], [9], [6], [6], [-32], [6], [-22], [0], [-37], [18], [-24], [-36], [-38], [-8], [40], [18], [7], [-29], [2], [-32], [-24], [40], [-42], [38], [-4], [22], [-14], [-28], [-11], [-16], [14], [29], [36], [-12], [-9], [-14], [-8], [-30], [-28], [-16], [-30], [37], [22], [18], [-12], [-40], [-2], [39], [24], [-17], [-18], [-42], [-30], [-8], [-42], [-36], [-9], [-32], [17], [-48], [-14], [-14], [11], [-22], [-3], [-44], [32], [36], [-3], [-11], [-25], [-26], [-1], [-8], [36], [-32], [6], [32], [46], [2], [42], [-46], [-26], [33], [16], [11], [-43], [-47], [0], [-6], [-15], [8], [-49], [-56], [37], [51], [12], [42], [-52], [16], [25], [-53], [-44], [0], [-31], [65], [30], [41], [-8], [3], [10], [1], [-28], [-8], [5], [-61], [33], [50], [42], [-38], [39], [-28], [-18], [54], [6], [-4], [-32], [-60], [14], [-44], [-14], [63], [-18], [6], [-22], [21], [51], [40], [47], [40], [-22], [-40], [-31], [49], [-18], [-31], [44], [-46], [56], [-26], [-37], [-22], [-16], [10], [-51], [49], [50], [-19], [-17], [18], [-12], [14], [26], [-18], [22], [-51], [-12], [12], [10], [-24], [-22], [53], [1], [19], [-36], [8], [0], [-59], [-43], [-67], [-4], [23], [51], [39], [-50], [26], [2], [10], [-2], [-50], [-26], [72], [-70], [-20], [79], [62], [41], [44], [26], [50], [55], [-53], [-12], [46], [28], [22], [48], [-38], [-58], [-17], [-36], [-77], [30], [73], [-69], [-47], [-52], [42], [21], [10], [-1], [-76], [7], [82], [28], [15], [-24], [88], [-44], [60], [-36], [-18], [-45], [-47], [-59], [66], [50], [66], [-78], [-7], [22], [-12], [87], [26], [-9], [-80], [-20], [-69], [5], [30], [-43], [4], [-59], [26], [-69], [-56], [42], [-44], [63], [67], [-49], [62], [-66], [-80], [-46], [22], [53], [6], [52], [-16], [-32], [29], [-41], [51], [-74], [-16], [0], [-32], [24], [67], [-50], [-9], [-87], [29], [-21], [24], [-91], [-12], [47], [-38], [73], [76], [19], [39], [-24], [24], [-87], [-54], [-68], [94], [29], [-68], [-20], [-30], [57], [94], [90], [-47], [-64], [9], [-20], [65], [17], [17], [66], [-68], [24], [84], [28], [17], [-5], [5], [9], [36], [-18], [-14], [-58], [-35], [72], [-60], [68], [42], [92], [-59], [57], [-41], [62], [86], [52], [81], [-105], [48], [-74], [-72], [24], [30], [-28], [8], [46], [88], [0], [-56], [-90], [-12], [-66]];
    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_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_1911_2_a_b(: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_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_1911_2_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1911_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 1]>,<5,R![4, 1]>],Snew);
    return Vf;
end function;