
// Make newform 1932.2.a.f in Magma, downloaded from the LMFDB on 25 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_f();".
// 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_f();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_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, 0], [1, 0], [-2, -1], [1, 0], [-1, 0], [-3, 5], [-5, 0], [3, -4], [1, 0], [-3, -2], [1, -6], [-5, 4], [-9, 2], [-5, 7], [-6, 6], [2, -1], [-2, -1], [7, -9], [4, -7], [7, -7], [-7, 4], [-1, -6], [-7, 10], [-15, -1], [-9, -2], [-4, -1], [-4, 4], [-13, -1], [10, -17], [8, -3], [3, 1], [7, -10], [-11, 4], [12, -7], [-10, 18], [2, 2], [-8, 14], [-6, -5], [13, -10], [-7, 10], [-14, 15], [3, -2], [-6, 14], [12, 6], [21, 1], [-14, 11], [15, 2], [-4, 9], [-12, -3], [10, -11], [4, 9], [24, -7], [-3, -14], [20, -10], [-10, 6], [-11, -10], [15, 3], [-13, 4], [23, 5], [-8, 10], [24, -13], [-4, 4], [-13, 26], [-7, -5], [-20, 12], [28, -1], [-14, -12], [21, -21], [11, -28], [24, -13], [7, -14], [-2, -9], [-3, -15], [7, 16], [8, -16], [-13, -2], [-9, 18], [14, -10], [9, -6], [9, 10], [-8, 3], [17, 13], [-3, 13], [4, -6], [-19, -6], [4, -8], [-24, 3], [18, -15], [-28, 15], [29, -4], [-1, 22], [1, -16], [-9, 32], [-3, 5], [0, -13], [-8, -7], [10, -2], [-14, 28], [-2, -4], [-2, -2], [8, -25], [-8, -10], [23, 9], [-16, -16], [5, 10], [14, -12], [-41, -1], [20, -34], [13, -11], [-38, 5], [-21, 41], [-5, 26], [-9, -13], [-27, 29], [7, -4], [-15, -1], [-19, 5], [24, -5], [20, 9], [-1, 0], [-29, -6], [17, 8], [-15, 9], [-3, -8], [-23, 23], [-34, 5], [-23, 31], [31, -32], [21, -36], [12, -6], [-17, -2], [2, 3], [-34, 7], [-3, 12], [-20, 8], [-36, 14], [-11, 6], [-6, 19], [-2, 26], [49, -1], [-15, -20], [30, -14], [4, -11], [36, 11], [-1, -2], [17, -15], [4, -30], [0, 14], [-2, 16], [8, -38], [-12, -28], [-40, 18], [15, 7], [-39, 15], [-2, -29], [-6, 30], [19, 0], [18, 13], [-13, 0], [28, -24], [-30, 20], [-33, 35], [-34, -8], [-15, 19], [29, 19], [-1, 6], [-35, 15], [-21, 2], [6, 21], [-5, 27], [3, -31], [-50, 8], [-35, 9], [-15, 0], [12, -32], [21, -10], [-35, 3], [-20, 15], [-18, 9], [-2, -23], [-28, 15], [13, -31], [-40, 21], [41, 13], [9, 20], [35, -31], [6, -16], [-33, -10], [-40, 21], [11, -14], [-12, 3], [36, -39], [16, 18], [-47, -2], [21, 17], [-3, 3], [-25, 49], [8, -18], [-2, -32], [12, -45], [18, 24], [4, -8], [24, 13], [-1, 27], [1, 24], [30, 20], [-47, 26], [24, 9], [0, -23], [-29, -20], [-34, 2], [2, 3], [-11, -26], [-44, 36], [-29, 33], [-14, 37], [-37, 14], [-41, 25], [5, 2], [31, -44], [-3, -43], [26, 28], [-5, 39], [-56, 20], [49, 0], [2, 29], [-29, 46], [36, -16], [-7, -15], [-27, -4], [61, -4], [43, -21], [12, -7], [48, -32], [25, 3], [-23, 11], [2, 26], [9, 24], [-11, 4], [19, 6], [-37, 4], [-20, -11], [-12, -18], [29, -14], [-35, -2], [13, 19], [-16, -12], [36, -64], [-23, 36], [3, 2], [55, 4], [70, 0], [-35, -16], [49, 8], [-63, 8], [40, -42], [-63, 12], [-47, 40], [45, 19], [37, -30], [-13, 17], [18, 12], [-40, 3], [-13, 32], [-11, 31], [69, -2], [-6, -36], [-63, 6], [25, -6], [-4, -3], [39, 6], [17, -24], [-15, 1], [-14, -26], [7, 34], [-22, 16], [-21, 12], [45, 14], [-29, -16], [31, 10], [58, -14], [21, 27], [23, -10], [-35, 6], [6, -25], [51, 0], [15, -52], [-34, -8], [-19, 15], [-56, 12], [-7, -7], [49, -15], [-41, -13], [3, -52], [-24, 12], [25, -10], [-44, -12], [23, -5], [51, -12], [-17, -38], [-41, 33], [-42, -4], [-7, -46], [4, -5], [4, 12], [11, -26], [-20, -39], [21, -52], [8, -34], [-35, 31], [-3, 0], [47, -32], [-16, 17], [11, 0], [1, -18], [-8, 16], [5, -12], [-65, -4], [-5, -52], [-18, -30], [-14, -20], [-11, -33], [-18, -5], [33, 0], [-35, 22], [-22, 51], [-5, 22], [-2, 33], [66, -6], [-44, 46], [16, -56], [21, -32], [63, -21], [-52, 51], [10, 38], [14, 48], [-52, 46], [-2, 22], [44, -11], [-36, 5], [13, -4], [-54, 4], [21, 17], [-59, 20], [18, -44], [-57, -1], [4, -35], [-6, 25], [-82, 11], [61, 4], [21, 19], [-27, 40], [-63, -8], [46, -81], [-23, 46], [44, -16], [-32, 58], [-41, 20], [-13, 18], [-21, -4], [45, 10], [23, -14], [-27, -40], [76, 0], [42, -26], [24, 12], [29, 3], [-6, -34], [33, -69], [31, -27], [39, 18], [28, 32], [-20, -30], [-20, -24], [37, 32], [-34, -35], [-28, 51], [6, -54], [58, -24], [71, -10], [-59, 32], [-29, -37], [26, -54], [11, -25], [-18, -23], [23, 17], [-25, 25], [-26, 8], [-29, 32], [48, 10], [55, 18], [-14, -29], [-62, 36], [-46, -14], [47, -49], [-18, -29], [47, -12], [11, -8], [15, -35], [55, -32], [37, 10], [27, -25], [16, -10], [-29, 41], [-29, 25], [3, 15], [-12, 52], [-40, 50], [52, -40], [18, -43], [41, 21], [6, 22], [28, -8], [63, -7], [-59, 25], [38, -20], [-27, 2], [-19, 6], [39, 6], [-6, 34], [17, 4], [53, -66], [32, -43], [1, -45], [-37, -1], [-14, 14], [-67, -13], [-32, 42], [-20, 49], [61, -45]];
    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_f();".
// 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_f(:prec:=2)
    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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1932_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![5, 5, 1]>,<11,R![1, 1]>],Snew);
    return Vf;
end function;