
// Make newform 1932.2.a.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1932_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_1932_2_a_a();".
// 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_1932_2_a_a();".
// 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_1932_a();"
function MakeCharacter_1932_a()
    N := 1932;
    order := 1;
    char_gens := [967, 1289, 829, 925];
    v := [1, 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_1932_a_Hecke(Kf)
    return MakeCharacter_1932_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], [0], [-1], [-5], [-6], [4], [7], [-1], [2], [10], [-2], [-7], [8], [9], [11], [3], [-11], [8], [0], [8], [10], [-14], [-10], [10], [-19], [-3], [4], [4], [18], [11], [1], [23], [16], [1], [-17], [1], [19], [-3], [-14], [16], [14], [5], [13], [10], [11], [-21], [18], [-22], [-19], [-24], [-4], [11], [-18], [-3], [-21], [-10], [8], [11], [-10], [-4], [32], [0], [15], [21], [-18], [-5], [-22], [18], [-6], [-22], [0], [11], [10], [2], [-26], [-6], [-34], [-11], [22], [-14], [-8], [7], [-41], [40], [-4], [6], [10], [18], [-1], [10], [-28], [28], [-2], [20], [-4], [-3], [26], [-17], [-17], [24], [-6], [8], [9], [36], [-22], [21], [38], [-26], [16], [8], [26], [-18], [20], [-30], [49], [-19], [28], [-28], [-24], [-11], [17], [28], [24], [32], [-5], [-22], [-40], [-23], [-2], [-20], [51], [-4], [-20], [15], [-38], [4], [45], [30], [50], [-2], [-36], [41], [19], [18], [-42], [-28], [37], [-24], [26], [-5], [-30], [48], [-56], [40], [8], [-42], [50], [7], [40], [12], [39], [12], [-42], [-37], [-18], [-41], [-8], [-30], [-15], [11], [34], [27], [8], [10], [54], [-35], [42], [19], [-46], [21], [22], [-35], [29], [39], [-38], [-3], [-4], [-31], [48], [-22], [32], [4], [29], [43], [-36], [-26], [50], [36], [45], [-65], [-52], [-58], [-43], [14], [-53], [16], [-66], [36], [-30], [45], [-9], [-26], [-34], [32], [58], [-11], [42], [16], [18], [-17], [-33], [60], [56], [-23], [-43], [-66], [-40], [24], [-4], [49], [12], [0], [44], [17], [-56], [35], [-46], [36], [-24], [-47], [-52], [48], [47], [-19], [11], [-30], [-14], [14], [61], [8], [-8], [53], [45], [-42], [30], [12], [-35], [-65], [-18], [-64], [-69], [46], [-7], [63], [-65], [7], [14], [8], [76], [48], [-18], [46], [-22], [-64], [2], [72], [-1], [-12], [-24], [9], [-40], [-42], [10], [18], [78], [74], [-21], [28], [-30], [45], [14], [-30], [-32], [50], [-32], [-12], [59], [75], [-2], [-58], [30], [6], [-36], [-18], [-69], [12], [-5], [-73], [-14], [-65], [-66], [3], [-24], [-1], [-81], [63], [-36], [-29], [24], [41], [34], [-3], [45], [-25], [75], [16], [84], [-13], [13], [10], [12], [-76], [-31], [16], [15], [-34], [-6], [-58], [-64], [82], [-67], [15], [2], [-29], [-26], [60], [17], [50], [-62], [22], [11], [-12], [-31], [-34], [29], [-70], [18], [6], [-6], [20], [39], [-32], [9], [56], [-17], [-81], [-70], [-50], [-32], [60], [-66], [13], [-23], [62], [-36], [-91], [-29], [-36], [-16], [-84], [-26], [9], [4], [68], [11], [33], [-32], [76], [-12], [-4], [21], [38], [40], [57], [86], [-49], [-38], [-78], [22], [-40], [64], [86], [34], [39], [78], [44], [42], [24], [-36], [-6], [6], [-9], [-20], [54], [-14], [78], [-28], [0], [-84], [22], [-81], [-46], [-68], [16], [45], [-47], [-46], [42], [-37]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1932_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1932_2_a_a();".
// 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_1932_2_a_a(:prec:=1)
    chi := MakeCharacter_1932_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_1932_2_a_a();".
// 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_1932_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1932_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<11,R![5, 1]>],Snew);
    return Vf;
end function;